This commit is contained in:
2023-03-24 17:09:30 +03:00
parent 437841c8dd
commit 84b64b7d80
433 changed files with 4246 additions and 6516 deletions

View File

@@ -2,7 +2,6 @@ package rg
import (
"context"
"errors"
"net/http"
"strconv"
@@ -13,44 +12,31 @@ import (
type AccessGrantRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// User or group name to grant access
// Required: true
User string `url:"user" json:"user"`
User string `url:"user" json:"user" validate:"required"`
// Access rights to set, one of:
// - "R"
// - "RCX"
// - "ARCXDU"
// Required: true
Right string `url:"right" json:"right"`
Right string `url:"right" json:"right" validate:"accessType"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
func (rgrq AccessGrantRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
if rgrq.User == "" {
return errors.New("field User can not be empty")
}
validate := validators.StringInSlice(rgrq.Right, []string{"R", "RCX", "ARCXDU"})
if !validate {
return errors.New("field Right can only be one of 'R', 'RCX' or 'ARCXDU'")
}
return nil
}
// AccessGrant grants user or group access to the resource group as specified
func (r RG) AccessGrant(ctx context.Context, req AccessGrantRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/accessGrant"

View File

@@ -2,42 +2,34 @@ package rg
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for revoke access
type AccessRevokeRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// User or group name to revoke access
// Required: true
User string `url:"user" json:"user"`
User string `url:"user" json:"user" validate:"required"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
func (rgrq AccessRevokeRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
if rgrq.User == "" {
return errors.New("field User can not be empty")
}
return nil
}
// AccessRevoke revokes specified user or group access from the resource group
func (r RG) AccessRevoke(ctx context.Context, req AccessRevokeRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/accessRevoke"

View File

@@ -3,37 +3,29 @@ package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list of all computes with their relationships
type AffinityGroupComputesRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Affinity group label
// Required: true
AffinityGroup string `url:"affinityGroup" json:"affinityGroup"`
}
func (rgrq AffinityGroupComputesRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
if rgrq.AffinityGroup == "" {
return errors.New("field AffinityGroup cat not be empty")
}
return nil
AffinityGroup string `url:"affinityGroup" json:"affinityGroup" validate:"required"`
}
// AffinityGroupComputes gets list of all computes with their relationships to another computes
func (r RG) AffinityGroupComputes(ctx context.Context, req AffinityGroupComputesRequest) (ListAffinityGroups, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/affinityGroupComputes"

View File

@@ -3,37 +3,29 @@ package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list computes from affinity group
type AffinityGroupsGetRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Label affinity group
// Required: true
AffinityGroup string `url:"affinityGroup" json:"affinityGroup"`
}
func (rgrq AffinityGroupsGetRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
if rgrq.AffinityGroup == "" {
return errors.New("field AffinityGroup cat not be empty")
}
return nil
AffinityGroup string `url:"affinityGroup" json:"affinityGroup" validate:"required"`
}
// AffinityGroupsGet gets list computes in the specified affinity group
func (r RG) AffinityGroupsGet(ctx context.Context, req AffinityGroupsGetRequest) ([]uint64, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/affinityGroupsGet"

View File

@@ -3,30 +3,25 @@ package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list of affinity groups from resource group
type AffinityGroupsListRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
}
func (rgrq AffinityGroupsListRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
}
// AffinityGroupsList gets all currently defined affinity groups in this resource group with compute IDs
func (r RG) AffinityGroupsList(ctx context.Context, req AffinityGroupsListRequest) (map[string][]uint64, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/affinityGroupsList"

View File

@@ -3,30 +3,25 @@ package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get audit
type AuditsRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
}
func (rgrq AuditsRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
}
// Audits gets audit records for the specified resource group object
func (r RG) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/audits"

View File

@@ -2,24 +2,25 @@ package rg
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for create resource group
type CreateRequest struct {
// Account, which will own this resource group
// Required: true
AccountID uint64 `url:"accountId" json:"accountId"`
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
// Grid ID
// Required: true
GID uint64 `url:"gid" json:"gid"`
GID uint64 `url:"gid" json:"gid" validate:"required"`
// Name of this resource group. Must be unique within the account
// Required: true
Name string `url:"name" json:"name"`
Name string `url:"name" json:"name" validate:"required,min=2"`
// Max size of memory in MB
// Required: false
@@ -53,7 +54,7 @@ type CreateRequest struct {
// - PUBLIC
// - NONE
// Required: false
DefNet string `url:"def_net,omitempty" json:"def_net,omitempty"`
DefNet string `url:"def_net,omitempty" json:"def_net,omitempty" validate:"omitempty,rgDefNet"`
// Private network IP CIDR if default network PRIVATE
// Required: false
@@ -80,25 +81,13 @@ type CreateRequest struct {
RegisterComputes bool `url:"registerComputes,omitempty" json:"registerComputes,omitempty"`
}
func (rgrq CreateRequest) validate() error {
if rgrq.AccountID == 0 {
return errors.New("field AccountID can not be empty or equal to 0")
}
if rgrq.GID == 0 {
return errors.New("field GID can not be empty or equal to 0")
}
if len(rgrq.Name) < 2 {
return errors.New("field Name can not be shorter than two bytes")
}
return nil
}
// Create creates resource group
func (r RG) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return 0, err
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/create"

View File

@@ -2,16 +2,17 @@ package rg
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for delete resource group
type DeleteRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Set to True if you want force delete non-empty resource group
// Required: false
@@ -27,19 +28,13 @@ type DeleteRequest struct {
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
func (rgrq DeleteRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
// Delete deletes resource group
func (r RG) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/delete"

View File

@@ -2,35 +2,30 @@ package rg
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for disable resource group
type DisableRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
func (rgrq DisableRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
// Disable disables resource group
func (r RG) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/disable"

View File

@@ -2,35 +2,30 @@ package rg
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for enable resource group
type EnableRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
func (rgrq EnableRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
// Enable enables resource group
func (r RG) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/enable"

View File

@@ -3,34 +3,29 @@ package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get detailed information about resource group
type GetRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
func (rgrq GetRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
// Get gets current configuration of the resource group
func (r RG) Get(ctx context.Context, req GetRequest) (*RecordResourceGroup, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/get"

View File

@@ -3,34 +3,29 @@ package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list of computes
type ListComputesRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
func (rgrq ListComputesRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
// ListComputes gets list of all compute instances under specified resource group, accessible by the user
func (r RG) ListComputes(ctx context.Context, req ListComputesRequest) (ListComputes, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/listComputes"

View File

@@ -3,30 +3,25 @@ package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list load balancers
type ListLBRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
}
func (rgrq ListLBRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
}
// ListLB gets list all load balancers in the specified resource group, accessible by the user
func (r RG) ListLB(ctx context.Context, req ListLBRequest) (ListLB, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/listLb"

View File

@@ -3,30 +3,25 @@ package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list port forward rules
type ListPFWRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
}
func (rgrq ListPFWRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
}
// ListPFW gets list port forward rules for the specified resource group
func (r RG) ListPFW(ctx context.Context, req ListPFWRequest) (ListPortForwards, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/listPFW"

View File

@@ -3,34 +3,29 @@ package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get list VINSes
type ListVINSRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
func (rgrq ListVINSRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
// ListVINS gets list all ViNSes under specified resource group, accessible by the user
func (r RG) ListVINS(ctx context.Context, req ListVINSRequest) (ListVINS, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/listVins"

View File

@@ -2,35 +2,30 @@ package rg
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for restore resource group
type RestoreRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
func (rgrq RestoreRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
// Restore restores resource group from recycle bin
func (r RG) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/restore"

View File

@@ -2,7 +2,6 @@ package rg
import (
"context"
"errors"
"net/http"
"strconv"
@@ -13,40 +12,31 @@ import (
type SetDefNetRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Network type
// Should be one of:
// - "PUBLIC"
// - "PRIVATE"
// Required: true
NetType string `url:"netType" json:"netType"`
NetType string `url:"netType" json:"netType" validate:"rgNetType"`
// Network ID
// Required: false
NetID uint64 `url:"netId" json:"netId"`
NetID uint64 `url:"netId,omitempty" json:"netId,omitempty"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
func (rgrq SetDefNetRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
if !validators.StringInSlice(rgrq.NetType, []string{"PUBLIC", "PRIVATE"}) {
return errors.New("field NetType can only be one of 'PUBLIC' or 'PRIVATE'")
}
return nil
}
// SetDefNet sets default network for attach associated virtual machines
func (r RG) SetDefNet(ctx context.Context, req SetDefNetRequest) (uint64, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return 0, err
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/setDefNet"

View File

@@ -2,16 +2,17 @@ package rg
import (
"context"
"errors"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for update resource group
type UpdateRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// New name
// Required: false
@@ -50,19 +51,13 @@ type UpdateRequest struct {
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
func (rgrq UpdateRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
// Update updates resource group
func (r RG) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return false, err
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/update"

View File

@@ -3,34 +3,29 @@ package rg
import (
"context"
"encoding/json"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for get report of resource usage
type UsageRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
func (rgrq UsageRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("field RGID can not be empty or equal to 0")
}
return nil
}
// Usage gets report resource usage on the resource group
func (r RG) Usage(ctx context.Context, req UsageRequest) (*RecordResourceUsage, error) {
err := req.validate()
err := validators.ValidateRequest(req)
if err != nil {
return nil, err
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/rg/usage"