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,11 +1,14 @@
// 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: client,

View File

@@ -9,35 +9,45 @@ 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"`
UserName string `url:"username"`
// ID of account to add to
// Required: true
AccountID uint64 `url:"accountId"`
// Name of the user to be given rights
// Required: true
UserName string `url:"username"`
// 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.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")
}
isValid := validators.StringInSlice(arq.AccessType, []string{"R", "RCX", "ARCXDU"})
if !isValid {
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
}
// 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,19 +7,23 @@ 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")
}
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
}
@@ -30,11 +34,13 @@ func (a Account) Audits(ctx context.Context, req AuditsRequest) (AccountAuditsLi
if err != nil {
return nil, err
}
result := AccountAuditsList{}
err = json.Unmarshal(res, &result)
list := ListAudits{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return result, nil
return list, nil
}

View File

@@ -5,34 +5,92 @@ 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 uint `url:"maxMemoryCapacity,omitempty"`
MaxVDiskCapacity uint `url:"maxVDiskCapacity,omitempty"`
MaxCPUCapacity uint `url:"maxCPUCapacity,omitempty"`
MaxNetworkPeerTransfer uint `url:"maxNetworkPeerTransfer,omitempty"`
MaxNumPublicIP uint `url:"maxNumPublicIP,omitempty"`
SendAccessEmails bool `url:"sendAccessEmails,omitempty"`
GPUUnits uint `url:"gpu_units,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"`
// 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"`
// List of strings with pools
// i.e.: ["sep1_poolName1", "sep2_poolName2", etc]
// Required: false
UniqPools []string `url:"uniqPools,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
}
@@ -44,10 +102,10 @@ func (a Account) Create(ctx context.Context, req CreateRequest) (uint64, error)
return 0, err
}
id, err := strconv.ParseUint(string(res), 10, 64)
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return id, nil
return result, nil
}

View File

@@ -6,24 +6,35 @@ import (
"net/http"
)
// Request struct for delete account
type DeleteRequest struct {
AccountID uint64 `url:"accountId"`
Reason string `url:"reason"`
Permanently bool `url:"permanently,omitempty"`
// ID of account to delete
// Required: true
AccountID uint64 `url:"accountId"`
// Reason to delete
// Required: true
Reason string `url:"reason"`
// 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")
}
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 := req.validate()
if err != nil {
return false, err
}

View File

@@ -6,24 +6,35 @@ import (
"net/http"
)
// Request struct for delete group accounts
type DeleteAccountsRequest struct {
// IDs of accounts
// Required: true
AccountsIDs []uint64 `url:"accountIds"`
Reason string `url:"reason"`
Permanently bool `url:"permanently,omitempty"`
// Reason for deletion
// Required: true
Reason string `url:"reason"`
// Whether to completely destroy accounts or not
// Required: false
Permanently bool `url:"permanently,omitempty"`
}
func (arq DeleteAccountsRequest) Validate() error {
if arq.AccountsIDs == nil || len(arq.AccountsIDs) == 0 {
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 := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,13 +7,22 @@ import (
"strconv"
)
// Request struct for revoke access to account
type DeleteUserRequest struct {
AccountID uint64 `url:"accountId"`
UserName string `url:"username"`
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
UserName string `url:"username"`
// 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 must be set")
}
@@ -24,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
}
@@ -41,5 +51,6 @@ func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest) (bool, e
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -7,23 +7,31 @@ import (
"strconv"
)
// Request struct for disable account
type DisableRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId"`
Reason string `url:"reason"`
// Reason to disable
// Required: true
Reason string `url:"reason"`
}
func (arq DisableRequest) Validate() error {
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
}
// Disable disables an account
func (a Account) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -6,19 +6,24 @@ import (
"net/http"
)
// Request struct for disable group accounts
type DisableAccountsRequest struct {
// IDs of accounts
// Required: true
AccountIDs []uint64 `url:"accountIds,omitempty"`
}
func (arq DisableAccountsRequest) Validate() error {
if arq.AccountIDs == nil || len(arq.AccountIDs) == 0 {
func (arq DisableAccountsRequest) validate() error {
if len(arq.AccountIDs) == 0 {
return errors.New("validation-error: field AccountIDs must be set")
}
return nil
}
// DisableAccounts disables accounts
func (a Account) DisableAccounts(ctx context.Context, req DisableAccountsRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,23 +7,31 @@ import (
"strconv"
)
// Request struct for enable account
type EnableRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId"`
Reason string `url:"reason"`
// Reason to enable
// Required: true
Reason string `url:"reason"`
}
func (arq EnableRequest) Validate() error {
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
}
// Enable enables an account
func (a Account) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -6,19 +6,24 @@ import (
"net/http"
)
// Request for enable group accounts
type EnableAccountsRequest struct {
// IDs od accounts
// Required: true
AccountIDs []uint64 `url:"accountIds"`
}
func (arq EnableAccountsRequest) Validate() error {
if arq.AccountIDs == nil || len(arq.AccountIDs) == 0 {
func (arq EnableAccountsRequest) validate() error {
if len(arq.AccountIDs) == 0 {
return errors.New("validation-error: field AccountIDs must be set")
}
return nil
}
// EnableAccounts enables accounts
func (a Account) EnableAccounts(ctx context.Context, req EnableAccountsRequest) (bool, error) {
err := req.Validate()
err := req.validate()
if err != nil {
return false, err
}

View File

@@ -7,35 +7,41 @@ 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 must be set")
}
return nil
}
func (a Account) Get(ctx context.Context, req GetRequest) (GetResponse, error) {
err := req.Validate()
// Get gets information about account
func (a Account) Get(ctx context.Context, req GetRequest) (*RecordAccount, error) {
err := req.validate()
if err != nil {
return GetResponse{}, err
return nil, err
}
url := "/cloudbroker/account/get"
result := GetResponse{}
info := RecordAccount{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return GetResponse{}, err
return nil, err
}
err = json.Unmarshal(res, &result)
err = json.Unmarshal(res, &info)
if err != nil {
return GetResponse{}, err
return nil, err
}
return result, nil
return &info, nil
}

View File

@@ -6,23 +6,32 @@ import (
"net/http"
)
// Request struct for get list of accounts
type ListRequest struct {
Page uint64 `url:"page,omitempty"`
Size uint64 `url:"size,omitempty"`
// 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) (ListInfoResponse, error) {
// List gets list all accounts the user has access to
func (a Account) List(ctx context.Context, req ListRequest) (ListAccounts, error) {
url := "/cloudbroker/account/list"
result := ListInfoResponse{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return ListInfoResponse{}, err
}
err = json.Unmarshal(res, &result)
if err != nil {
return ListInfoResponse{}, err
return nil, err
}
return result, nil
list := ListAccounts{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
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 must be set")
}
@@ -19,25 +22,26 @@ func (arq ListComputesRequest) Validate() error {
return nil
}
// 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 := req.validate()
if err != nil {
return ListComputes{}, err
return nil, err
}
url := "/cloudbroker/account/listComputes"
result := ListComputes{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return ListComputes{}, err
return nil, err
}
err = json.Unmarshal(res, &result)
list := ListComputes{}
err = json.Unmarshal(res, &list)
if err != nil {
return ListComputes{}, err
return nil, err
}
return result, nil
return list, nil
}

View File

@@ -6,24 +6,32 @@ import (
"net/http"
)
// Request struct for get list deleted accounts
type ListDeletedRequest struct {
Page uint64 `url:"page,omitempty"`
Size uint64 `url:"size,omitempty"`
// 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) (ListInfoResponse, error) {
// ListDeleted gets list all deleted accounts the user has access to
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListAccounts, error) {
url := "/cloudbroker/account/listDeleted"
result := ListInfoResponse{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return ListInfoResponse{}, err
return nil, err
}
err = json.Unmarshal(res, &result)
list := ListAccounts{}
err = json.Unmarshal(res, &list)
if err != nil {
return ListInfoResponse{}, err
return nil, err
}
return result, err
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 must be set")
}
@@ -19,25 +22,26 @@ func (arq ListDisksRequest) Validate() error {
return nil
}
// 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 := req.validate()
if err != nil {
return ListDisks{}, err
return nil, err
}
url := "/cloudbroker/account/listDisks"
result := ListDisks{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return ListDisks{}, err
return nil, err
}
err = json.Unmarshal(res, &result)
list := ListDisks{}
err = json.Unmarshal(res, &list)
if err != nil {
return ListDisks{}, err
return nil, err
}
return result, 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 must be set")
}
@@ -19,25 +22,26 @@ func (arq ListFlipGroupsRequest) Validate() error {
return nil
}
func (a Account) ListFlipGroups(ctx context.Context, req ListFlipGroupsRequest) (ListFlipGroups, 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 ListFlipGroups{}, err
return nil, err
}
url := "/cloudbroker/account/listFlipGroups"
result := ListFlipGroups{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return ListFlipGroups{}, err
return nil, err
}
err = json.Unmarshal(res, &result)
list := ListFLIPGroups{}
err = json.Unmarshal(res, &list)
if err != nil {
return ListFlipGroups{}, err
return nil, err
}
return result, 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 must be set")
}
@@ -19,25 +22,26 @@ func (arq ListRGRequest) Validate() error {
return nil
}
// 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 := req.validate()
if err != nil {
return ListRG{}, err
return nil, err
}
url := "/cloudbroker/account/listRG"
result := ListRG{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return ListRG{}, err
return nil, err
}
err = json.Unmarshal(res, &result)
list := ListRG{}
err = json.Unmarshal(res, &list)
if err != nil {
return ListRG{}, err
return nil, err
}
return result, 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 must be set")
}
@@ -19,25 +22,26 @@ func (arq ListVINSRequest) Validate() error {
return nil
}
// 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 := req.validate()
if err != nil {
return ListVINS{}, err
return nil, err
}
url := "/cloudbroker/account/listVins"
result := ListVINS{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return ListVINS{}, err
}
err = json.Unmarshal(res, &result)
list := ListVINS{}
err = json.Unmarshal(res, &list)
if err != nil {
return ListVINS{}, err
return nil, err
}
return result, nil
return list, nil
}

View File

@@ -1,214 +1,500 @@
package account
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 audirs
type ListAudits []ItemAudit
type Resources struct {
Current Current `json:"Current"`
Reserved Reserved `json:"Reserved"`
type RecordResources struct {
// Current information about resources
Current Resource `json:"Current"`
// Reserved information about resources
Reserved Resource `json:"Reserved"`
}
type Current struct {
CPU uint64 `json:"cpu"`
DiskSize uint64 `json:"disksize"`
ExtIPs uint64 `json:"extips"`
ExtTraffic uint64 `json:"exttraffic"`
GPU uint64 `json:"gpu"`
RAM uint64 `json:"ram"`
}
type Reserved struct {
CPU uint64 `json:"cpu"`
DiskSize uint64 `json:"disksize"`
ExtIPs uint64 `json:"extips"`
ExtTraffic uint64 `json:"exttraffic"`
GPU uint64 `json:"gpu"`
RAM uint64 `json:"ram"`
type Resource struct {
// 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"`
// Number of grafic cores
GPU int64 `json:"gpu"`
// Number of RAM
RAM int64 `json:"ram"`
}
// Access Control List
type ACL struct {
Explicit bool `json:"explicit"`
GUID string `json:"guid"`
Right string `json:"right"`
Status string `json:"status"`
Type string `json:"type"`
// Whether access is explicitly specified
Explicit bool `json:"explicit"`
// GUID
GUID string `json:"guid"`
// Access rights
Right string `json:"right"`
// Status
Status string `json:"status"`
// Type
Type string `json:"type"`
// User group ID
UserGroupID string `json:"userGroupId"`
}
// 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"`
// CuC
CuC float64 `json:"CU_C"`
// CuD
CuD float64 `json:"CU_D"`
// CuI
CuI float64 `json:"CU_I"`
// CuM
CuM float64 `json:"CU_M"`
// CuNP
CuNP float64 `json:"CU_NP"`
// GPUUnits
GPUUnits float64 `json:"gpu_units"`
}
type InfoResponse struct {
DCLocation string `json:"DCLocation"`
CKey string `json:"_ckey"`
ACL []ACL `json:"acl"`
Company string `json:"company"`
CompanyURL string `json:"companyurl"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DeactivationTime 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"`
Status string `json:"status"`
UpdatedTime uint64 `json:"updatedTime"`
Version uint64 `json:"version"`
VINS []uint64 `json:"vins"`
}
type GetResponse struct {
Resources Resources `json:"Resources"`
InfoResponse
}
// Main information about account
type InfoAccount struct {
// DCLocation
DCLocation string `json:"DCLocation"`
type ListInfoResponse []struct {
Meta []interface{} `json:"_meta"`
InfoResponse
}
// CKey
CKey string `json:"_ckey"`
type ListComputes []Compute
type Compute 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"`
ID uint64 `json:"id"`
Name 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"`
}
// Access Control List
ACL []ACL `json:"acl"`
type ListDisks []Disk
// Company
Company string `json:"company"`
type Disk 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"`
}
// Company URL
CompanyURL string `json:"companyurl"`
type ListFlipGroups []FlipGroup
// Created by
CreatedBy string `json:"createdBy"`
type FlipGroup 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"`
// Deactivation time
DeactivationTime float64 `json:"deactivationTime"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
Desc 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"`
// 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"`
// Send access emails
SendAccessEmails bool `json:"sendAccessEmails"`
// Status
Status string `json:"status"`
// UpdatedTime
UpdatedTime uint64 `json:"updatedTime"`
// Version
Version uint64 `json:"version"`
// List of VINS IDs
VINS []uint64 `json:"vins"`
}
// Deatailed information about account
type RecordAccount struct {
// Resources
Resources RecordResources `json:"Resources"`
// Main information about account
InfoAccount
}
// More information about account
type ItemAccount struct {
// Meta
Meta []interface{} `json:"_meta"`
// Main information about account
InfoAccount
}
// List of accounts
type ListAccounts []ItemAccount
// List of computes
type ListComputes []ItemCompute
// Main information about compute
type ItemCompute struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
// Number of CPU
CPUs uint64 `json:"cpus"`
// Created by
CreatedBy string `json:"createdBy"`
// Created time
CreatedTime uint64 `json:"createdTime"`
// Deleted by
DeletedBy string `json:"deletedBy"`
// Deleted time
DeletedTime uint64 `json:"deletedTime"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Number of RAM
RAM uint64 `json:"ram"`
// Registered
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 managed
UserManaged bool `json:"userManaged"`
// VINS Connected
VINSConnected uint64 `json:"vinsConnected"`
}
// List of disks
type ListDisks []ItemDisk
// Main information about disks
type ItemDisk struct {
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Pool
Pool string `json:"pool"`
// SepID
SepID uint64 `json:"sepId"`
// Size max
SizeMax uint64 `json:"sizeMax"`
// Type
Type string `json:"type"`
}
// List of FLIPGroups
type ListFLIPGroups []ItemFLIPGroup
// 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"`
}
// Computes info
type Computes struct {
// Started
Started uint64 `json:"Started"`
// Stopped
Stopped uint64 `json:"Stopped"`
}
// Consumed
type Consumed struct {
CPU uint64 `json:"cpu"`
DiskSize uint64 `json:"disksize"`
ExtIPs uint64 `json:"extips"`
// Number of CPU
CPU uint64 `json:"cpu"`
// Disk size
DiskSize uint64 `json:"disksize"`
// External IPs
ExtIPs uint64 `json:"extips"`
// External traffic
ExtTraffic uint64 `json:"exttraffic"`
GPU uint64 `json:"gpu"`
RAM uint64 `json:"ram"`
// Number of GPU
GPU uint64 `json:"gpu"`
// Number of RAM
RAM uint64 `json:"ram"`
}
// Limits
type Limits struct {
CPU int64 `json:"cpu"`
DiskSize int64 `json:"disksize"`
ExtIPs int64 `json:"extips"`
// Number of CPU
CPU int64 `json:"cpu"`
// Disk size
DiskSize int64 `json:"disksize"`
// External IPs
ExtIPs int64 `json:"extips"`
// External traffic
ExtTraffic int64 `json:"exttraffic"`
GPU int64 `json:"gpu"`
RAM int64 `json:"ram"`
// Number of GPU
GPU int64 `json:"gpu"`
// Number of RAM
RAM int64 `json:"ram"`
}
// Resources of resource group
type RGResuorces struct {
// Consumed
Consumed Consumed `json:"Consumed"`
Limits Limits `json:"Limits"`
Reserved Reserved `json:"Reserved"`
// Limits
Limits Limits `json:"Limits"`
// Reserved
Reserved Resource `json:"Reserved"`
}
type RG struct {
Computes Computes `json:"Computes"`
Resources RGResuorces `json:"Resources"`
CreatedBy string `json:"createdBy"`
CreatedTime uint64 `json:"createdTime"`
DeletedBy string `json:"deletedBy"`
DeletedTime uint64 `json:"deletedTime"`
ID uint64 `json:"id"`
Milestones uint64 `json:"milestones"`
Name 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 {
// Compute
Computes Computes `json:"Computes"`
type ListRG []RG
// Resources of resource group
Resources RGResuorces `json:"Resources"`
type VINS struct {
AccountID uint64 `json:"accountId"`
AccountName string `json:"accountName"`
Computes uint64 `json:"computes"`
CreatedBy string `json:"createdBy"`
// 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
ID uint64 `json:"id"`
// Milestones
Milestones uint64 `json:"milestones"`
// Name
Name string `json:"name"`
// Status
Status string `json:"status"`
// Updated by
UpdatedBy string `json:"updatedBy"`
// Updated time
UpdatedTime uint64 `json:"updatedTime"`
// Number of VINSes
VINSes uint64 `json:"vinses"`
}
// List of resource groups
type ListRG []ItemRG
// Main information about VINS
type ItemVINS struct {
// Account ID
AccountID uint64 `json:"accountId"`
// Account name
AccountName string `json:"accountName"`
// 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"`
// PriVNFDevID
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 ListVINS []VINS
// List of VINSes
type ListVINS []ItemVINS

View File

@@ -6,12 +6,18 @@ import (
"net/http"
)
// Request struct for restore a deleted account
type RestoreRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId"`
Reason string `url:"reason"`
// Reason to restore
// Required: true
Reason string `url:"reason"`
}
func (arq RestoreRequest) Validate() error {
func (arq RestoreRequest) validate() error {
if arq.AccountID == 0 {
return errors.New("validation-error: field AccountID must be set")
}
@@ -22,8 +28,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
}
@@ -36,4 +43,4 @@ func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error)
}
return true, nil
}
}

View File

@@ -5,33 +5,95 @@ import (
"errors"
"net/http"
"strconv"
"github.com/rudecs/decort-sdk/internal/validators"
)
// Request struct for update account
type UpdateRequest struct {
AccountID uint64 `url:"accountId"`
Name string `url:"name"`
MaxMemoryCapacity uint64 `url:"maxMemoryCapacity,omitempty"`
MaxVDiskCapacity uint64 `url:"maxVDiskCapacity,omitempty"`
MaxCPUCapacity uint64 `url:"maxCPUCapacity,omitempty"`
// ID of account
// Required: true
AccountID uint64 `url:"accountId"`
// 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"`
// List of strings with pools
// i.e.: ["sep1_poolName1", "sep2_poolName2", etc]
// Required: false
UniqPools []string `url:"uniqPools,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 must be set")
}
if arq.Name == "" {
return errors.New("validation-error: field Name 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
}
// 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

@@ -7,13 +7,25 @@ import (
"strconv"
)
// 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 must be set")
}
@@ -27,8 +39,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
}