Skip to content

Commit 8ef3fc0

Browse files
committed
fixup: check name length
1 parent 9e84aed commit 8ef3fc0

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

internal/cmd/auth/security_group/create/create.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
4545
}
4646

4747
func configureFlags(cmd *cobra.Command) {
48-
cmd.Flags().String("name", "", "the name of the security group")
48+
cmd.Flags().String("name", "", "the name of the security group. Must be <= 63 chars")
4949
cmd.Flags().String("description", "", "an optional description of the security group. Must be <= 127 chars")
5050
cmd.Flags().Bool("stateful", false, "create a stateful or a stateless security group")
5151
cmd.Flags().StringSlice("labels", nil, "a list of labels in the form <key>=<value>")
@@ -95,6 +95,13 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
9595
if globalFlags.ProjectId == "" {
9696
return nil, &errors.ProjectIdError{}
9797
}
98+
name := flags.FlagToStringValue(p, cmd, "name")
99+
if len(name) >= 64 {
100+
return nil, &errors.ArgValidationError{
101+
Arg: "invalid name",
102+
Details: "name exceeds 63 characters in length",
103+
}
104+
}
98105

99106
labels := make(map[string]any)
100107
for _, label := range flags.FlagToStringSliceValue(p, cmd, "labels") {
@@ -117,7 +124,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
117124
}
118125
model := inputModel{
119126
GlobalFlagModel: globalFlags,
120-
Name: flags.FlagToStringValue(p, cmd, "name"),
127+
Name: name,
121128

122129
Labels: labels,
123130
Description: description,

internal/cmd/auth/security_group/create/create_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ func TestParseInput(t *testing.T) {
123123
}),
124124
isValid: false,
125125
},
126+
{
127+
description: "name too long",
128+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
129+
flagValues["name"] = strings.Repeat("toolong", 1000)
130+
}),
131+
isValid: false,
132+
},
126133
{
127134
description: "description too long",
128135
flagValues: fixtureFlagValues(func(flagValues map[string]string) {

0 commit comments

Comments
 (0)