Files
decort-golang-sdk/pkg/cloudbroker/apiaccess/list.go

80 lines
2.1 KiB
Go
Raw Normal View History

2023-06-23 15:13:22 +03:00
package apiaccess
import (
"context"
"encoding/json"
"net/http"
2024-04-16 14:26:06 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2023-06-23 15:13:22 +03:00
)
2023-10-23 12:40:54 +03:00
// ListRequest struct to get list of all non deleted apiaccess instances.
2023-06-23 15:13:22 +03:00
type ListRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by name apiaccess
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Find by status apiaccess
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
2025-05-07 13:15:39 +03:00
// Find by description
// Required: false
Desc string `url:"desc,omitempty" json:"desc,omitempty"`
2023-06-23 15:13:22 +03:00
// Find by created after time (unix timestamp)
// Required: false
2025-04-09 11:21:07 +03:00
CreatedAfter uint64 `url:"created_after,omitempty" json:"created_after,omitempty"`
2023-06-23 15:13:22 +03:00
// Find by created before time (unix timestamp)
// Required: false
2025-04-09 11:21:07 +03:00
CreatedBefore uint64 `url:"created_before,omitempty" json:"created_before,omitempty"`
2023-06-23 15:13:22 +03:00
2024-04-16 14:26:06 +03:00
// Sort by one of supported fields, format +|-(field)
// Required: false
2025-04-09 11:21:07 +03:00
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty" validate:"omitempty,sortBy"`
2024-04-16 14:26:06 +03:00
2023-06-23 15:13:22 +03:00
// 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"`
}
2023-10-23 12:40:54 +03:00
// List gets list of all non deleted apiaccess instances as a ListAPIAccess struct
2023-06-23 15:13:22 +03:00
func (a APIAccess) List(ctx context.Context, req ListRequest) (*ListAPIAccess, error) {
2024-04-16 14:26:06 +03:00
2023-10-23 12:40:54 +03:00
res, err := a.ListRaw(ctx, req)
2023-06-23 15:13:22 +03:00
if err != nil {
2023-10-23 12:40:54 +03:00
return nil, err
2023-06-23 15:13:22 +03:00
}
info := ListAPIAccess{}
2023-10-23 12:40:54 +03:00
err = json.Unmarshal(res, &info)
2023-06-23 15:13:22 +03:00
if err != nil {
return nil, err
}
2023-10-23 12:40:54 +03:00
return &info, nil
}
// ListRaw gets list of all non deleted apiaccess instances as an array of bytes
func (a APIAccess) 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 := "/cloudbroker/apiaccess/list"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
2023-06-23 15:13:22 +03:00
}