From acab17c361373e5bd3b689708195fa48f18dbafb Mon Sep 17 00:00:00 2001 From: Karsten Kosmala Date: Tue, 13 Feb 2024 10:32:58 +0100 Subject: [PATCH] fix: removing last rule from firewall fails with invalid_input error (#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` --- internal/cmd/firewall/delete_rule.go | 2 +- internal/cmd/firewall/delete_rule_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cmd/firewall/delete_rule.go b/internal/cmd/firewall/delete_rule.go index 69577e49..52df4fa0 100644 --- a/internal/cmd/firewall/delete_rule.go +++ b/internal/cmd/firewall/delete_rule.go @@ -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) diff --git a/internal/cmd/firewall/delete_rule_test.go b/internal/cmd/firewall/delete_rule_test.go index b693a79f..297456fd 100644 --- a/internal/cmd/firewall/delete_rule_test.go +++ b/internal/cmd/firewall/delete_rule_test.go @@ -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}}).