Skip to content

Commit 04fb9ce

Browse files
authored
Merge pull request #53 from G-Core/feature/CDP-617_support_2_step_deletion
CDP-617 support 2-step deletion for rules and resources
2 parents 93a9598 + f6812cc commit 04fb9ce

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

resources/resources.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ type UpdateRequest struct {
5353
Options *gcore.Options `json:"options,omitempty"`
5454
}
5555

56+
type ActivateRequest struct {
57+
Active bool `json:"active"`
58+
}
59+
5660
type Resource struct {
5761
ID int64 `json:"id"`
5862
Name string `json:"name"`

resources/service.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ func (s *Service) Update(ctx context.Context, id int64, req *UpdateRequest) (*Re
4747

4848
func (s *Service) Delete(ctx context.Context, resourceID int64) error {
4949
path := fmt.Sprintf("/cdn/resources/%d", resourceID)
50+
51+
var body ActivateRequest = ActivateRequest{
52+
Active: false,
53+
}
54+
var resource Resource
55+
56+
// deactivate the resource instance before deletion
57+
if err := s.r.Request(ctx, http.MethodPatch, path, &body, &resource); err != nil {
58+
return fmt.Errorf("request: %w", err)
59+
}
60+
5061
if err := s.r.Request(ctx, http.MethodDelete, path, nil, nil); err != nil {
5162
return fmt.Errorf("request: %w", err)
5263
}

rules/rules.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ type UpdateRequest struct {
3535
Options *gcore.Options `json:"options,omitempty"`
3636
}
3737

38+
type ActivateRequest struct {
39+
Active bool `json:"active"`
40+
}
41+
3842
type Rule struct {
3943
ID int64 `json:"id"`
4044
Name string `json:"name"`

rules/service.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ func (s *Service) Update(ctx context.Context, resourceID, ruleID int64, req *Upd
5353

5454
func (s *Service) Delete(ctx context.Context, resourceID, ruleID int64) error {
5555
path := fmt.Sprintf("/cdn/resources/%d/rules/%d", resourceID, ruleID)
56+
57+
var body ActivateRequest = ActivateRequest{
58+
Active: false,
59+
}
60+
var rule Rule
61+
62+
// deactivate the rule instance before deletion
63+
if err := s.r.Request(ctx, http.MethodPatch, path, &body, &rule); err != nil {
64+
return fmt.Errorf("request: %w", err)
65+
}
66+
5667
if err := s.r.Request(ctx, http.MethodDelete, path, nil, nil); err != nil {
5768
return fmt.Errorf("request: %w", err)
5869
}

0 commit comments

Comments
 (0)