Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
- pack download-sbom -> pack sbom download ....
- Add warning message for pack inspect-image <> --bom
- Remove --local flag
- Add -o shorthand for --output-dir flag

Signed-off-by: Anthony Emengo <aemengo@vmware.com>
  • Loading branch information
Anthony Emengo committed Feb 2, 2022
1 parent e638b02 commit 7db1ac5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func NewPackCommand(logger ConfigurableLogger) (*cobra.Command, error) {
rootCmd.AddCommand(commands.InspectImage(logger, imagewriter.NewFactory(), cfg, packClient))
rootCmd.AddCommand(commands.NewStackCommand(logger))
rootCmd.AddCommand(commands.Rebase(logger, cfg, packClient))
rootCmd.AddCommand(commands.DownloadSBOM(logger, packClient))
rootCmd.AddCommand(commands.NewSBOMCommand(logger, cfg, packClient))

rootCmd.AddCommand(commands.InspectBuildpack(logger, cfg, packClient))
rootCmd.AddCommand(commands.InspectBuilder(logger, cfg, packClient, builderwriter.NewFactory()))
Expand Down
17 changes: 5 additions & 12 deletions internal/commands/download_sbom.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package commands

import (
"github.com/pkg/errors"
"github.com/spf13/cobra"

cpkg "github.com/buildpacks/pack/pkg/client"
"github.com/buildpacks/pack/pkg/logging"
)

type DownloadSBOMFlags struct {
Local bool
Remote bool
DestinationDir string
}
Expand All @@ -20,16 +18,12 @@ func DownloadSBOM(
) *cobra.Command {
var flags DownloadSBOMFlags
cmd := &cobra.Command{
Use: "download-sbom <image-name>",
Use: "download <image-name>",
Args: cobra.ExactArgs(1),
Short: "Download SBoM from specified image",
Long: "Download layer containing Structured Bill of Materials (SBoM) from specified image",
Example: "pack download-sbom buildpacksio/pack",
Example: "pack sbom download buildpacksio/pack",
RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
if flags.Local && flags.Remote {
return errors.New("expected either '--local' or '--remote', not both")
}

img := args[0]
options := cpkg.DownloadSBOMOptions{
Daemon: !flags.Remote,
Expand All @@ -39,9 +33,8 @@ func DownloadSBOM(
return client.DownloadSBOM(img, options)
}),
}
AddHelpFlag(cmd, "download-sbom")
cmd.Flags().BoolVar(&flags.Local, "local", false, "Pull SBoM from local daemon (Default)")
cmd.Flags().BoolVar(&flags.Remote, "remote", false, "Pull SBoM from remote registry")
cmd.Flags().StringVar(&flags.DestinationDir, "output-dir", ".", "Path to export SBoM contents.\nIt defaults export to the current working directory.")
AddHelpFlag(cmd, "download")
cmd.Flags().BoolVar(&flags.Remote, "remote", false, "Download SBoM of image in remote registry (without pulling image)")
cmd.Flags().StringVarP(&flags.DestinationDir, "output-dir", "o", ".", "Path to export SBoM contents.\nIt defaults export to the current working directory.")
return cmd
}
9 changes: 0 additions & 9 deletions internal/commands/download_sbom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,6 @@ func testDownloadSBOMCommand(t *testing.T, when spec.G, it spec.S) {
})
})

when("both --local and --remote are specified", func() {
it("returns a user-friendly message", func() {
command.SetArgs([]string{"some/image", "--local", "--remote"})

err := command.Execute()
h.AssertError(t, err, "expected either '--local' or '--remote', not both")
})
})

when("the client returns an error", func() {
it("returns the error", func() {
mockClient.EXPECT().DownloadSBOM("some/image", cpkg.DownloadSBOMOptions{
Expand Down
4 changes: 4 additions & 0 deletions internal/commands/inspect_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func InspectImage(
remote, remoteErr := client.InspectImage(img, false)
local, localErr := client.InspectImage(img, true)

if flags.BOM {
logger.Warn("Using the '--bom' flag with 'pack inspect-image <image-name>' is deprecated. Users are encouraged to use 'pack sbom download <image-name>'.")
}

if err := w.Print(logger, sharedImageInfo, local, remote, localErr, remoteErr); err != nil {
return err
}
Expand Down
20 changes: 20 additions & 0 deletions internal/commands/sbom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package commands

import (
"github.com/spf13/cobra"

"github.com/buildpacks/pack/internal/config"
"github.com/buildpacks/pack/pkg/logging"
)

func NewSBOMCommand(logger logging.Logger, cfg config.Config, client PackClient) *cobra.Command {
cmd := &cobra.Command{
Use: "sbom",
Short: "Interact with SBoM",
RunE: nil,
}

cmd.AddCommand(DownloadSBOM(logger, client))
AddHelpFlag(cmd, "sbom")
return cmd
}

0 comments on commit 7db1ac5

Please sign in to comment.