Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c9e4ae6afe | |||
| 2a1593f45f | |||
| 190f24dac1 | |||
| 256dba5134 | |||
| b7137683ab | |||
| 10e3e19892 |
48
CHANGELOG.md
48
CHANGELOG.md
@@ -1,44 +1,4 @@
|
||||
## Version 1.4.0
|
||||
|
||||
### Features
|
||||
|
||||
- Actualized SDK to platform version 3.8.6:
|
||||
- Added required field networkPlugin to requests in:
|
||||
- /cloudapi/cloudbroker/k8s/create;
|
||||
- /cloudbroker/k8ci/create.
|
||||
- Added networkPlugin field in models:
|
||||
- /cloudapi/cloudbroker/k8s;
|
||||
- /cloudbroker/k8ci.
|
||||
- Updated list of compute objects fields and added list of group objects in bservice model.
|
||||
- Added cpuAllocationRatio and cpuAllocationParameter fields in models:
|
||||
- /cloudapi/cloudbroker/rg;
|
||||
- /cloudapi/cloudbroker/account.
|
||||
- Added setCpuAllocationRatio endpoint support in:
|
||||
- /cloudbroker/account;
|
||||
- /cloudbroker/rg.
|
||||
- Added /cloudbrocker/grid/setCpuAllocationRatioForVM endpoint support.
|
||||
- Added setCpuAllocationParameter endpoint support in:
|
||||
- /cloudbroker/account;
|
||||
- /cloudbroker/rg;
|
||||
- /cloudbroker/grid.
|
||||
- Added cloudapi/cloudbroker/compute/changeLinkState endpoint support.
|
||||
|
||||
- Added enabled field in cloudapi/compute models:
|
||||
- interfaces in compute/list response;
|
||||
- RecordNetAttach (compute/netAttach response).
|
||||
|
||||
- Added cloudapi/compute/bootOrderSet endpoint support.
|
||||
|
||||
- Added cloudapi/compute/bootOrderGet endpoint support.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- Fixed pciSlot field type in models:
|
||||
- cloudapi/cloudbroker/computes;
|
||||
- cloudapi/cloudbroker/vins.
|
||||
|
||||
- Fixed handling cloudapi/account/restore endpoint response (panicked when marhalling).
|
||||
|
||||
- Added missing field diskType in cloudapi/compute/diskAttach request.
|
||||
|
||||
- Added missing eBurst field in cloudapi/extnet QOS model.
|
||||
## Version 1.4.4
|
||||
|
||||
### Features
|
||||
- Added "Timeout" param to Config/LegacyConfig that allows configuring HTTP client timeout
|
||||
|
||||
17
README.md
17
README.md
@@ -118,6 +118,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
||||
| SSOURL | string | Да | URL адрес сервиса аутентификации и авторизации |
|
||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
||||
| Token | string | Нет | JWT токен |
|
||||
|
||||
@@ -127,6 +128,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||
)
|
||||
|
||||
func main(){
|
||||
// Настройка конфигурации
|
||||
cfg := config.Config{
|
||||
@@ -136,6 +138,8 @@ func main(){
|
||||
DecortURL: "https://mr4.digitalenergy.online",
|
||||
Retries: 5,
|
||||
}
|
||||
|
||||
cfg.SetTimeout(5 * time.Minute)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -165,6 +169,7 @@ func main() {
|
||||
"ssoUrl": "https://sso.digitalenergy.online",
|
||||
"decortUrl": "https://mr4.digitalenergy.online",
|
||||
"retries": 5,
|
||||
"timeout": "5m",
|
||||
"sslSkipVerify": false
|
||||
}
|
||||
```
|
||||
@@ -177,6 +182,7 @@ appSecret: <APP_SECRET>
|
||||
ssoUrl: https://sso.digitalenergy.online
|
||||
decortUrl: https://mr4.digitalenergy.online
|
||||
retries: 5
|
||||
timeout: 5m
|
||||
sslSkipVerify: false
|
||||
```
|
||||
|
||||
@@ -204,6 +210,8 @@ func main() {
|
||||
Retries: 5,
|
||||
}
|
||||
|
||||
cfg.SetTimeout(5 * time.Minute)
|
||||
|
||||
// Создание клиента
|
||||
client := decort.New(cfg)
|
||||
}
|
||||
@@ -647,6 +655,8 @@ func main() {
|
||||
DecortURL: "<DECORT_URL>",
|
||||
Retries: 5,
|
||||
}
|
||||
|
||||
cfg.SetTimeout(5 * time.Minute)
|
||||
|
||||
// Создание клиента
|
||||
client := decort.New(cfg)
|
||||
@@ -693,6 +703,7 @@ func main() {
|
||||
| Password | string | Да | пароль legacy пользователя |
|
||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
||||
| Token | string | Нет | JWT токен |
|
||||
|
||||
@@ -711,6 +722,8 @@ func main(){
|
||||
DecortURL: "https://mr4.digitalenergy.online",
|
||||
Retries: 5,
|
||||
}
|
||||
|
||||
legacyCfg.SetTimeout(5 * time.Minute)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -739,6 +752,7 @@ func main() {
|
||||
"password": "<PASSWORD>",
|
||||
"decortUrl": "https://mr4.digitalenergy.online",
|
||||
"retries": 5,
|
||||
"timeout": "5m",
|
||||
"sslSkipVerify": true
|
||||
}
|
||||
```
|
||||
@@ -749,6 +763,7 @@ username: <USERNAME>
|
||||
password: <PASSWORD>
|
||||
decortUrl: https://mr4.digitalenergy.online
|
||||
retries: 5
|
||||
timeout: 5m
|
||||
sslSkipVerify: true
|
||||
```
|
||||
### Создание legacy клиента
|
||||
@@ -774,6 +789,8 @@ func main() {
|
||||
Retries: 5,
|
||||
}
|
||||
|
||||
legacyCfg.SetTimeout(5 * time.Minute)
|
||||
|
||||
// Создание клиента
|
||||
legacyClient := decort.NewLegacy(cfg)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package config
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
@@ -44,6 +45,15 @@ type Config struct {
|
||||
// Skip verify, true by default
|
||||
// Required: false
|
||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||
|
||||
// HTTP client timeout, unlimited if left empty
|
||||
// Required: false
|
||||
Timeout Duration `json:"timeout" yaml:"timeout"`
|
||||
}
|
||||
|
||||
// SetTimeout is used to set HTTP client timeout.
|
||||
func (c *Config) SetTimeout(dur time.Duration) {
|
||||
c.Timeout = Duration(dur)
|
||||
}
|
||||
|
||||
// ParseConfigJSON parses Config from specified JSON-formatted file.
|
||||
|
||||
@@ -3,6 +3,7 @@ package config
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
@@ -38,6 +39,15 @@ type LegacyConfig struct {
|
||||
// Skip verify, true by default
|
||||
// Required: false
|
||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||
|
||||
// HTTP client timeout, unlimited if left empty
|
||||
// Required: false
|
||||
Timeout Duration `json:"timeout" yaml:"timeout"`
|
||||
}
|
||||
|
||||
// SetTimeout is used to set HTTP client timeout.
|
||||
func (c *LegacyConfig) SetTimeout(dur time.Duration) {
|
||||
c.Timeout = Duration(dur)
|
||||
}
|
||||
|
||||
// ParseLegacyConfigJSON parses LegacyConfig from specified JSON-formatted file.
|
||||
|
||||
50
config/timeouts.go
Normal file
50
config/timeouts.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Duration is a wrapper around time.Duration (used for better user experience)
|
||||
type Duration time.Duration
|
||||
|
||||
func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
var v interface{}
|
||||
if err := unmarshal(&v); err != nil {
|
||||
return err
|
||||
}
|
||||
switch value := v.(type) {
|
||||
case string:
|
||||
tmp, err := time.ParseDuration(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*d = Duration(tmp)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("Invalid duration %v", value)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Duration) UnmarshalJSON(b []byte) error {
|
||||
var v interface{}
|
||||
if err := json.Unmarshal(b, &v); err != nil {
|
||||
return err
|
||||
}
|
||||
switch value := v.(type) {
|
||||
case string:
|
||||
tmp, err := time.ParseDuration(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*d = Duration(tmp)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("Invalid duration %v", value)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Duration) Get() time.Duration {
|
||||
return time.Duration(*d)
|
||||
}
|
||||
3
go.mod
3
go.mod
@@ -5,14 +5,15 @@ go 1.20
|
||||
require (
|
||||
github.com/go-playground/validator/v10 v10.11.2
|
||||
github.com/google/go-querystring v1.1.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
golang.org/x/crypto v0.5.0 // indirect
|
||||
golang.org/x/sys v0.4.0 // indirect
|
||||
golang.org/x/text v0.6.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
6
go.sum
6
go.sum
@@ -1,3 +1,4 @@
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
||||
@@ -11,10 +12,14 @@ github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
|
||||
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
@@ -26,6 +31,7 @@ golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
|
||||
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -35,6 +35,6 @@ func NewHttpClient(cfg config.Config) *http.Client {
|
||||
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
|
||||
Timeout: 5 * time.Minute,
|
||||
Timeout: cfg.Timeout.Get(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||
)
|
||||
@@ -28,6 +27,6 @@ func NewLegacyHttpClient(cfg config.LegacyConfig) *http.Client {
|
||||
decortURL: cfg.DecortURL,
|
||||
},
|
||||
|
||||
Timeout: 5 * time.Minute,
|
||||
Timeout: cfg.Timeout.Get(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,29 +7,20 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
once sync.Once
|
||||
instance *DecortValidator
|
||||
once sync.Once
|
||||
decortValidator = validator.New()
|
||||
)
|
||||
|
||||
type DecortValidator struct {
|
||||
decortValidator *validator.Validate
|
||||
}
|
||||
|
||||
// getDecortValidator returns singleton instance of DecortValidator.
|
||||
func getDecortValidator() *validator.Validate {
|
||||
if instance == nil {
|
||||
once.Do(func() {
|
||||
instance = new(DecortValidator)
|
||||
instance.decortValidator = validator.New()
|
||||
once.Do(func() {
|
||||
err := registerAllValidators(decortValidator)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
})
|
||||
|
||||
err := registerAllValidators(instance.decortValidator)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return instance.decortValidator
|
||||
return decortValidator
|
||||
}
|
||||
|
||||
// registerAllValidators registers all custom validators in DecortValidator.
|
||||
|
||||
@@ -44,7 +44,7 @@ type CreateRequest struct {
|
||||
|
||||
// If true send emails when a user is granted access to resources
|
||||
// Required: false
|
||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty" json:"sendAccessEmails,omitempty"`
|
||||
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
|
||||
|
||||
// Limit (positive) or disable (0) GPU resources
|
||||
// Required: false
|
||||
|
||||
@@ -40,7 +40,7 @@ type UpdateRequest struct {
|
||||
|
||||
// If true send emails when a user is granted access to resources
|
||||
// Required: false
|
||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty" json:"sendAccessEmails,omitempty"`
|
||||
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
|
||||
|
||||
// Limit (positive) or disable (0) GPU resources
|
||||
// Required: false
|
||||
|
||||
@@ -19,8 +19,9 @@ type PFWAddRequest struct {
|
||||
PublicPortStart uint64 `url:"publicPortStart" json:"publicPortStart" validate:"required"`
|
||||
|
||||
// End port number (inclusive) for the ranged rule
|
||||
// Default value: -1
|
||||
// Required: false
|
||||
PublicPortEnd uint64 `url:"publicPortEnd,omitempty" json:"publicPortEnd,omitempty"`
|
||||
PublicPortEnd int64 `url:"publicPortEnd,omitempty" json:"publicPortEnd,omitempty"`
|
||||
|
||||
// Internal base port number
|
||||
// Required: true
|
||||
|
||||
@@ -9,14 +9,14 @@ import (
|
||||
)
|
||||
|
||||
// Request struct for disable/enable kubernetes cluster
|
||||
type DisabelEnableRequest struct {
|
||||
type DisableEnableRequest struct {
|
||||
// Kubernetes cluster ID
|
||||
// Required: true
|
||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||
}
|
||||
|
||||
// Disable disables kubernetes cluster by ID
|
||||
func (k8s K8S) Disable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
|
||||
func (k8s K8S) Disable(ctx context.Context, req DisableEnableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
@@ -40,7 +40,7 @@ func (k8s K8S) Disable(ctx context.Context, req DisabelEnableRequest) (bool, err
|
||||
}
|
||||
|
||||
// Enable enables kubernetes cluster by ID
|
||||
func (k8s K8S) Enable(ctx context.Context, req DisabelEnableRequest) (bool, error) {
|
||||
func (k8s K8S) Enable(ctx context.Context, req DisableEnableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
|
||||
@@ -2,9 +2,8 @@ package k8s
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
@@ -24,11 +23,11 @@ type WorkerAddRequest struct {
|
||||
}
|
||||
|
||||
// WorkerAdd add worker nodes to a Kubernetes cluster
|
||||
func (k8s K8S) WorkerAdd(ctx context.Context, req WorkerAddRequest) (bool, error) {
|
||||
func (k8s K8S) WorkerAdd(ctx context.Context, req WorkerAddRequest) ([]uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,12 +35,14 @@ func (k8s K8S) WorkerAdd(ctx context.Context, req WorkerAddRequest) (bool, error
|
||||
|
||||
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
result := make([]uint64, 0)
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
||||
@@ -44,7 +44,7 @@ type CreateRequest struct {
|
||||
|
||||
// If true send emails when a user is granted access to resources
|
||||
// Required: false
|
||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty" json:"sendAccessEmails,omitempty"`
|
||||
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
|
||||
|
||||
// Limit (positive) or disable (0) GPU resources
|
||||
// Required: false
|
||||
|
||||
@@ -48,7 +48,7 @@ type UpdateRequest struct {
|
||||
|
||||
// If true send emails when a user is granted access to resources
|
||||
// Required: false
|
||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty" json:"sendAccessEmails,omitempty"`
|
||||
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
|
||||
|
||||
// Limit (positive) or disable (0) GPU resources
|
||||
// Required: false
|
||||
|
||||
8
pkg/cloudbroker/backup.go
Normal file
8
pkg/cloudbroker/backup.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package cloudbroker
|
||||
|
||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/backup"
|
||||
|
||||
// Accessing the Backup method group
|
||||
func (cb *CloudBroker) Backup() *backup.Backup {
|
||||
return backup.New(cb.client)
|
||||
}
|
||||
17
pkg/cloudbroker/backup/backup.go
Normal file
17
pkg/cloudbroker/backup/backup.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package backup
|
||||
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to backup
|
||||
type Backup struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for backup endpoints
|
||||
func New(client interfaces.Caller) *Backup {
|
||||
return &Backup{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
81
pkg/cloudbroker/backup/create_disk_backup.go
Normal file
81
pkg/cloudbroker/backup/create_disk_backup.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package backup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Request struct for creating disk backup
|
||||
type CreateDiskBackupRequest struct {
|
||||
// Compute ID
|
||||
// Required: true
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Disk ID
|
||||
// Required: true
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Backup path
|
||||
// Required: true
|
||||
BackupPath string `url:"backupPath" json:"backupPath" validate:"required"`
|
||||
|
||||
// Async API Call
|
||||
// For async call use CreateDiskBackupAsync
|
||||
// For sync call use CreateDiskBackup
|
||||
// Required: true
|
||||
async bool `url:"async"`
|
||||
}
|
||||
|
||||
// CreateDiskBackup creates disk backup
|
||||
func (b Backup) CreateDiskBackup(ctx context.Context, req CreateDiskBackupRequest) (ListInfoBackup, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
req.async = false
|
||||
|
||||
url := "/cloudbroker/backup/createDiskBackup"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make(ListInfoBackup, 0)
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// CreateDiskBackupAsync creates disk backup
|
||||
func (b Backup) CreateDiskBackupAsync(ctx context.Context, req CreateDiskBackupRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
req.async = true
|
||||
|
||||
url := "/cloudbroker/backup/createDiskBackup"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
83
pkg/cloudbroker/backup/create_disks_backup.go
Normal file
83
pkg/cloudbroker/backup/create_disks_backup.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package backup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Disk struct {
|
||||
// Disk ID
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Backup path
|
||||
BackupPath string `url:"backupPath" json:"backupPath" validate:"required"`
|
||||
}
|
||||
|
||||
// Request struct for creating disks backup
|
||||
type CreateDisksBackupRequest struct {
|
||||
// Compute ID
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Disks
|
||||
Disks []Disk `url:"disks" json:"disks" validate:"required,dive"`
|
||||
|
||||
// Async API Call
|
||||
// For async call use CreateDisksBackupAsync
|
||||
// For sync call use CreateDisksBackup
|
||||
// Required: true
|
||||
async bool `url:"async"`
|
||||
}
|
||||
|
||||
// CreateDisksBackup creates disks backup
|
||||
func (b Backup) CreateDisksBackup(ctx context.Context, req CreateDisksBackupRequest) (ListInfoBackup, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
req.async = false
|
||||
|
||||
url := "/cloudbroker/backup/createDisksBackup"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make(ListInfoBackup, 0)
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// CreateDisksBackupAsync creates disks backup
|
||||
func (b Backup) CreateDisksBackupAsync(ctx context.Context, req CreateDisksBackupRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
req.async = true
|
||||
|
||||
url := "/cloudbroker/backup/createDisksBackup"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
73
pkg/cloudbroker/backup/delete_disk_backup.go
Normal file
73
pkg/cloudbroker/backup/delete_disk_backup.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package backup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Request struct for deleting disk backup
|
||||
type DeleteDiskBackupRequest struct {
|
||||
// Backup path
|
||||
BackupPath string `url:"backupPath" json:"backupPath" validate:"required"`
|
||||
|
||||
// Backup file
|
||||
BackupFile string `url:"backupFile" json:"backupFile" validate:"required"`
|
||||
|
||||
// Async API Call
|
||||
// For async call use DeleteDiskBackupAsync
|
||||
// For sync call use DeleteDiskBackup
|
||||
// Required: true
|
||||
async bool `url:"async"`
|
||||
}
|
||||
|
||||
// DeleteDiskBackup deletes disk backup
|
||||
func (b Backup) DeleteDiskBackup(ctx context.Context, req DeleteDiskBackupRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
req.async = false
|
||||
|
||||
url := "/cloudbroker/backup/deleteDiskBackup"
|
||||
|
||||
res, err := b.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
|
||||
}
|
||||
|
||||
// DeleteDiskBackupAsync deletes disk backup
|
||||
func (b Backup) DeleteDiskBackupAsync(ctx context.Context, req DeleteDiskBackupRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
req.async = true
|
||||
|
||||
url := "/cloudbroker/backup/deleteDiskBackup"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
40
pkg/cloudbroker/backup/list_backup_paths.go
Normal file
40
pkg/cloudbroker/backup/list_backup_paths.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package backup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for getting list of backup paths
|
||||
type ListBackupPathsRequest struct {
|
||||
// Grid ID
|
||||
GID uint64 `url:"gridId" json:"gridId" validate:"required"`
|
||||
}
|
||||
|
||||
// ListBackupPaths gets list of backup paths
|
||||
func (b Backup) ListBackupPaths(ctx context.Context, req ListBackupPathsRequest) ([]string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudbroker/backup/listBackupPaths"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]string, 0)
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
31
pkg/cloudbroker/backup/models.go
Normal file
31
pkg/cloudbroker/backup/models.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package backup
|
||||
|
||||
// Main info about backup
|
||||
type InfoBackup struct {
|
||||
// Compute ID
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
|
||||
// Disk ID
|
||||
DiskID uint64 `json:"diskId"`
|
||||
|
||||
// Backup path
|
||||
BackupPath string `json:"backupPath"`
|
||||
|
||||
// Possible error
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
// CreateDisksBackup response
|
||||
type ListInfoBackup []InfoBackup
|
||||
|
||||
// RestoreDiskFromFile response
|
||||
type InfoRestoredDisk struct {
|
||||
// Compute ID
|
||||
ComputeID uint64 `json:"computeId"`
|
||||
|
||||
// Disk ID
|
||||
DiskID uint64 `json:"diskId"`
|
||||
}
|
||||
|
||||
// RestoreDisksFromFile response
|
||||
type ListInfoRestoredDisk []InfoRestoredDisk
|
||||
81
pkg/cloudbroker/backup/restore_disk_from_backup.go
Normal file
81
pkg/cloudbroker/backup/restore_disk_from_backup.go
Normal file
@@ -0,0 +1,81 @@
|
||||
package backup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Request struct for restoring disk from backup
|
||||
type RestoreDiskFromBackupRequest struct {
|
||||
// Compute ID
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
// Disk ID
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Backup path
|
||||
BackupPath string `url:"backupPath" json:"backupPath" validate:"required"`
|
||||
|
||||
// Backup file
|
||||
BackupFile string `url:"backupFile" json:"backupFile" validate:"required"`
|
||||
|
||||
// Async API Call
|
||||
// For async call use RestoreDiskFromBackupAsync
|
||||
// For sync call use RestoreDiskFromBackup
|
||||
// Required: true
|
||||
async bool `url:"async"`
|
||||
}
|
||||
|
||||
// RestoreDiskFromBackup restores disk from backup
|
||||
func (b Backup) RestoreDiskFromBackup(ctx context.Context, req RestoreDiskFromBackupRequest) (ListInfoRestoredDisk, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
req.async = false
|
||||
|
||||
url := "/cloudbroker/backup/restoreDiskFromBackup"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make(ListInfoRestoredDisk, 0)
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// RestoreDiskFromBackupAsync restores disk from backup
|
||||
func (b Backup) RestoreDiskFromBackupAsync(ctx context.Context, req RestoreDiskFromBackupRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
req.async = true
|
||||
|
||||
url := "/cloudbroker/backup/restoreDiskFromBackup"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
86
pkg/cloudbroker/backup/restore_disks_from_backup.go
Normal file
86
pkg/cloudbroker/backup/restore_disks_from_backup.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package backup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type BackupFile struct {
|
||||
// Disk ID
|
||||
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
|
||||
|
||||
// Backup path
|
||||
BackupPath string `url:"backupPath" json:"backupPath" validate:"required"`
|
||||
|
||||
// Backup file
|
||||
BackupFile string `url:"backupFile" json:"backupFile" validate:"required"`
|
||||
}
|
||||
|
||||
// Request struct for restoring disks from backup
|
||||
type RestoreDisksFromBackupRequest struct {
|
||||
// Compute ID
|
||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
||||
|
||||
//Backup files
|
||||
BackupFiles []BackupFile `url:"backupFiles" json:"backupFiles" validate:"required,dive"`
|
||||
|
||||
// Async API Call
|
||||
// For async call use RestoreDisksFromBackupAsync
|
||||
// For sync call use RestoreDisksFromBackup
|
||||
// Required: true
|
||||
async bool `url:"async"`
|
||||
}
|
||||
|
||||
// RestoreDisksFromBackup restores disks from backup
|
||||
func (b Backup) RestoreDisksFromBackup(ctx context.Context, req RestoreDisksFromBackupRequest) (ListInfoRestoredDisk, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
req.async = false
|
||||
|
||||
url := "/cloudbroker/backup/restoreDisksFromBackup"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make(ListInfoRestoredDisk, 0)
|
||||
|
||||
err = json.Unmarshal(res, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// RestoreDisksFromBackupAsync restores disks from backup
|
||||
func (b Backup) RestoreDisksFromBackupAsync(ctx context.Context, req RestoreDisksFromBackupRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
req.async = true
|
||||
|
||||
url := "/cloudbroker/backup/restoreDisksFromBackup"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
result := strings.ReplaceAll(string(res), "\"", "")
|
||||
|
||||
return result, nil
|
||||
}
|
||||
@@ -19,8 +19,9 @@ type PFWAddRequest struct {
|
||||
PublicPortStart uint64 `url:"publicPortStart" json:"publicPortStart" validate:"required"`
|
||||
|
||||
// End port number (inclusive) for the ranged rule
|
||||
// Default value: -1
|
||||
// Required: false
|
||||
PublicPortEnd uint64 `url:"publicPortEnd,omitempty" json:"publicPortEnd,omitempty"`
|
||||
PublicPortEnd int64 `url:"publicPortEnd,omitempty" json:"publicPortEnd,omitempty"`
|
||||
|
||||
// Internal base port number
|
||||
// Required: true
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"appId": "<APP_ID>",
|
||||
"appSecret": "<APP_SECRET>",
|
||||
"ssoUrl": "https://sso.digitalenergy.online",
|
||||
"decortUrl": "https://mr4.digitalenergy.online",
|
||||
"retries": 5,
|
||||
"sslSkipVerify": false
|
||||
"appId": "<APP_ID>",
|
||||
"appSecret": "<APP_SECRET>",
|
||||
"ssoUrl": "https://sso.digitalenergy.online",
|
||||
"decortUrl": "https://mr4.digitalenergy.online",
|
||||
"retries": 5,
|
||||
"timeout": "5m",
|
||||
"sslSkipVerify": false
|
||||
}
|
||||
|
||||
@@ -3,4 +3,5 @@ appSecret: <APP_SECRET>
|
||||
ssoUrl: https://sso.digitalenergy.online
|
||||
decortUrl: https://mr4.digitalenergy.online
|
||||
retries: 5
|
||||
timeout: 5m
|
||||
sslSkipVerify: false
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"username": "<USERNAME>",
|
||||
"password": "<PASSWORD>",
|
||||
"decortUrl": "https://mr4.digitalenergy.online",
|
||||
"retries": 5,
|
||||
"sslSkipVerify": true
|
||||
"username": "<USERNAME>",
|
||||
"password": "<PASSWORD>",
|
||||
"decortUrl": "https://mr4.digitalenergy.online",
|
||||
"retries": 5,
|
||||
"timeout": "5m",
|
||||
"sslSkipVerify": true
|
||||
}
|
||||
|
||||
@@ -2,4 +2,5 @@ username: <USERNAME>
|
||||
password: <PASSWORD>
|
||||
decortUrl: https://mr4.digitalenergy.online
|
||||
retries: 5
|
||||
timeout: 5m
|
||||
sslSkipVerify: true
|
||||
|
||||
Reference in New Issue
Block a user