Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make element id unique for proper grouping #338

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions pkg/compliance/bsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,50 +362,50 @@ func bsiComponentDepth(doc sbom.Document, component sbom.GetComponent) *db.Recor
if component.GetPrimaryCompInfo().IsPresent() {
result = strings.Join(bsiGetAllPrimaryDepenciesByName, ", ")
score = 10.0
return db.NewRecordStmt(COMP_DEPTH, component.GetName(), result, score, "")
return db.NewRecordStmt(COMP_DEPTH, common.UniqueElementID(component), result, score, "")
}

dependencies = doc.GetRelationships(common.GetID(component.GetSpdxID()))
if dependencies == nil {
if bsiPrimaryDependencies[common.GetID(component.GetSpdxID())] {
return db.NewRecordStmt(COMP_DEPTH, component.GetName(), "included-in", 10.0, "")
return db.NewRecordStmt(COMP_DEPTH, common.UniqueElementID(component), "included-in", 10.0, "")
}
return db.NewRecordStmt(COMP_DEPTH, component.GetName(), "no-relationship", 0.0, "")
return db.NewRecordStmt(COMP_DEPTH, common.UniqueElementID(component), "no-relationship", 0.0, "")
}
allDepByName = common.GetDependenciesByName(dependencies, bsiCompIDWithName)
if bsiPrimaryDependencies[common.GetID(component.GetSpdxID())] {
allDepByName = append([]string{"included-in"}, allDepByName...)
result = strings.Join(allDepByName, ", ")
return db.NewRecordStmt(COMP_DEPTH, component.GetName(), result, 10.0, "")
return db.NewRecordStmt(COMP_DEPTH, common.UniqueElementID(component), result, 10.0, "")
}
result = strings.Join(allDepByName, ", ")
return db.NewRecordStmt(COMP_DEPTH, component.GetName(), result, 10.0, "")
return db.NewRecordStmt(COMP_DEPTH, common.UniqueElementID(component), result, 10.0, "")

} else if doc.Spec().GetSpecType() == "cyclonedx" {
if component.GetPrimaryCompInfo().IsPresent() {
result = strings.Join(bsiGetAllPrimaryDepenciesByName, ", ")
score = 10.0
return db.NewRecordStmt(COMP_DEPTH, component.GetName(), result, score, "")
return db.NewRecordStmt(COMP_DEPTH, common.UniqueElementID(component), result, score, "")
}
id := component.GetID()
dependencies = doc.GetRelationships(id)
if len(dependencies) == 0 {
if bsiPrimaryDependencies[id] {
return db.NewRecordStmt(COMP_DEPTH, component.GetName(), "included-in", 10.0, "")
return db.NewRecordStmt(COMP_DEPTH, common.UniqueElementID(component), "included-in", 10.0, "")
}
return db.NewRecordStmt(COMP_DEPTH, component.GetName(), "no-relationship", 0.0, "")
return db.NewRecordStmt(COMP_DEPTH, common.UniqueElementID(component), "no-relationship", 0.0, "")
}
allDepByName = common.GetDependenciesByName(dependencies, bsiCompIDWithName)
if bsiPrimaryDependencies[id] {
allDepByName = append([]string{"included-in"}, allDepByName...)
result = strings.Join(allDepByName, ", ")
return db.NewRecordStmt(COMP_DEPTH, component.GetName(), result, 10.0, "")
return db.NewRecordStmt(COMP_DEPTH, common.UniqueElementID(component), result, 10.0, "")
}
result = strings.Join(allDepByName, ", ")
return db.NewRecordStmt(COMP_DEPTH, component.GetName(), result, 10.0, "")
return db.NewRecordStmt(COMP_DEPTH, common.UniqueElementID(component), result, 10.0, "")
}

return db.NewRecordStmt(COMP_DEPTH, component.GetName(), "no-relationships", 0.0, "")
return db.NewRecordStmt(COMP_DEPTH, common.UniqueElementID(component), "no-relationships", 0.0, "")
}

