diff --git a/pkg/v2/base.go b/pkg/v2/base.go index 3384f56..9f7b441 100644 --- a/pkg/v2/base.go +++ b/pkg/v2/base.go @@ -7,11 +7,12 @@ import ( ) const ( - rootPath = "/zones" - zonePath = "/zones/%v" - zonePathUpdateState = "/zones/%v/state" - rrsetPath = "/zones/%v/rrset" - singleRRSetPath = "/zones/%v/rrset/%v" + rootPath = "/zones" + zonePath = "/zones/%v" + zonePathUpdateState = "/zones/%v/state" + zonePathUpdateProtection = "/zones/%v/protection" + rrsetPath = "/zones/%v/rrset" + singleRRSetPath = "/zones/%v/rrset/%v" ) type ( @@ -31,6 +32,7 @@ type ( DeleteZone(ctx context.Context, zoneID string) error UpdateZoneState(ctx context.Context, zoneID string, disabled bool) error UpdateZoneComment(ctx context.Context, zoneID string, comment string) error + UpdateProtectionState(ctx context.Context, zoneID string, protected bool) error } RRSetManager[S any] interface { diff --git a/pkg/v2/testing/test_utils.go b/pkg/v2/testing/test_utils.go index ee6346c..f97db47 100644 --- a/pkg/v2/testing/test_utils.go +++ b/pkg/v2/testing/test_utils.go @@ -17,11 +17,12 @@ const ( ) const ( - rootPath = "/zones" - zonePath = "/zones/%v" - zonePathUpdateState = "/zones/%v/state" - rrsetPath = "/zones/%v/rrset" - singleRRSetPath = "/zones/%v/rrset/%v" + rootPath = "/zones" + zonePath = "/zones/%v" + zonePathUpdateState = "/zones/%v/state" + zonePathUpdateProtection = "/zones/%v/protection" + rrsetPath = "/zones/%v/rrset" + singleRRSetPath = "/zones/%v/rrset/%v" ) var ( diff --git a/pkg/v2/testing/zoneManager_test.go b/pkg/v2/testing/zoneManager_test.go index 9adc457..8a134eb 100644 --- a/pkg/v2/testing/zoneManager_test.go +++ b/pkg/v2/testing/zoneManager_test.go @@ -147,3 +147,16 @@ func (s *ZoneManageSuite) TestUpdateZoneState_state_updated() { s.Nil(err) } + +func (s *ZoneManageSuite) TestUpdateProtectionState_OK() { + path := fmt.Sprintf(zonePathUpdateProtection, testID) + httpmock.RegisterResponder( + http.MethodPatch, + fmt.Sprintf("%s%s", testAPIURL, path), + httpmock.NewBytesResponder(http.StatusNoContent, []byte{}), + ) + + err := testClient.UpdateProtectionState(testCtx, testID, true) + + s.Nil(err) +} diff --git a/pkg/v2/zoneManager.go b/pkg/v2/zoneManager.go index a36d4b9..6a522ba 100644 --- a/pkg/v2/zoneManager.go +++ b/pkg/v2/zoneManager.go @@ -40,6 +40,9 @@ type ( zoneUpdateState struct { Disabled bool `json:"disabled"` } + zoneProtectionState struct { + Protected bool `json:"protected"` + } ) func (z *Zone) CreationForm() (io.Reader, error) { @@ -123,3 +126,20 @@ func (c *Client) UpdateZoneState(ctx context.Context, zoneID string, disabled bo return err } + +// UpdateProtectionState request to enable/disable zone protection from delete operation. +func (c *Client) UpdateProtectionState(ctx context.Context, zoneID string, protected bool) error { + updateState, err := json.Marshal(zoneProtectionState{ + Protected: protected, + }) + if err != nil { + return fmt.Errorf("zone marshal: %w", err) + } + form := bytes.NewReader(updateState) + r, e := c.prepareRequest( + ctx, http.MethodPatch, fmt.Sprintf(zonePathUpdateProtection, zoneID), form, nil, nil, + ) + _, err = processRequest[Zone](c.httpClient, r, e) + + return err +}