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.
59 lines
1.6 KiB
59 lines
1.6 KiB
package account
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
)
|
|
|
|
// GetConsumptionRequest struct to download the resources tracking files for an account
|
|
type GetConsumptionRequest struct {
|
|
// ID an account
|
|
// Required: true
|
|
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
|
|
// Epoch represents the start time
|
|
// Required: true
|
|
Start float64 `url:"start" json:"start" validate:"required"`
|
|
|
|
// Epoch represents the end time
|
|
// Required: true
|
|
End float64 `url:"end" json:"end" validate:"required"`
|
|
}
|
|
|
|
// GetConsumption downloads the resources tracking files for an account within a given period
|
|
func (a Account) GetConsumption(ctx context.Context, req GetConsumptionRequest) (string, error) {
|
|
err := validators.ValidateRequest(req)
|
|
if err != nil {
|
|
return "", validators.ValidationErrors(validators.GetErrors(err))
|
|
}
|
|
|
|
url := "/cloudapi/account/getConsumption"
|
|
|
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return string(res), nil
|
|
|
|
}
|
|
|
|
// GetConsumptionGet downloads the resources tracking files for an account within a given period
|
|
func (a Account) GetConsumptionGet(ctx context.Context, req GetConsumptionRequest) (string, error) {
|
|
err := validators.ValidateRequest(req)
|
|
if err != nil {
|
|
return "", validators.ValidationErrors(validators.GetErrors(err))
|
|
}
|
|
|
|
url := "/cloudapi/account/getConsumption"
|
|
|
|
res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return string(res), nil
|
|
}
|