This commit is contained in:
stSolo
2022-12-22 17:56:47 +03:00
parent 8712561853
commit d4b1ab7133
672 changed files with 28509 additions and 4419 deletions

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get audit
type AuditsRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId"`
}
func (rgrq AuditsRequest) Validate() error {
func (rgrq AuditsRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
@@ -19,21 +22,26 @@ func (rgrq AuditsRequest) Validate() error {
return nil
}
func (r RG) Audits(ctx context.Context, req AuditsRequest) (AuditList, error) {
if err := req.Validate(); err != nil {
return nil, err
}
url := "/cloudapi/rg/audits"
auditListRaw, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
// Audits gets audit records for the specified resource group object
func (r RG) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
err := req.validate()
if err != nil {
return nil, err
}
auditList := AuditList{}
if err := json.Unmarshal(auditListRaw, &auditList); err != nil {
url := "/cloudapi/rg/audits"
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
return auditList, nil
list := ListAudits{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
}