func bsiComponentLicense(component sbom.GetComponent) *db.Record {
Expand All @@ -414,7 +414,7 @@ func bsiComponentLicense(component sbom.GetComponent) *db.Record {

if len(licenses) == 0 {
// fmt.Printf("component %s : %s has no licenses\n", component.Name(), component.Version())
return db.NewRecordStmt(COMP_LICENSE, component.GetName(), "not-compliant", score, "")
return db.NewRecordStmt(COMP_LICENSE, common.UniqueElementID(component), "not-compliant", score, "")
}

var spdx, aboutcode, custom int
Expand Down Expand Up @@ -442,10 +442,10 @@ func bsiComponentLicense(component sbom.GetComponent) *db.Record {

if total != len(licenses) {
score = 0.0
return db.NewRecordStmt(COMP_LICENSE, component.GetName(), "not-compliant", score, "")
return db.NewRecordStmt(COMP_LICENSE, common.UniqueElementID(component), "not-compliant", score, "")
}

return db.NewRecordStmt(COMP_LICENSE, component.GetName(), "compliant", 10.0, "")
return db.NewRecordStmt(COMP_LICENSE, common.UniqueElementID(component), "compliant", 10.0, "")
}

func bsiComponentSourceHash(component sbom.GetComponent) *db.Record {
Expand All @@ -457,7 +457,7 @@ func bsiComponentSourceHash(component sbom.GetComponent) *db.Record {
score = 10.0
}

return db.NewRecordStmtOptional(COMP_SOURCE_HASH, component.GetName(), result, score)
return db.NewRecordStmtOptional(COMP_SOURCE_HASH, common.UniqueElementID(component), result, score)
}

func bsiComponentOtherUniqIDs(component sbom.GetComponent) *db.Record {
Expand All @@ -470,7 +470,7 @@ func bsiComponentOtherUniqIDs(component sbom.GetComponent) *db.Record {
result = string(purl[0])
score = 10.0

return db.NewRecordStmtOptional(COMP_OTHER_UNIQ_IDS, component.GetName(), result, score)
return db.NewRecordStmtOptional(COMP_OTHER_UNIQ_IDS, common.UniqueElementID(component), result, score)
}

cpes := component.GetCpes()
Expand All @@ -479,29 +479,29 @@ func bsiComponentOtherUniqIDs(component sbom.GetComponent) *db.Record {
result = string(cpes[0])
score = 10.0

return db.NewRecordStmtOptional(COMP_OTHER_UNIQ_IDS, component.GetName(), result, score)
return db.NewRecordStmtOptional(COMP_OTHER_UNIQ_IDS, common.UniqueElementID(component), result, score)
}

return db.NewRecordStmtOptional(COMP_OTHER_UNIQ_IDS, component.GetName(), "", 0.0)
return db.NewRecordStmtOptional(COMP_OTHER_UNIQ_IDS, common.UniqueElementID(component), "", 0.0)
}

func bsiComponentDownloadURL(component sbom.GetComponent) *db.Record {
result := component.GetDownloadLocationURL()

if result != "" {
return db.NewRecordStmtOptional(COMP_DOWNLOAD_URL, component.GetName(), result, 10.0)
return db.NewRecordStmtOptional(COMP_DOWNLOAD_URL, common.UniqueElementID(component), result, 10.0)
}
return db.NewRecordStmtOptional(COMP_DOWNLOAD_URL, component.GetName(), "", 0.0)
return db.NewRecordStmtOptional(COMP_DOWNLOAD_URL, common.UniqueElementID(component), "", 0.0)
}

func bsiComponentSourceCodeURL(component sbom.GetComponent) *db.Record {
result := component.SourceCodeURL()

if result != "" {
return db.NewRecordStmtOptional(COMP_SOURCE_CODE_URL, component.GetName(), result, 10.0)
return db.NewRecordStmtOptional(COMP_SOURCE_CODE_URL, common.UniqueElementID(component), result, 10.0)
}

return db.NewRecordStmtOptional(COMP_SOURCE_CODE_URL, component.GetName(), "", 0.0)
return db.NewRecordStmtOptional(COMP_SOURCE_CODE_URL, common.UniqueElementID(component), "", 0.0)
}

func bsiComponentHash(component sbom.GetComponent) *db.Record {
Expand All @@ -519,27 +519,27 @@ func bsiComponentHash(component sbom.GetComponent) *db.Record {
}
}

return db.NewRecordStmt(COMP_HASH, component.GetName(), result, score, "")
return db.NewRecordStmt(COMP_HASH, common.UniqueElementID(component), result, score, "")
}

func bsiComponentVersion(component sbom.GetComponent) *db.Record {
result := component.GetVersion()

if result != "" {
return db.NewRecordStmt(COMP_VERSION, component.GetName(), result, 10.0, "")
return db.NewRecordStmt(COMP_VERSION, common.UniqueElementID(component), result, 10.0, "")
}

return db.NewRecordStmt(COMP_VERSION, component.GetName(), "", 0.0, "")
return db.NewRecordStmt(COMP_VERSION, common.UniqueElementID(component), "", 0.0, "")
}

func bsiComponentName(component sbom.GetComponent) *db.Record {
result := component.GetName()

if result != "" {
return db.NewRecordStmt(COMP_NAME, component.GetName(), result, 10.0, "")
return db.NewRecordStmt(COMP_NAME, common.UniqueElementID(component), result, 10.0, "")
}

return db.NewRecordStmt(COMP_NAME, component.GetName(), "", 0.0, "")
return db.NewRecordStmt(COMP_NAME, common.UniqueElementID(component), "", 0.0, "")
}

func bsiComponentCreator(component sbom.GetComponent) *db.Record {
Expand All @@ -554,7 +554,7 @@ func bsiComponentCreator(component sbom.GetComponent) *db.Record {
}

if result != "" {
return db.NewRecordStmt(COMP_CREATOR, component.GetName(), result, score, "")
return db.NewRecordStmt(COMP_CREATOR, common.UniqueElementID(component), result, score, "")
}

if supplier.GetURL() != "" {
Expand All @@ -563,7 +563,7 @@ func bsiComponentCreator(component sbom.GetComponent) *db.Record {
}

if result != "" {
return db.NewRecordStmt(COMP_CREATOR, component.GetName(), result, score, "")
return db.NewRecordStmt(COMP_CREATOR, common.UniqueElementID(component), result, score, "")
}

if supplier.GetContacts() != nil {
Expand All @@ -576,7 +576,7 @@ func bsiComponentCreator(component sbom.GetComponent) *db.Record {
}

if result != "" {
return db.NewRecordStmt(COMP_CREATOR, component.GetName(), result, score, "")
return db.NewRecordStmt(COMP_CREATOR, common.UniqueElementID(component), result, score, "")
}
}
}
Expand All @@ -590,7 +590,7 @@ func bsiComponentCreator(component sbom.GetComponent) *db.Record {
}

if result != "" {
return db.NewRecordStmt(COMP_CREATOR, component.GetName(), result, score, "")
return db.NewRecordStmt(COMP_CREATOR, common.UniqueElementID(component), result, score, "")
}

if manufacturer.GetURL() != "" {
Expand All @@ -599,7 +599,7 @@ func bsiComponentCreator(component sbom.GetComponent) *db.Record {
}

if result != "" {
return db.NewRecordStmt(COMP_CREATOR, component.GetName(), result, score, "")
return db.NewRecordStmt(COMP_CREATOR, common.UniqueElementID(component), result, score, "")
}

if manufacturer.GetContacts() != nil {
Expand All @@ -612,10 +612,10 @@ func bsiComponentCreator(component sbom.GetComponent) *db.Record {
}

if result != "" {
return db.NewRecordStmt(COMP_CREATOR, component.GetName(), result, score, "")
return db.NewRecordStmt(COMP_CREATOR, common.UniqueElementID(component), result, score, "")
}
}
}

return db.NewRecordStmt(COMP_CREATOR, component.GetName(), "", 0.0, "")
return db.NewRecordStmt(COMP_CREATOR, common.UniqueElementID(component), "", 0.0, "")
}
4 changes: 4 additions & 0 deletions pkg/compliance/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,7 @@ func GetDependenciesByName(dependencies []string, compIDWithName map[string]stri
func GetID(componentID string) string {
return "SPDXRef-" + componentID
}

func UniqueElementID(component sbom.GetComponent) string {
return component.GetName() + "-" + component.GetVersion()
}
22 changes: 11 additions & 11 deletions pkg/compliance/fsct/fsct.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func fsctPackageName(component sbom.GetComponent) *db.Record {
score = 10.0
maturity = "Minimum"
}
return db.NewRecordStmt(COMP_NAME, component.GetName(), result, score, maturity)
return db.NewRecordStmt(COMP_NAME, common.UniqueElementID(component), result, score, maturity)
}

func fsctPackageVersion(component sbom.GetComponent) *db.Record {
Expand All @@ -208,7 +208,7 @@ func fsctPackageVersion(component sbom.GetComponent) *db.Record {
maturity = "Minimum"
}

return db.NewRecordStmt(COMP_VERSION, component.GetName(), result, score, maturity)
return db.NewRecordStmt(COMP_VERSION, common.UniqueElementID(component), result, score, maturity)
}

func fsctPackageSupplier(component sbom.GetComponent) *db.Record {
Expand All @@ -230,7 +230,7 @@ func fsctPackageSupplier(component sbom.GetComponent) *db.Record {
maturity = "None"
}

return db.NewRecordStmt(COMP_SUPPLIER, component.GetName(), result, score, maturity)
return db.NewRecordStmt(COMP_SUPPLIER, common.UniqueElementID(component), result, score, maturity)
}

func fsctPackageUniqIDs(component sbom.GetComponent) *db.Record {
Expand Down Expand Up @@ -274,7 +274,7 @@ func fsctPackageUniqIDs(component sbom.GetComponent) *db.Record {
maturity = "Minimum"
result = strings.Join(uniqIDResults, ", ")
}
return db.NewRecordStmt(COMP_UNIQ_ID, component.GetName(), result, score, maturity)
return db.NewRecordStmt(COMP_UNIQ_ID, common.UniqueElementID(component), result, score, maturity)
}

func fsctPackageHash(doc sbom.Document, component sbom.GetComponent) *db.Record {
Expand Down Expand Up @@ -308,7 +308,7 @@ func fsctPackageHash(doc sbom.Document, component sbom.GetComponent) *db.Record
maturity = "None"
}

return db.NewRecordStmt(COMP_CHECKSUM, component.GetName(), result, score, maturity)
return db.NewRecordStmt(COMP_CHECKSUM, common.UniqueElementID(component), result, score, maturity)
}

