-
Notifications
You must be signed in to change notification settings - Fork 594
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
Include purl info in the event #5092
Conversation
/it |
1 similar comment
/it |
cmd/mavenBuild.go
Outdated
func getPurlForThePomAndDeleteIndividualBom(pomFilePath string) string { | ||
bomPath := filepath.Join(filepath.Dir(pomFilePath) + "/target/" + mvnBomFilename + ".xml") | ||
if exists, _ := piperutils.FileExists(bomPath); exists { | ||
bom, err := piperutils.GetBom(bomPath) | ||
if err != nil { | ||
log.Entry().Warnf("failed to get bom file %s: %v", bomPath, err) | ||
return "" | ||
} | ||
|
||
log.Entry().Debugf("Found purl: %s for the bomPath: %s", bom.Metadata.Component.Purl, bomPath) | ||
purl := bom.Metadata.Component.Purl | ||
|
||
// Check if the BOM is an aggregated BOM | ||
if !isAggregatedBOM(bom) { | ||
// Delete the individual BOM file | ||
err = os.Remove(bomPath) | ||
if err != nil { | ||
log.Entry().Warnf("failed to delete bom file %s: %v", bomPath, err) | ||
} | ||
} | ||
|
||
return purl | ||
} | ||
log.Entry().Debugf("bom file doesn't exist and hence no pURL info: %v", bomPath) | ||
return "" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code could be rewritten in a more 'Go way'.
func getPurlForThePomAndDeleteIndividualBom(pomFilePath string) string {
bomPath := filepath.Join(filepath.Dir(pomFilePath), "target", mvnBomFilename+".xml")
exists, _ := piperutils.FileExists(bomPath)
if !exists {
log.Entry().Debugf("bom file doesn't exist and hence no pURL info: %v", bomPath)
return ""
}
bom, err := piperutils.GetBom(bomPath)
if err != nil {
log.Entry().Warnf("failed to get bom file %s: %v", bomPath, err)
return ""
}
log.Entry().Debugf("Found purl: %s for the bomPath: %s", bom.Metadata.Component.Purl, bomPath)
purl := bom.Metadata.Component.Purl
if !isAggregatedBOM(bom) {
if err := os.Remove(bomPath); err != nil {
log.Entry().Warnf("failed to delete bom file %s: %v", bomPath, err)
}
}
return purl
}
This will reduce cognitive load by getting rid of nested if-else statements
pkg/npm/publish.go
Outdated
@@ -225,6 +226,20 @@ func (exec *Execute) publish(packageJSON, registry, username, password string, p | |||
return nil | |||
} | |||
|
|||
func getPurl(packageJSON string) string { | |||
expectedBomFilePath := filepath.Join(filepath.Dir(packageJSON) + "/" + npmBomFilename) | |||
if exists, _ := CredentialUtils.FileExists(expectedBomFilePath); exists { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
pkg/piperutils/cyclonedxBom.go
Outdated
return Bom{}, err | ||
} | ||
defer xmlFile.Close() | ||
byteValue, _ := io.ReadAll(xmlFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignoring errors is not recommended
@Googlom I have addressed your comments, please have a look again. Could you please also trigger it test run. Thanks |
Quality Gate passedIssues Measures |
/it-go |
Changes
As part of build coordinates purl information is added by reading the cyclonedx BOM.