mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
* fix spdx namespace and add scheme range assertions Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * validate SPDX document name from source metadata Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * comment why namespace tests only check prefix Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
46 lines
993 B
Go
46 lines
993 B
Go
package spdxhelpers
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"path"
|
|
|
|
"github.com/anchore/syft/internal"
|
|
"github.com/anchore/syft/syft/source"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func DocumentNameAndNamespace(srcMetadata source.Metadata) (string, string, error) {
|
|
name, err := DocumentName(srcMetadata)
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
return name, DocumentNamespace(name, srcMetadata), nil
|
|
}
|
|
|
|
func DocumentNamespace(name string, srcMetadata source.Metadata) string {
|
|
input := "unknown-source-type"
|
|
switch srcMetadata.Scheme {
|
|
case source.ImageScheme:
|
|
input = "image"
|
|
case source.DirectoryScheme:
|
|
input = "dir"
|
|
case source.FileScheme:
|
|
input = "file"
|
|
}
|
|
|
|
uniqueID := uuid.Must(uuid.NewRandom())
|
|
identifier := path.Join(input, uniqueID.String())
|
|
if name != "." {
|
|
identifier = path.Join(input, fmt.Sprintf("%s-%s", name, uniqueID.String()))
|
|
}
|
|
|
|
u := url.URL{
|
|
Scheme: "https",
|
|
Host: "anchore.com",
|
|
Path: path.Join(internal.ApplicationName, identifier),
|
|
}
|
|
|
|
return u.String()
|
|
}
|