Skip to content

Commit b70f0c7

Browse files
committed
fix(registry validation): adding input validation
1 parent af08f7a commit b70f0c7

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

pkg/cmd/flag/flag.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ func RequiredWhenNonInteractiveError(flags ...string) error {
4949
}
5050
return fmt.Errorf("%v %v required when not running interactively", flagsF, flagTitle)
5151
}
52+
53+
func OutOfRangeError(flag string, value int32) *Error {
54+
return &Error{Err: fmt.Errorf("out of range value of %d for %v, only positive values are allowed", value, flag)}
55+
}

pkg/cmd/registry/list/list.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ func NewListCommand(f *factory.Factory) *cobra.Command {
6464
if opts.outputFormat != "" && !flagutil.IsValidInput(opts.outputFormat, flagutil.ValidOutputFormats...) {
6565
return flag.InvalidValueError("output", opts.outputFormat, flagutil.ValidOutputFormats...)
6666
}
67+
if !flagutil.IsInputInRange(opts.page) {
68+
return flag.OutOfRangeError("page", opts.page)
69+
}
70+
71+
if !flagutil.IsInputInRange(opts.limit) {
72+
return flag.OutOfRangeError("limit", opts.limit)
73+
}
6774

6875
return runList(opts)
6976
},

pkg/cmdutil/flags/flags.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ func EnableOutputFlagCompletion(cmd *cobra.Command) {
3535
return ValidOutputFormats, cobra.ShellCompDirectiveNoSpace
3636
})
3737
}
38+
39+
func IsInputInRange(input int32) bool {
40+
return input > 0
41+
}

0 commit comments

Comments
 (0)