Skip to content

Commit d95dfcf

Browse files
committed
add check for protocol if port range info is provided
1 parent 2eafba0 commit d95dfcf

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

internal/cmd/beta/security-group/rule/create/create.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
179179
}
180180
}
181181

182+
if (model.PortRangeMin != nil || model.PortRangeMax != nil) && (model.ProtocolNumber == nil && model.ProtocolName == nil) {
183+
return nil, &cliErr.SecurityGroupRuleProtocolMissingForPortRangeError{
184+
Cmd: cmd,
185+
}
186+
}
187+
182188
if p.IsVerbosityDebug() {
183189
modelStr, err := print.BuildDebugStrFromInputModel(model)
184190
if err != nil {

internal/pkg/errors/errors.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,21 @@ To enable it, run:
151151

152152
IAAS_SECURITY_GROUP_RULE_PROTOCOL_PARAMETERS_CONFLICT = `"icmp-parameter-code" and "icmp-parameter-type" attributes can't be provided if "protocol-name" is not "icmp" or "ipv6-icmp"`
153153

154+
IAAS_SECURITY_GROUP_RULE_PROTOCOL_MISSING_FOR_PORT_RANGE = `"protocol-name" or "protocol-number" must be provided if "port-range-min" and "port-range-max" attributes are given`
155+
154156
IAAS_SERVER_NIC_ATTACH_MISSING_NIC_ID = `The "network-interface-id" flag must be provided if the "create" flag is not provided.`
155157

156158
IAAS_SERVER_NIC_DETACH_MISSING_NIC_ID = `The "network-interface-id" flag must be provided if the "delete" flag is not provided.`
157159
)
158160

161+
type SecurityGroupRuleProtocolMissingForPortRangeError struct {
162+
Cmd *cobra.Command
163+
}
164+
165+
func (e *SecurityGroupRuleProtocolMissingForPortRangeError) Error() string {
166+
return IAAS_SECURITY_GROUP_RULE_PROTOCOL_MISSING_FOR_PORT_RANGE
167+
}
168+
159169
type SecurityGroupRuleProtocolParametersConflictError struct {
160170
Cmd *cobra.Command
161171
}

0 commit comments

Comments
 (0)