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.
69 lines
1.7 KiB
69 lines
1.7 KiB
package user
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
)
|
|
|
|
// ListRequest struct to get all non deleted user instances.
|
|
type ListRequest struct {
|
|
// Find by ID.
|
|
// Required: false
|
|
ByID string `url:"by_id,omitempty" json:"by_id,omitempty"`
|
|
|
|
// Find by active. True or False.
|
|
// Required: false
|
|
Active bool `url:"active,omitempty" json:"active,omitempty"`
|
|
|
|
// Find by serviceaccount. True or False.
|
|
// Required: false
|
|
ServiceAccount bool `url:"serviceaccount,omitempty" json:"serviceaccount,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, maximum - 100.
|
|
// Required: false
|
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
|
}
|
|
|
|
// List gets all non deleted user instances as a ListUsers struct
|
|
func (u User) List(ctx context.Context, req ListRequest) (*ListUsers, error) {
|
|
|
|
res, err := u.ListRaw(ctx, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
list := ListUsers{}
|
|
|
|
err = json.Unmarshal(res, &list)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &list, nil
|
|
}
|
|
|
|
// ListRaw gets all non deleted user instances as an array of bytes
|
|
func (u User) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
|
|
|
err := validators.ValidateRequest(req)
|
|
if err != nil {
|
|
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
}
|
|
|
|
url := "/cloudbroker/user/list"
|
|
|
|
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
return res, err
|
|
}
|