Skip to content

flarectl/firewall_rules: ensure we return errors and halt#586

Merged
jacobbednarz merged 1 commit intomasterfrom
handle-bad-auth-for-access-rules
Feb 4, 2021
Merged

flarectl/firewall_rules: ensure we return errors and halt#586
jacobbednarz merged 1 commit intomasterfrom
handle-bad-auth-for-access-rules

Conversation

@jacobbednarz
Copy link
Copy Markdown
Contributor

Updates the error handling in the flarectl firewall rules to return
the exception should we recieve one and not continue on triggering a
panic due to resp.Result being nil.

Fixes #585

Updates the error handling in the `flarectl` firewall rules to return
the exception should we recieve one and not continue on triggering a
panic due to `resp.Result` being nil.

Fixes #585
@jacobbednarz
Copy link
Copy Markdown
Contributor Author

@jsha would you mind pulling this one locally and confirming it fixes your issue? in the other thread, i see you mentioned you got a different authentication error however i suspect mine is just due to missing permissions which should demonstrate the same codepath.

CleanShot 2021-02-04 at 13 36 48@2x

@jacobbednarz
Copy link
Copy Markdown
Contributor Author

in the linked issue, i also think --value='{"target":"ip","value","198.51.100.4"}' is wrong. by the looks, the getConfiguration method automagically works this out for you when you provide the string value.

func getConfiguration(c *cli.Context) cloudflare.AccessRuleConfiguration {
configuration := cloudflare.AccessRuleConfiguration{}
if c.String("value") != "" {
ip := net.ParseIP(c.String("value"))
_, cidr, cidrErr := net.ParseCIDR(c.String("value"))
_, asnErr := strconv.ParseInt(c.String("value"), 10, 32)
if ip != nil {
configuration.Target = "ip"
configuration.Value = ip.String()
} else if cidrErr == nil {
cidr.IP = cidr.IP.Mask(cidr.Mask)
configuration.Target = "ip_range"
configuration.Value = cidr.String()
} else if asnErr == nil {
configuration.Target = "asn"
configuration.Value = c.String("value")
} else {
configuration.Target = "country"
configuration.Value = c.String("value")
}
}
return configuration
}

i think --value="198.51.100.4" should do the job you're after.

@jsha
Copy link
Copy Markdown

jsha commented Feb 4, 2021

Works like a charm! And you're right about the --value flag, thanks.

@jacobbednarz jacobbednarz merged commit 2e2f704 into master Feb 4, 2021
@jacobbednarz jacobbednarz deleted the handle-bad-auth-for-access-rules branch February 4, 2021 03:16
@jacobbednarz
Copy link
Copy Markdown
Contributor Author

awesome, i'll tee this up for the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nil pointer dereference in firewall.go

2 participants