Skip to content

Commit ebc0fe6

Browse files
feat(iam): add a method to clone a policy (#1450)
Co-authored-by: Rémy Léone <[email protected]>
1 parent a86ff60 commit ebc0fe6

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

api/iam/v1alpha1/iam_sdk.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,37 @@ func (s *API) DeletePolicy(req *DeletePolicyRequest, opts ...scw.RequestOption)
17251725
return nil
17261726
}
17271727

1728+
type ClonePolicyRequest struct {
1729+
PolicyID string `json:"-"`
1730+
}
1731+
1732+
func (s *API) ClonePolicy(req *ClonePolicyRequest, opts ...scw.RequestOption) (*Policy, error) {
1733+
var err error
1734+
1735+
if fmt.Sprint(req.PolicyID) == "" {
1736+
return nil, errors.New("field PolicyID cannot be empty in request")
1737+
}
1738+
1739+
scwReq := &scw.ScalewayRequest{
1740+
Method: "POST",
1741+
Path: "/iam/v1alpha1/policies/" + fmt.Sprint(req.PolicyID) + "/clone",
1742+
Headers: http.Header{},
1743+
}
1744+
1745+
err = scwReq.SetBody(req)
1746+
if err != nil {
1747+
return nil, err
1748+
}
1749+
1750+
var resp Policy
1751+
1752+
err = s.client.Do(scwReq, &resp, opts...)
1753+
if err != nil {
1754+
return nil, err
1755+
}
1756+
return &resp, nil
1757+
}
1758+
17281759
type SetRulesRequest struct {
17291760
// PolicyID: id of policy to update
17301761
PolicyID string `json:"policy_id"`

0 commit comments

Comments
 (0)