-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include purl info in the event (#5092)
- Loading branch information
Showing
7 changed files
with
378 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package piperutils | ||
|
||
import ( | ||
"encoding/xml" | ||
"github.com/SAP/jenkins-library/pkg/log" | ||
"io" | ||
"os" | ||
) | ||
|
||
// To serialize the cyclonedx BOM file | ||
type Bom struct { | ||
Metadata Metadata `xml:"metadata"` | ||
} | ||
|
||
type Metadata struct { | ||
Component BomComponent `xml:"component"` | ||
Properties []BomProperty `xml:"properties>property"` | ||
} | ||
|
||
type BomProperty struct { | ||
Name string `xml:"name,attr"` | ||
Value string `xml:"value,attr"` | ||
} | ||
|
||
type BomComponent struct { | ||
Purl string `xml:"purl"` | ||
} | ||
|
||
func GetBom(absoluteBomPath string) (Bom, error) { | ||
xmlFile, err := os.Open(absoluteBomPath) | ||
if err != nil { | ||
log.Entry().Debugf("failed to open bom file %s", absoluteBomPath) | ||
return Bom{}, err | ||
} | ||
defer xmlFile.Close() | ||
byteValue, err := io.ReadAll(xmlFile) | ||
if err != nil { | ||
log.Entry().Debugf("failed to read bom file %s", absoluteBomPath) | ||
return Bom{}, err | ||
} | ||
var bom Bom | ||
err = xml.Unmarshal(byteValue, &bom) | ||
if err != nil { | ||
log.Entry().Debugf("failed to unmarshal bom file %s", absoluteBomPath) | ||
return Bom{}, err | ||
} | ||
return bom, nil | ||
} |
Oops, something went wrong.