Skip to content

Commit

Permalink
Add validation for reserved label
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Searcy <joe@twr.io>
  • Loading branch information
phenixblue committed Jul 26, 2023
1 parent a74ee14 commit 63e8348
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/imgpkg/cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ func (po *PushOptions) Run() error {
return err
}

err = po.validateFlags()
if err != nil {
return err
}

var imageURL string

isBundle := po.BundleFlags.Bundle != ""
Expand Down Expand Up @@ -145,3 +150,17 @@ func (po *PushOptions) pushImage(registry registry.Registry) (string, error) {
logger := util.NewUILevelLogger(util.LogWarn, util.NewLogger(po.ui))
return plainimage.NewContents(po.FileFlags.Files, po.FileFlags.ExcludedFilePaths, po.FileFlags.PreservePermissions).Push(uploadRef, po.Labels, registry, logger)
}

// validateFlags checks if the provided flags are valid
func (po *PushOptions) validateFlags() error {

// Verify the user did NOT specify a reserved OCI label
_, present := po.Labels[bundle.BundleConfigLabel]

if present {
return fmt.Errorf("label '%s' is reserved and cannot be overriden. Please use a different key", bundle.BundleConfigLabel)
}

return nil

}

0 comments on commit 63e8348

Please sign in to comment.