parent
e10ee7f801
commit
825b1a0a00
@ -0,0 +1,50 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ChangeSecGroupsRequest struct to change security groups for compute
|
||||
type ChangeSecGroupsRequest struct {
|
||||
// Identifier compute
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
|
||||
|
||||
// Interface name or MAC address
|
||||
// Required: true
|
||||
Interface string `url:"interface" json:"interface" validate:"required"`
|
||||
|
||||
// List of security group IDs to assign to this interface
|
||||
// Required: false
|
||||
SecGroups []uint64 `url:"security_groups,omitempty" json:"security_groups,omitempty"`
|
||||
|
||||
// Flag indicating whether security groups are enabled for this interface
|
||||
// Required: false
|
||||
EnableSecGroups bool `url:"enable_secgroups,omitempty" json:"enable_secgroups,omitempty"`
|
||||
}
|
||||
|
||||
// ChangeSecGroups changes security groups for compute
|
||||
func (c Compute) ChangeSecGroups(ctx context.Context, req ChangeSecGroupsRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/change_security_groups"
|
||||
|
||||
res, err := c.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
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ChangeDiskStoragePolicyRequest struct to change storage policy for disk
|
||||
type ChangeDiskStoragePolicyRequest struct {
|
||||
// ID of the disk
|
||||
// Required: true
|
||||
DiskID uint64 `url:"disk_id" json:"disk_id" validate:"required"`
|
||||
|
||||
// ID of the storage policy to which to connect for disk
|
||||
// Required: true
|
||||
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||
}
|
||||
|
||||
// ChangeDiskStoragePolicy changes storage policy for disk
|
||||
func (d Disks) ChangeDiskStoragePolicy(ctx context.Context, req ChangeDiskStoragePolicyRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/disks/change_disk_storage_policy"
|
||||
|
||||
res, err := d.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
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type ChangeStoragePolicyRequest struct {
|
||||
// ID of the image to change the storage policy
|
||||
// Required: true
|
||||
ImageID uint64 `url:"image_id" json:"image_id" validate:"required"`
|
||||
|
||||
// ID of the storage policy to move the image to
|
||||
// Required: true
|
||||
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||
}
|
||||
|
||||
// ChangeStoragePolicy changes the storage policy of the image chosen
|
||||
func (i Image) ChangeStoragePolicy(ctx context.Context, req ChangeStoragePolicyRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/image/change_storage_policy"
|
||||
|
||||
res, err := i.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
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package securitygroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type CreateRequest struct {
|
||||
// Account ID that owns security group
|
||||
// Required: true
|
||||
AccountID uint64 `url:"account_id" json:"account_id" validate:"required"`
|
||||
|
||||
// Security group name
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Security group description
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty" json:"description,omitempty"`
|
||||
}
|
||||
|
||||
func (sg SecurityGroup) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/security_group/create"
|
||||
|
||||
res, err := sg.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
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package securitygroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type CreateRuleRequest struct {
|
||||
// Security group ID
|
||||
// Required: true
|
||||
SecurityGroupID uint64 `url:"security_group_id" json:"security_group_id" validate:"required"`
|
||||
|
||||
// Traffic direction (inbound/outbound)
|
||||
// Required: true
|
||||
Direction string `url:"direction" json:"direction" validate:"required,securityGroupDirection"`
|
||||
|
||||
// IP protocol version
|
||||
// Default: IPv4
|
||||
// Required: false
|
||||
Ethertype string `url:"ethertype,omitempty" json:"ethertype,omitempty" validate:"omitempty,securityGroupEthertype"`
|
||||
|
||||
// Network protocol, available values : icmp, tcp, udp
|
||||
// Required: false
|
||||
Protocol string `url:"protocol,omitempty" json:"protocol,omitempty" validate:"omitempty,securityGroupProtocol"`
|
||||
|
||||
// Start port number (for TCP/UDP)
|
||||
// Required: false
|
||||
PortRangeMin uint64 `url:"port_range_min,omitempty" json:"port_range_min,omitempty"`
|
||||
|
||||
// End port number (for TCP/UDP)
|
||||
// Required: false
|
||||
PortRangeMax uint64 `url:"port_range_max,omitempty" json:"port_range_max,omitempty"`
|
||||
|
||||
// Remote IP prefix in CIDR notation
|
||||
// Required: false
|
||||
RemoteIPPrefix string `url:"remote_ip_prefix,omitempty" json:"remote_ip_prefix,omitempty"`
|
||||
}
|
||||
|
||||
func (sg SecurityGroup) CreateRule(ctx context.Context, req CreateRuleRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/security_group/create_rule"
|
||||
|
||||
res, err := sg.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
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package securitygroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type DeleteRequest struct {
|
||||
// Security group ID
|
||||
// Required: true
|
||||
SecurityGroupID uint64 `url:"security_group_id" json:"security_group_id" validate:"required"`
|
||||
}
|
||||
|
||||
func (sg SecurityGroup) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/security_group/delete"
|
||||
|
||||
res, err := sg.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
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package securitygroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type DeleteRuleRequest struct {
|
||||
// Security group ID
|
||||
// Required: true
|
||||
SecurityGroupID uint64 `url:"security_group_id" json:"security_group_id" validate:"required"`
|
||||
|
||||
// Rule ID
|
||||
// Required: true
|
||||
RuleID uint64 `url:"rule_id" json:"rule_id" validate:"required"`
|
||||
}
|
||||
|
||||
func (sg SecurityGroup) DeleteRule(ctx context.Context, req DeleteRuleRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/security_group/delete_rule"
|
||||
|
||||
res, err := sg.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
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package securitygroup
|
||||
|
||||
// FilterByID returns ListSecurityGroups with specified ID.
|
||||
func (lsg ListSecurityGroups) FilterByID(id uint64) ListSecurityGroups {
|
||||
predicate := func(isg ItemSecurityGroup) bool {
|
||||
return isg.ID == id
|
||||
}
|
||||
|
||||
return lsg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByID returns ListSecurityGroups with specified Name.
|
||||
func (lsg ListSecurityGroups) FilterByName(name string) ListSecurityGroups {
|
||||
predicate := func(isg ItemSecurityGroup) bool {
|
||||
return isg.Name == name
|
||||
}
|
||||
|
||||
return lsg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByCreatedBy returns ListSecurityGroups with specified CreatedBy.
|
||||
func (lsg ListSecurityGroups) FilterByCreatedBy(createdBy string) ListSecurityGroups {
|
||||
predicate := func(isg ItemSecurityGroup) bool {
|
||||
return isg.CreatedBy == createdBy
|
||||
}
|
||||
|
||||
return lsg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByDescription returns ListSecurityGroups with specified Description.
|
||||
func (lsg ListSecurityGroups) FilterByDescription(description string) ListSecurityGroups {
|
||||
predicate := func(isg ItemSecurityGroup) bool {
|
||||
return isg.Description == description
|
||||
}
|
||||
|
||||
return lsg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByUpdatedBy returns ListSecurityGroups with specified UpdatedBy.
|
||||
func (lsg ListSecurityGroups) FilterByUpdatedBy(updatedBy string) ListSecurityGroups {
|
||||
predicate := func(isg ItemSecurityGroup) bool {
|
||||
return isg.UpdatedBy == updatedBy
|
||||
}
|
||||
|
||||
return lsg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByAccountID returns ListSecurityGroups with specified AccountID.
|
||||
func (lsg ListSecurityGroups) FilterByAccountID(accountID uint64) ListSecurityGroups {
|
||||
predicate := func(isg ItemSecurityGroup) bool {
|
||||
return isg.AccountID == accountID
|
||||
}
|
||||
|
||||
return lsg.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering ListSecurityGroups based on a user-specified predicate.
|
||||
func (lsg ListSecurityGroups) FilterFunc(predicate func(ItemSecurityGroup) bool) ListSecurityGroups {
|
||||
var result ListSecurityGroups
|
||||
|
||||
for _, item := range lsg.Data {
|
||||
if predicate(item) {
|
||||
result.Data = append(result.Data, item)
|
||||
}
|
||||
}
|
||||
|
||||
result.EntryCount = uint64(len(result.Data))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first found ItemSecurityGroup
|
||||
// If none was found, returns an empty struct.
|
||||
func (lsg ListSecurityGroups) FindOne() ItemSecurityGroup {
|
||||
if len(lsg.Data) == 0 {
|
||||
return ItemSecurityGroup{}
|
||||
}
|
||||
|
||||
return lsg.Data[0]
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package securitygroup
|
||||
|
||||
import "testing"
|
||||
|
||||
var securityGroups = ListSecurityGroups{
|
||||
Data: []ItemSecurityGroup{
|
||||
{
|
||||
ID: 1,
|
||||
AccountID: 1,
|
||||
Name: "sg1",
|
||||
Description: "some desc",
|
||||
CreatedBy: "user",
|
||||
},
|
||||
{
|
||||
ID: 3,
|
||||
AccountID: 3,
|
||||
Name: "sg3",
|
||||
Description: "some desc",
|
||||
CreatedBy: "anotheruser",
|
||||
},
|
||||
{
|
||||
ID: 5,
|
||||
AccountID: 3,
|
||||
Name: "sg5",
|
||||
Description: "some other desc",
|
||||
CreatedBy: "anotheruser",
|
||||
UpdatedBy: "user",
|
||||
},
|
||||
},
|
||||
EntryCount: 3,
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := securityGroups.FilterByID(1).FindOne()
|
||||
if actual.ID != 1 {
|
||||
t.Fatal("expected ID 1, found: ", actual.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := securityGroups.FilterByName("sg3").FindOne()
|
||||
if actual.Name != "sg3" {
|
||||
t.Fatal("expected Name sg3, found: ", actual.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByDescription(t *testing.T) {
|
||||
actual := securityGroups.FilterByDescription("some desc")
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.Description != "some desc" {
|
||||
t.Fatal("expected Description 'some desc', found: ", item.Description)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByAccountID(t *testing.T) {
|
||||
actual := securityGroups.FilterByAccountID(1).FindOne()
|
||||
if actual.AccountID != 1 {
|
||||
t.Fatal("expected AccountID 1, found: ", actual.AccountID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByCreatedBy(t *testing.T) {
|
||||
actual := securityGroups.FilterByCreatedBy("anotheruser")
|
||||
|
||||
if len(actual.Data) != 2 {
|
||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
||||
}
|
||||
|
||||
for _, item := range actual.Data {
|
||||
if item.CreatedBy != "anotheruser" {
|
||||
t.Fatal("expected CreatedBy 'anotheruser', found: ", item.CreatedBy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByUpdatedBy(t *testing.T) {
|
||||
actual := securityGroups.FilterByUpdatedBy("user").FindOne()
|
||||
if actual.UpdatedBy != "user" {
|
||||
t.Fatal("expected UpdatedBy 'user', found: ", actual.UpdatedBy)
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package securitygroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
// ID of security group
|
||||
// Required: true
|
||||
SecurityGroupID uint64 `url:"security_group_id" json:"security_group_id" validate:"required"`
|
||||
}
|
||||
|
||||
func (sg SecurityGroup) Get(ctx context.Context, req GetRequest) (*RecordSecurityGroup, error) {
|
||||
res, err := sg.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordSecurityGroup{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
func (sg SecurityGroup) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/security_group/get"
|
||||
|
||||
res, err := sg.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package securitygroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
// Search by security group id
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Search by account id
|
||||
// Required: false
|
||||
AccountID uint64 `url:"account_id,omitempty" json:"account_id,omitempty"`
|
||||
|
||||
// Search by security group name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Search by security group description
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty" json:"description,omitempty"`
|
||||
|
||||
// Search by created after time (unix timestamp)
|
||||
// Required: false
|
||||
CreatedMin uint64 `url:"created_min,omitempty" json:"created_min,omitempty"`
|
||||
|
||||
// Search by created before time (unix timestamp)
|
||||
// Required: false
|
||||
CreatedMax uint64 `url:"created_max,omitempty" json:"created_max,omitempty"`
|
||||
|
||||
// Search by updated after time (unix timestamp)
|
||||
// Required: false
|
||||
UpdatedMin uint64 `url:"updated_min,omitempty" json:"updated_min,omitempty"`
|
||||
|
||||
// Search by updated before time (unix timestamp)
|
||||
// Required: false
|
||||
UpdatedMax uint64 `url:"updated_max,omitempty" json:"updated_max,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format ±<field>
|
||||
// Required: false
|
||||
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty"`
|
||||
|
||||
// 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 security groups as a ListSecurityGroups struct
|
||||
func (sg SecurityGroup) List(ctx context.Context, req ListRequest) (*ListSecurityGroups, error) {
|
||||
|
||||
res, err := sg.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListSecurityGroups{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets list of security groups as an array of bytes
|
||||
func (sg SecurityGroup) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/security_group/list"
|
||||
|
||||
res, err := sg.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package securitygroup
|
||||
|
||||
type ListSecurityGroups struct {
|
||||
Data []ItemSecurityGroup `json:"data"`
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
type ItemSecurityGroup struct {
|
||||
ID uint64 `json:"id"`
|
||||
AccountID uint64 `json:"account_id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Rules Rules `json:"rules"`
|
||||
CreatedAt uint64 `json:"created_at"`
|
||||
UpdatedAt uint64 `json:"updated_at"`
|
||||
CreatedBy string `json:"created_by"`
|
||||
UpdatedBy string `json:"updated_by"`
|
||||
}
|
||||
|
||||
type RecordSecurityGroup struct {
|
||||
ID uint64 `json:"id"`
|
||||
AccountID uint64 `json:"account_id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Rules Rules `json:"rules"`
|
||||
CreatedAt uint64 `json:"created_at"`
|
||||
UpdatedAt uint64 `json:"updated_at"`
|
||||
CreatedBy string `json:"created_by"`
|
||||
UpdatedBy string `json:"updated_by"`
|
||||
}
|
||||
|
||||
type Rules []Rule
|
||||
|
||||
type Rule struct {
|
||||
ID uint64 `json:"id"`
|
||||
Direction string `json:"direction"`
|
||||
Ethertype string `json:"ethertype"`
|
||||
Protocol string `json:"protocol"`
|
||||
PortRangeMin uint64 `json:"port_range_min"`
|
||||
PortRangeMax uint64 `json:"port_range_max"`
|
||||
RemoteIPPrefix string `json:"remote_ip_prefix"`
|
||||
RemoteGroupID uint64 `json:"remote_group_id"`
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package securitygroup
|
||||
|
||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
|
||||
// Structure for creating request to storage policy
|
||||
type SecurityGroup struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for stack endpoint
|
||||
func New(client interfaces.Caller) *SecurityGroup {
|
||||
return &SecurityGroup{
|
||||
client: client,
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package securitygroup
|
||||
|
||||
import "sort"
|
||||
|
||||
// SortByCreatedAt sorts ListSecurityGroups by the CreatedAt field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lsg ListSecurityGroups) SortByCreatedAt(inverse bool) ListSecurityGroups {
|
||||
if len(lsg.Data) < 2 {
|
||||
return lsg
|
||||
}
|
||||
|
||||
sort.Slice(lsg.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lsg.Data[i].CreatedAt > lsg.Data[j].CreatedAt
|
||||
}
|
||||
|
||||
return lsg.Data[i].CreatedAt < lsg.Data[j].CreatedAt
|
||||
})
|
||||
|
||||
return lsg
|
||||
}
|
||||
|
||||
// SortByUpdatedAt sorts ListSecurityGroups by the UpdatedAt field in ascending order.
|
||||
//
|
||||
// If inverse param is set to true, the order is reversed.
|
||||
func (lsg ListSecurityGroups) SortByUpdatedAt(inverse bool) ListSecurityGroups {
|
||||
if len(lsg.Data) < 2 {
|
||||
return lsg
|
||||
}
|
||||
|
||||
sort.Slice(lsg.Data, func(i, j int) bool {
|
||||
if inverse {
|
||||
return lsg.Data[i].UpdatedAt > lsg.Data[j].UpdatedAt
|
||||
}
|
||||
|
||||
return lsg.Data[i].UpdatedAt < lsg.Data[j].UpdatedAt
|
||||
})
|
||||
|
||||
return lsg
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package securitygroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type UpdateRequest struct {
|
||||
// Security group ID
|
||||
// Required: true
|
||||
SecurityGroupID uint64 `url:"security_group_id" json:"security_group_id" validate:"required"`
|
||||
|
||||
// New security group name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// New security group description
|
||||
// Required: false
|
||||
Description string `url:"description,omitempty" json:"description,omitempty"`
|
||||
}
|
||||
|
||||
func (sg SecurityGroup) Update(ctx context.Context, req UpdateRequest) (*RecordSecurityGroup, error) {
|
||||
res, err := sg.UpdateRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordSecurityGroup{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
func (sg SecurityGroup) UpdateRaw(ctx context.Context, req UpdateRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/security_group/update"
|
||||
|
||||
res, err := sg.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
securitygroup "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/security_group"
|
||||
)
|
||||
|
||||
// Accessing the Security Group method group
|
||||
func (ca *CloudAPI) SecurityGroup() *securitygroup.SecurityGroup {
|
||||
return securitygroup.New(ca.client)
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package storagepolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type GetRequest struct {
|
||||
// ID of storage policy
|
||||
// Required: true
|
||||
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||
}
|
||||
|
||||
func (sp StoragePolicy) Get(ctx context.Context, req GetRequest) (*InfoStoragePolicy, error) {
|
||||
res, err := sp.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := InfoStoragePolicy{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
func (sp StoragePolicy) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/storage_policy/get"
|
||||
|
||||
res, err := sp.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package storagepolicy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type ListRequest struct {
|
||||
// ID of account ID
|
||||
// Required: true
|
||||
AccountID uint64 `url:"account_id" json:"account_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"`
|
||||
|
||||
// Search by storage policy ID
|
||||
// Required: false
|
||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||
|
||||
// Search by storage policy name
|
||||
// Required: false
|
||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||
|
||||
// Search by storage policy status
|
||||
// Required: false
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
|
||||
// Search by storage policy desc
|
||||
// Required: false
|
||||
Desc string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||
|
||||
// Search by storage policy iops limit
|
||||
// Required: false
|
||||
LimitIOPS uint64 `url:"limit_iops,omitempty" json:"limit_iops,omitempty"`
|
||||
|
||||
// Sort by one of supported fields, format ±<field>
|
||||
// Required: false
|
||||
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty"`
|
||||
|
||||
// Search by resgroup id
|
||||
// Required: false
|
||||
ResgroupID uint64 `url:"resgroup_id,omitempty" json:"resgroup_id,omitempty"`
|
||||
|
||||
// Search by sep id
|
||||
// Required: false
|
||||
SepID uint64 `url:"sep_id,omitempty" json:"sep_id,omitempty"`
|
||||
|
||||
// Search by pool name
|
||||
// Required: false
|
||||
PoolName string `url:"pool_name,omitempty" json:"pool_name,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list of storage policies as a ListStoragePolicies struct
|
||||
func (sp StoragePolicy) List(ctx context.Context, req ListRequest) (*ListStoragePolicies, error) {
|
||||
|
||||
res, err := sp.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListStoragePolicies{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets list of storage policies as an array of bytes
|
||||
func (sp StoragePolicy) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/storage_policy/list"
|
||||
|
||||
res, err := sp.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package storagepolicy
|
||||
|
||||
type ListStoragePolicies struct {
|
||||
Data []ItemStoragePolicy `json:"data"`
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
type ItemStoragePolicy struct {
|
||||
ID uint64 `json:"id"`
|
||||
GUID uint64 `json:"guid"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
AccessSepPools ListAccessSepPools `json:"access_seps_pools"`
|
||||
Status string `json:"status"`
|
||||
LimitIOPS uint64 `json:"limit_iops"`
|
||||
Usage Usage `json:"usage"`
|
||||
}
|
||||
|
||||
type InfoStoragePolicy struct {
|
||||
ID uint64 `json:"id"`
|
||||
GUID uint64 `json:"guid"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
AccessSepPools ListAccessSepPools `json:"access_seps_pools"`
|
||||
Status string `json:"status"`
|
||||
LimitIOPS uint64 `json:"limit_iops"`
|
||||
Usage Usage `json:"usage"`
|
||||
}
|
||||
|
||||
type ListAccessSepPools []AccessSepPool
|
||||
|
||||
type AccessSepPool struct {
|
||||
SepID uint64 `json:"sep_id"`
|
||||
PoolNames []string `json:"pool_names"`
|
||||
}
|
||||
|
||||
type Usage struct {
|
||||
Accounts []uint64 `json:"accounts"`
|
||||
Resgroups []uint64 `json:"resgroups"`
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package storagepolicy
|
||||
|
||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
|
||||
// Structure for creating request to storage policy
|
||||
type StoragePolicy struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for stack endpoint
|
||||
func New(client interfaces.Caller) *StoragePolicy {
|
||||
return &StoragePolicy{
|
||||
client: client,
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package cloudapi
|
||||
|
||||
import (
|
||||
storagepolicy "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/storage_policy"
|
||||
)
|
||||
|
||||
// Accessing the Storage Policy method group
|
||||
func (ca *CloudAPI) StoragePolicy() *storagepolicy.StoragePolicy {
|
||||
return storagepolicy.New(ca.client)
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// AddStoragePolicyRequest struct for adding storage policy to the account
|
||||
type AddStoragePolicyRequest struct {
|
||||
// ID of account to add to
|
||||
// Required: true
|
||||
AccountID uint64 `url:"account_id" json:"account_id" validate:"required"`
|
||||
|
||||
// ID of the storage policy to which to connect account
|
||||
// Required: true
|
||||
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||
|
||||
// Limit storage resources GB. Or -1 unlimit
|
||||
// Required: false
|
||||
Limit int `url:"limit,omitempty" json:"limit,omitempty"`
|
||||
}
|
||||
|
||||
// AddStoragePolicy add storage policy to the account.
|
||||
func (a Account) AddStoragePolicy(ctx context.Context, req AddStoragePolicyRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/add_storage_policy"
|
||||
|
||||
res, err := a.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
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// DelStoragePolicyRequest struct for deleting storage policy to the account
|
||||
type DelStoragePolicyRequest struct {
|
||||
// ID of account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"account_id" json:"account_id" validate:"required"`
|
||||
|
||||
// ID of the storage policy to which to disconnect account
|
||||
// Required: true
|
||||
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||
}
|
||||
|
||||
// DelStoragePolicy delete storage policy to the account.
|
||||
func (a Account) DelStoragePolicy(ctx context.Context, req DelStoragePolicyRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/account/del_storage_policy"
|
||||
|
||||
res, err := a.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
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ChangeSecGroupsRequest struct to change security groups for compute
|
||||
type ChangeSecGroupsRequest struct {
|
||||
// Identifier compute
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"compute_id" json:"compute_id" validate:"required"`
|
||||
|
||||
// Interface name or MAC address
|
||||
// Required: true
|
||||
Interface string `url:"interface" json:"interface" validate:"required"`
|
||||
|
||||
// List of security group IDs to assign to this interface
|
||||
// Required: false
|
||||
SecGroups []uint64 `url:"security_groups,omitempty" json:"security_groups,omitempty"`
|
||||
|
||||
// Flag indicating whether security groups are enabled for this interface
|
||||
// Required: false
|
||||
EnableSecGroups bool `url:"enable_secgroups,omitempty" json:"enable_secgroups,omitempty"`
|
||||
}
|
||||
|
||||
// ChangeSecGroups changes security groups for compute
|
||||
func (c Compute) ChangeSecGroups(ctx context.Context, req ChangeSecGroupsRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/compute/change_security_groups"
|
||||
|
||||
res, err := c.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
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package disks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ChangeDiskStoragePolicyRequest struct to change storage policy for disk
|
||||
type ChangeDiskStoragePolicyRequest struct {
|
||||
// ID of the disk
|
||||
// Required: true
|
||||
DiskID uint64 `url:"disk_id" json:"disk_id" validate:"required"`
|
||||
|
||||
// ID of the storage policy to which to connect account
|
||||
// Required: true
|
||||
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||
}
|
||||
|
||||
// ChangeDiskStoragePolicy changes storage policy for disk
|
||||
func (d Disks) ChangeDiskStoragePolicy(ctx context.Context, req ChangeDiskStoragePolicyRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/disks/change_disk_storage_policy"
|
||||
|
||||
res, err := d.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
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type ChangeStoragePolicyRequest struct {
|
||||
// ID of the image to change the storage policy
|
||||
// Required: true
|
||||
ImageID uint64 `url:"image_id" json:"image_id" validate:"required"`
|
||||
|
||||
// ID of the storage policy to move the image to
|
||||
// Required: true
|
||||
StoragePolicyID uint64 `url:"storage_policy_id" json:"storage_policy_id" validate:"required"`
|
||||
}
|
||||
|
||||
// ChangeStoragePolicy changes the storage policy of the image chosen
|
||||
func (i Image) ChangeStoragePolicy(ctx context.Context, req ChangeStoragePolicyRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudbroker/image/change_storage_policy"
|
||||
|
||||
res, err := i.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
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue