Files
decort-golang-sdk/pkg/cloudapi/account/list.go

77 lines
1.8 KiB
Go
Raw Normal View History

2022-10-03 16:56:47 +03:00
package account
import (
"context"
"encoding/json"
"net/http"
2024-04-16 14:26:06 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-10-03 16:56:47 +03:00
)
2023-10-23 12:40:54 +03:00
// ListRequest struct to get list of accounts
2022-10-03 16:56:47 +03:00
type ListRequest struct {
2023-06-30 11:21:47 +03:00
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name
// Required: false
2023-07-07 12:40:03 +03:00
Name string `url:"name,omitempty" json:"name,omitempty"`
2023-06-30 11:21:47 +03:00
// Find by access control list
// Required: false
ACL string `url:"acl,omitempty" json:"acl,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
2024-04-16 14:26:06 +03:00
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
2025-08-29 12:51:25 +03:00
// Sort by zone id
// Default value: 0
// Required: false
ZoneID uint64 `url:"zone_id,omitempty" json:"zone_id,omitempty"`
2022-12-22 17:56:47 +03:00
// Page number
// Required: false
2023-06-30 11:21:47 +03:00
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
2022-12-22 17:56:47 +03:00
// Page size
// Required: false
2023-06-30 11:21:47 +03:00
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
2022-10-03 16:56:47 +03:00
}
2023-10-23 12:40:54 +03:00
// List gets a list of all accounts the user has access to a ListAccounts struct
2023-06-30 11:21:47 +03:00
func (a Account) List(ctx context.Context, req ListRequest) (*ListAccounts, error) {
2024-04-16 14:26:06 +03:00
2023-10-23 12:40:54 +03:00
res, err := a.ListRaw(ctx, req)
2022-10-03 16:56:47 +03:00
if err != nil {
return nil, err
}
2022-12-22 17:56:47 +03:00
list := ListAccounts{}
2022-10-03 16:56:47 +03:00
2022-12-22 17:56:47 +03:00
err = json.Unmarshal(res, &list)
2022-10-03 16:56:47 +03:00
if err != nil {
return nil, err
}
2023-06-30 11:21:47 +03:00
return &list, nil
2022-10-03 16:56:47 +03:00
}
2023-10-23 12:40:54 +03:00
// ListRaw gets a list of all accounts the user has access to as an array of bytes
func (a Account) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
2024-04-16 14:26:06 +03:00
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
2023-10-23 12:40:54 +03:00
url := "/cloudapi/account/list"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}