-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(accept-risk) accept posture risk (#556)
* accept posture risk * fix name * fix * fix * Refactor attribute section in secure posture accept risk documentation * fix test * fix * fix * open the option to put expires_at * ExpiresAt must be in the future * fix docs * fix * fix * fix * add fix
- Loading branch information
1 parent
8633c57
commit 740b2d2
Showing
8 changed files
with
645 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package v2 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
) | ||
|
||
const ( | ||
AcceptPostureRiskCreatePath = "%s/api/cspm/v1/compliance/risk-acceptances" | ||
AcceptPostureRiskGetPath = "%s/api/cspm/v1/compliance/risk-acceptances/%s" | ||
AcceptPostureRiskDelete = "%s/api/cspm/v1/compliance/violations/revoke" | ||
AcceptPostureRiskUpdate = "%s/api/cspm/v1/compliance/risk-acceptances/%s" | ||
) | ||
|
||
type PostureAcceptRiskInterface interface { | ||
Base | ||
SaveAcceptPostureRisk(ctx context.Context, p *AccepetPostureRiskRequest) (*AcceptPostureRiskResponse, string, error) | ||
GetAcceptancePostureRisk(ctx context.Context, id string) (*AcceptPostureRiskResponse, string, error) | ||
DeleteAcceptancePostureRisk(ctx context.Context, p *DeleteAcceptPostureRisk) error | ||
UpdateAcceptancePostureRisk(ctx context.Context, p *UpdateAccepetPostureRiskRequest) (*AcceptPostureRisk, string, error) | ||
} | ||
|
||
func (c *Client) SaveAcceptPostureRisk(ctx context.Context, p *AccepetPostureRiskRequest) (*AcceptPostureRiskResponse, string, error) { | ||
payload, err := Marshal(p) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
response, err := c.requester.Request(ctx, http.MethodPost, c.getPostureControlURL(AcceptPostureRiskCreatePath), payload) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
|
||
defer response.Body.Close() | ||
if response.StatusCode != http.StatusOK && response.StatusCode != http.StatusCreated { | ||
errStatus, err := c.ErrorAndStatusFromResponse(response) | ||
return nil, errStatus, err | ||
} | ||
resp, err := Unmarshal[AcceptPostureRiskResponse](response.Body) | ||
|
||
if err != nil { | ||
return nil, "", err | ||
} | ||
|
||
return &resp, "", nil | ||
} | ||
|
||
func (c *Client) GetAcceptancePostureRisk(ctx context.Context, id string) (*AcceptPostureRiskResponse, string, error) { | ||
response, err := c.requester.Request(ctx, http.MethodGet, fmt.Sprintf(AcceptPostureRiskGetPath, c.config.url, id), nil) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
defer response.Body.Close() | ||
|
||
if response.StatusCode != http.StatusOK { | ||
errStatus, err := c.ErrorAndStatusFromResponse(response) | ||
return nil, errStatus, err | ||
} | ||
|
||
wrapper, err := Unmarshal[AcceptPostureRiskResponse](response.Body) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
return &wrapper, "", nil | ||
} | ||
|
||
func (c *Client) DeleteAcceptancePostureRisk(ctx context.Context, p *DeleteAcceptPostureRisk) error { | ||
payload, err := Marshal(p) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
response, err := c.requester.Request(ctx, http.MethodPost, fmt.Sprintf(AcceptPostureRiskDelete, c.config.url), payload) | ||
if err != nil { | ||
return err | ||
} | ||
defer response.Body.Close() | ||
|
||
if response.StatusCode != http.StatusNoContent && response.StatusCode != http.StatusOK && response.StatusCode != http.StatusNotFound { | ||
return c.ErrorFromResponse(response) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *Client) UpdateAcceptancePostureRisk(ctx context.Context, p *UpdateAccepetPostureRiskRequest) (*AcceptPostureRisk, string, error) { | ||
payload, err := Marshal(p) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
response, err := c.requester.Request(ctx, http.MethodPatch, fmt.Sprintf(AcceptPostureRiskUpdate, c.config.url, p.AcceptanceID), payload) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
defer response.Body.Close() | ||
if response.StatusCode != http.StatusOK && response.StatusCode != http.StatusCreated { | ||
errStatus, err := c.ErrorAndStatusFromResponse(response) | ||
return nil, errStatus, err | ||
} | ||
resp, err := Unmarshal[AcceptPostureRiskResponse](response.Body) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
|
||
return &resp.Data, "", nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.