Skip to content

Commit 2f6e0c3

Browse files
authored
fix(updater): network restrictions not enabled (#4887)
## Summary Mitigates workflow failures caused by `400` responses from network restrictions endpoints when projects are not entitled to manage restrictions and local config has `db.network_restrictions.enabled = false` or not set. The fix ensures we only read/update network restrictions when local config explicitly enables the feature, while preserving strict failure behavior when it is enabled.
1 parent 3b68bf2 commit 2f6e0c3

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

pkg/config/updater.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ func (u *ConfigUpdater) UpdateDbConfig(ctx context.Context, projectRef string, c
107107
}
108108

109109
func (u *ConfigUpdater) UpdateDbNetworkRestrictionsConfig(ctx context.Context, projectRef string, n networkRestrictions, filter ...func(string) bool) error {
110+
if !n.Enabled {
111+
return nil
112+
}
110113
networkRestrictionsConfig, err := u.client.V1GetNetworkRestrictionsWithResponse(ctx, projectRef)
111114
if err != nil {
112115
return errors.Errorf("failed to read network restrictions config: %w", err)

pkg/config/updater_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,41 @@ func TestUpdateDbConfig(t *testing.T) {
119119
})
120120
}
121121

122+
func TestUpdateDbNetworkRestrictionsConfig(t *testing.T) {
123+
server := "http://localhost"
124+
client, err := v1API.NewClientWithResponses(server)
125+
require.NoError(t, err)
126+
127+
t.Run("skips update if disabled locally", func(t *testing.T) {
128+
updater := NewConfigUpdater(*client)
129+
// Run test
130+
err := updater.UpdateDbNetworkRestrictionsConfig(context.Background(), "test-project", networkRestrictions{})
131+
// Check result
132+
assert.NoError(t, err)
133+
assert.False(t, gock.HasUnmatchedRequest())
134+
})
135+
136+
t.Run("returns error on 400 when enabled locally", func(t *testing.T) {
137+
updater := NewConfigUpdater(*client)
138+
// Setup mock server
139+
defer gock.Off()
140+
gock.New(server).
141+
Get("/v1/projects/test-project/network-restrictions").
142+
Reply(http.StatusBadRequest).
143+
JSON(map[string]any{
144+
"message": "project not allowed to set up network restrictions",
145+
})
146+
// Run test
147+
err := updater.UpdateDbNetworkRestrictionsConfig(context.Background(), "test-project", networkRestrictions{
148+
Enabled: true,
149+
})
150+
// Check result
151+
assert.Error(t, err)
152+
assert.Contains(t, err.Error(), "unexpected status 400")
153+
assert.True(t, gock.IsDone())
154+
})
155+
}
156+
122157
func TestUpdateExperimentalConfig(t *testing.T) {
123158
server := "http://localhost"
124159
client, err := v1API.NewClientWithResponses(server)

0 commit comments

Comments
 (0)