This commit is contained in:
2023-10-23 12:40:54 +03:00
parent b069c31745
commit b666789c7d
73 changed files with 1134 additions and 641 deletions

View File

@@ -8,15 +8,32 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get information about account
// GetRequest struct to get information about account
type GetRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// Get gets information about account
// Get gets information about account as a RecordAccount struct
func (a Account) Get(ctx context.Context, req GetRequest) (*RecordAccount, error) {
res, err := a.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := RecordAccount{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets information about account as an array of bytes
func (a Account) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
@@ -26,17 +43,6 @@ func (a Account) Get(ctx context.Context, req GetRequest) (*RecordAccount, error
url := "/cloudbroker/account/get"
info := RecordAccount{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
return res, err
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// Request struct for get list of accounts
// ListRequest struct to get list of accounts
type ListRequest struct {
// Find by ID
// Required: false
@@ -33,11 +33,9 @@ type ListRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list all accounts the user has access to
// List gets list of all accounts the user has access to as a ListAccounts struct
func (a Account) List(ctx context.Context, req ListRequest) (*ListAccounts, error) {
url := "/cloudbroker/account/list"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := a.ListRaw(ctx, req)
if err != nil {
return nil, err
}
@@ -51,3 +49,11 @@ func (a Account) List(ctx context.Context, req ListRequest) (*ListAccounts, erro
return &list, nil
}
// ListRaw gets 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) {
url := "/cloudbroker/account/list"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -29,10 +29,10 @@ type RecordResourceConsumption struct {
type ItemResourceConsumption struct {
// Current information about resources
Current Resource `json:"Current"`
Consumed Resource `json:"consumed"`
// Reserved information about resources
Reserved Resource `json:"Reserved"`
Reserved Resource `json:"reserved"`
// ID of account
AccountID uint64 `json:"id"`
@@ -54,7 +54,7 @@ type Resource struct {
DiskSize float64 `json:"disksize"`
// Disk size max
DiskSizeMax uint64 `json:"disksizemax"`
DiskSizeMax float64 `json:"disksizemax"`
// Number of External IPs
ExtIPs int64 `json:"extips"`
@@ -414,33 +414,6 @@ type Computes struct {
Stopped uint64 `json:"Stopped"`
}
// Consumed
type Consumed struct {
// Number of CPU
CPU uint64 `json:"cpu"`
// Disk size
DiskSize float64 `json:"disksize"`
// Disk size max
DiskSizeMax int64 `json:"disksizemax"`
// External IPs
ExtIPs uint64 `json:"extips"`
// External traffic
ExtTraffic uint64 `json:"exttraffic"`
// Number of GPU
GPU uint64 `json:"gpu"`
// Number of RAM
RAM uint64 `json:"ram"`
// SEPs
SEPs map[string]map[string]DiskUsage `json:"seps"`
}
// Limits
type Limits struct {
// Number of CPU
@@ -471,7 +444,7 @@ type Limits struct {
// Resources of resource group
type RGResuorces struct {
// Consumed
Consumed Consumed `json:"Consumed"`
Consumed Resource `json:"Consumed"`
// Limits
Limits Limits `json:"Limits"`