Skip to content

Commit

Permalink
check artifact path when creating entry
Browse files Browse the repository at this point in the history
Signed-off-by: Samsondeen Dare <samsondeen.dare@hashicorp.com>
  • Loading branch information
dsa0x committed Aug 11, 2022
1 parent 6882d35 commit 8fa6ed6
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 7 deletions.
7 changes: 0 additions & 7 deletions cmd/rekor-cli/app/pflag_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ 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
}

Expand All @@ -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 != "" {
Expand Down
3 changes: 3 additions & 0 deletions pkg/types/alpine/v0.0.1/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/types/helm/v0.0.1/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/types/jar/v0.0.1/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/types/rekord/v0.0.1/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/types/rpm/v0.0.1/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/types/tuf/v0.0.1/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8fa6ed6

Please sign in to comment.