package account import ( "context" "net/http" "strconv" "repository.basistech.ru/BASIS/dynamix-golang-sdk/v16/internal/validators" ) // AddStoragePolicyRequest struct for adding storage policy to the account type AddStoragePolicyRequest struct { // ID of account to add to // Required: true AccountID uint64 `url:"account_id" json:"account_id" validate:"required"` // ID of the storage policy to which to connect account // Required: true StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"` // Limit storage resources GB. Or -1 unlimit // Required: false Limit int `url:"limit,omitempty" json:"limit,omitempty"` } type wrapperAddStoragePolicyRequest struct { AddStoragePolicyRequest AsyncMode bool `url:"async_mode" json:"async_mode"` } // AddStoragePolicy add storage policy to the account. func (a Account) AddStoragePolicy(ctx context.Context, req AddStoragePolicyRequest) (bool, error) { err := validators.ValidateRequest(req) if err != nil { return false, validators.ValidationErrors(validators.GetErrors(err)) } url := "/cloudbroker/account/add_storage_policy" reqWrapped := wrapperAddStoragePolicyRequest{ AddStoragePolicyRequest: req, AsyncMode: false, } res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped) if err != nil { return false, err } result, err := strconv.ParseBool(string(res)) if err != nil { return false, err } return result, nil } // AddStoragePolicyAsync add storage policy to the account in async mode func (a Account) AddStoragePolicyAsync(ctx context.Context, req AddStoragePolicyRequest) (string, error) { err := validators.ValidateRequest(req) if err != nil { return "", validators.ValidationErrors(validators.GetErrors(err)) } url := "/cloudbroker/account/add_storage_policy" reqWrapped := wrapperAddStoragePolicyRequest{ AddStoragePolicyRequest: req, AsyncMode: true, } res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped) if err != nil { return "", err } return string(res), nil }