This commit is contained in:
asteam
2025-07-15 17:39:18 +03:00
parent 1f8637400f
commit 7dacf35cd6
163 changed files with 4322 additions and 504 deletions

View File

@@ -0,0 +1,42 @@
package account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AddZoneRequest struct for adding zone to account for a user
type AddZoneRequest struct {
// ID of account to add to
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// IDs of zones
// Required: true
ZoneIDs []uint64 `url:"zoneIds" json:"zoneIds" validate:"required"`
}
// AddUser gives a user access rights.
func (a Account) AddZone(ctx context.Context, req AddZoneRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/addZone"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -60,9 +60,17 @@ type CreateRequest struct {
UniqPools []string `url:"uniqPools,omitempty" json:"uniqPools,omitempty"`
// Advanced compute features,
// one of: hugepages, numa, cpupin, vfnic, dpdk, changemac
// one of: hugepages, numa, cpupin, vfnic, dpdk, changemac, trunk
// Required: false
ComputeFeatures []string `url:"computeFeatures,omitempty" json:"computeFeatures,omitempty" validate:"omitempty,computeFeatures"`
// Default zone ID
// Required: false
DefaultZoneID uint64 `url:"defaultZoneId,omitempty" json:"defaultZoneId,omitempty"`
// Zones
// Required: false
ZoneIDs []uint64 `url:"zoneIds,omitempty" json:"zoneIds,omitempty"`
}
// Create creates account

View File

@@ -20,25 +20,21 @@ type DeleteRequest struct {
// Name of account
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
// Reason of deleting
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
// 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) {
func (a Account) Delete(ctx context.Context, req DeleteRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/delete"
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
result, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
return "", err
}
return true, nil
return string(result), nil
}

View File

@@ -19,18 +19,18 @@ type DeleteAccountsRequest struct {
}
// DeleteAccounts destroys a group of accounts
func (a Account) DeleteAccounts(ctx context.Context, req DeleteAccountsRequest) (bool, error) {
func (a Account) DeleteAccounts(ctx context.Context, req DeleteAccountsRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/deleteAccounts"
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
return "", err
}
return true, nil
return string(res), nil
}

View File

