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 trunk
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AccessGrant struct to grant access to a trunk to some accounts
type AccessGrantRequest struct {
// ID of the trunk to disable
// Required: true
TrunkID uint64 `url:"id" json:"id" validate:"required"`
// IDs of the accounts to grant access to
// Required: true
AccountIDs []uint64 `url:"account_ids" json:"account_ids" validate:"required"`
}
// AccessGrant grants access to a trunk
func (t Trunk) AccessGrant(ctx context.Context, req AccessGrantRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/trunk/access_grant"
res, err := t.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 trunk
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AccessRevoke struct to grant access to a trunk to some accounts
type AccessRevokeRequest struct {
// ID of the trunk to disable
// Required: true
TrunkID uint64 `url:"id" json:"id" validate:"required"`
// IDs of the accounts to revoke access from
// Required: true
AccountIDs []uint64 `url:"account_ids" json:"account_ids" validate:"required"`
}
// AccessRevoke revokes access to a trunk from accounts
func (t Trunk) AccessRevoke(ctx context.Context, req AccessRevokeRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/trunk/access_revoke"
res, err := t.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,58 @@
package trunk
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// CreateRequest struct to create a trunk
type CreateRequest struct {
// Name of the trunk
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// List of trunk tags (values between 1-4095)
// Required: true
TrunkTags string `url:"trunk_tags" json:"trunk_tags" validate:"required,trunkTags"`
// OVS bridge name
// Required: true
OVSBridge string `url:"ovs_bridge" json:"ovs_bridge" validate:"required"`
// Description of the trunk
// Required: false
Description string `url:"description,omitempty" json:"description,omitempty"`
// List of account IDs with access to this trunk
// Required: false
AccountIDs []uint64 `url:"account_ids,omitempty" json:"account_ids,omitempty"`
// Native VLAN ID
// Required: false
NativeVLANID uint64 `url:"native_vlan_id,omitempty" json:"native_vlan_id,omitempty"`
}
// Create creates a user.
func (t Trunk) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/trunk/create"
res, err := t.client.DecortApiCall(ctx, http.MethodPost, url, 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,38 @@
package trunk
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DestroyRequest struct to destroy a trunk
type DestroyRequest struct {
// ID of the trunk to destroy
// Required: true
TrunkID uint64 `url:"id" json:"id" validate:"required"`
}
// Destroy destroys a trunk
func (t Trunk) Destroy(ctx context.Context, req DestroyRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/trunk/destroy"
res, err := t.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,38 @@
package trunk
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DisableRequest struct to disable a trunk
type DisableRequest struct {
// ID of the trunk to disable
// Required: true
TrunkID uint64 `url:"id" json:"id" validate:"required"`
}
// Disable disables a trunk by ID
func (t Trunk) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/trunk/disable"
res, err := t.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,38 @@
package trunk
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// EnableRequest struct to enable a trunk
type EnableRequest struct {
// ID of the trunk to enable
// Required: true
TrunkID uint64 `url:"id" json:"id" validate:"required"`
}
// Enable enables a trunk
func (t Trunk) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/trunk/enable"
res, err := t.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 trunk
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetRequest struct to get information about a trunk
type GetRequest struct {
// ID of trunk
// Required: true
TrunkID uint64 `url:"id" json:"id" validate:"required"`
}
// Get gets detailed information about a trunk as a ItemTrunk struct
func (t Trunk) Get(ctx context.Context, req GetRequest) (*ItemTrunk, error) {
res, err := t.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := ItemTrunk{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets detailed information about a trunk as an array of bytes
func (t Trunk) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/trunk/get"
res, err := t.client.DecortApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -0,0 +1,61 @@
package trunk
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ListRequest struct to get list of trunks
type ListRequest struct {
// Account access ID to filter by
AccountIDs []uint64 `url:"account_ids,omitempty" json:"account_ids,omitempty"`
// ID of the trunk to filter by
IDs []uint64 `url:"ids,omitempty" json:"ids,omitempty"`
// Sort by one of supported fields, format ±<field>
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty"`
// Trunk tags to filter by
TrunkTags string `url:"trunk_tags,omitempty" json:"trunk_tags,omitempty" validate:"omitempty,trunkTags"`
// Page number
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list of all trunks as a ListTrunks struct
func (t Trunk) List(ctx context.Context, req ListRequest) (*ListTrunks, error) {
res, err := t.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListTrunks{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of all trunks as an array of bytes
func (t Trunk) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/trunk/list"
res, err := t.client.DecortApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -0,0 +1,59 @@
package trunk
type ItemTrunk struct {
// List of account IDs with access to this trunk
AccountIDs []uint64 `json:"accountIds"`
// Created at
CreatedAt uint64 `json:"created_at"`
// Created by
CreatedBy string `json:"created_by"`
// Deleted at
DeletedAt uint64 `json:"deleted_at"`
// Deleted by
DeletedBy string `json:"deleted_by"`
// Description of a trunk
Description string `json:"description"`
// GUID
GUID uint64 `json:"guid"`
// ID of a trunk
ID uint64 `json:"id"`
// MAC
MAC string `json:"mac"`
// Name of a trunk
Name string `json:"name"`
// Native VLAN ID
NativeVLANID uint64 `json:"nativeVlanId"`
// OVS bridge name
OVSBridge string `json:"ovsBridge"`
// If the trunk is enabled
Status string `json:"status"`
// List of trunk tags (values between 1-4095)
TrunkTags string `json:"trunkTags"`
// Updated at
UpdatedAt uint64 `json:"updated_at"`
// Updated by
UpdatedBy string `json:"updated_by"`
}
// List of trunks
type ListTrunks struct {
Data []ItemTrunk `json:"data"`
EntryCount uint64 `json:"entryCount"`
}

View File

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

View File

@@ -0,0 +1,54 @@
package trunk
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// UpdateRequest struct to update a trunk
type UpdateRequest struct {
// ID of the trunk to update
// Required: true
TrunkID uint64 `url:"id" json:"id" validate:"required"`
// New name of the trunk
// Required: true
Name string `url:"name" json:"name" validate:"required"`
// List of trunk tags (values between 1-4095)
// Required: true
TrunkTags string `url:"trunk_tags" json:"trunk_tags" validate:"required,trunkTags"`
// New description of the trunk
// Required: false
Description string `url:"description,omitempty" json:"description,omitempty"`
// New native VLAN ID
// Required: false
NativeVLANID uint64 `url:"native_vlan_id,omitempty" json:"native_vlan_id,omitempty"`
}
// Update updates a trunk
func (t Trunk) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/trunk/update"
res, err := t.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
}