github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/internal/task/relationship_tasks.go (about)

     1  package task
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/anchore/syft/internal/relationship"
     7  	"github.com/anchore/syft/internal/sbomsync"
     8  	"github.com/anchore/syft/syft/artifact"
     9  	"github.com/anchore/syft/syft/cataloging"
    10  	"github.com/anchore/syft/syft/file"
    11  	"github.com/anchore/syft/syft/source"
    12  )
    13  
    14  var _ artifact.Identifiable = (*sourceIdentifierAdapter)(nil)
    15  
    16  type sourceIdentifierAdapter struct {
    17  	desc source.Description
    18  }
    19  
    20  func (s sourceIdentifierAdapter) ID() artifact.ID {
    21  	return artifact.ID(s.desc.ID)
    22  }
    23  
    24  func NewRelationshipsTask(cfg cataloging.RelationshipsConfig, src source.Description) Task {
    25  	fn := func(_ context.Context, resolver file.Resolver, builder sbomsync.Builder) error {
    26  		relationship.Finalize(
    27  			resolver,
    28  			builder,
    29  			cfg,
    30  			&sourceIdentifierAdapter{desc: src})
    31  
    32  		return nil
    33  	}
    34  
    35  	return NewTask("relationships-cataloger", fn)
    36  }