Skip to content

Commit

Permalink
Re-expose commands. (sigstore#883)
Browse files Browse the repository at this point in the history
I was trying to pull in the recent upstream updates to a downstream repo that was invoking the CLI via `cli.Sign().Exec(...)` and this regressed in the cobra migration.  In a perfect world, we could pull in the CLI functionality without needing to go through `cobra.Command` to do it, but we're not there yet.  The alternative to `cli.Sign().Exec(...)` is `cli.SignCmd(...)`, which takes 11 arguments and growing each release.  The alternative fo `cli.Attest().Exec(...)` is `cli.AttestCmd(...)` with 9 arguments.  etc, etc, etc...

What's more, the above functions are also colocated with their cobra wrappers so we also can't save on not vendoring cobra yet, so it's a mystery to me why we'd force folks to not use this interface.

Fixes: sigstore#880

Signed-off-by: Matt Moore <[email protected]>
  • Loading branch information
mattmoor authored and developer-guy committed Oct 14, 2021
1 parent 4d4d796 commit 42d4ce7
Show file tree
Hide file tree
Showing 33 changed files with 303 additions and 70 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/verify-docgen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: deps
run: sudo apt-get update && sudo apt-get install -yq libpcsclite-dev
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
Expand Down
4 changes: 2 additions & 2 deletions cmd/cosign/cli/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/sigstore/cosign/cmd/cosign/cli/options"
)