func IsComponentPartOfPrimaryDependency(id string) bool {
Expand All @@ -329,7 +329,7 @@ func fsctPackageDependencies(doc sbom.Document, component sbom.GetComponent) *db
result = strings.Join(GetAllPrimaryDepenciesByName, ", ")
score = 10.0
maturity = "Minimum"
return db.NewRecordStmt(COMP_RELATIONSHIP, component.GetName(), result, score, maturity)
return db.NewRecordStmt(COMP_RELATIONSHIP, common.UniqueElementID(component), result, score, maturity)
}

// get dependencies for normal component
Expand Down Expand Up @@ -359,7 +359,7 @@ func fsctPackageDependencies(doc sbom.Document, component sbom.GetComponent) *db
result = strings.Join(GetAllPrimaryDepenciesByName, ", ")
score = 10.0
maturity = "Minimum"
return db.NewRecordStmt(COMP_RELATIONSHIP, component.GetName(), result, score, maturity)
return db.NewRecordStmt(COMP_RELATIONSHIP, common.UniqueElementID(component), result, score, maturity)
}

dependencies = doc.GetRelationships(component.GetID())
Expand Down Expand Up @@ -402,15 +402,15 @@ func fsctPackageDependencies(doc sbom.Document, component sbom.GetComponent) *db

}

