diff --git a/cmd/rekor-cli/app/pflag_groups.go b/cmd/rekor-cli/app/pflag_groups.go index 112379c8b..aeabc4aec 100644 --- a/cmd/rekor-cli/app/pflag_groups.go +++ b/cmd/rekor-cli/app/pflag_groups.go @@ -122,14 +122,10 @@ func validateArtifactPFlags(uuidValid, indexValid bool) error { return errors.New("either 'entry' or 'artifact' or 'artifact-hash' must be specified") } - if viper.GetString("artifact-hash") != "" && viper.GetString("artifact") == "" { - return errors.New("'artifact-hash' can only be used with 'artifact'") - } - return nil } -func CreatePropsFromPflags() (*types.ArtifactProperties, error) { +func CreatePropsFromPflags() *types.ArtifactProperties { props := &types.ArtifactProperties{} artifactString := viper.GetString("artifact") @@ -142,9 +138,6 @@ func CreatePropsFromPflags() (*types.ArtifactProperties, error) { } props.ArtifactHash = viper.GetString("artifact-hash") - if props.ArtifactHash != "" && props.ArtifactPath == nil { - return nil, errors.New("'artifact-hash' can only be used with 'artifact'") - } signatureString := viper.GetString("signature") if signatureString != "" { @@ -170,7 +163,7 @@ func CreatePropsFromPflags() (*types.ArtifactProperties, error) { props.AdditionalAuthenticatedData, _ = base64.StdEncoding.DecodeString(b64aad) } - return props, nil + return props } //TODO: add tests for this diff --git a/cmd/rekor-cli/app/pflags_test.go b/cmd/rekor-cli/app/pflags_test.go index 807471584..6b1faa07b 100644 --- a/cmd/rekor-cli/app/pflags_test.go +++ b/cmd/rekor-cli/app/pflags_test.go @@ -433,10 +433,7 @@ func TestArtifactPFlags(t *testing.T) { if err != nil { t.Errorf("error parsing typeStr: %v", err) } - props, err := CreatePropsFromPflags() - if err != nil { - t.Errorf("error creating props: %v", err) - } + props := CreatePropsFromPflags() if _, err := types.NewProposedEntry(context.Background(), typeStr, versionStr, *props); err != nil { t.Errorf("unexpected result in '%v' building entry: %v", tc.caseDesc, err) } diff --git a/cmd/rekor-cli/app/upload.go b/cmd/rekor-cli/app/upload.go index 1f28371ae..32739e409 100644 --- a/cmd/rekor-cli/app/upload.go +++ b/cmd/rekor-cli/app/upload.go @@ -108,10 +108,7 @@ var uploadCmd = &cobra.Command{ return nil, err } - props, err := CreatePropsFromPflags() - if err != nil { - return nil, err - } + props := CreatePropsFromPflags() entry, err = types.NewProposedEntry(context.Background(), typeStr, versionStr, *props) if err != nil { diff --git a/cmd/rekor-cli/app/verify.go b/cmd/rekor-cli/app/verify.go index 099ba826a..ead7b6457 100644 --- a/cmd/rekor-cli/app/verify.go +++ b/cmd/rekor-cli/app/verify.go @@ -113,10 +113,7 @@ var verifyCmd = &cobra.Command{ return nil, err } - props, err := CreatePropsFromPflags() - if err != nil { - return nil, err - } + props := CreatePropsFromPflags() entry, err := types.NewProposedEntry(context.Background(), typeStr, versionStr, *props) if err != nil { diff --git a/pkg/types/alpine/v0.0.1/entry.go b/pkg/types/alpine/v0.0.1/entry.go index 0b283f9b1..3a68cebe1 100644 --- a/pkg/types/alpine/v0.0.1/entry.go +++ b/pkg/types/alpine/v0.0.1/entry.go @@ -299,6 +299,9 @@ func (v V001Entry) CreateFromArtifactProperties(ctx context.Context, props types artifactBytes := props.ArtifactBytes if artifactBytes == nil { var artifactReader io.ReadCloser + if props.ArtifactPath == nil { + return nil, errors.New("path to artifact file must be specified") + } if props.ArtifactPath.IsAbs() { artifactReader, err = util.FileOrURLReadCloser(ctx, props.ArtifactPath.String(), nil) if err != nil { diff --git a/pkg/types/helm/v0.0.1/entry.go b/pkg/types/helm/v0.0.1/entry.go index 5f6406aa4..55f68fe30 100644 --- a/pkg/types/helm/v0.0.1/entry.go +++ b/pkg/types/helm/v0.0.1/entry.go @@ -294,6 +294,9 @@ func (v V001Entry) CreateFromArtifactProperties(ctx context.Context, props types artifactBytes := props.ArtifactBytes if artifactBytes == nil { var artifactReader io.ReadCloser + if props.ArtifactPath == nil { + return nil, errors.New("path to artifact file must be specified") + } if props.ArtifactPath.IsAbs() { artifactReader, err = util.FileOrURLReadCloser(ctx, props.ArtifactPath.String(), nil) if err != nil { diff --git a/pkg/types/jar/v0.0.1/entry.go b/pkg/types/jar/v0.0.1/entry.go index 67378704c..d694c38b7 100644 --- a/pkg/types/jar/v0.0.1/entry.go +++ b/pkg/types/jar/v0.0.1/entry.go @@ -283,6 +283,9 @@ func (v *V001Entry) CreateFromArtifactProperties(ctx context.Context, props type artifactBytes := props.ArtifactBytes if artifactBytes == nil { var artifactReader io.ReadCloser + if props.ArtifactPath == nil { + return nil, errors.New("path to artifact file must be specified") + } if props.ArtifactPath.IsAbs() { artifactReader, err = util.FileOrURLReadCloser(ctx, props.ArtifactPath.String(), nil) if err != nil { diff --git a/pkg/types/rekord/v0.0.1/entry.go b/pkg/types/rekord/v0.0.1/entry.go index 3603651a8..4c566a054 100644 --- a/pkg/types/rekord/v0.0.1/entry.go +++ b/pkg/types/rekord/v0.0.1/entry.go @@ -343,6 +343,9 @@ func (v V001Entry) CreateFromArtifactProperties(ctx context.Context, props types artifactBytes := props.ArtifactBytes if artifactBytes == nil { var artifactReader io.ReadCloser + if props.ArtifactPath == nil { + return nil, errors.New("path to artifact file must be specified") + } if props.ArtifactPath.IsAbs() { artifactReader, err = util.FileOrURLReadCloser(ctx, props.ArtifactPath.String(), nil) if err != nil { diff --git a/pkg/types/rpm/v0.0.1/entry.go b/pkg/types/rpm/v0.0.1/entry.go index f6b5ec30f..b8b00a8f5 100644 --- a/pkg/types/rpm/v0.0.1/entry.go +++ b/pkg/types/rpm/v0.0.1/entry.go @@ -319,6 +319,9 @@ func (v V001Entry) CreateFromArtifactProperties(ctx context.Context, props types artifactBytes := props.ArtifactBytes if artifactBytes == nil { var artifactReader io.ReadCloser + if props.ArtifactPath == nil { + return nil, errors.New("path to artifact file must be specified") + } if props.ArtifactPath.IsAbs() { artifactReader, err = util.FileOrURLReadCloser(ctx, props.ArtifactPath.String(), nil) if err != nil { diff --git a/pkg/types/tuf/v0.0.1/entry.go b/pkg/types/tuf/v0.0.1/entry.go index 57923241b..e53e069a9 100644 --- a/pkg/types/tuf/v0.0.1/entry.go +++ b/pkg/types/tuf/v0.0.1/entry.go @@ -306,6 +306,9 @@ func (v V001Entry) CreateFromArtifactProperties(ctx context.Context, props types re.TufObj.Metadata = &models.TUFV001SchemaMetadata{} if artifactBytes == nil { var artifactReader io.ReadCloser + if props.ArtifactPath == nil { + return nil, errors.New("path to artifact file must be specified") + } if props.ArtifactPath.IsAbs() { artifactReader, err = util.FileOrURLReadCloser(ctx, props.ArtifactPath.String(), nil) if err != nil {