This commit is contained in:
2023-03-24 17:09:30 +03:00
parent 437841c8dd
commit 84b64b7d80
433 changed files with 4246 additions and 6516 deletions

View File

@@ -2,7 +2,6 @@ package account
import (
"context"
"errors"
"net/http"
"strconv"
@@ -13,43 +12,27 @@ import (
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
UserName string `url:"username" json:"username"`
Username string `url:"username" json:"username" 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.UserName == "" {
return errors.New("validation-error: field UserName can not be empty")
}
if arq.AccessType == "" {
return errors.New("validation-error: field AccessType can not be empty")
}
validate := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
if !validate {
return errors.New("validation-error: field AccessType can be only R, RCX or ARCXDU")
}
return nil
AccessType string `url:"accesstype" json:"accesstype" validate:"accessType"`
}
// 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 := "/cloudbroker/account/addUser"

View File

@@ -3,29 +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 := "/cloudbroker/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
@@ -55,23 +56,14 @@ type CreateRequest struct {
UniqPools []string `url:"uniqPools,omitempty" json:"uniqPools,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 := "/cloudbroker/account/create"

View File

@@ -2,41 +2,33 @@ 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"`
// Reason to delete
// Required: true
Reason string `url:"reason" json:"reason"`
Reason string `url:"reason" json:"reason" 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")
}
if arq.Reason == "" {
return errors.New("validation-error: field Reason 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 := "/cloudbroker/account/delete"

View File

@@ -2,41 +2,33 @@ package account
import (
"context"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for delete group accounts
type DeleteAccountsRequest struct {
// IDs of accounts
// Required: true
AccountsIDs []uint64 `url:"accountIds" json:"accountIds"`
AccountsIDs []uint64 `url:"accountIds" json:"accountIds" validate:"min=1"`
// Reason for deletion
// Required: true
Reason string `url:"reason" json:"reason"`
Reason string `url:"reason" json:"reason" validate:"required"`
// Whether to completely destroy accounts or not
// Required: false
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
}
func (arq DeleteAccountsRequest) validate() error {
if len(arq.AccountsIDs) == 0 {
return errors.New("validation-error: field AccountIDs must be set")
}
if arq.Reason == "" {
return errors.New("validation-error: field Reason must be set")
}
return nil
}
// DeleteAccounts destroy a group of accounts
func (a Account) DeleteAccounts(ctx context.Context, req DeleteAccountsRequest) (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 := "/cloudbroker/account/deleteAccounts"

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
UserName string `url:"username" json:"username"`
UserName string `url:"username" json:"username" 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 must be set")
}
if arq.UserName == "" {
return errors.New("validation-error: field UserName must be set")
}
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 := "/cloudbroker/account/deleteUser"

View File

@@ -2,38 +2,30 @@ package account
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for disable account
type DisableRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Reason to disable
// Required: true
Reason string `url:"reason" json:"reason"`
}
func (arq DisableRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID must be set")
}
if arq.Reason == "" {
return errors.New("validation-error: field Reason must be set")
}
return nil
Reason string `url:"reason" json:"reason" validate:"required"`
}
// Disable disables an account
func (a Account) Disable(ctx context.Context, req DisableRequest) (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 := "/cloudbroker/account/disable"

View File

@@ -2,30 +2,25 @@ package account
import (
"context"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for disable group accounts
type DisableAccountsRequest struct {
// IDs of accounts
// Required: true
AccountIDs []uint64 `url:"accountIds,omitempty" json:"accountIds,omitempty"`
}
func (arq DisableAccountsRequest) validate() error {
if len(arq.AccountIDs) == 0 {
return errors.New("validation-error: field AccountIDs must be set")
}
return nil
AccountIDs []uint64 `url:"accountIds" json:"accountIds" validate:"min=1"`
}
// DisableAccounts disables accounts
func (a Account) DisableAccounts(ctx context.Context, req DisableAccountsRequest) (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 := "/cloudbroker/account/disableAccounts"

View File

@@ -2,38 +2,30 @@ package account
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for enable account
type EnableRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Reason to enable
// Required: true
Reason string `url:"reason" json:"reason"`
}
func (arq EnableRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID must be set")
}
if arq.Reason == "" {
return errors.New("field Reason must be set")
}
return nil
Reason string `url:"reason" json:"reason" validate:"required"`
}
// Enable enables an account
func (a Account) Enable(ctx context.Context, req EnableRequest) (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 := "/cloudbroker/account/enable"

View File

@@ -2,30 +2,25 @@ package account
import (
"context"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request for enable group accounts
type EnableAccountsRequest struct {
// IDs od accounts
// Required: true
AccountIDs []uint64 `url:"accountIds" json:"accountIds"`
}
func (arq EnableAccountsRequest) validate() error {
if len(arq.AccountIDs) == 0 {
return errors.New("validation-error: field AccountIDs must be set")
}
return nil
AccountIDs []uint64 `url:"accountIds" json:"accountIds" validate:"min=1"`
}
// EnableAccounts enables accounts
func (a Account) EnableAccounts(ctx context.Context, req EnableAccountsRequest) (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 := "/cloudbroker/account/enableAccounts"

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 must be set")
}
return nil
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// Get gets information about account
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 := "/cloudbroker/account/get"

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 must be set")
}
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 := "/cloudbroker/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 must be set")
}
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 := "/cloudbroker/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 must be set")
}
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 := "/cloudbroker/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 must be set")
}
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 := "/cloudbroker/account/listRG"

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 must be set")
}
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 := "/cloudbroker/account/listVins"