return db.NewRecordStmt(COMP_RELATIONSHIP, component.GetName(), result, score, maturity)
return db.NewRecordStmt(COMP_RELATIONSHIP, common.UniqueElementID(component), result, score, maturity)
}

func fsctPackageLicense(component sbom.GetComponent) *db.Record {
result, score, maturity := "", 0.0, "None"

licenses := component.Licenses()
if len(licenses) == 0 {
return db.NewRecordStmt(COMP_LICENSE, component.GetName(), result, score, maturity)
return db.NewRecordStmt(COMP_LICENSE, common.UniqueElementID(component), result, score, maturity)
}

hasFullName, hasIdentifier, hasText, hasURL, hasSpdx := false, false, false, false, false
Expand Down Expand Up @@ -451,7 +451,7 @@ func fsctPackageLicense(component sbom.GetComponent) *db.Record {
// Truncate license content to 1-2 lines
_ = truncateContent(licenseContent, 100) // Adjust the length as needed

return db.NewRecordStmt(COMP_LICENSE, component.GetName(), result, score, maturity)
return db.NewRecordStmt(COMP_LICENSE, common.UniqueElementID(component), result, score, maturity)
}

// Helper function to truncate content
Expand All @@ -476,5 +476,5 @@ func fsctPackageCopyright(component sbom.GetComponent) *db.Record {
result = truncateContent(result, 50)
}

return db.NewRecordStmt(COMP_COPYRIGHT, component.GetName(), result, score, maturity)
return db.NewRecordStmt(COMP_COPYRIGHT, common.UniqueElementID(component), result, score, maturity)
}
Loading