Skip to content

Commit

Permalink
fix: filter shell filename completions to appropriate extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Feb 12, 2025
1 parent 988b7fd commit 7aedf88
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cli/slsa-verifier/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func verifyArtifactCmd() *cobra.Command {
o.AddFlags(cmd)
// --provenance-path must be supplied when verifying an artifact.
cmd.MarkFlagRequired("provenance-path")
cmd.MarkFlagFilename("provenance-path", verify.CommonFilenameExtensions...)
return cmd
}

Expand Down Expand Up @@ -137,6 +138,12 @@ func verifyNpmPackageCmd() *cobra.Command {
}
return nil
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
return []string{"tgz"}, cobra.ShellCompDirectiveFilterFileExt
},
Short: "Verifies SLSA provenance for an npm package tarball [experimental]",
Run: func(cmd *cobra.Command, args []string) {
v := verify.VerifyNpmPackageCommand{
Expand Down
6 changes: 6 additions & 0 deletions cli/slsa-verifier/verify/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type VerifyOptions struct {

var _ Interface = (*VerifyOptions)(nil)

var CommonFilenameExtensions = []string{"sigstore", "intoto", "intoto.jsonl", "json"}

// AddFlags implements Interface.
func (o *VerifyOptions) AddFlags(cmd *cobra.Command) {
/* Builder options */
Expand Down Expand Up @@ -73,6 +75,7 @@ func (o *VerifyOptions) AddFlags(cmd *cobra.Command) {
/* Other options */
cmd.Flags().StringVar(&o.ProvenancePath, "provenance-path", "",
"path to a provenance file")
cmd.MarkFlagFilename("provenance-path", CommonFilenameExtensions...)

cmd.Flags().StringVar(&o.ProvenanceRepository, "provenance-repository", "",
"image repository for provenance with format: <registry>/<repository>")
Expand Down Expand Up @@ -123,6 +126,7 @@ func (o *VerifyNpmOptions) AddFlags(cmd *cobra.Command) {

cmd.Flags().StringVar(&o.AttestationsPath, "attestations-path", "",
"path to a file containing the attestations")
cmd.MarkFlagFilename("attestations-path", CommonFilenameExtensions...)

cmd.Flags().StringVar(&o.PackageName, "package-name", "",
"the package name")
Expand Down Expand Up @@ -164,6 +168,7 @@ func (o *VerifyVSAOptions) AddFlags(cmd *cobra.Command) {

cmd.Flags().StringVar(&o.AttestationPath, "attestation-path", "",
"path to a file containing the attestation")
cmd.MarkFlagFilename("attestation-path", CommonFilenameExtensions...)

cmd.Flags().StringVar(&o.VerifierID, "verifier-id", "",
"the unique verifier ID who created the attestation")
Expand All @@ -182,6 +187,7 @@ func (o *VerifyVSAOptions) AddFlags(cmd *cobra.Command) {

cmd.Flags().StringVar(&o.PublicKeyPath, "public-key-path", "",
"path to a public key file")
cmd.MarkFlagFilename("public-key-path", "pem")

cmd.Flags().StringVar(&o.PublicKeyID, "public-key-id", "",
"[optional] the ID of the public key, defaults to the SHA256 digest of the base64-encoded public key")
Expand Down

0 comments on commit 7aedf88

Please sign in to comment.