v1.5.0-gamma

This commit is contained in:
2023-06-30 11:21:47 +03:00
parent 29c7f143fe
commit f50f71ab0d
98 changed files with 2369 additions and 1150 deletions

View File

@@ -14,8 +14,8 @@ type DeleteRequest struct {
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Reason to delete
// Required: true
Reason string `url:"reason" json:"reason" validate:"required"`
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
// Whether to completely delete the account
// Required: false

View File

@@ -14,8 +14,8 @@ type DeleteAccountsRequest struct {
AccountsIDs []uint64 `url:"accountIds" json:"accountIds" validate:"min=1"`
// Reason for deletion
// Required: true
Reason string `url:"reason" json:"reason" validate:"required"`
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
// Whether to completely destroy accounts or not
// Required: false

View File

@@ -1,34 +1,34 @@
package account
// FilterByID returns ListAccounts with specified ID.
func (la ListAccounts) FilterByID(id uint64) ListAccounts {
// FilterByID returns ListDeleted with specified ID.
func (ld ListDeleted) FilterByID(id uint64) ListDeleted {
predicate := func(ia ItemAccount) bool {
return ia.ID == id
}
return la.FilterFunc(predicate)
return ld.FilterFunc(predicate)
}
// FilterByName returns ListAccounts with specified Name.
func (la ListAccounts) FilterByName(name string) ListAccounts {
// FilterByName returns ListDeleted with specified Name.
func (ld ListDeleted) FilterByName(name string) ListDeleted {
predicate := func(ia ItemAccount) bool {
return ia.Name == name
}
return la.FilterFunc(predicate)
return ld.FilterFunc(predicate)
}
// FilterByStatus returns ListAccounts with specified Status.
func (la ListAccounts) FilterByStatus(status string) ListAccounts {
// FilterByStatus returns ListDeleted with specified Status.
func (ld ListDeleted) FilterByStatus(status string) ListDeleted {
predicate := func(ia ItemAccount) bool {
return ia.Status == status
}
return la.FilterFunc(predicate)
return ld.FilterFunc(predicate)
}
// FilterByUserGroupID returns ListAccounts with specified UserGroupID.
func (la ListAccounts) FilterByUserGroupID(userGroupID string) ListAccounts {
// FilterByUserGroupID returns ListDeleted with specified UserGroupID.
func (ld ListDeleted) FilterByUserGroupID(userGroupID string) ListDeleted {
predicate := func(ia ItemAccount) bool {
acl := ia.ACL
@@ -41,32 +41,32 @@ func (la ListAccounts) FilterByUserGroupID(userGroupID string) ListAccounts {
return false
}
return la.FilterFunc(predicate)
return ld.FilterFunc(predicate)
}
// FilterByCompany returns ListAccounts with specified Company.
func (la ListAccounts) FilterByCompany(company string) ListAccounts {
// FilterByCompany returns ListDeleted with specified Company.
func (ld ListDeleted) FilterByCompany(company string) ListDeleted {
predicate := func(ia ItemAccount) bool {
return ia.Company == company
}
return la.FilterFunc(predicate)
return ld.FilterFunc(predicate)
}
// FilterByCreatedBy returns ListAccounts created by specified user.
func (la ListAccounts) FilterByCreatedBy(createdBy string) ListAccounts {
// FilterByCreatedBy returns ListDeleted created by specified user.
func (ld ListDeleted) FilterByCreatedBy(createdBy string) ListDeleted {
predicate := func(ia ItemAccount) bool {
return ia.CreatedBy == createdBy
}
return la.FilterFunc(predicate)
return ld.FilterFunc(predicate)
}
// FilterFunc allows filtering ListAccounts based on a user-specified predicate.
func (la ListAccounts) FilterFunc(predicate func(ItemAccount) bool) ListAccounts {
var result ListAccounts
// FilterFunc allows filtering ListDeleted based on a user-specified predicate.
func (ld ListDeleted) FilterFunc(predicate func(ItemAccount) bool) ListDeleted {
var result ListDeleted
for _, item := range la {
for _, item := range ld {
if predicate(item) {
result = append(result, item)
}
@@ -77,10 +77,10 @@ func (la ListAccounts) FilterFunc(predicate func(ItemAccount) bool) ListAccounts
// FindOne returns first found ItemAccount.
// If none was found, returns an empty struct.
func (la ListAccounts) FindOne() ItemAccount {
if len(la) == 0 {
func (ld ListDeleted) FindOne() ItemAccount {
if len(ld) == 0 {
return ItemAccount{}
}
return la[0]
return ld[0]
}

View File

@@ -4,7 +4,7 @@ import (
"testing"
)
var accounts = ListAccounts{
var accounts = ListDeleted{
ItemAccount{
Meta: []interface{}{},
InfoAccount: InfoAccount{

View File

@@ -0,0 +1,42 @@
package account
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for getting resource consumption
type GetResourceConsumptionRequest struct {
// ID an account
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// GetResourceConsumption show amount of consumed and reserved resources (cpu, ram, disk) by specific account
func (a Account) GetResourceConsumption(ctx context.Context, req GetResourceConsumptionRequest) (*RecordResources, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudbroker/account/getResourceConsumption"
info := RecordResources{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -8,6 +8,22 @@ import (
// Request struct for get list of accounts
type ListRequest struct {
// Find by ID
// Required: false
ByID uint64 `url:"by_id" json:"by_id"`
// Find by name
// Required: false
Name string `urL:"name" json:"name"`
// Find by access control list
// Required: false
ACL string `url:"acl" json:"acl"`
// Find by status
// Required: false
Status string `url:"status" json:"status"`
// Page number
// Required: false
Page uint64 `url:"page" json:"page"`
@@ -18,7 +34,7 @@ type ListRequest struct {
}
// List gets list all accounts the user has access to
func (a Account) List(ctx context.Context, req ListRequest) (ListAccounts, error) {
func (a Account) List(ctx context.Context, req ListRequest) (*ListAccounts, error) {
url := "/cloudbroker/account/list"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -33,5 +49,5 @@ func (a Account) List(ctx context.Context, req ListRequest) (ListAccounts, error
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -18,7 +18,7 @@ type ListDeletedRequest struct {
}
// ListDeleted gets list all deleted accounts the user has access to
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListAccounts, error) {
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListDeleted, error) {
url := "/cloudbroker/account/listDeleted"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
@@ -26,7 +26,7 @@ func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListA
return nil, err
}
list := ListAccounts{}
list := ListDeleted{}
err = json.Unmarshal(res, &list)
if err != nil {

View File

@@ -0,0 +1,26 @@
package account
import (
"context"
"encoding/json"
"net/http"
)
// ListResourceConsumption show data list amount of consumed and reserved resources (cpu, ram, disk) by specific accounts
func (a Account) ListResourceConsumption(ctx context.Context) (*ListResources, error) {
url := "/cloudbroker/account/listResourceConsumption"
info := ListResources{}
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, nil)
if err != nil {
return nil, err
}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -27,6 +27,17 @@ type RecordResources struct {
// Reserved information about resources
Reserved Resource `json:"Reserved"`
// ID of account
AccountID uint64 `json:"id"`
}
type ListResources struct {
// Data
Data []RecordResources `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
type Resource struct {
@@ -61,7 +72,7 @@ type DiskUsage struct {
DiskSize float64 `json:"disksize"`
// Disk size max
DiskSizeMax uint64 `json:"disksizemax"`
DiskSizeMax float64 `json:"disksizemax"`
}
// Access Control List
@@ -87,12 +98,15 @@ type ACL struct {
// Resource limits
type ResourceLimits struct {
// CuC
// CuC
CuC float64 `json:"CU_C"`
// CuD
CuD float64 `json:"CU_D"`
// CuDM
CuDM float64 `json:"CU_DM"`
// CuI
CuI float64 `json:"CU_I"`
@@ -183,9 +197,6 @@ type InfoAccount struct {
// Deatailed information about account
type RecordAccount struct {
// Resources
Resources RecordResources `json:"Resources"`
// Main information about account
InfoAccount
}
@@ -200,7 +211,14 @@ type ItemAccount struct {
}
// List of accounts
type ListAccounts []ItemAccount
type ListDeleted []ItemAccount
// List of accounts
type ListAccounts struct {
Data []ItemAccount `json:"data"`
EntryCount uint64 `json:"entryCount"`
}
// List of computes
type ListComputes []ItemCompute
@@ -379,7 +397,7 @@ type Consumed struct {
CPU uint64 `json:"cpu"`
// Disk size
DiskSize uint64 `json:"disksize"`
DiskSize float64 `json:"disksize"`
// Disk size max
DiskSizeMax int64 `json:"disksizemax"`

View File

@@ -14,8 +14,8 @@ type RestoreRequest struct {
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Reason to restore
// Required: true
Reason string `url:"reason" json:"reason" validate:"required"`
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
// Restore restores a deleted account

View File

@@ -6,13 +6,33 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/serialization"
)
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (ld ListDeleted) Serialize(params ...string) (serialization.Serialized, error) {
if len(ld) == 0 {
return []byte{}, nil
}
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(ld, prefix, indent)
}
return json.Marshal(ld)
}
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (la ListAccounts) Serialize(params ...string) (serialization.Serialized, error) {
if len(la) == 0 {
if la.EntryCount == 0 {
return []byte{}, nil
}

View File

@@ -2,20 +2,77 @@ package account
import "sort"
// SortByCreatedTime sorts ListDeleted by the CreatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (ld ListDeleted) SortByCreatedTime(inverse bool) ListDeleted {
if len(ld) < 2 {
return ld
}
sort.Slice(ld, func(i, j int) bool {
if inverse {
return ld[i].CreatedTime > ld[j].CreatedTime
}
return ld[i].CreatedTime < ld[j].CreatedTime
})
return ld
}
// SortByUpdatedTime sorts ListDeleted by the UpdatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (ld ListDeleted) SortByUpdatedTime(inverse bool) ListDeleted {
if len(ld) < 2 {
return ld
}
sort.Slice(ld, func(i, j int) bool {
if inverse {
return ld[i].UpdatedTime > ld[j].UpdatedTime
}
return ld[i].UpdatedTime < ld[j].UpdatedTime
})
return ld
}
// SortByDeletedTime sorts ListDeleted by the DeletedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (ld ListDeleted) SortByDeletedTime(inverse bool) ListDeleted {
if len(ld) < 2 {
return ld
}
sort.Slice(ld, func(i, j int) bool {
if inverse {
return ld[i].DeletedTime > ld[j].DeletedTime
}
return ld[i].DeletedTime < ld[j].DeletedTime
})
return ld
}
// SortByCreatedTime sorts ListAccounts by the CreatedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (la ListAccounts) SortByCreatedTime(inverse bool) ListAccounts {
if len(la) < 2 {
if la.EntryCount < 2 {
return la
}
sort.Slice(la, func(i, j int) bool {
sort.Slice(la.Data, func(i, j int) bool {
if inverse {
return la[i].CreatedTime > la[j].CreatedTime
return la.Data[i].CreatedTime > la.Data[j].CreatedTime
}
return la[i].CreatedTime < la[j].CreatedTime
return la.Data[i].CreatedTime < la.Data[j].CreatedTime
})
return la
@@ -25,35 +82,35 @@ func (la ListAccounts) SortByCreatedTime(inverse bool) ListAccounts {
//
// If inverse param is set to true, the order is reversed.
func (la ListAccounts) SortByUpdatedTime(inverse bool) ListAccounts {
if len(la) < 2 {
if la.EntryCount < 2 {
return la
}
sort.Slice(la, func(i, j int) bool {
sort.Slice(la.Data, func(i, j int) bool {
if inverse {
return la[i].UpdatedTime > la[j].UpdatedTime
return la.Data[i].UpdatedTime > la.Data[j].UpdatedTime
}
return la[i].UpdatedTime < la[j].UpdatedTime
return la.Data[i].UpdatedTime < la.Data[j].UpdatedTime
})
return la
}
// SortByDeletedTime sorts ListAccounts by the DeletedTime field in ascending order.
// SortByDeletedTime sorts LisAccounts by the DeletedTime field in ascending order.
//
// If inverse param is set to true, the order is reversed.
func (la ListAccounts) SortByDeletedTime(inverse bool) ListAccounts {
if len(la) < 2 {
if la.EntryCount < 2 {
return la
}
sort.Slice(la, func(i, j int) bool {
sort.Slice(la.Data, func(i, j int) bool {
if inverse {
return la[i].DeletedTime > la[j].DeletedTime
return la.Data[i].DeletedTime > la.Data[j].DeletedTime
}
return la[i].DeletedTime < la[j].DeletedTime
return la.Data[i].DeletedTime < la.Data[j].DeletedTime
})
return la

View File

@@ -14,18 +14,10 @@ type UpdateRequest struct {
// Required: true
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Display name
// Name of the account
// Required: false
Name string `url:"name" json:"name"`
// Name of the account
// Required: true
Username string `url:"username,omitempty" json:"username,omitempty"`
// Email
// Required: false
EmailAddress string `url:"emailaddress,omitempty" json:"emailaddress,omitempty" validate:"omitempty,email"`
// Max size of memory in MB
// Required: false
MaxMemoryCapacity int64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`