When creating civo firewall, `--create-rules=false` still creates default firewall rules
Opened this issue · 5 comments
Issue
After creating the civo network "test-net", creating a civo firewall with the command civo fw create test-fw -n test-net --create-rules false
, creates the default rules (same as when the --create-rules
is true
:
For example:
Acceptance Criteria
- When the user performs the command
civo create fw
with the flag--create-rules=false
, there will be no rules created for the firewall.
Yeah there is a couple of issues with this that we need to fix. In the meantime the work around is to run the command like this:
civo fw create test-fw -n test-net --create-rules=false
So the "issue" here is the following:
--create-rules
is a boolean flag. Generally speaking in CLI tools created in go, boolean flags require the = sign to change them. This is probably because they are intended to be used without any arguments, generally speaking.
So in our case, the issue is that our default is to create rules, so having a flag called --create-rules feels a little redundant. In reality we should have just created a flag called --no-default-rules
or something like that instead. That way the user would have never need to run it as --no-default-rules=false
and there would be no confusion.
These are some ways we can tackle this problem:
- Create an additional
--no-default-rules
flag, leave the current one as legacy and perhaps remove it in the future. - Make it abundantly clear you need an equal sign for the current flag in the documentation. This could still lead to confusion.
I am partial to the first solution.
Hi Team,
I worked on this issue, and would like to explain my approach for review.
In here,
- I created a new flag
--no-default-rules
as suggested above.
firewallCreateCmd.Flags().BoolVarP(&noDefaultRules, "no-default-rules", "", false, "the no-default-rules flag will ensure no default rules are created for the firewall, if is not defined will be set to false")
- Added a pre-run to set the value of
createRules
tofalse
if flag--no-default-rules
is specified.
firewallCreateCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
if noDefaultRules {
createRules =false
}
return nil
}
I also updated the documentation:
Result:
- without
--no-default-rules
:
- with
--no-default-rules
:
Regards!
Hi @uzaxirr,
Whenever you have a moment, could you please review this?
hii @Praveen005 Please create a PR