You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.1 KiB
81 lines
2.1 KiB
package audit
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
)
|
|
|
|
// ListRequest struct to give list of account audits
|
|
type ListRequest struct {
|
|
|
|
// Find all audits after point in time (unixtime)
|
|
// Required: false
|
|
TimestampAt uint64 `url:"timestampAt,omitempty" json:"timestampAt,omitempty"`
|
|
|
|
// Find all audits before point in time (unixtime)
|
|
// Required: false
|
|
TimestampTo uint64 `url:"timestampTo,omitempty" json:"timestampTo,omitempty"`
|
|
|
|
// Find by user (Mongo RegExp supported)
|
|
// Required: false
|
|
User string `url:"user,omitempty" json:"user,omitempty"`
|
|
|
|
// Find by api endpoint (Mongo RegExp supported)
|
|
// Required: false
|
|
Call string `url:"call,omitempty" json:"call,omitempty"`
|
|
|
|
// Find by HTTP min status code
|
|
// Required: false
|
|
MinStatusCode uint64 `url:"minStatusCode,omitempty" json:"minStatusCode,omitempty"`
|
|
|
|
// Find by HTTP max status code
|
|
// Required: false
|
|
MaxStatusCode uint64 `url:"maxStatusCode,omitempty" json:"maxStatusCode,omitempty"`
|
|
|
|
// Sort by one of supported fields, format +|-(field)
|
|
// Required: false
|
|
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
|
|
|
// Page number
|
|
// Required: false
|
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
|
|
|
// Page size
|
|
// Required: false
|
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
|
}
|
|
|
|
// List gets audit records for the specified account object
|
|
func (a Audit) List(ctx context.Context, req ListRequest) (*ListAudits, error) {
|
|
|
|
res, err := a.ListRaw(ctx, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
list := ListAudits{}
|
|
|
|
err = json.Unmarshal(res, &list)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &list, nil
|
|
}
|
|
|
|
// ListRaw gets list of audit records an array of bytes
|
|
func (a Audit) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
|
|
|
if err := validators.ValidateRequest(req); err != nil {
|
|
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
}
|
|
|
|
url := "/cloudbroker/audit/list"
|
|
|
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
return res, err
|
|
}
|