@@ -25,17 +25,10 @@ import (
2525)
2626
2727const (
28- productFlag = "product"
29- typeFlag = "type"
30- sourceIpFlag = "sourceIp"
31- instanceIdFlag = "instanceId"
32- directionFlag = "direction"
33- descriptionFlag = "description"
34- etherTypeFlag = "etherType"
35- portRangeFlag = "portRange"
36- protocolFlag = "protocol"
37- offsetFlag = "offset"
38- securityGroupIdFlag = "securityGroupId"
28+ productFlag = "product"
29+ typeFlag = "type"
30+ sourceIpFlag = "sourceIp"
31+ instanceIdFlag = "instanceId"
3932)
4033
4134type inputModel struct {
@@ -121,17 +114,10 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
121114}
122115
123116func configureFlags (cmd * cobra.Command ) {
124- cmd .Flags ().String (productFlag , "" , "The source service (e.g., Load Balancer , Redis) where you want to attach a rule" )
117+ cmd .Flags ().String (productFlag , "" , "The source service (e.g., Edge Cloud , Redis) where you want to attach a rule" )
125118 cmd .Flags ().StringP (typeFlag , "t" , "" , "Type (ACL/SecurityRule/SecurityGroup) You can check /provider-options route for them. Unfortunately, this field could be only ACL for the CLI version" )
126119 cmd .Flags ().StringP (sourceIpFlag , "s" , "" , "The IP (CIDR) to which the rule applies (e.g. 192.168.0.1/32)" )
127120 cmd .Flags ().StringP (instanceIdFlag , "i" , "" , "Instance ID that will have attached your rule" )
128- cmd .Flags ().StringP (directionFlag , "d" , "" , "Direction (the direction of the traffic, typically ingress or egress, for security rules type)" )
129- cmd .Flags ().StringP (descriptionFlag , "D" , "" , "Description" )
130- cmd .Flags ().StringP (etherTypeFlag , "e" , "" , "Specifies the bound of the rule (for security rules type)" )
131- cmd .Flags ().StringP (portRangeFlag , "r" , "" , "Port range (the Port range to which the rule applies, for security rules type)" )
132- cmd .Flags ().String (protocolFlag , "" , "The network protocol (e.g. TCP, UDP, ICMP, for security rules type)" )
133- cmd .Flags ().Int32P (offsetFlag , "f" , - 1 , "Offset - Position in the ACL list of an instance, will be ignored at creation" )
134- cmd .Flags ().StringP (securityGroupIdFlag , "g" , "" , "Security group ID - The ID of the Security Group" )
135121
136122 err := flags .MarkFlagsRequired (cmd , instanceIdFlag )
137123 cobra .CheckErr (err )
@@ -159,17 +145,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
159145 model := inputModel {
160146 GlobalFlagModel : globalFlags ,
161147
162- Product : flags .FlagToStringPointer (p , cmd , productFlag ),
163- Type : flags .FlagToStringPointer (p , cmd , typeFlag ),
164- SourceIp : flags .FlagToStringPointer (p , cmd , sourceIpFlag ),
165- InstanceId : flags .FlagToStringPointer (p , cmd , instanceIdFlag ),
166- Direction : flags .FlagToStringPointer (p , cmd , directionFlag ),
167- Description : flags .FlagToStringPointer (p , cmd , descriptionFlag ),
168- EtherType : flags .FlagToStringPointer (p , cmd , etherTypeFlag ),
169- PortRange : flags .FlagToStringPointer (p , cmd , portRangeFlag ),
170- Protocol : flags .FlagToStringPointer (p , cmd , protocolFlag ),
171- Offset : flags .FlagToInt32Pointer (p , cmd , offsetFlag ),
172- SecurityGroupId : flags .FlagToStringPointer (p , cmd , securityGroupIdFlag ),
148+ Product : flags .FlagToStringPointer (p , cmd , productFlag ),
149+ Type : flags .FlagToStringPointer (p , cmd , typeFlag ),
150+ SourceIp : flags .FlagToStringPointer (p , cmd , sourceIpFlag ),
151+ InstanceId : flags .FlagToStringPointer (p , cmd , instanceIdFlag ),
173152 }
174153
175154 p .DebugInputModel (model )
@@ -179,28 +158,15 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
179158func buildRequest (ctx context.Context , model * inputModel , apiClient * ufw.APIClient ) (ufw.ApiCreateRuleRequest , error ) {
180159 req := apiClient .DefaultAPI .CreateRule (ctx , model .ProjectId , model .Region )
181160
182- //providerOptions, err := apiClient.DefaultAPI.ListProviderOptions(ctx, model.Region).Execute()
183- //
184- //if err != nil {
185- // return req, fmt.Errorf("get provider options: %w", err)
186- //}
187- //
188- //if *model.Type != types.Types {
189- // return req, fmt.Errorf("invalid rule type: %s", *model.Type)
190- //}
161+ if * model .Type != "ACL" {
162+ return req , fmt .Errorf ("invalid rule type: %s" , * model .Type )
163+ }
191164
192165 req = req .CreateRulePayload (ufw.CreateRulePayload {
193- Product : * model .Product ,
194- Type : * model .Type ,
195- SourceIP : * model .SourceIp ,
196- InstanceId : * model .InstanceId ,
197- Direction : model .Direction ,
198- Description : model .Description ,
199- EtherType : model .EtherType ,
200- PortRange : model .PortRange ,
201- Protocol : model .Protocol ,
202- Offset : model .Offset ,
203- SecurityGroupId : model .SecurityGroupId ,
166+ Product : * model .Product ,
167+ Type : * model .Type ,
168+ SourceIP : * model .SourceIp ,
169+ InstanceId : * model .InstanceId ,
204170 })
205171
206172 return req , nil
0 commit comments