This commit is contained in:
stSolo
2022-12-22 17:56:47 +03:00
parent 8712561853
commit d4b1ab7133
672 changed files with 28509 additions and 4419 deletions

View File

@@ -1,13 +1,16 @@
// API Actor API for managing account
package account
import (
"github.com/rudecs/decort-sdk/interfaces"
)
// Structure for creating request to account
type Account struct {
client interfaces.Caller
}
// Builder for account endpoints
func New(client interfaces.Caller) *Account {
return &Account{
client,

View File

@@ -9,25 +9,34 @@ import (
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for adding permission to access to account for a user
type AddUserRequest struct {
AccountID uint64 `url:"accountId"`
UserID string `url:"userId"`
// ID of account to add to
// Required: true
AccountID uint64 `url:"accountId"`
// Name of the user to be given rights
// Required: true
UserID string `url:"userId"`
// Account permission types:
// - 'R' for read only access
// - 'RCX' for Write
// - 'ARCXDU' for Admin
// Required: true
AccessType string `url:"accesstype"`
}
func (arq AddUserRequest) Validate() error {
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")
@@ -36,8 +45,9 @@ func (arq AddUserRequest) Validate() error {
return nil
}
// AddUser gives a user access rights.
func (a Account) AddUser(ctx context.Context, req AddUserRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for give list account audits
type AuditsRequest struct {
// ID of the account
// Required: true
AccountID uint64 `url:"accountId"`
}
func (arq AuditsRequest) Validate() error {
func (arq AuditsRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
@@ -19,25 +22,26 @@ func (arq AuditsRequest) Validate() error {
return nil
}
func (a Account) Audits(ctx context.Context, req AuditsRequest) (AccountAuditsList, error) {
err := req.Validate()
// Audits gets audit records for the specified account object
func (a Account) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
err := req.validate()
if err != nil {
return nil, err
}
url := "/cloudapi/account/audits"
auditsRaw, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
audits := AccountAuditsList{}
list := ListAudits{}
err = json.Unmarshal(auditsRaw, &audits)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return audits, nil
return list, nil
}

View File

@@ -5,35 +5,87 @@ import (
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for creating account
type CreateRequest struct {
Name string `url:"name"`
Username string `url:"username"`
EmailAddress string `url:"emailaddress,omitempty"`
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"`
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"`
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"`
// Display name
// Required: true
Name string `url:"name"`
// Name of the account
// Required: true
Username string `url:"username"`
// Email
// Required: false
EmailAddress string `url:"emailaddress,omitempty"`
// Max size of memory in MB
// Required: false
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"`
// Max size of aggregated vdisks in GB
// Required: false
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"`
// Max number of CPU cores
// Required: false
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"`
// Max sent/received network transfer peering
// Required: false
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"`
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"`
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
GPUUnits uint64 `url:"gpu_units,omitempty"`
// Max number of assigned public IPs
// Required: false
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"`
// If true send emails when a user is granted access to resources
// Required: false
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
// Limit (positive) or disable (0) GPU resources
// Required: false
GPUUnits uint64 `url:"gpu_units,omitempty"`
// Resource types available to create in this account
// Each element in a resource type slice must be one of:
// - compute
// - vins
// - k8s
// - openshift
// - lb
// - flipgroup
// Required: false
ResTypes []string `url:"resourceTypes,omitempty"`
}
func (arq CreateRequest) Validate() error {
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")
}
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
}
// 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 := req.validate()
if err != nil {
return 0, err
}

View File

@@ -6,21 +6,27 @@ import (
"net/http"
)
// Request struct for delete account
type DeleteRequest struct {
AccountID uint64 `url:"accountId"`
Permanently bool `url:"permanently,omitempty"`
// ID of account to delete
// Required: true
AccountID uint64 `url:"accountId"`
// Whether to completely delete the account
// Required: false
Permanently bool `url:"permanently,omitempty"`
}
func (arq DeleteRequest) Validate() error {
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 := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,17 +7,25 @@ import (
"strconv"
)
// Request struct for revoke access to account
type DeleteUserRequest struct {
AccountID uint64 `url:"accountId"`
UserID string `url:"userId"`
RecursiveDelete bool `url:"recursivedelete,omitempty"`
// ID of the account
// Required: true
AccountID uint64 `url:"accountId"`
// ID or emailaddress of the user to remove
// Required: true
UserID string `url:"userId"`
// Recursively revoke access rights from owned cloudspaces and vmachines
// Required: false
RecursiveDelete bool `url:"recursivedelete,omitempty"`
}
func (arq DeleteUserRequest) Validate() error {
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")
}
@@ -25,8 +33,9 @@ func (arq DeleteUserRequest) Validate() error {
return nil
}
// DeleteUser revokes user access from the account
func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for change status of account
type DisabelEnableRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId"`
}
func (arq DisabelEnableRequest) Validate() error {
func (arq DisabelEnableRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (arq DisabelEnableRequest) Validate() error {
return nil
}
// Disable disables an account
func (a Account) Disable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -40,8 +44,9 @@ func (a Account) Disable(ctx context.Context, req DisabelEnableRequest) (bool, e
return result, nil
}
// Enable enables an account
func (a Account) Enable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get information about account
type GetRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
}
func (arq GetRequest) Validate() error {
func (arq GetRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (arq GetRequest) Validate() error {
return nil
}
func (a Account) Get(ctx context.Context, req GetRequest) (*AccountWithResources, error) {
err := req.Validate()
// Get gets account details
func (a Account) Get(ctx context.Context, req GetRequest) (*RecordAccount, error) {
err := req.validate()
if err != nil {
return nil, err
}
@@ -32,13 +36,13 @@ func (a Account) Get(ctx context.Context, req GetRequest) (*AccountWithResources
return nil, err
}
account := &AccountWithResources{}
info := RecordAccount{}
err = json.Unmarshal(res, &account)
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return account, nil
return &info, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// 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"`
}
func (arq GetConsumedAccountUnitsRequest) Validate() error {
func (arq GetConsumedAccountUnitsRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
@@ -19,8 +22,14 @@ func (arq GetConsumedAccountUnitsRequest) Validate() error {
return nil
}
// GetConsumedAccountUnits calculates the currently consumed units for all cloudspaces and resource groups in the account.
// Calculated cloud units are returned in a dict which includes:
// - CU_M: consumed memory in MB
// - CU_C: number of cpu cores
// - 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 := req.validate()
if err != nil {
return nil, err
}
@@ -32,13 +41,12 @@ func (a Account) GetConsumedAccountUnits(ctx context.Context, req GetConsumedAcc
return nil, err
}
rl := &ResourceLimits{}
info := ResourceLimits{}
err = json.Unmarshal(res, &rl)
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return rl, nil
return &info, nil
}

View File

@@ -9,20 +9,24 @@ import (
"github.com/rudecs/decort-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"`
CUType string `url:"cutype"`
// Cloud unit resource type
// Required: true
CUType string `url:"cutype"`
}
func (arq GetConsumedCloudUnitsByTypeRequest) Validate() error {
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")
@@ -31,8 +35,20 @@ func (arq GetConsumedCloudUnitsByTypeRequest) Validate() error {
return nil
}
// GetConsumedCloudUnitsByType calculates the currently consumed cloud units of the specified type for all cloudspaces
// and resource groups in the account.
// Possible types of cloud units are include:
//
// - CU_M: returns consumed memory in MB
// - CU_C: returns number of virtual cpu cores
// - CU_D: returns consumed virtual disk storage in GB
// - CU_S: returns consumed primary storage (NAS) in TB
// - CU_A: returns consumed secondary storage (Archive) in TB
// - CU_NO: returns sent/received network transfer in operator in GB
// - 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 := req.validate()
if err != nil {
return 0, err
}
@@ -50,5 +66,4 @@ func (a Account) GetConsumedCloudUnitsByType(ctx context.Context, req GetConsume
}
return result, nil
}

View File

@@ -6,21 +6,28 @@ import (
"net/http"
)
// Request struct for download the resources tracking files for an account
type GetConsumtionRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
Start uint64 `url:"start"`
End uint64 `url:"end"`
// Epoch represents the start time
// Required: true
Start uint64 `url:"start"`
// Epoch represents the end time
// Required: true
End uint64 `url:"end"`
}
func (arq GetConsumtionRequest) Validate() error {
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")
}
@@ -28,8 +35,9 @@ func (arq GetConsumtionRequest) Validate() error {
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()
err := req.validate()
if err != nil {
return "", err
}
@@ -45,21 +53,19 @@ 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()
err := req.validate()
if err != nil {
return "", err
}
url := "/account/getConsumtion"
prefix := "/cloudapi"
url := "/cloudapi//account/getConsumtion"
url = prefix + url
res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// 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"`
}
func (arq GetReservedAccountUnitsRequest) Validate() error {
func (arq GetReservedAccountUnitsRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
@@ -19,8 +22,15 @@ func (arq GetReservedAccountUnitsRequest) Validate() error {
return nil
}
// GetReservedAccountUnits calculates the reserved units for all cloudspaces and resource groups in the account.
// Calculated cloud units are returned in a dict which includes:
//
// - CU_M: reserved memory in MB
// - CU_C: number of cpu cores
// - 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 := req.validate()
if err != nil {
return nil, err
}
@@ -32,13 +42,12 @@ func (a Account) GetReservedAccountUnits(ctx context.Context, req GetReservedAcc
return nil, err
}
rl := &ResourceLimits{}
info := ResourceLimits{}
err = json.Unmarshal(res, &rl)
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return rl, nil
return &info, nil
}

View File

@@ -6,12 +6,19 @@ import (
"net/http"
)
// Request struct for get list of accounts
type ListRequest struct {
// Page number
// Required: false
Page uint64 `url:"page"`
// Page size
// Required: false
Size uint64 `url:"size"`
}
func (a Account) List(ctx context.Context, req ListRequest) (AccountCloudApiList, error) {
// List gets list all accounts the user has access to
func (a Account) List(ctx context.Context, req ListRequest) (ListAccounts, error) {
url := "/cloudapi/account/list"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -19,13 +26,12 @@ func (a Account) List(ctx context.Context, req ListRequest) (AccountCloudApiList
return nil, err
}
accountList := AccountCloudApiList{}
list := ListAccounts{}
err = json.Unmarshal(res, &accountList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return accountList, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for a get list compute instances
type ListComputesRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
}
func (arq ListComputesRequest) Validate() error {
func (arq ListComputesRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (arq ListComputesRequest) Validate() error {
return nil
}
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (AccountComputesList, error) {
err := req.Validate()
// 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()
if err != nil {
return nil, err
}
@@ -32,13 +36,12 @@ func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (Acc
return nil, err
}
accountComputesList := AccountComputesList{}
list := ListComputes{}
err = json.Unmarshal(res, &accountComputesList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return accountComputesList, nil
return list, nil
}

View File

@@ -6,12 +6,19 @@ import (
"net/http"
)
// Request struct for get list deleted accounts
type ListDeletedRequest struct {
// Page number
// Required: false
Page uint64 `url:"page"`
// Page size
// Required: false
Size uint64 `url:"size"`
}
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (AccountCloudApiList, error) {
// ListDeleted gets list all deleted accounts the user has access to
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListAccounts, error) {
url := "/cloudapi/account/listDeleted"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -19,13 +26,12 @@ func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (Accou
return nil, err
}
accountList := AccountCloudApiList{}
list := ListAccounts{}
err = json.Unmarshal(res, &accountList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return accountList, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get list deleted disks
type ListDisksRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
}
func (arq ListDisksRequest) Validate() error {
func (arq ListDisksRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (arq ListDisksRequest) Validate() error {
return nil
}
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (AccountDisksList, error) {
err := req.Validate()
// ListDisks gets list all currently unattached disks under specified account
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (ListDisks, error) {
err := req.validate()
if err != nil {
return nil, err
}
@@ -32,13 +36,12 @@ func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (AccountDi
return nil, err
}
accountDisksList := AccountDisksList{}
list := ListDisks{}
err = json.Unmarshal(res, &accountDisksList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return accountDisksList, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
type ListFlipGroupsRequest struct {
// Request struct for get list FLIPGroups
type ListFLIPGroupsRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
}
func (arq ListFlipGroupsRequest) Validate() error {
func (arq ListFLIPGroupsRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (arq ListFlipGroupsRequest) Validate() error {
return nil
}
func (a Account) ListFlipGroups(ctx context.Context, req ListFlipGroupsRequest) (AccountFlipGroupsList, error) {
err := req.Validate()
// 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()
if err != nil {
return nil, err
}
@@ -32,13 +36,12 @@ func (a Account) ListFlipGroups(ctx context.Context, req ListFlipGroupsRequest)
return nil, err
}
accountFlipGroupsList := AccountFlipGroupsList{}
list := ListFLIPGroups{}
err = json.Unmarshal(res, &accountFlipGroupsList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return accountFlipGroupsList, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get list resource groups
type ListRGRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
}
func (arq ListRGRequest) Validate() error {
func (arq ListRGRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (arq ListRGRequest) Validate() error {
return nil
}
func (a Account) ListRG(ctx context.Context, req ListRGRequest) (AccountRGList, error) {
err := req.Validate()
// 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()
if err != nil {
return nil, err
}
@@ -32,13 +36,12 @@ func (a Account) ListRG(ctx context.Context, req ListRGRequest) (AccountRGList,
return nil, err
}
accountRGList := AccountRGList{}
list := ListRG{}
err = json.Unmarshal(res, &accountRGList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return accountRGList, nil
return list, nil
}

View File

@@ -7,12 +7,18 @@ import (
"net/http"
)
// Request struct for get list templates
type ListTemplatesRequest struct {
AccountID uint64 `url:"accountId"`
IncludeDeleted bool `url:"includedeleted"`
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
// Include deleted images
// Required: false
IncludeDeleted bool `url:"includedeleted"`
}
func (arq ListTemplatesRequest) Validate() error {
func (arq ListTemplatesRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
@@ -20,8 +26,9 @@ func (arq ListTemplatesRequest) Validate() error {
return nil
}
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (AccountTemplatesList, error) {
err := req.Validate()
// 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()
if err != nil {
return nil, err
}
@@ -33,13 +40,12 @@ func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (A
return nil, err
}
accountTemplatesList := AccountTemplatesList{}
list := ListTemplates{}
err = json.Unmarshal(res, &accountTemplatesList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return accountTemplatesList, nil
return list, nil
}

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get list VINS
type ListVINSRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
}
func (arq ListVINSRequest) Validate() error {
func (arq ListVINSRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (arq ListVINSRequest) Validate() error {
return nil
}
func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (AccountVINSList, error) {
err := req.Validate()
// 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()
if err != nil {
return nil, err
}
@@ -32,13 +36,12 @@ func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (AccountVINS
return nil, err
}
accountVINSList := AccountVINSList{}
list := ListVINS{}
err = json.Unmarshal(res, &accountVINSList)
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return accountVINSList, nil
return list, nil
}

View File

@@ -1,229 +1,547 @@
package account
type AccountACLRecord struct {
IsExplicit bool `json:"explicit"`
GUID string `json:"guid"`
Rights string `json:"right"`
Status string `json:"status"`
Type string `json:"type"`
UgroupID string `json:"userGroupId"`
CanBeDeleted bool `json:"canBeDeleted"`
// Access Control List
type RecordACL struct {
// Whether access is explicitly specified
IsExplicit bool `json:"explicit"`
// GUID
GUID string `json:"guid"`
// Access rights
Rights string `json:"right"`
// Status
Status string `json:"status"`
// Account Type
Type string `json:"type"`
// Account owner ID
UgroupID string `json:"userGroupId"`
// Is it possible to remove
CanBeDeleted bool `json:"canBeDeleted"`
}
// Resource limits
type ResourceLimits struct {
CUC float64 `json:"CU_C"`
CUD float64 `json:"CU_D"`
CUI float64 `json:"CU_I"`
CUM float64 `json:"CU_M"`
CUNP float64 `json:"CU_NP"`
// Number of cores
CUC float64 `json:"CU_C"`
// Disk size, GB
CUD float64 `json:"CU_D"`
// Number of public IP addresses
CUI float64 `json:"CU_I"`
// RAM size, MB
CUM float64 `json:"CU_M"`
// Traffic volume, GB
CUNP float64 `json:"CU_NP"`
// Number of graphics cores
GPUUnits float64 `json:"gpu_units"`
}
type AccountRecord struct {
DCLocation string `json:"DCLocation"`
CKey string `jspn:"_ckey"`
Meta []interface{} `json:"_meta"`
ACL []AccountACLRecord `json:"acl"`
Company string `json:"company"`
CompanyURL string `json:"companyurl"`
CreatedBy string `jspn:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DeactiovationTime float64 `json:"deactivationTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime uint64 `json:"deletedTime"`
DisplayName string `json:"displayname"`
GUID uint64 `json:"guid"`
ID uint64 `json:"id"`
Name string `json:"name"`
ResourceLimits ResourceLimits `json:"resourceLimits"`
SendAccessEmails bool `json:"sendAccessEmails"`
ServiceAccount bool `json:"serviceAccount"`
Status string `json:"status"`
UpdatedTime uint64 `json:"updatedTime"`
Version uint64 `json:"version"`
VINS []uint64 `json:"vins"`
// Main information of account
type InfoAccount struct {
// Segment
DCLocation string `json:"DCLocation"`
// Key
CKey string `jspn:"_ckey"`
// Meta
Meta []interface{} `json:"_meta"`
// Access Control List
ACL []RecordACL `json:"acl"`
// Company
Company string `json:"company"`
// Company URL
CompanyURL string `json:"companyurl"`
// Created by
CreatedBy string `jspn:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deactiovation time
DeactiovationTime float64 `json:"deactivationTime"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Display name
DisplayName string `json:"displayname"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Resource Limits
ResourceLimits ResourceLimits `json:"resourceLimits"`
// If true send emails when a user is granted access to resources
SendAccessEmails bool `json:"sendAccessEmails"`
// Service Account
ServiceAccount bool `json:"serviceAccount"`
// Status
Status string `json:"status"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// Version
Version uint64 `json:"version"`
// List VINS in account
VINS []uint64 `json:"vins"`
}
type AccountList []AccountRecord
// Main information in one of if the list of accounts
type ItemAccount struct {
// Access Control List
ACL []RecordACL `json:"acl"`
type AccountCloudApi struct {
ACL []AccountACLRecord `json:"acl"`
CreatedTime uint64 `json:"createdTime"`
DeletedTime uint64 `json:"deletedTime"`
ID uint64 `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
UpdatedTime uint64 `json:"updatedTime"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Status
Status string `json:"status"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
}
type AccountCloudApiList []AccountCloudApi
// List of accounts
type ListAccounts []ItemAccount
// Resources used
type Resource struct {
CPU int64 `json:"cpu"`
DiskSize int64 `json:"disksize"`
ExtIPs int64 `json:"extips"`
// Number of cores
CPU int64 `json:"cpu"`
// Disk size
DiskSize int64 `json:"disksize"`
// Number of External IPs
ExtIPs int64 `json:"extips"`
// External traffic
ExtTraffic int64 `json:"exttraffic"`
GPU int64 `json:"gpu"`
RAM int64 `json:"ram"`
// Number of grafic cores
GPU int64 `json:"gpu"`
// Number of RAM
RAM int64 `json:"ram"`
}
// Information about resources
type Resources struct {
Current Resource `json:"Current"`
// Current information about resources
Current Resource `json:"Current"`
// Reserved information about resources
Reserved Resource `json:"Reserved"`
}
// Information about computes
type Computes struct {
// Number of started computes
Started uint64 `json:"started"`
// Number of stopped computes
Stopped uint64 `json:"stopped"`
}
// Information about machines
type Machines struct {
// Number of running machines
Running uint64 `json:"running"`
Halted uint64 `json:"halted"`
// Number of halted machines
Halted uint64 `json:"halted"`
}
type AccountWithResources struct {
Account
// Сomplete information about account
type RecordAccount struct {
// Main information about account
InfoAccount
// Resources
Resources Resources `json:"Resources"`
Computes Computes `json:"computes"`
Machines Machines `json:"machines"`
VINSes uint64 `json:"vinses"`
// Computes
Computes Computes `json:"computes"`
// Machines
Machines Machines `json:"machines"`
// Number of VINSes
VINSes uint64 `json:"vinses"`
}
type AccountCompute struct {
AccountID uint64 `json:"accountId"`
AccountName string `json:"accountName"`
CPUs uint64 `json:"cpus"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime uint64 `json:"deletedTime"`
ComputeID uint64 `json:"id"`
ComputeName string `json:"name"`
RAM uint64 `json:"ram"`
Registered bool `json:"registered"`
RGID uint64 `json:"rgId"`
RGName string `json:"rgName"`
Status string `json:"status"`
TechStatus string `json:"techStatus"`
TotalDisksSize uint64 `json:"totalDisksSize"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime uint64 `json:"updatedTime"`
UserManaged bool `json:"userManaged"`
VINSConnected uint64 `json:"vinsConnected"`
}
// Main information about compute
type ItemCompute struct {
// ID an account
AccountID uint64 `json:"accountId"`
type AccountComputesList []AccountCompute
type AccountDisk struct {
ID uint64 `json:"id"`
Name string `json:"name"`
Pool string `json:"pool"`
SepID uint64 `json:"sepId"`
SizeMax uint64 `json:"sizeMax"`
Type string `json:"type"`
}
type AccountDisksList []AccountDisk
type AccountVIN struct {
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
Computes uint64 `json:"computes"`
CreatedBy string `json:"createdBy"`
// Number of CPU
CPUs uint64 `json:"cpus"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
ExternalIP string `json:"externalIP"`
ID uint64 `json:"id"`
Name string `json:"name"`
Network string `json:"network"`
PriVnfDevID uint64 `json:"priVnfDevId"`
RGID uint64 `json:"rgId"`
RGName string `json:"rgName"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
// ID compute
ComputeID uint64 `json:"id"`
// Compute name
ComputeName string `json:"name"`
// Number of RAM
RAM uint64 `json:"ram"`
// Registered or not
Registered bool `json:"registered"`
// Resource group ID
RGID uint64 `json:"rgId"`
// Resource group Name
RGName string `json:"rgName"`
// Status
Status string `json:"status"`
// Tech status
TechStatus string `json:"techStatus"`
// Total disks size
TotalDisksSize uint64 `json:"totalDisksSize"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// User controlled or not
UserManaged bool `json:"userManaged"`
// Number of connected VINS
VINSConnected uint64 `json:"vinsConnected"`
}
// List of computes
type ListComputes []ItemCompute
// Main information about disk
type ItemDisk struct {
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Pool
Pool string `json:"pool"`
// ID SEP
SEPID uint64 `json:"sepId"`
// Max size
SizeMax uint64 `json:"sizeMax"`
// Disk type
Type string `json:"type"`
}
// List of disks
type ListDisks []ItemDisk
// Main information about VINS
type ItemVINS struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Name of account
AccountName string `json:"accountName"`
// Number of computes
Computes uint64 `json:"computes"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// External IP
ExternalIP string `json:"externalIP"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Network
Network string `json:"network"`
// NNFDev ID
PriVNFDevID uint64 `json:"priVnfDevId"`
// Resource group ID
RGID uint64 `json:"rgId"`
// Resource group name
RGName string `json:"rgName"`
// Status
Status string `json:"status"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
}
type AccountVINSList []AccountVIN
// List of VINS
type ListVINS []ItemVINS
type AccountAudit struct {
Call string `json:"call"`
// Main info about audit
type ItemAudit struct {
// Call
Call string `json:"call"`
// Response time
ResponseTime float64 `json:"responsetime"`
StatusCode uint64 `json:"statuscode"`
Timestamp float64 `json:"timestamp"`
User string `json:"user"`
// Status code
StatusCode uint64 `json:"statuscode"`
// Timestamp
Timestamp float64 `json:"timestamp"`
// User
User string `json:"user"`
}
type AccountAuditsList []AccountAudit
// List of audits
type ListAudits []ItemAudit
type AccountRGComputes struct {
Started uint64 `json:"Started"`
Stopped uint64 `json:"Stopped"`
// Information compute in resource group
type RGComputes struct {
// Number of started computes
Started uint64 `json:"started"`
// Number of stopped computes
Stopped uint64 `json:"stopped"`
}
type AccountRGResources struct {
// Resources of Resource group
type RGResources struct {
// Consumed
Consumed Resource `json:"Consumed"`
Limits Resource `json:"Limits"`
// Limits
Limits Resource `json:"Limits"`
// Reserved
Reserved Resource `json:"Reserved"`
}
type AccountRG struct {
Computes AccountRGComputes `json:"Computes"`
Resources AccountRGResources `json:"Resources"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime uint64 `json:"deletedTime"`
RGID uint64 `json:"id"`
Milestones uint64 `json:"milestones"`
RGName string `json:"name"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
UpdatedTime uint64 `json:"updatedTime"`
VINSes uint64 `json:"vinses"`
}
// Main information about resource group
type ItemRG struct {
// Computes
Computes RGComputes `json:"Computes"`
type AccountRGList []AccountRG
// Resources
Resources RGResources `json:"Resources"`
type AccountTemplate struct {
UNCPath string `json:"UNCPath"`
AccountID uint64 `json:"accountId"`
Description string `json:"desc"`
ID uint64 `json:"id"`
Name string `json:"name"`
Public bool `json:"public"`
Size uint64 `json:"size"`
Status string `json:"status"`
Type string `json:"type"`
Username string `json:"username"`
}
// Created by
CreatedBy string `json:"createdBy"`
type AccountTemplatesList []AccountTemplate
type AccountFlipGroup struct {
AccountID uint64 `json:"accountId"`
ClientType string `json:"clientType"`
ConnType string `json:"connType"`
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
DefaultGW string `json:"defaultGW"`
DeletedBy string `json:"deletedBy"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Resource group ID
RGID uint64 `json:"id"`
// Milestones
Milestones uint64 `json:"milestones"`
// Resource group name
RGName string `json:"name"`
// Status
Status string `json:"status"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// Number of VINS
VINSes uint64 `json:"vinses"`
}
// List of Resource groups
type ListRG []ItemRG
// Main information about template
type ItemTemplate struct {
// UNCPath
UNCPath string `json:"UNCPath"`
// Account ID
AccountID uint64 `json:"accountId"`
// Description
Description string `json:"desc"`
GID uint64 `json:"gid"`
GUID uint64 `json:"guid"`
ID uint64 `json:"id"`
IP string `json:"ip"`
Milestones uint64 `json:"milestones"`
Name string `json:"name"`
NetID uint64 `json:"netId"`
NetType string `json:"netType"`
NetMask uint64 `json:"netmask"`
Status string `json:"status"`
UpdatedBy string `json:"updatedBy"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Public or not
Public bool `json:"public"`
// Size
Size uint64 `json:"size"`
// Status
Status string `json:"status"`
// Type
Type string `json:"type"`
// Username
Username string `json:"username"`
}
// List of templates
type ListTemplates []ItemTemplate
// Main information about FLIPGroup
type ItemFLIPGroup struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Client type
ClientType string `json:"clientType"`
// Connection type
ConnType string `json:"connType"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Default GW
DefaultGW string `json:"defaultGW"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// Description
Description string `json:"desc"`
// Grid ID
GID uint64 `json:"gid"`
// GUID
GUID uint64 `json:"guid"`
// ID
ID uint64 `json:"id"`
// IP
IP string `json:"ip"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// Network ID
NetID uint64 `json:"netId"`
// Network type
NetType string `json:"netType"`
// Network mask
NetMask uint64 `json:"netmask"`
// Status
Status string `json:"status"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
}
type AccountFlipGroupsList []AccountFlipGroup
// List of FLIPGroups
type ListFLIPGroups []ItemFLIPGroup

View File

@@ -7,11 +7,14 @@ import (
"strconv"
)
// Request struct for restore a deleted account
type RestoreRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
}
func (arq RestoreRequest) Validate() error {
func (arq RestoreRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
@@ -19,8 +22,9 @@ func (arq RestoreRequest) Validate() error {
return nil
}
// Restore restores a deleted account
func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}
@@ -38,5 +42,4 @@ func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error)
}
return result, nil
}

View File

@@ -5,30 +5,79 @@ import (
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for updaate account
type UpdateRequest struct {
AccountID uint64 `url:"accountId"`
Name string `url:"name,omitempty"`
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"`
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"`
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"`
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
// Name of the account
// Required: false
Name string `url:"name,omitempty"`
// Max size of memory in MB
// Required: false
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"`
// Max size of aggregated vdisks in GB
// Required: false
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"`
// Max number of CPU cores
// Required: false
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"`
// Max sent/received network transfer peering
// Required: false
MaxNetworkPeerTransfer uint64 `url:"maxNetworkPeerTransfer,omitempty"`
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"`
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
GPUUnits uint64 `url:"gpu_units,omitempty"`
// Max number of assigned public IPs
// Required: false
MaxNumPublicIP uint64 `url:"maxNumPublicIP,omitempty"`
// If true send emails when a user is granted access to resources
// Required: false
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
// Limit (positive) or disable (0) GPU resources
// Required: false
GPUUnits uint64 `url:"gpu_units,omitempty"`
// Resource types available to create in this account
// Each element in a resource type slice must be one of:
// - compute
// - vins
// - k8s
// - openshift
// - lb
// - flipgroup
// Required: false
ResTypes []string `url:"resourceTypes,omitempty"`
}
func (arq UpdateRequest) Validate() error {
func (arq UpdateRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID can not be empty or equal to 0")
}
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
}
// 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 := req.validate()
if err != nil {
return false, err
}

View File

@@ -9,25 +9,34 @@ import (
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for update user access rights
type UpdateUserRequest struct {
AccountID uint64 `url:"accountId"`
UserID string `url:"userId"`
// ID of the account
// Required: true
AccountID uint64 `url:"accountId"`
// Userid/Email for registered users or emailaddress for unregistered users
// Required: true
UserID string `url:"userId"`
// Account permission types:
// - 'R' for read only access
// - 'RCX' for Write
// - 'ARCXDU' for Admin
// Required: true
AccessType string `url:"accesstype"`
}
func (arq UpdateUserRequest) Validate() error {
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")
@@ -36,8 +45,9 @@ func (arq UpdateUserRequest) Validate() error {
return nil
}
// UpdateUser updates user access rights
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}