Skip to content

Commit

Permalink
Normalize certificate flag names
Browse files Browse the repository at this point in the history
This changes the flag names to use certificate instead of
the abbreviated cert. To avoid breaking clients, we add
a global alias that translates between the two.

Signed-off-by: Hayden Blauzvern <[email protected]>
  • Loading branch information
haydentherapper committed May 11, 2022
1 parent 7a3c04f commit 276e113
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 32 deletions.
25 changes: 25 additions & 0 deletions cmd/cosign/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/google/go-containerregistry/pkg/logs"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"sigs.k8s.io/release-utils/version"

cranecmd "github.com/google/go-containerregistry/cmd/crane/cmd"
Expand All @@ -31,6 +32,27 @@ var (
ro = &options.RootOptions{}
)

func normalizeCertificateFlags(_ *pflag.FlagSet, name string) pflag.NormalizedName {
switch name {
case "cert":
name = "certificate"
break
case "cert-email":
name = "certificate-email"
break
case "cert-chain":
name = "certificate-chain"
break
case "cert-oidc-issuer":
name = "certificate-oidc-issuer"
break
case "output-cert":
name = "output-certificate"
break
}
return pflag.NormalizedName(name)
}

func New() *cobra.Command {
var (
out, stdout *os.File
Expand Down Expand Up @@ -97,5 +119,8 @@ func New() *cobra.Command {
cmd.AddCommand(version.WithFont("starwars"))

cmd.AddCommand(cranecmd.NewCmdAuthLogin("cosign"))

cmd.SetGlobalNormalizationFunc(normalizeCertificateFlags)

return cmd
}
4 changes: 2 additions & 2 deletions cmd/cosign/cli/options/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ func (o *AttestOptions) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&o.Key, "key", "",
"path to the private key file, KMS URI or Kubernetes Secret")

cmd.Flags().StringVar(&o.Cert, "cert", "",
cmd.Flags().StringVar(&o.Cert, "certificate", "",
"path to the X.509 certificate in PEM format to include in the OCI Signature")

cmd.Flags().StringVar(&o.CertChain, "cert-chain", "",
cmd.Flags().StringVar(&o.CertChain, "certificate-chain", "",
"path to a list of CA X.509 certificates in PEM format which will be needed "+
"when building the certificate chain for the signing certificate. "+
"Must start with the parent intermediate CA certificate of the "+
Expand Down
8 changes: 4 additions & 4 deletions cmd/cosign/cli/options/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ var _ Interface = (*RekorOptions)(nil)

// AddFlags implements Interface
func (o *CertVerifyOptions) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&o.Cert, "cert", "",
cmd.Flags().StringVar(&o.Cert, "certificate", "",
"path to the public certificate")

cmd.Flags().StringVar(&o.CertEmail, "cert-email", "",
cmd.Flags().StringVar(&o.CertEmail, "certificate-email", "",
"the email expected in a valid Fulcio certificate")

cmd.Flags().StringVar(&o.CertOidcIssuer, "cert-oidc-issuer", "",
cmd.Flags().StringVar(&o.CertOidcIssuer, "certificate-oidc-issuer", "",
"the OIDC issuer expected in a valid Fulcio certificate, e.g. https://token.actions.githubusercontent.com or https://oauth2.sigstore.dev/auth")

cmd.Flags().StringVar(&o.CertChain, "cert-chain", "",
cmd.Flags().StringVar(&o.CertChain, "certificate-chain", "",
"path to a list of CA certificates in PEM format which will be needed "+
"when building the certificate chain for the signing certificate. "+
"Must start with the parent intermediate CA certificate of the "+
Expand Down
4 changes: 2 additions & 2 deletions cmd/cosign/cli/options/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func (o *SignOptions) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&o.Key, "key", "",
"path to the private key file, KMS URI or Kubernetes Secret")

cmd.Flags().StringVar(&o.Cert, "cert", "",
cmd.Flags().StringVar(&o.Cert, "certificate", "",
"path to the X.509 certificate in PEM format to include in the OCI Signature")

cmd.Flags().StringVar(&o.CertChain, "cert-chain", "",
cmd.Flags().StringVar(&o.CertChain, "certificate-chain", "",
"path to a list of CA X.509 certificates in PEM format which will be needed "+
"when building the certificate chain for the signing certificate. "+
"Must start with the parent intermediate CA certificate of the "+
Expand Down
4 changes: 2 additions & 2 deletions doc/cosign_attest.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions doc/cosign_dockerfile_verify.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions doc/cosign_manifest_verify.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions doc/cosign_sign.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions doc/cosign_verify-attestation.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions doc/cosign_verify-blob.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 276e113

Please sign in to comment.