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.
85 lines
2.2 KiB
85 lines
2.2 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:"timestamp_at,omitempty" json:"timestamp_at,omitempty"`
|
|
|
|
// Find all audits before point in time (unixtime)
|
|
// Required: false
|
|
TimestampTo uint64 `url:"timestamp_to,omitempty" json:"timestamp_to,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 request id
|
|
// Required: false
|
|
RequestID string `url:"request_id,omitempty" json:"request_id,omitempty"`
|
|
|
|
// Find by HTTP min status code
|
|
// Required: false
|
|
MinStatusCode uint64 `url:"min_status_code,omitempty" json:"min_status_code,omitempty"`
|
|
|
|
// Find by HTTP max status code
|
|
// Required: false
|
|
MaxStatusCode uint64 `url:"max_status_code,omitempty" json:"max_status_code,omitempty"`
|
|
|
|
// Sort by one of supported fields, format +|-(field)
|
|
// Required: false
|
|
SortBy string `url:"sort_by,omitempty" json:"sort_by,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
|
|
}
|