Skip to content

Commit

Permalink
fix: removing last rule from firewall fails with invalid_input error (#…
Browse files Browse the repository at this point in the history
…696)

If you try to delete last firewall rule, rule is `null` but should be
`[]`, resulting in error message

> hcloud: invalid input in field 'rules' (invalid_input)

`hcloud firewall delete-rule --direction in --protocol tcp --source-ips
'8.8.8.8/32' --port 443 f2b`
  • Loading branch information
kossmac authored Feb 13, 2024
1 parent 6dd443f commit acab17c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/firewall/delete_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ var DeleteRuleCmd = base.Cmd{
}
}

var rules []hcloud.FirewallRule
var rules = make([]hcloud.FirewallRule, 0)
for _, existingRule := range firewall.Rules {
if !reflect.DeepEqual(existingRule, rule) {
rules = append(rules, existingRule)
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/firewall/delete_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestDeleteRule(t *testing.T) {
Get(gomock.Any(), "test").
Return(fw, nil, nil)
fx.Client.FirewallClient.EXPECT().
SetRules(gomock.Any(), fw, hcloud.FirewallSetRulesOpts{Rules: nil}).
SetRules(gomock.Any(), fw, hcloud.FirewallSetRulesOpts{Rules: []hcloud.FirewallRule{}}).
Return([]*hcloud.Action{{ID: 123}, {ID: 321}}, nil, nil)
fx.ActionWaiter.EXPECT().
WaitForActions(gomock.Any(), gomock.Any(), []*hcloud.Action{{ID: 123}, {ID: 321}}).
Expand Down

0 comments on commit acab17c

Please sign in to comment.