mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
33 lines
696 B
Go
33 lines
696 B
Go
package spdxhelpers
|
|
|
|
import (
|
|
"path"
|
|
"strings"
|
|
|
|
"github.com/anchore/syft/syft/source"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func DocumentName(srcMetadata source.Metadata) string {
|
|
switch srcMetadata.Scheme {
|
|
case source.ImageScheme:
|
|
return cleanSPDXName(srcMetadata.ImageMetadata.UserInput)
|
|
case source.DirectoryScheme:
|
|
return cleanSPDXName(srcMetadata.Path)
|
|
}
|
|
|
|
// TODO: is this alright?
|
|
return uuid.Must(uuid.NewRandom()).String()
|
|
}
|
|
|
|
func cleanSPDXName(name string) string {
|
|
// remove # according to specification
|
|
name = strings.ReplaceAll(name, "#", "-")
|
|
|
|
// remove : for url construction
|
|
name = strings.ReplaceAll(name, ":", "-")
|
|
|
|
// clean relative pathing
|
|
return path.Clean(name)
|
|
}
|