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

feat: add namespace arg when producing doc #588

Merged
merged 1 commit into from
Jan 26, 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
11 changes: 6 additions & 5 deletions cmd/stacker/bom.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,19 @@ func doBomBuild(ctx *cli.Context) error {
}

func doBomVerify(ctx *cli.Context) error {
if ctx.Args().Len() != 4 {
if ctx.Args().Len() != 5 {
return errors.Errorf("wrong number of args")
}

dest := ctx.Args().Get(0)
name := ctx.Args().Get(1)
author := ctx.Args().Get(2)
org := ctx.Args().Get(3)
namespace := ctx.Args().Get(1)
name := ctx.Args().Get(2)
author := ctx.Args().Get(3)
org := ctx.Args().Get(4)

// first merge all individual sbom artifacts that may have been generated
iDir := types.InternalStackerDir
if err := bom.MergeDocuments(iDir+"/artifacts", name, author, org, dest); err != nil {
if err := bom.MergeDocuments(iDir+"/artifacts", namespace, name, author, org, dest); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,5 @@ require (

replace (
github.com/opencontainers/umoci => github.com/project-stacker/umoci v0.0.0-20240122204034-cb3aca58b2ec
stackerbuild.io/stacker-bom => github.com/project-stacker/stacker-bom v0.0.6-0.20240118174508-52fb507e9d2e
stackerbuild.io/stacker-bom => github.com/project-stacker/stacker-bom v0.0.6-0.20240125170016-363073df9862
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,8 @@ github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndr
github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=
github.com/proglottis/gpgme v0.1.3 h1:Crxx0oz4LKB3QXc5Ea0J19K/3ICfy3ftr5exgUK1AU0=
github.com/proglottis/gpgme v0.1.3/go.mod h1:fPbW/EZ0LvwQtH8Hy7eixhp1eF3G39dtx7GUN+0Gmy0=
github.com/project-stacker/stacker-bom v0.0.6-0.20240118174508-52fb507e9d2e h1:BYJ7UPVH+4YErCyfZGdUqMzp2wBeVGq26wNuohOEn4E=
github.com/project-stacker/stacker-bom v0.0.6-0.20240118174508-52fb507e9d2e/go.mod h1:iKH3F0e8i3eNB6JbtGKv8qpgDSfUDUn+t8KoQ9Wf6pE=
github.com/project-stacker/stacker-bom v0.0.6-0.20240125170016-363073df9862 h1:SFnn7tNrursXkAfIltfETcwVbX7mtM6qxnehoEbfgZ4=
github.com/project-stacker/stacker-bom v0.0.6-0.20240125170016-363073df9862/go.mod h1:iKH3F0e8i3eNB6JbtGKv8qpgDSfUDUn+t8KoQ9Wf6pE=
github.com/project-stacker/umoci v0.0.0-20240122204034-cb3aca58b2ec h1:59Z20xRtwyzB7D/CRsueFkrIT1vJwWVtMe0riQb3kiE=
github.com/project-stacker/umoci v0.0.0-20240122204034-cb3aca58b2ec/go.mod h1:XUXUpCpA/Y8aJWezK1i8o4WDR0Y/vhMcWg+FUNQkKMQ=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
Expand Down
1 change: 1 addition & 0 deletions pkg/stacker/bom.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func VerifyLayerArtifacts(sc types.StackerConfig, storage types.Storage, l types

cmd = append(cmd, "bom", "verify",
fmt.Sprintf(types.InternalStackerDir+"/artifacts/%s.json", tag),
l.Bom.Namespace,
tag, l.Annotations[types.AuthorAnnotation], l.Annotations[types.OrgAnnotation])

err = c.Execute(cmd, os.Stdin)
Expand Down
9 changes: 7 additions & 2 deletions pkg/types/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@
}

type Bom struct {
Generate bool `yaml:"generate" json:"generate"`
Packages []Package `yaml:"packages" json:"packages,omitempty"`
Generate bool `yaml:"generate" json:"generate"`
Namespace string `yaml:"namespace" json:"namespace"`
Packages []Package `yaml:"packages" json:"packages,omitempty"`
}

func getStringOrStringSlice(data interface{}, xform func(string) ([]string, error)) ([]string, error) {
Expand Down Expand Up @@ -332,6 +333,10 @@
}

if layer.Bom != nil && layer.Bom.Generate {
if layer.Bom.Namespace == "" {
return nil, errors.Errorf("for bom generation, namespace must be set")
}

Check warning on line 338 in pkg/types/layer.go

View check run for this annotation

Codecov / codecov/patch

pkg/types/layer.go#L337-L338

Added lines #L337 - L338 were not covered by tests

if layer.Annotations == nil {
return nil, errors.Errorf("for bom generation %s, %s and %s annotations must be set",
AuthorAnnotation, OrgAnnotation, LicenseAnnotation)
Expand Down
4 changes: 4 additions & 0 deletions test/bom.bats
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bom-parent:
url: $CENTOS_OCI
bom:
generate: true
namespace: "https://test.io/artifacts"
packages:
- name: pkg1
version: 1.0.0
Expand Down Expand Up @@ -75,6 +76,7 @@ bom-parent:
url: $CENTOS_OCI
bom:
generate: true
namespace: "https://test.io/artifacts"
packages:
- name: pkg1
version: 1.0.0
Expand Down Expand Up @@ -115,6 +117,7 @@ bom-child:
tag: bom-parent
bom:
generate: true
namespace: "https://test.io/artifacts"
packages:
- name: pkg3
version: 1.0.0
Expand Down Expand Up @@ -163,6 +166,7 @@ bom-alpine:
url: $ALPINE_OCI
bom:
generate: true
namespace: "https://test.io/artifacts"
packages:
- name: pkg1
version: 1.0.0
Expand Down
Loading