update go.mod and imports

This commit is contained in:
2023-03-17 12:54:34 +03:00
parent f3a1a4c83f
commit 437841c8dd
268 changed files with 4019 additions and 2045 deletions

View File

@@ -2,7 +2,7 @@
package account
import (
"repos.digitalenergy.online/BASIS/decort-golang-sdk/interfaces"
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
)
// Structure for creating request to account

View File

@@ -2,54 +2,37 @@ package account
import (
"context"
"errors"
"net/http"
"strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for adding permission to access to account for a user
type AddUserRequest struct {
// ID of account to add to
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Name of the user to be given rights
// Required: true
UserID string `url:"userId" json:"userId"`
UserID string `url:"userId" json:"userId" validate:"required"`
// Account permission types:
// - 'R' for read only access
// - 'RCX' for Write
// - 'ARCXDU' for Admin
// Required: true
AccessType string `url:"accesstype" json:"accesstype"`
}
func (arq AddUserRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
if arq.UserID == "" {
return errors.New("validation-error: field UserID can not be empty")
}
if arq.AccessType == "" {
return errors.New("validation-error: field AccessType can not be empty")
}
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
if !isValid {
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
}
return nil
AccessType string `url:"accesstype" json:"accesstype" validate:"required,accountAccessType"`
}
// AddUser gives a user access rights.
func (a Account) AddUser(ctx context.Context, req AddUserRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/addUser"

View File

@@ -3,30 +3,25 @@ package account
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for give list account audits
type AuditsRequest struct {
// ID of the account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
}
func (arq AuditsRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// Audits gets audit records for the specified account object
func (a Account) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/audits"

View File

@@ -2,24 +2,25 @@ package account
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for creating account
type CreateRequest struct {
// Display name
// Required: true
Name string `url:"name" json:"name"`
Name string `url:"name" json:"name" validate:"required"`
// Name of the account
// Required: true
Username string `url:"username" json:"username"`
Username string `url:"username" json:"username" validate:"required"`
// Email
// Required: false
EmailAddress string `url:"emailaddress,omitempty" json:"emailaddress,omitempty"`
EmailAddress string `url:"emailaddress,omitempty" json:"emailaddress,omitempty" validate:"omitempty,email"`
// Max size of memory in MB
// Required: false
@@ -50,23 +51,14 @@ type CreateRequest struct {
GPUUnits int64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"`
}
func (arq CreateRequest) validate() error {
if arq.Name == "" {
return errors.New("validation-error: field Name can not be empty")
}
if arq.Username == "" {
return errors.New("validation-error: field Username can not be empty")
}
return nil
}
// Create creates account
// Setting a cloud unit maximum to -1 or empty will not put any restrictions on the resource
func (a Account) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return 0, err
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/create"

View File

@@ -2,33 +2,29 @@ package account
import (
"context"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for delete account
type DeleteRequest struct {
// ID of account to delete
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Whether to completely delete the account
// Required: false
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
}
func (arq DeleteRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID must be set")
}
return nil
}
// Delete completes delete an account from the system Returns true if account is deleted or was already deleted or never existed
func (a Account) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/delete"

View File

@@ -2,42 +2,34 @@ package account
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for revoke access to account
type DeleteUserRequest struct {
// ID of the account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// ID or emailaddress of the user to remove
// Required: true
UserID string `url:"userId" json:"userId"`
UserID string `url:"userId" json:"userId" validate:"required"`
// Recursively revoke access rights from owned cloudspaces and vmachines
// Required: false
RecursiveDelete bool `url:"recursivedelete,omitempty" json:"recursivedelete,omitempty"`
}
func (arq DeleteUserRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
if arq.UserID == "" {
return errors.New("validation-error: field UserID can not be empty")
}
return nil
}
// DeleteUser revokes user access from the account
func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/deleteUser"

View File

@@ -2,31 +2,26 @@ package account
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for change status of account
type DisabelEnableRequest struct {
type DisableEnableRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
}
func (arq DisabelEnableRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// Disable disables an account
func (a Account) Disable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
err := req.validate()
func (a Account) Disable(ctx context.Context, req DisableEnableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/disable"
@@ -45,10 +40,12 @@ func (a Account) Disable(ctx context.Context, req DisabelEnableRequest) (bool, e
}
// Enable enables an account
func (a Account) Enable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
err := req.validate()
func (a Account) Enable(ctx context.Context, req DisableEnableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/enable"

View File

@@ -3,30 +3,25 @@ package account
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get information about account
type GetRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
}
func (arq GetRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// Get gets account details
func (a Account) Get(ctx context.Context, req GetRequest) (*RecordAccount, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/get"

View File

@@ -3,23 +3,16 @@ package account
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for calculate the currently consumed units for all cloudspaces and resource groups in the account
type GetConsumedAccountUnitsRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
}
func (arq GetConsumedAccountUnitsRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// GetConsumedAccountUnits calculates the currently consumed units for all cloudspaces and resource groups in the account.
@@ -29,9 +22,11 @@ func (arq GetConsumedAccountUnitsRequest) validate() error {
// - CU_D: consumed vdisk storage in GB
// - CU_I: number of public IPs
func (a Account) GetConsumedAccountUnits(ctx context.Context, req GetConsumedAccountUnitsRequest) (*ResourceLimits, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/getConsumedAccountUnits"

View File

@@ -2,37 +2,21 @@ package account
import (
"context"
"errors"
"net/http"
"strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for calculate the currently consumed cloud units of the specified type for all cloudspaces and resource groups in the account
type GetConsumedCloudUnitsByTypeRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Cloud unit resource type
// Required: true
CUType string `url:"cutype" json:"cutype"`
}
func (arq GetConsumedCloudUnitsByTypeRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
if arq.CUType == "" {
return errors.New("validation-error: field CUType can not be empty")
}
isValid := validators.StringInSlice(arq.CUType, []string{"CU_M", "CU_C", "CU_D", "CU_S", "CU_A", "CU_NO", "CU_I", "CU_NP"})
if !isValid {
return errors.New("validation-error: field AccessType can be only CU_M, CU_C, CU_D, CU_S, CU_A, CU_NO, CU_I or CU_NP")
}
return nil
CUType string `url:"cutype" json:"cutype" validate:"required,accountCUType"`
}
// GetConsumedCloudUnitsByType calculates the currently consumed cloud units of the specified type for all cloudspaces
@@ -48,9 +32,11 @@ func (arq GetConsumedCloudUnitsByTypeRequest) validate() error {
// - CU_NP: returns sent/received network transfer peering in GB
// - CU_I: returns number of public IPs
func (a Account) GetConsumedCloudUnitsByType(ctx context.Context, req GetConsumedCloudUnitsByTypeRequest) (float64, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return 0, err
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/getConsumedCloudUnitsByType"

View File

@@ -2,47 +2,36 @@ package account
import (
"context"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for download the resources tracking files for an account
type GetConsumtionRequest struct {
type GetConsumptionRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Epoch represents the start time
// Required: true
Start uint64 `url:"start" json:"start"`
Start uint64 `url:"start" json:"start" validate:"required"`
// Epoch represents the end time
// Required: true
End uint64 `url:"end" json:"end"`
End uint64 `url:"end" json:"end" validate:"required"`
}
func (arq GetConsumtionRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
if arq.Start == 0 {
return errors.New("validation-error: field Start can not be empty or equal to 0")
}
if arq.End == 0 {
return errors.New("validation-error: field End can not be empty or equal to 0")
}
return nil
}
// GetConsumtion downloads the resources tracking files for an account within a given period
func (a Account) GetConsumtion(ctx context.Context, req GetConsumtionRequest) (string, error) {
err := req.validate()
// 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 "", err
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/getConsumtion"
url := "/cloudapi/account/getConsumption"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
@@ -53,14 +42,16 @@ func (a Account) GetConsumtion(ctx context.Context, req GetConsumtionRequest) (s
}
// GetConsumtionGet downloads the resources tracking files for an account within a given period
func (a Account) GetConsumtionGet(ctx context.Context, req GetConsumtionRequest) (string, error) {
err := req.validate()
// 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 "", err
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi//account/getConsumtion"
url := "/cloudapi/account/getConsumption"
res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req)
if err != nil {

View File

@@ -3,23 +3,16 @@ package account
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for calculate the reserved units for all cloudspaces and resource groups in the account
type GetReservedAccountUnitsRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
}
func (arq GetReservedAccountUnitsRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// GetReservedAccountUnits calculates the reserved units for all cloudspaces and resource groups in the account.
@@ -30,9 +23,11 @@ func (arq GetReservedAccountUnitsRequest) validate() error {
// - CU_D: reserved vdisk storage in GB
// - CU_I: number of public IPs
func (a Account) GetReservedAccountUnits(ctx context.Context, req GetReservedAccountUnitsRequest) (*ResourceLimits, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/getReservedAccountUnits"

View File

@@ -3,30 +3,25 @@ package account
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for a get list compute instances
type ListComputesRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
}
func (arq ListComputesRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// ListComputes gets list all compute instances under specified account, accessible by the user
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (ListComputes, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/listComputes"

View File

@@ -3,30 +3,25 @@ package account
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list deleted disks
type ListDisksRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
}
func (arq ListDisksRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// ListDisks gets list all currently unattached disks under specified account
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (ListDisks, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/listDisks"

View File

@@ -3,30 +3,25 @@ package account
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list FLIPGroups
type ListFLIPGroupsRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
}
func (arq ListFLIPGroupsRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// ListFLIPGroups gets list all FLIPGroups under specified account, accessible by the user
func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest) (ListFLIPGroups, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/listFlipGroups"

View File

@@ -3,30 +3,25 @@ package account
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list resource groups
type ListRGRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
}
func (arq ListRGRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// ListRG gets list all resource groups under specified account, accessible by the user
func (a Account) ListRG(ctx context.Context, req ListRGRequest) (ListRG, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/listRG"

View File

@@ -3,34 +3,29 @@ package account
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list templates
type ListTemplatesRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Include deleted images
// Required: false
IncludeDeleted bool `url:"includedeleted" json:"includedeleted"`
}
func (arq ListTemplatesRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
}
// ListTemplates gets list templates which can be managed by this account
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (ListTemplates, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/listTemplates"

View File

@@ -3,30 +3,25 @@ package account
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list VINS
type ListVINSRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
}
func (arq ListVINSRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// ListVINS gets list all ViNSes under specified account, accessible by the user
func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/listVins"

View File

@@ -2,31 +2,26 @@ package account
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for restore a deleted account
type RestoreRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
}
func (arq RestoreRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// Restore restores a deleted account
func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/restore"

View File

@@ -3,7 +3,7 @@ package account
import (
"encoding/json"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/serialization"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/serialization"
)
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.

View File

@@ -2,16 +2,17 @@ package account
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for updaate account
type UpdateRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Name of the account
// Required: false
@@ -46,19 +47,13 @@ type UpdateRequest struct {
GPUUnits uint64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"`
}
func (arq UpdateRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
return nil
}
// Update updates an account name and resource types and limits
func (a Account) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/update"

View File

@@ -2,54 +2,37 @@ package account
import (
"context"
"errors"
"net/http"
"strconv"
"repos.digitalenergy.online/BASIS/decort-golang-sdk/internal/validators"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for update user access rights
type UpdateUserRequest struct {
// ID of the account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Userid/Email for registered users or emailaddress for unregistered users
// Required: true
UserID string `url:"userId" json:"userId"`
UserID string `url:"userId" json:"userId" validate:"required"`
// Account permission types:
// - 'R' for read only access
// - 'RCX' for Write
// - 'ARCXDU' for Admin
// Required: true
AccessType string `url:"accesstype" json:"accesstype"`
}
func (arq UpdateUserRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
if arq.UserID == "" {
return errors.New("validation-error: field UserID can not be empty")
}
if arq.AccessType == "" {
return errors.New("validation-error: field AccessType can not be empty")
}
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
if !isValid {
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
}
return nil
AccessType string `url:"accesstype" json:"accesstype" validate:"required,accountAccessType"`
}
// UpdateUser updates user access rights
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/updateUser"