func addAttach(topLevel *cobra.Command) {
func Attach() *cobra.Command {
cmd := &cobra.Command{
Use: "attach",
Short: "Provides utilities for attaching artifacts to other artifacts in a registry",
Expand All @@ -33,7 +33,7 @@ func addAttach(topLevel *cobra.Command) {
attachSBOM(),
)

topLevel.AddCommand(cmd)
return cmd
}

func attachSignature() *cobra.Command {
Expand Down
4 changes: 2 additions & 2 deletions cmd/cosign/cli/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/sigstore/cosign/cmd/cosign/cli/sign"
)

func addAttest(topLevel *cobra.Command) {
func Attest() *cobra.Command {
o := &options.AttestOptions{}

cmd := &cobra.Command{
Expand Down Expand Up @@ -74,5 +74,5 @@ func addAttest(topLevel *cobra.Command) {
},
}
o.AddFlags(cmd)
topLevel.AddCommand(cmd)
return cmd
}
4 changes: 2 additions & 2 deletions cmd/cosign/cli/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
ociremote "github.com/sigstore/cosign/pkg/oci/remote"
)

func addClean(topLevel *cobra.Command) {
func Clean() *cobra.Command {
o := &options.RegistryOptions{}

cmd := &cobra.Command{
Expand All @@ -42,7 +42,7 @@ func addClean(topLevel *cobra.Command) {
}

o.AddFlags(cmd)
topLevel.AddCommand(cmd)
return cmd
}

func CleanCmd(ctx context.Context, regOpts options.RegistryOptions, imageRef string) error {
Expand Down
44 changes: 22 additions & 22 deletions cmd/cosign/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,28 @@ func New() *cobra.Command {
ro.AddFlags(cmd)

// Add sub-commands.
addPublicKey(cmd)
addPolicy(cmd)
addGenerate(cmd)
addSign(cmd)
addSignBlob(cmd)
addGenerateKeyPair(cmd)
addAttest(cmd)
addUpload(cmd)
addDownload(cmd)
addAttach(cmd)
addVerify(cmd)
addVerifyAttestation(cmd)
addVerifyBlob(cmd)
addManifest(cmd)
addDockerfile(cmd)
addCopy(cmd)
addClean(cmd)
addTriangulate(cmd)
addInitialize(cmd)
addPIVTool(cmd)
addVersion(cmd)
addCompletion(cmd)
cmd.AddCommand(Attach())
cmd.AddCommand(Attest())
cmd.AddCommand(Clean())
cmd.AddCommand(Completion())
cmd.AddCommand(Copy())
cmd.AddCommand(Dockerfile())
cmd.AddCommand(Download())
cmd.AddCommand(Generate())
cmd.AddCommand(GenerateKeyPair())
cmd.AddCommand(Initialize())
cmd.AddCommand(Manifest())
cmd.AddCommand(PIVTool())
cmd.AddCommand(Policy())
cmd.AddCommand(PublicKey())
cmd.AddCommand(Sign())
cmd.AddCommand(SignBlob())
cmd.AddCommand(Upload())
cmd.AddCommand(Verify())
cmd.AddCommand(VerifyAttestation())
cmd.AddCommand(VerifyBlob())
cmd.AddCommand(Triangulate())
cmd.AddCommand(Version())

return cmd
}
4 changes: 2 additions & 2 deletions cmd/cosign/cli/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/spf13/cobra"
)

func addCompletion(topLevel *cobra.Command) {
func Completion() *cobra.Command {
completionCmd := &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate completion script",
Expand Down Expand Up @@ -67,5 +67,5 @@ PowerShell:
},
}

topLevel.AddCommand(completionCmd)
return completionCmd
}
4 changes: 2 additions & 2 deletions cmd/cosign/cli/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/sigstore/cosign/cmd/cosign/cli/options"
)

func addCopy(topLevel *cobra.Command) {
func Copy() *cobra.Command {
o := &options.CopyOptions{}

cmd := &cobra.Command{
Expand All @@ -46,5 +46,5 @@ func addCopy(topLevel *cobra.Command) {
}

o.AddFlags(cmd)
topLevel.AddCommand(cmd)
return cmd
}
4 changes: 2 additions & 2 deletions cmd/cosign/cli/dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/sigstore/cosign/cmd/cosign/cli/options"
)

func addDockerfile(topLevel *cobra.Command) {
func Dockerfile() *cobra.Command {
cmd := &cobra.Command{
Use: "dockerfile",
Short: "Provides utilities for discovering images in and performing operations on Dockerfiles",
Expand All @@ -33,7 +33,7 @@ func addDockerfile(topLevel *cobra.Command) {
dockerfileVerify(),
)

topLevel.AddCommand(cmd)
return cmd
}

func dockerfileVerify() *cobra.Command {
Expand Down
4 changes: 2 additions & 2 deletions cmd/cosign/cli/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/sigstore/cosign/cmd/cosign/cli/options"
)

func addDownload(topLevel *cobra.Command) {
func Download() *cobra.Command {
cmd := &cobra.Command{
Use: "download",
Short: "Provides utilities for downloading artifacts and attached artifacts in a registry",
Expand All @@ -33,7 +33,7 @@ func addDownload(topLevel *cobra.Command) {
downloadSBOM(),
)

topLevel.AddCommand(cmd)
return cmd
}

func downloadSignature() *cobra.Command {
Expand Down
4 changes: 2 additions & 2 deletions cmd/cosign/cli/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/sigstore/cosign/cmd/cosign/cli/options"
)

func addGenerate(topLevel *cobra.Command) {
func Generate() *cobra.Command {
o := &options.GenerateOptions{}

cmd := &cobra.Command{
Expand Down Expand Up @@ -53,5 +53,5 @@ to sign payloads with your own tooling or algorithms.`,
}

o.AddFlags(cmd)
topLevel.AddCommand(cmd)
return cmd
}
4 changes: 2 additions & 2 deletions cmd/cosign/cli/generate_key_pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/sigstore/cosign/cmd/cosign/cli/options"
)

func addGenerateKeyPair(topLevel *cobra.Command) {
func GenerateKeyPair() *cobra.Command {
o := &options.GenerateKeyPairOptions{}

cmd := &cobra.Command{
Expand Down Expand Up @@ -68,5 +68,5 @@ CAVEATS:
}

o.AddFlags(cmd)
topLevel.AddCommand(cmd)
return cmd
}
4 changes: 2 additions & 2 deletions cmd/cosign/cli/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/sigstore/cosign/cmd/cosign/cli/options"
)

func addInitialize(topLevel *cobra.Command) {
func Initialize() *cobra.Command {
o := &options.InitializeOptions{}

cmd := &cobra.Command{
Expand Down Expand Up @@ -57,5 +57,5 @@ with Fulcio root CA) are pulled form the trusted metadata.`,
}

o.AddFlags(cmd)
topLevel.AddCommand(cmd)
return cmd
}
4 changes: 2 additions & 2 deletions cmd/cosign/cli/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/sigstore/cosign/cmd/cosign/cli/options"
)

func addManifest(topLevel *cobra.Command) {
func Manifest() *cobra.Command {
cmd := &cobra.Command{
Use: "manifest",
Short: "Provides utilities for discovering images in and performing operations on Kubernetes manifests",
Expand All @@ -33,7 +33,7 @@ func addManifest(topLevel *cobra.Command) {
manifestVerify(),
)

topLevel.AddCommand(cmd)
return cmd
}

func manifestVerify() *cobra.Command {
Expand Down
4 changes: 2 additions & 2 deletions cmd/cosign/cli/piv_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

var pivToolForce bool

func addPIVTool(topLevel *cobra.Command) {
func PIVTool() *cobra.Command {
cmd := &cobra.Command{
Use: "piv-tool",
Short: "Provides utilities for managing a hardware token",
Expand All @@ -49,7 +49,7 @@ func addPIVTool(topLevel *cobra.Command) {
cmd.PersistentFlags().BoolVarP(&pivToolForce, "no-input", "f", false,
"skip warnings and confirmations")

topLevel.AddCommand(cmd)
return cmd
}

func pivToolSetManagementKey() *cobra.Command {
Expand Down
7 changes: 5 additions & 2 deletions cmd/cosign/cli/piv_tool_disabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"github.com/spf13/cobra"
)

func addPIVTool(_ *cobra.Command) {
// disabled.
func PIVTool() *cobra.Command {
return &cobra.Command{
Use: "piv-tool",
Short: "This cosign was not built with piv-tool support!",
}
}
4 changes: 2 additions & 2 deletions cmd/cosign/cli/policy_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func rootPath(imageRef string) string {
return filepath.Join(imageRef, "root.json")
}

func addPolicy(topLevel *cobra.Command) {
func Policy() *cobra.Command {
cmd := &cobra.Command{
Use: "policy",
Short: "subcommand to manage a keyless policy.",
Expand All @@ -68,7 +68,7 @@ func addPolicy(topLevel *cobra.Command) {
signPolicy(),
)

topLevel.AddCommand(cmd)
return cmd
}

func initPolicy() *cobra.Command {
Expand Down
4 changes: 2 additions & 2 deletions cmd/cosign/cli/public_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/sigstore/cosign/cmd/cosign/cli/publickey"
)

func addPublicKey(topLevel *cobra.Command) {
func PublicKey() *cobra.Command {
o := &options.PublicKeyOptions{}

cmd := &cobra.Command{
Expand Down Expand Up @@ -82,5 +82,5 @@ func addPublicKey(topLevel *cobra.Command) {
}

o.AddFlags(cmd)
topLevel.AddCommand(cmd)
return cmd
}
4 changes: 2 additions & 2 deletions cmd/cosign/cli/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/sigstore/cosign/cmd/cosign/cli/sign"
)

func addSign(topLevel *cobra.Command) {
func Sign() *cobra.Command {
o := &options.SignOptions{}

cmd := &cobra.Command{
Expand Down Expand Up @@ -99,5 +99,5 @@ func addSign(topLevel *cobra.Command) {
}

o.AddFlags(cmd)
topLevel.AddCommand(cmd)
return cmd
}
4 changes: 2 additions & 2 deletions cmd/cosign/cli/signblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/sigstore/cosign/cmd/cosign/cli/sign"
)

func addSignBlob(topLevel *cobra.Command) {
func SignBlob() *cobra.Command {
o := &options.SignBlobOptions{}

cmd := &cobra.Command{
Expand Down Expand Up @@ -82,5 +82,5 @@ func addSignBlob(topLevel *cobra.Command) {
}

o.AddFlags(cmd)
topLevel.AddCommand(cmd)
return cmd
}
4 changes: 2 additions & 2 deletions cmd/cosign/cli/triangulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/sigstore/cosign/cmd/cosign/cli/triangulate"
)

func addTriangulate(topLevel *cobra.Command) {
func Triangulate() *cobra.Command {
o := &options.TriangulateOptions{}

cmd := &cobra.Command{
Expand All @@ -40,5 +40,5 @@ func addTriangulate(topLevel *cobra.Command) {
}

o.AddFlags(cmd)
topLevel.AddCommand(cmd)
return cmd
}
4 changes: 2 additions & 2 deletions cmd/cosign/cli/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/sigstore/cosign/cmd/cosign/cli/upload"
)

func addUpload(topLevel *cobra.Command) {
func Upload() *cobra.Command {
cmd := &cobra.Command{
Use: "upload",
Short: "Provides utilities for uploading artifacts to a registry",
Expand All @@ -35,7 +35,7 @@ func addUpload(topLevel *cobra.Command) {
uploadWASM(),
)

topLevel.AddCommand(cmd)
return cmd
}

func uploadBlob() *cobra.Command {
Expand Down
Loading

0 comments on commit 42d4ce7

Please sign in to comment.