diff --git a/cmd/rekor-cli/app/pflag_groups.go b/cmd/rekor-cli/app/pflag_groups.go index 03c3c4142..9cf7818e1 100644 --- a/cmd/rekor-cli/app/pflag_groups.go +++ b/cmd/rekor-cli/app/pflag_groups.go @@ -26,8 +26,6 @@ import ( "github.com/sigstore/rekor/pkg/types" "github.com/spf13/cobra" "github.com/spf13/viper" - - "golang.org/x/exp/slices" ) // addFlagToCmd adds the specified command of a specified type to the command's flag set @@ -188,7 +186,7 @@ func ParseTypeFlag(typeStr string) (string, string, error) { case 1: return typeStrings[0], "", nil case 2: - if !slices.Contains(ti.SupportedVersions(), typeStrings[1]) { + if !ti.IsSupportedVersion(typeStrings[1]) { return "", "", fmt.Errorf("type %v does not support version %v", typeStrings[0], typeStrings[1]) } return typeStrings[0], typeStrings[1], nil diff --git a/pkg/types/types.go b/pkg/types/types.go index b271fd761..256bacd3a 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -23,6 +23,7 @@ import ( "github.com/sigstore/rekor/pkg/generated/models" "github.com/sigstore/rekor/pkg/log" + "golang.org/x/exp/slices" ) // TypeMap stores mapping between type strings and entry constructors @@ -42,6 +43,7 @@ type TypeImpl interface { CreateProposedEntry(context.Context, string, ArtifactProperties) (models.ProposedEntry, error) DefaultVersion() string SupportedVersions() []string + IsSupportedVersion(string) bool UnmarshalEntry(pe models.ProposedEntry) (EntryImpl, error) } @@ -62,10 +64,16 @@ func (rt *RekorType) VersionedUnmarshal(pe models.ProposedEntry, version string) return entry, entry.Unmarshal(pe) } +// SupportedVersions returns a list of versions of this type that can be currently entered into the log func (rt *RekorType) SupportedVersions() []string { return rt.VersionMap.SupportedVersions() } +// IsSupportedVersion returns true if the version can be inserted into the log, and false if not +func (rt *RekorType) IsSupportedVersion(proposedVersion string) bool { + return slices.Contains(rt.SupportedVersions(), proposedVersion) +} + // ListImplementedTypes returns a list of all type strings currently known to // be implemented func ListImplementedTypes() []string {