converter

package
v0.7.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package converter provides pluggable parsers for vulnerability scanner output.

Each scanner produces JSON in a unique format. Converters normalize this output into a common Vulnerability structure for unified storage and querying.

Supported scanners:

  • grype: Anchore Grype scanner
  • trivy: Aqua Security Trivy scanner
  • snyk: Snyk Container scanner
  • clair: CoreOS Clair scanner
  • osv: Google OSV-Scanner
  • anchore: Anchore Engine (legacy)

The Registry pattern enables auto-detection of scanner format:

registry := converter.DefaultRegistry()
conv, err := registry.Detect(jsonContainer)
if err != nil {
    // unknown format
}
vulns, err := conv.Convert(ctx, jsonContainer)

To add a new scanner, implement the Converter interface:

type Converter interface {
    Name() string
    CanHandle(c *gabs.Container) bool
    Convert(ctx context.Context, c *gabs.Container) ([]*data.Vulnerability, error)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Converter

type Converter interface {
	// Name returns the converter's identifier (e.g., "grype", "trivy").
	Name() string

	// CanHandle returns true if this converter can process the given JSON container.
	CanHandle(c *gabs.Container) bool

	// Convert transforms scanner output into normalized vulnerabilities.
	Convert(ctx context.Context, c *gabs.Container) ([]*data.Vulnerability, error)
}

Converter defines the interface for vulnerability scanner output converters.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages registered converters and provides detection/lookup.

func DefaultRegistry

func DefaultRegistry() *Registry

DefaultRegistry returns a registry with all built-in converters registered.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new converter registry with all available converters.

func (*Registry) All

func (r *Registry) All() []Converter

All returns all registered converters.

func (*Registry) Detect

func (r *Registry) Detect(c *gabs.Container) (Converter, error)

Detect attempts to find a converter that can handle the given JSON container.

func (*Registry) Get

func (r *Registry) Get(name string) (Converter, bool)

Get returns a converter by name, or nil if not found.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns the names of all registered converters.

func (*Registry) Register

func (r *Registry) Register(c Converter)

Register adds a converter to the registry.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL