@@ -38,6 +38,7 @@ func CreateCommand() commands.Command {
3838 BaseCommand : commands .New (
3939 "create" ,
4040 "Create a new firewall rule" ,
41+ "upctl server firewall create 00038afc-d526-4148-af0e-d2f1eeaded9b --direction in --action drop" ,
4142 "upctl server firewall create 00038afc-d526-4148-af0e-d2f1eeaded9b --direction in --action accept --family IPv4" ,
4243 "upctl server firewall create 00038afc-d526-4148-af0e-d2f1eeaded9b --direction in --action drop --family IPv4 --src-ipaddress-block 10.11.0.88/24" ,
4344 ),
@@ -51,6 +52,13 @@ func (s *createCommand) MaximumExecutions() int {
5152
5253// InitCommand implements Command.InitCommand
5354func (s * createCommand ) InitCommand () {
55+ s .Cobra ().Long = `Create a new firewall rule
56+
57+ To edit the default rule of the firewall, set only --direction and --action
58+ parameters. This creates catch-all rule that will take effect when no other rule
59+ matches. Note that the default rule must be positioned after all other rules.
60+ Use --position parameter or create default rule after other rules.`
61+
5462 flagSet := & pflag.FlagSet {}
5563
5664 flagSet .StringVar (& s .direction , "direction" , "" , "Rule direction. Available: in / out" )
@@ -80,11 +88,7 @@ func (s *createCommand) Execute(exec commands.Executor, arg string) (output.Outp
8088 return nil , fmt .Errorf ("action is required" )
8189 }
8290
83- if s .family == "" {
84- return nil , fmt .Errorf ("family (IPv4/IPv6) is required" )
85- }
86-
87- if s .family != "IPv4" && s .family != "IPv6" {
91+ if s .family != "" && s .family != "IPv4" && s .family != "IPv6" {
8892 return nil , fmt .Errorf ("invalid family, use either IPv4 or IPv6" )
8993 }
9094
@@ -133,6 +137,7 @@ func (s *createCommand) Execute(exec commands.Executor, arg string) (output.Outp
133137 msg := fmt .Sprintf ("creating firewall rule for server %v" , arg )
134138 logline := exec .NewLogEntry (msg )
135139 logline .StartedNow ()
140+
136141 res , err := exec .Firewall ().CreateFirewallRule (& request.CreateFirewallRuleRequest {
137142 ServerUUID : arg ,
138143 FirewallRule : upcloud.FirewallRule {
0 commit comments