Skip to content

Commit

Permalink
refactor: remove application name property (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
nscuro authored Sep 27, 2021
1 parent 375e844 commit d54784c
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 33 deletions.
3 changes: 0 additions & 3 deletions e2e/testdata/snapshots/TestAppCmdSimple
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
<name>testmod-simple</name>
<version>v0.0.0-20210716183230-c7ea7c975ab8</version>
<purl>pkg:golang/[email protected]</purl>
<properties>
<property name="cdx:gomod:application:name">001</property>
</properties>
</component>
</metadata>
<components>
Expand Down
3 changes: 0 additions & 3 deletions e2e/testdata/snapshots/TestAppCmdSimpleMultiCommandPURL
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
<name>testmod-simple</name>
<version>v0.0.0-20210901192510-dc2d14d2351d</version>
<purl>pkg:golang/[email protected]#cmd/purl</purl>
<properties>
<property name="cdx:gomod:application:name">purl</property>
</properties>
</component>
</metadata>
<components>
Expand Down
3 changes: 0 additions & 3 deletions e2e/testdata/snapshots/TestAppCmdSimpleMultiCommandUUID
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
<name>testmod-simple</name>
<version>v0.0.0-20210901192510-dc2d14d2351d</version>
<purl>pkg:golang/[email protected]#cmd/uuid</purl>
<properties>
<property name="cdx:gomod:application:name">uuid</property>
</properties>
</component>
</metadata>
<components>
Expand Down
3 changes: 0 additions & 3 deletions e2e/testdata/snapshots/TestAppCmdSimpleWithFiles
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
<name>testmod-simple</name>
<version>v0.0.0-20210716183230-c7ea7c975ab8</version>
<purl>pkg:golang/[email protected]</purl>
<properties>
<property name="cdx:gomod:application:name">001</property>
</properties>
<components>
<component type="file">
<name>main.go</name>
Expand Down
3 changes: 0 additions & 3 deletions e2e/testdata/snapshots/TestAppCmdVendored
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
<name>testmod-vendored</name>
<version>v0.0.0-20210716185931-5c9f3d791930</version>
<purl>pkg:golang/[email protected]</purl>
<properties>
<property name="cdx:gomod:application:name">001</property>
</properties>
</component>
</metadata>
<components>
Expand Down
3 changes: 0 additions & 3 deletions e2e/testdata/snapshots/TestAppCmdVendoredWithFiles
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
<name>testmod-vendored</name>
<version>v0.0.0-20210716185931-5c9f3d791930</version>
<purl>pkg:golang/[email protected]</purl>
<properties>
<property name="cdx:gomod:application:name">001</property>
</properties>
<components>
<component type="file">
<name>main.go</name>
Expand Down
15 changes: 0 additions & 15 deletions internal/cli/cmd/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,8 @@ func enrichWithApplicationDetails(bom *cdx.BOM, moduleDir, mainFile string) {
mainFileRel := strings.TrimPrefix(mainFileAbs, moduleDirAbs)
mainFileRel = strings.TrimPrefix(mainFileRel, "/")

// The application name is the name of the directory that contains
// the main file. There may be cases where this is not true.
// We could add a -name flag to override this in the future.
var applicationName string

if mainDir, _ := filepath.Split(mainFileRel); mainDir != "" {
mainDir = strings.TrimSuffix(mainDir, "/")
applicationName = filepath.Base(mainDir)

oldPURL := bom.Metadata.Component.PackageURL
newPURL := oldPURL + "#" + mainDir
Expand All @@ -286,14 +280,5 @@ func enrichWithApplicationDetails(bom *cdx.BOM, moduleDir, mainFile string) {
break
}
}
} else {
applicationName = filepath.Base(moduleDirAbs)
}

applicationNameProperty := sbom.NewProperty("application:name", applicationName)
if bom.Metadata.Component.Properties == nil {
bom.Metadata.Component.Properties = &[]cdx.Property{applicationNameProperty}
} else {
*bom.Metadata.Component.Properties = append([]cdx.Property{applicationNameProperty}, *bom.Metadata.Component.Properties...)
}
}

0 comments on commit d54784c

Please sign in to comment.