Skip to content

Commit 3a33496

Browse files
committed
refactor: rename ExtractArtifacts to ExtractArtifactIds for precision
The flag gates artifact ID extraction specifically (the name/purl used to identify internal modules), not general artifact data. The previous name caused confusion with CI/CD artifact concepts.
1 parent f0a7697 commit 3a33496

6 files changed

Lines changed: 33 additions & 30 deletions

File tree

pkg/extractor/extract.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ var ErrExtractorNotFound = errors.New("could not determine extractor")
149149
// ScanContext is used to pass context to extractors
150150
// It is passed to extractors to allow them to access the root directory of the scan as well as the reporter
151151
type ScanContext struct {
152-
EnabledParsers map[string]bool
153-
RootDir string
154-
Reporter reporter.Reporter
155-
ExtractMavenPomArtifactIds bool
152+
EnabledParsers map[string]bool
153+
RootDir string
154+
Reporter reporter.Reporter
155+
ExtractArtifactIds bool
156156
}
157157

158158
func ExtractDeps(f DepFile, context ScanContext) (Lockfile, error) {
@@ -201,7 +201,7 @@ func ExtractDeps(f DepFile, context ScanContext) (Lockfile, error) {
201201
return parsedLockfile, err
202202
}
203203
defer depFile.Close()
204-
if context.ExtractMavenPomArtifactIds {
204+
if context.ExtractArtifactIds {
205205
if e, ok := extractor.(ArtifactExtractor); ok {
206206
artifact, err := e.GetArtifact(depFile, context)
207207
if err == nil {

pkg/extractor/python/parse-pyproject-toml-artifact_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ version = "1.0.0"
3131
}
3232
defer f.Close()
3333

34-
artifact, err := python.PyProjectExtractor.GetArtifact(f, extractor.ScanContext{ExtractArtifacts: true})
34+
artifact, err := python.PyProjectExtractor.GetArtifact(f, extractor.ScanContext{ExtractArtifactIds: true})
3535
if err != nil {
3636
t.Fatalf("unexpected error: %v", err)
3737
}
@@ -69,7 +69,7 @@ version = "1.0.0"
6969
}
7070
defer f.Close()
7171

72-
artifact, err := python.PyProjectExtractor.GetArtifact(f, extractor.ScanContext{ExtractArtifacts: true})
72+
artifact, err := python.PyProjectExtractor.GetArtifact(f, extractor.ScanContext{ExtractArtifactIds: true})
7373
if err != nil {
7474
t.Fatalf("expected no error, got: %v", err)
7575
}
@@ -78,7 +78,7 @@ version = "1.0.0"
7878
}
7979
}
8080

81-
func TestPyProjectTOMLExtractor_GetArtifact_ExtractArtifactsDisabled(t *testing.T) {
81+
func TestPyProjectTOMLExtractor_GetArtifact_ExtractArtifactIdsDisabled(t *testing.T) {
8282
t.Parallel()
8383

8484
dir := t.TempDir()
@@ -97,13 +97,13 @@ name = "my-lib"
9797
}
9898
defer f.Close()
9999

100-
// ExtractArtifacts is false — should return nil
101-
artifact, err := python.PyProjectExtractor.GetArtifact(f, extractor.ScanContext{ExtractArtifacts: false})
100+
// ExtractArtifactIds is false — should return nil
101+
artifact, err := python.PyProjectExtractor.GetArtifact(f, extractor.ScanContext{ExtractArtifactIds: false})
102102
if err != nil {
103103
t.Fatalf("expected no error, got: %v", err)
104104
}
105105
if artifact != nil {
106-
t.Errorf("expected nil artifact when ExtractArtifacts is false, got %+v", artifact)
106+
t.Errorf("expected nil artifact when ExtractArtifactIds is false, got %+v", artifact)
107107
}
108108
}
109109

@@ -155,7 +155,7 @@ func TestPyProjectTOMLExtractor_GetArtifact_NormalizesName(t *testing.T) {
155155
}
156156
defer f.Close()
157157

158-
artifact, err := python.PyProjectExtractor.GetArtifact(f, extractor.ScanContext{ExtractArtifacts: true})
158+
artifact, err := python.PyProjectExtractor.GetArtifact(f, extractor.ScanContext{ExtractArtifactIds: true})
159159
if err != nil {
160160
t.Fatalf("unexpected error: %v", err)
161161
}

pkg/extractor/python/parse-pyproject-toml.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ func isConcreteVersion(version string) bool {
357357
// own path as Filename so that findArtifact can match packages from sibling
358358
// lockfiles (e.g. requirements.txt) against this module.
359359
func (e PyProjectTOMLExtractor) GetArtifact(f extractor.DepFile, ctx extractor.ScanContext) (*models.ScannedArtifact, error) {
360-
if !ctx.ExtractArtifacts {
360+
if !ctx.ExtractArtifactIds {
361361
return nil, nil
362362
}
363363

pkg/sbomgen/build_files.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func parseArtifactID(purl string) string {
232232
func buildProcessorContext(bom *cyclonedx.BOM) ProcessorContext {
233233
ctx := ProcessorContext{
234234
FileDependencies: make(map[string][]string),
235-
ArtifactIDs: make(map[string]string),
235+
ArtifactIDs: make(map[string]string),
236236
}
237237

238238
for _, comp := range *bom.Components {

pkg/sbomgen/sbomgen.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,21 @@ type Options struct {
3131
// ExcludePaths is a list of glob patterns to exclude from scanning.
3232
ExcludePaths []string
3333

34-
// ExtractMavenPomArtifactIds controls whether Maven pom.xml artifact IDs
35-
// and parent dependency relationships are extracted and included in the SBOM.
34+
// ExtractArtifactIds controls whether build file artifact IDs and dependency
35+
// relationships are extracted and included in the SBOM. When true, extractors
36+
// that implement ArtifactExtractor produce file-type components and dependency
37+
// edges, enabling GetBuildFileTrees dependency and ID resolution.
3638
// Defaults to true in DefaultOptions.
37-
ExtractMavenPomArtifactIds bool
39+
ExtractArtifactIds bool
3840
}
3941

4042
// DefaultOptions returns Options with sensible defaults:
4143
// recursive scanning enabled, no exclusions, and artifact extraction enabled.
4244
func DefaultOptions() Options {
4345
return Options{
44-
Recursive: true,
45-
ExcludePaths: []string{},
46-
ExtractMavenPomArtifactIds: true,
46+
Recursive: true,
47+
ExcludePaths: []string{},
48+
ExtractArtifactIds: true,
4749
}
4850
}
4951

@@ -57,10 +59,10 @@ func GenerateSBOM(dirs []string, opts Options) ([]byte, error) {
5759
}
5860

5961
actions := scanner.ScannerActions{
60-
DirectoryPaths: dirs,
61-
ExcludePaths: opts.ExcludePaths,
62-
Recursive: opts.Recursive,
63-
ExtractMavenPomArtifactIds: opts.ExtractMavenPomArtifactIds,
62+
DirectoryPaths: dirs,
63+
ExcludePaths: opts.ExcludePaths,
64+
Recursive: opts.Recursive,
65+
ExtractArtifactIds: opts.ExtractArtifactIds,
6466
}
6567

6668
r := reporter.NewCycloneDXReporter(&bytes.Buffer{}, &bytes.Buffer{}, reporter.WarnLevel)

pkg/scanner/datadog_sbom_generator.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ type ScannerActions struct {
4848
ManifestParsers bool
4949
DDEnvVars DDEnvVars
5050
ExitOnConfigFailure bool
51-
// ExtractMavenPomArtifactIds controls whether Maven pom.xml artifact IDs
52-
// and parent dependency relationships are extracted and included in the SBOM.
51+
// ExtractArtifactIds controls whether build file artifact IDs and dependency
52+
// relationships are extracted and included in the SBOM. When true, extractors
53+
// that implement ArtifactExtractor produce ScannedArtifact entries.
5354
// When false, ScannedArtifact entries are never produced.
54-
ExtractMavenPomArtifactIds bool
55+
ExtractArtifactIds bool
5556
}
5657

5758
type DDEnvVars struct {
@@ -82,7 +83,7 @@ var ErrAPIFailed = models.ErrAPIFailed
8283
// scanDir walks through the given directory to try to find any relevant files
8384
// These include:
8485
// - Any lockfiles with scanLockfile
85-
func scanDir(r reporter.Reporter, dir string, repoRoot string, recursive bool, useGitIgnore bool, enabledParsers map[string]bool, cliExcludePaths []string, configExcludePaths []string, extractMavenPomArtifactIds bool) ([]extractor.PackageDetails, []models.ScannedArtifact, error) {
86+
func scanDir(r reporter.Reporter, dir string, repoRoot string, recursive bool, useGitIgnore bool, enabledParsers map[string]bool, cliExcludePaths []string, configExcludePaths []string, extractArtifacts bool) ([]extractor.PackageDetails, []models.ScannedArtifact, error) {
8687
scanRoot := dir
8788
// Normalize the scan root once before exclusion matching.
8889
if absPath, err := filepath.Abs(dir); err == nil {
@@ -154,7 +155,7 @@ func scanDir(r reporter.Reporter, dir string, repoRoot string, recursive bool, u
154155
return nil
155156
}
156157

157-
context := extractor.ScanContext{EnabledParsers: enabledParsers, RootDir: dir, Reporter: r, ExtractMavenPomArtifactIds: extractMavenPomArtifactIds}
158+
context := extractor.ScanContext{EnabledParsers: enabledParsers, RootDir: dir, Reporter: r, ExtractArtifactIds: extractArtifacts}
158159
pkgs, artifact, err := scanLockfile(path, context)
159160
if err != nil {
160161
r.Warnf("Attempted to scan lockfile but failed: %s (%v)\n", path, err.Error())
@@ -303,7 +304,7 @@ func DoScan(actions ScannerActions, r reporter.Reporter) (models.VulnerabilityRe
303304
absolutePath = absPath
304305
}
305306
r.Infof("Scanning directory '%s', resolved absolute path '%s'\n", dir, absolutePath)
306-
pkgs, artifacts, err := scanDir(r, dir, repoRoot, actions.Recursive, !actions.NoIgnore, enabledParsers, actions.ExcludePaths, configExcludePaths, actions.ExtractMavenPomArtifactIds)
307+
pkgs, artifacts, err := scanDir(r, dir, repoRoot, actions.Recursive, !actions.NoIgnore, enabledParsers, actions.ExcludePaths, configExcludePaths, actions.ExtractArtifactIds)
307308
if err != nil {
308309
return models.VulnerabilityResults{}, err
309310
}

0 commit comments

Comments
 (0)