@@ -13,10 +13,6 @@ type DisableRequest struct {
// ID of account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Reason of disabling
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
// Disable disables an account

View File

@@ -12,25 +12,21 @@ type DisableAccountsRequest struct {
// IDs of accounts
// Required: true
AccountIDs []uint64 `url:"accountIds" json:"accountIds" validate:"min=1"`
// Reason of disabling
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
// DisableAccounts disables accounts
func (a Account) DisableAccounts(ctx context.Context, req DisableAccountsRequest) (bool, error) {
func (a Account) DisableAccounts(ctx context.Context, req DisableAccountsRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/disableAccounts"
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
return "", err
}
return true, nil
return string(res), nil
}

View File

@@ -15,18 +15,18 @@ type EnableAccountsRequest struct {
}
// EnableAccounts enables accounts
func (a Account) EnableAccounts(ctx context.Context, req EnableAccountsRequest) (bool, error) {
func (a Account) EnableAccounts(ctx context.Context, req EnableAccountsRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/enableAccounts"
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
return "", err
}
return true, nil
return string(res), nil
}

View File

@@ -9,16 +9,6 @@ var accounts = ListAccounts{
{
Meta: []interface{}{},
InfoAccount: InfoAccount{
ACL: []ACL{
{
Explicit: true,
GUID: "",
Right: "CXDRAU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "not_really_timofey_tkachev_1@decs3o",
},
},
CreatedTime: 1676878820,
DeletedTime: 0,
ID: 132847,
@@ -26,20 +16,20 @@ var accounts = ListAccounts{
Status: "CONFIRMED",
UpdatedTime: 1676645275,
},
ACL: []ACL{
{
Explicit: true,
GUID: "",
Right: "CXDRAU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "not_really_timofey_tkachev_1@decs3o",
},
},
},
{
Meta: []interface{}{},
InfoAccount: InfoAccount{
ACL: []ACL{
{
Explicit: true,
GUID: "",
Right: "CXDRAU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "timofey_tkachev_1@decs3o",
},
},
CreatedTime: 1676645275,
DeletedTime: 1677723401,
ID: 132846,
@@ -47,28 +37,20 @@ var accounts = ListAccounts{
Status: "DELETED",
UpdatedTime: 1676645275,
},
ACL: []ACL{
{
Explicit: true,
GUID: "",
Right: "CXDRAU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "timofey_tkachev_1@decs3o",
},
},
},
{
Meta: []interface{}{},
InfoAccount: InfoAccount{
ACL: []ACL{
{
Explicit: true,
GUID: "",
Right: "CXDRAU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "timofey_tkachev_1@decs3o",
},
{
Explicit: true,
GUID: "",
Right: "CXDRAU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "second_account@decs3o",
},
},
CreatedTime: 1676883850,
DeletedTime: 1676883899,
ID: 132848,
@@ -76,6 +58,24 @@ var accounts = ListAccounts{
Status: "DELETED",
UpdatedTime: 1676878820,
},
ACL: []ACL{
{
Explicit: true,
GUID: "",
Right: "CXDRAU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "timofey_tkachev_1@decs3o",
},
{
Explicit: true,
GUID: "",
Right: "CXDRAU",
Status: "CONFIRMED",
Type: "U",
UserGroupID: "second_account@decs3o",
},
},
},
},
EntryCount: 3,

View File

@@ -102,6 +102,15 @@ type ACL struct {
UserGroupID string `json:"userGroupId"`
}
// Access Control List with emails field
type ACLWithEmails struct {
// ACL
ACL
// Emails
Emails []string `json:"emails"`
}
// Resource limits
type ResourceLimits struct {
// CuC
@@ -134,9 +143,6 @@ type InfoAccount struct {
// CKey
CKey string `json:"_ckey"`
// Access Control List
ACL []ACL `json:"acl"`
// Company
Company string `json:"company"`
@@ -205,12 +211,30 @@ type InfoAccount struct {
// List of VINS IDs
VINS []uint64 `json:"vins"`
// Default zone ID
DefaultZoneID uint64 `json:"defaultZoneId"`
}
// Deatailed information about the account zone
type ZoneID struct {
// ID of zone
ID int64 `json:"id"`
// Name of zone
Name string `json:"name"`
}
// Deatailed information about account
type RecordAccount struct {
// Main information about account
InfoAccount
// Access Control List
ACL []ACLWithEmails `json:"acl"`
// Zones IDs
ZoneIDs []ZoneID
}
// More information about account
@@ -218,8 +242,14 @@ type ItemAccount struct {
// Meta
Meta []interface{} `json:"_meta"`
// Access Control List
ACL []ACL `json:"acl"`
// Main information about account
InfoAccount
// Zones
ZoneIDs []uint64
}
// List of accounts

View File

@@ -0,0 +1,42 @@
package account
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// RemoveZoneRequest struct for removing zone from account for a user
type RemoveZoneRequest struct {
// ID of account to add to
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// IDs of zones
// Required: true
ZoneIDs []uint64 `url:"zoneIds" json:"zoneIds" validate:"required"`
}
// RemoveZone removes zones with ids provided from a user.
func (a Account) RemoveZone(ctx context.Context, req RemoveZoneRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/removeZone"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -12,25 +12,21 @@ type RestoreRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Reason of disabling
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
// Restore restores a deleted account
func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
func (a Account) Restore(ctx context.Context, req RestoreRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/account/restore"
_, err = a.client.DecortApiCall(ctx, http.MethodPost, url, req)
result, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return false, err
return "", err
}
return true, nil
return string(result), nil
}

View File

@@ -59,6 +59,10 @@ type UpdateRequest struct {
// Default: false
// Required: false
ClearUniqPools bool `url:"clearUniqPools" json:"clearUniqPools"`
// Default zone ID
// Required: false
DefaultZoneID uint64 `url:"defaultZoneId,omitempty" json:"defaultZoneId,omitempty"`
}
// Update updates an account name and resource types and limits

View File

@@ -15,7 +15,7 @@ type UpdateComputeFeaturesRequest struct {
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Advanced compute features,
// one of: hugepages, numa, cpupin, vfnic, dpdk, changemac
// one of: hugepages, numa, cpupin, vfnic, dpdk, changemac, trunk
// Required: false
ComputeFeatures []string `url:"computeFeatures,omitempty" json:"computeFeatures,omitempty" validate:"omitempty,computeFeatures"`
}