v1.16.4
This commit is contained in:
dayterr
2026-09-18 16:49:20 +03:00
parent b39021820a
commit bf932e5ef9
161 changed files with 2375 additions and 227 deletions

View File

@@ -0,0 +1,47 @@
package vmfolder
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AddACLAccessRequest adds ACL access to a vm folder
type AddACLAccessRequest struct {
// ID of a folder
// Required: true
FolderID uint64 `url:"folder_id" json:"folder_id" validate:"required"`
// User or group name to grant access
// Required: true
User string `url:"user" json:"user" validate:"required"`
// ID of a folder
// Required: true
Right string `url:"right" json:"right" validate:"required"`
}
// AddACLAccess adds ACL access to a vm folder
func (v VMFolder) AddACLAccess(ctx context.Context, req AddACLAccessRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/vmfolder/add_acl_access"
res, err := v.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,42 @@
package vmfolder
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ComputesMoveRequest struct to move computes to a vm folder
type ComputesMoveRequest struct {
// IDs of computes to move
// Required: true
ComputeIDs []uint64 `url:"compute_ids" json:"compute_ids" validate:"required"`
// Target vm folder ID
// Required: true
FolderID uint64 `url:"folder_id" json:"folder_id" validate:"required"`
}
// ComputesMove moves computes to a vm folder
func (v VMFolder) ComputesMove(ctx context.Context, req ComputesMoveRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/vmfolder/computes_move"
res, err := v.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

@@ -0,0 +1,47 @@
package vmfolder
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// CreateRequest struct to create a vm folder
type CreateRequest struct {
// Resource Group ID
// Required: true
RGID uint64 `url:"rg_id" json:"rg_id" validate:"required"`
// Name
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// Parent ID
// Required: false
ParentID uint64 `url:"parent_id,omitempty" json:"parent_id,omitempty"`
}
// Create creates a vm folder
func (v VMFolder) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/vmfolder/create"
res, err := v.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}

View File

@@ -0,0 +1,43 @@
package vmfolder
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DeleteACLAccessRequest deletes ACL access from a vm folder
type DelACLAccessRequest struct {
// ID of a folder
// Required: true
FolderID uint64 `url:"folder_id" json:"folder_id"`
// User or group name to revoke access from
// Required: true
User string `url:"user" json:"user"`
}
// DeleteACLAccess deletes ACL access from a vm foler
func (v VMFolder) DeleteACLAccess(ctx context.Context, req DelACLAccessRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/vmfolder/del_acl_access"
res, err := v.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}

View File

@@ -0,0 +1,38 @@
package vmfolder
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DeleteRequest struct to delete a VM folder
type DeleteRequest struct {
// ID of a folder to delete
// Required: true
FolderID uint64 `url:"folder_id" json:"folder_id" validate:"required"`
}
// Delete deletes a vm folder
func (v VMFolder) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/vmfolder/delete"
res, err := v.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

@@ -0,0 +1,46 @@
package vmfolder
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetRequest struct to get detailed information about a vm folder
type GetRequest struct {
// ID of a folder
// Required: true
FolderID uint64 `url:"folder_id" json:"folder_id" validate:"required"`
}
// Get gets current configuration of the vm folder as a RecordVMFolder struct
func (v VMFolder) Get(ctx context.Context, req GetRequest) (*RecordVMFolder, error) {
res, err := v.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := RecordVMFolder{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets current configuration of the vm folder as an array of bytes
func (v VMFolder) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/vmfolder/get"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,55 @@
package vmfolder
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ListRequest struct to get list of vm folders
type ListRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rg_id" json:"rg_id" validate:"required"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list of all vm folders in a resource group as a ListVMFolder struct
func (v VMFolder) List(ctx context.Context, req ListRequest) (*ListVMFolder, error) {
res, err := v.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListVMFolder{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of all vm folders in a resource group as an array of bytes
func (v VMFolder) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/vmfolder/list"
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,82 @@
package vmfolder
// Detailed information about a folder
type RecordVMFolder struct {
// ID
ID uint64 `json:"id"`
// RG ID
RGID uint64 `json:"rg_id"`
// GID
GID uint64 `json:"gid"`
// Name of a folder
Name string `json:"name"`
// ACL
ACL []ACL `json:"acl"`
// Time of creation
CreatedTime uint64 `json:"created_time"`
// Parent ID
ParentID uint64 `json:"parent_id"`
// Status of a folder
Status string `json:"status"`
// Compute IDs
ComputeIDs []uint64 `json:"compute_ids"`
// Time of update
UpdatedTime uint64 `json:"updated_time"`
}
// ACL
type ACL struct {
// Explicit
Explicit bool `json:"explicit"`
// Right
Right string `json:"right"`
// Status
Status string `json:"status"`
// Type
Type string `json:"type"`
// User group ID
UserGroupID string `json:"userGroupId"`
}
// List of vm folders
type ListVMFolder struct {
// Entry count
EntryCount uint64 `json:"entryCount"`
// Data
Data []ItemVMFolder `json:"data"`
}
// Detailed information about a folder item
type ItemVMFolder struct {
// Folder ID
ID uint64 `json:"id"`
// Parent ID
ParentID uint64 `json:"parent_id"`
// Name
Name string `json:"name"`
// ACL
ACL []ACL `json:"acl"`
// Status
Status string `json:"status"`
// VM count
VMCount uint64 `json:"vm_count"`
}

View File

@@ -0,0 +1,42 @@
package vmfolder
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// MoveRequest to move a vm folder to a compute
type MoveRequest struct {
// VM Folder ID
// Required: true
FolderID uint64 `url:"folder_id" json:"folder_id"`
// New parent folder ID
// Required: true
NewParentID uint64 `url:"new_parent_id" json:"new_parent_id"`
}
// Move moves a vm folder to a compute
func (v VMFolder) Move(ctx context.Context, req MoveRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/vmfolder/move"
res, err := v.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

@@ -0,0 +1,42 @@
package vmfolder
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// RenameRequest struct to rename a VM folder
type RenameRequest struct {
// ID of a folder to rename
// Required: true
FolderID uint64 `url:"folder_id" json:"folder_id" validate:"required"`
// A new name
// Required: true
Name string `url:"name" json:"name" validate:"required"`
}
// Rename renames a vm folder
func (v VMFolder) Rename(ctx context.Context, req RenameRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/vmfolder/rename"
res, err := v.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

@@ -0,0 +1,17 @@
package vmfolder
import (
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
)
// Structure for creating request to VMFolder
type VMFolder struct {
client interfaces.Caller
}
// Builder for VMFolder endpoints
func New(client interfaces.Caller) *VMFolder {
return &VMFolder{
client,
}
}