Skip to content

📈 GetAuditInfo

Runs a security audit and returns the structured detailed result *AuditInfoResult. Equivalent to running composer audit --format=json and parsing it into a more fine-grained advisory structure.

When to use

Use it when you need a more structured and standardized audit result than AuditWithJSON. This method tolerates Composer's non-zero exit code when vulnerabilities are found: as long as standard output is non-empty, it still attempts to parse the JSON within.

Signature

go
func (c *Composer) GetAuditInfo() (*AuditInfoResult, error)

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
First return value*AuditInfoResultStructured audit result containing the advisory list and counts
Second return valueerrorReturned when execution or JSON parsing fails

AuditInfoResult fields:

FieldTypeDescription
Advisories[]AuditAdvisoryInfoList of security advisory details
CountintNumber of advisories (auto-filled during parsing)

Key fields of AuditAdvisoryInfo: PackageName, Version, Title, Severity (critical/high/medium/low), CVE, Link, ReportedAt.

Example

go
package main

import (
	"fmt"
	"log"

	"github.com/scagogogo/composer-skills/pkg/composer"
)

func main() {
	comp, err := composer.NewComposer("")
	if err != nil {
		log.Fatalf("initialization failed: %v", err)
	}

	result, err := comp.GetAuditInfo()
	if err != nil {
		log.Fatalf("security audit failed: %v", err)
	}

	fmt.Printf("%d advisories in total\n", result.Count)
	for _, adv := range result.Advisories {
		fmt.Printf("Vulnerability: %s (%s) - %s\n", adv.PackageName, adv.Severity, adv.Title)
		fmt.Printf("Details: %s\n", adv.Link)
	}
}

Advanced

  • Structured version with custom options: GetAuditInfoWithOptions(options map[string]string), which can append parameters such as no-dev and locked on top of the JSON output.
  • Manually parse any audit JSON output: use the package-level function ParseAuditInfoResult(output string).
  • Related methods: AuditWithJSON, HasVulnerabilities, GetHighSeverityVulnerabilities.

Released under the MIT License