-
Notifications
You must be signed in to change notification settings - Fork 556
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
Add --platform flag to cosign sbom download #1975
Changes from all commits
5e2ef3c
8b01b2a
9e71e2a
692f393
4049a33
67df61c
f0afd0d
b2f9054
342c3ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Copyright 2022 The Sigstore Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package options | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
// DownloadOptions is the struct for control | ||
type SBOMDownloadOptions struct { | ||
Platform string // Platform to download sboms | ||
} | ||
|
||
var _ Interface = (*SBOMDownloadOptions)(nil) | ||
|
||
// AddFlags implements Interface | ||
func (o *SBOMDownloadOptions) AddFlags(cmd *cobra.Command) { | ||
cmd.Flags().StringVar(&o.Platform, "platform", "", | ||
"download SBOM for a specific platform image") | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -934,7 +934,12 @@ func TestAttachSBOM(t *testing.T) { | |
defer cleanup() | ||
|
||
out := bytes.Buffer{} | ||
_, err := download.SBOMCmd(ctx, options.RegistryOptions{}, img.Name(), &out) | ||
|
||
_, errPl := download.SBOMCmd(ctx, options.RegistryOptions{}, options.SBOMDownloadOptions{Platform: "darwin/amd64"}, img.Name(), &out) | ||
if errPl == nil { | ||
t.Fatalf("Expected error when passing Platform to single arch image") | ||
} | ||
_, err := download.SBOMCmd(ctx, options.RegistryOptions{}, options.SBOMDownloadOptions{}, img.Name(), &out) | ||
if err == nil { | ||
t.Fatal("Expected error") | ||
} | ||
|
@@ -944,7 +949,7 @@ func TestAttachSBOM(t *testing.T) { | |
// Upload it! | ||
must(attach.SBOMCmd(ctx, options.RegistryOptions{}, "./testdata/bom-go-mod.spdx", "spdx", imgName), t) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should attach also take a platform? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I'll add |
||
|
||
sboms, err := download.SBOMCmd(ctx, options.RegistryOptions{}, imgName, &out) | ||
sboms, err := download.SBOMCmd(ctx, options.RegistryOptions{}, options.SBOMDownloadOptions{}, imgName, &out) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
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.
(not blocking) It looks like the
[]string
return value is only ever read in test/e2e_test.go, and never in the actual CLI command. Is that right?Maybe we should just have this return
error
alone, and refactor tests to not rely on the[]string
return value.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.
Yes, I agree. I think the command was meant to return more than one sbom but it is short-circuited to spit out the one sbom. We should discuss if it will be returning more than one SBOM and decide how to change this. I think the logic to download the SBOMs (and the rest) should me moved away from the CLI to a more general package.