View File

@@ -2,37 +2,29 @@ package account
import (
"context"
"errors"
"net/http"
"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"`
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Reason to restore
// Required: true
Reason string `url:"reason" json:"reason"`
}
func (arq RestoreRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID must be set")
}
if arq.Reason == "" {
return errors.New("validation-error: field Reason must be set")
}
return nil
Reason string `url:"reason" json:"reason" 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 := "/cloudbroker/account/restore"

View File

@@ -2,28 +2,29 @@ package account
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for update account
type UpdateRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// 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,omitempty" json:"username,omitempty"`
// 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
@@ -59,22 +60,13 @@ type UpdateRequest struct {
UniqPools []string `url:"uniqPools,omitempty" json:"uniqPools,omitempty"`
}
func (arq UpdateRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID must be set")
}
if arq.Name == "" {
return errors.New("validation-error: field Name must be set")
}
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 := "/cloudbroker/account/update"

View File

@@ -2,7 +2,6 @@ package account
import (
"context"
"errors"
"net/http"
"strconv"
@@ -13,7 +12,7 @@ import (
type UpdateResourceTypesRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Resource types available to create in this account
// Each element in a resource type slice must be one of:
@@ -24,29 +23,15 @@ type UpdateResourceTypesRequest struct {
// - lb
// - flipgroup
// Required: true
ResTypes []string `url:"resourceTypes" json:"resourceTypes"`
}
func (arq UpdateResourceTypesRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID must be set")
}
if len(arq.ResTypes) > 0 {
for _, value := range arq.ResTypes {
validate := validators.StringInSlice(value, []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"})
if !validate {
return errors.New("validation-error: Every resource type specified should be one of [compute, vins, k8s, openshift, lb, flipgroup]")
}
}
}
return nil
ResTypes []string `url:"resourceTypes" json:"resourceTypes" validate:"min=1,resTypes"`
}
func (a Account) UpdateResourceTypes(ctx context.Context, req UpdateResourceTypesRequest) (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 := "/cloudbroker/account/updateResourceTypes"

View File

@@ -2,48 +2,37 @@ package account
import (
"context"
"errors"
"net/http"
"strconv"
"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 must be set")
}
if arq.UserID == "" {
return errors.New("validation-error: field UserID must be set")
}
if arq.AccessType == "" {
return errors.New("validation-error: field AccessType must be set")
}
return nil
AccessType string `url:"accesstype" json:"accesstype" validate:"accessType"`
}
// 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 := "/cloudbroker/account/updateUser"