Skip to content

Commit

Permalink
feat(iam): add a method to clone a policy (#1450)
Browse files Browse the repository at this point in the history
Co-authored-by: Rémy Léone <[email protected]>
  • Loading branch information
scaleway-bot and remyleone authored Nov 3, 2022
1 parent a86ff60 commit ebc0fe6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions api/iam/v1alpha1/iam_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,37 @@ func (s *API) DeletePolicy(req *DeletePolicyRequest, opts ...scw.RequestOption)
return nil
}

type ClonePolicyRequest struct {
PolicyID string `json:"-"`
}

func (s *API) ClonePolicy(req *ClonePolicyRequest, opts ...scw.RequestOption) (*Policy, error) {
var err error

if fmt.Sprint(req.PolicyID) == "" {
return nil, errors.New("field PolicyID cannot be empty in request")
}

scwReq := &scw.ScalewayRequest{
Method: "POST",
Path: "/iam/v1alpha1/policies/" + fmt.Sprint(req.PolicyID) + "/clone",
Headers: http.Header{},
}

err = scwReq.SetBody(req)
if err != nil {
return nil, err
}

var resp Policy

err = s.client.Do(scwReq, &resp, opts...)
if err != nil {
return nil, err
}
return &resp, nil
}

type SetRulesRequest struct {
// PolicyID: id of policy to update
PolicyID string `json:"policy_id"`
Expand Down

0 comments on commit ebc0fe6

Please sign in to comment.