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,11 +12,11 @@ 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,
// Should be one of:
@@ -25,33 +24,20 @@ type AccessGrantRequest struct {
// - "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("validation-error: field RGID must be set")
}
if rgrq.User == "" {
return errors.New("validation-error: field User must be set")
}
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 := "/cloudbroker/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("validation-error: field RGID must be set")
}
if rgrq.User == "" {
return errors.New("validation-error: field User must be set")
}
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 := "/cloudbroker/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("validation-error: field RGID must be set")
}
if rgrq.AffinityGroup == "" {
return errors.New("validation-error: field AffinityGroup must be set")
}
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) (ListAffinityGroupCompute, 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 := "/cloudbroker/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("validation-error: field RGID must be set")
}
if rgrq.AffinityGroup == "" {
return errors.New("validation-error: field AffinityGroup must be set")
}
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 := "/cloudbroker/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("validation-error: field RGID must be set")
}
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 := "/cloudbroker/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("validation-error: field RGID must be set")
}
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 := "/cloudbroker/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"`
// 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
@@ -84,25 +85,13 @@ type CreateRequest struct {
UniqPools []string `url:"unuqPools,omitempty" json:"unuqPools,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 := "/cloudbroker/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("validation-error: field RGID must be set")
}
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 := "/cloudbroker/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("validation-error: field RGID must be set")
}
return nil
}
// Disable disables resource group by ID
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 := "/cloudbroker/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("validation-error: field RGID must be set")
}
return nil
}
// Enable enables resource group by ID
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 := "/cloudbroker/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("validation-error: field RGID must be set")
}
return nil
}
// Get gets current configuration of the resource group
func (r RG) Get(ctx context.Context, req GetRequest) (*RecordRG, 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 := "/cloudbroker/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("validation-error: field RGID must be set")
}
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 := "/cloudbroker/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("validation-error: field RGID must be set")
}
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 := "/cloudbroker/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("validation-error: field RGID must be set")
}
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) (ListPFW, 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 := "/cloudbroker/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("validation-error: field RGID must be set")
}
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 := "/cloudbroker/rg/listVins"

View File

@@ -2,15 +2,16 @@ package rg
import (
"context"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for delete several resource groups
type MassDeleteRequest struct {
// IDs of the resource groups
// Required: true
RGIDs []uint64 `url:"rgIds" json:"rgIds"`
RGIDs []uint64 `url:"rgIds" json:"rgIds" validate:"min=1"`
// Set to true if you want force delete non-empty resource groups
// Required: false
@@ -28,19 +29,13 @@ type MassDeleteRequest struct {
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
func (rgrq MassDeleteRequest) validate() error {
if len(rgrq.RGIDs) == 0 {
return errors.New("validation-error: field RGIDs must be set")
}
return nil
}
// MassDelete starts jobs to delete several resource groups
func (r RG) MassDelete(ctx context.Context, req MassDeleteRequest) (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 := "/cloudbroker/rg/massDelete"

View File

@@ -2,34 +2,29 @@ package rg
import (
"context"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for disable several resource groups
type MassDisableRequest struct {
// IDs of the resource groups
// Required: true
RGIDs []uint64 `url:"rgIds" json:"rgIds"`
RGIDs []uint64 `url:"rgIds" json:"rgIds" validate:"min=1"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
func (rgrq MassDisableRequest) validate() error {
if len(rgrq.RGIDs) == 0 {
return errors.New("validation-error: field RGIDs must be set")
}
return nil
}
// MassDisable start jobs to disable several resource groups
func (r RG) MassDisable(ctx context.Context, req MassDisableRequest) (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 := "/cloudbroker/rg/massDisable"

View File

@@ -2,34 +2,29 @@ package rg
import (
"context"
"errors"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for enable several resource groups
type MassEnableRequest struct {
// IDs of the resource groups
// Required: true
RGIDs []uint64 `url:"rgIds" json:"rgIds"`
RGIDs []uint64 `url:"rgIds" json:"rgIds" validate:"min=1"`
// Reason for action
// Required: false
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
}
func (rgrq MassEnableRequest) validate() error {
if len(rgrq.RGIDs) == 0 {
return errors.New("validation-error: field RGIDs must be set")
}
return nil
}
// MassEnable start jobs to enable several resource groups
func (r RG) MassEnable(ctx context.Context, req MassEnableRequest) (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 := "/cloudbroker/rg/massEnable"

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("validation-error: field RGID must be set")
}
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 := "/cloudbroker/rg/restore"

View File

@@ -2,7 +2,6 @@ package rg
import (
"context"
"errors"
"net/http"
"strconv"
@@ -13,41 +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("validation-error: field RGID must be set")
}
validate := validators.StringInSlice(rgrq.NetType, []string{"PUBLIC", "PRIVATE"})
if !validate {
return errors.New("validation-error: field NetType must be one of PRIVATE or PUBLIC")
}
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 := "/cloudbroker/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
@@ -54,19 +55,13 @@ type UpdateRequest struct {
UniqPools []string `url:"uniqPools,omitempty" json:"uniqPools,omitempty"`
}
func (rgrq UpdateRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
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 := "/cloudbroker/rg/update"

View File

@@ -2,7 +2,6 @@ package rg
import (
"context"
"errors"
"net/http"
"strconv"
@@ -13,7 +12,7 @@ import (
type UpdateResourceTypesRequest struct {
// ID of resource group
// Required: true
RGID uint64 `url:"rgId" json:"rgId"`
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Resource types available to create in this resource group
// Each element in a resource type slice must be one of:
@@ -24,29 +23,15 @@ type UpdateResourceTypesRequest struct {
// - lb
// - flipgroup
// Required: true
ResTypes []string `url:"resourceTypes" json:"resourceTypes"`
}
func (rgrq UpdateResourceTypesRequest) validate() error {
if rgrq.RGID == 0 {
return errors.New("validation-error: field RGID must be set")
}
if len(rgrq.ResTypes) > 0 {
for _, value := range rgrq.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
ResTypes []string `url:"resourceTypes" json:"resourceTypes" validate:"min=1,resTypes"`
}
func (r RG) UpdateResourceTypes(ctx context.Context, req UpdateResourceTypesRequest) (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 := "/cloudbroker/rg/updateResourceTypes"

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("validation-error: field RGID must be set")
}
return nil
}
// Usage gets report resource usage on the resource group
func (r RG) Usage(ctx context.Context, req UsageRequest) (*Reservation, 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 := "/cloudbroker/rg/usage"