Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 264538f492 | |||
| c06a3198f6 | |||
| c9e4ae6afe | |||
| 2a1593f45f | |||
| 190f24dac1 | |||
| 256dba5134 | |||
| b7137683ab | |||
| 10e3e19892 |
56
CHANGELOG.md
56
CHANGELOG.md
@@ -1,44 +1,12 @@
|
|||||||
## Version 1.4.0
|
## Version 1.4.6
|
||||||
|
|
||||||
### Features
|
### Bugfix
|
||||||
|
- Fixed returning value type of VINS.NATRuleAdd()
|
||||||
- Actualized SDK to platform version 3.8.6:
|
- Fixed RuleID field type of VINS.NATRuleDel() request struct
|
||||||
- Added required field networkPlugin to requests in:
|
- Added wrapper for requests to async methods
|
||||||
- /cloudapi/cloudbroker/k8s/create;
|
- - CloudAPI()/CloudBroker().Compute().CreateTemplate()
|
||||||
- /cloudbroker/k8ci/create.
|
|
||||||
- Added networkPlugin field in models:
|
### Feature
|
||||||
- /cloudapi/cloudbroker/k8s;
|
- Added cloubroker/apiaccess group of endpoints support
|
||||||
- /cloudbroker/k8ci.
|
- Added cloubroker/group group of endpoints support
|
||||||
- Updated list of compute objects fields and added list of group objects in bservice model.
|
- Added cloubroker/user group of endpoints support
|
||||||
- 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.
|
|
||||||
17
README.md
17
README.md
@@ -118,6 +118,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
| SSOURL | string | Да | URL адрес сервиса аутентификации и авторизации |
|
| SSOURL | string | Да | URL адрес сервиса аутентификации и авторизации |
|
||||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||||
|
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
||||||
| Token | string | Нет | JWT токен |
|
| Token | string | Нет | JWT токен |
|
||||||
|
|
||||||
@@ -127,6 +128,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
import (
|
import (
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main(){
|
func main(){
|
||||||
// Настройка конфигурации
|
// Настройка конфигурации
|
||||||
cfg := config.Config{
|
cfg := config.Config{
|
||||||
@@ -136,6 +138,8 @@ func main(){
|
|||||||
DecortURL: "https://mr4.digitalenergy.online",
|
DecortURL: "https://mr4.digitalenergy.online",
|
||||||
Retries: 5,
|
Retries: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.SetTimeout(5 * time.Minute)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -165,6 +169,7 @@ func main() {
|
|||||||
"ssoUrl": "https://sso.digitalenergy.online",
|
"ssoUrl": "https://sso.digitalenergy.online",
|
||||||
"decortUrl": "https://mr4.digitalenergy.online",
|
"decortUrl": "https://mr4.digitalenergy.online",
|
||||||
"retries": 5,
|
"retries": 5,
|
||||||
|
"timeout": "5m",
|
||||||
"sslSkipVerify": false
|
"sslSkipVerify": false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -177,6 +182,7 @@ appSecret: <APP_SECRET>
|
|||||||
ssoUrl: https://sso.digitalenergy.online
|
ssoUrl: https://sso.digitalenergy.online
|
||||||
decortUrl: https://mr4.digitalenergy.online
|
decortUrl: https://mr4.digitalenergy.online
|
||||||
retries: 5
|
retries: 5
|
||||||
|
timeout: 5m
|
||||||
sslSkipVerify: false
|
sslSkipVerify: false
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -204,6 +210,8 @@ func main() {
|
|||||||
Retries: 5,
|
Retries: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.SetTimeout(5 * time.Minute)
|
||||||
|
|
||||||
// Создание клиента
|
// Создание клиента
|
||||||
client := decort.New(cfg)
|
client := decort.New(cfg)
|
||||||
}
|
}
|
||||||
@@ -647,6 +655,8 @@ func main() {
|
|||||||
DecortURL: "<DECORT_URL>",
|
DecortURL: "<DECORT_URL>",
|
||||||
Retries: 5,
|
Retries: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.SetTimeout(5 * time.Minute)
|
||||||
|
|
||||||
// Создание клиента
|
// Создание клиента
|
||||||
client := decort.New(cfg)
|
client := decort.New(cfg)
|
||||||
@@ -693,6 +703,7 @@ func main() {
|
|||||||
| Password | string | Да | пароль legacy пользователя |
|
| Password | string | Да | пароль legacy пользователя |
|
||||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||||
|
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
||||||
| Token | string | Нет | JWT токен |
|
| Token | string | Нет | JWT токен |
|
||||||
|
|
||||||
@@ -711,6 +722,8 @@ func main(){
|
|||||||
DecortURL: "https://mr4.digitalenergy.online",
|
DecortURL: "https://mr4.digitalenergy.online",
|
||||||
Retries: 5,
|
Retries: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
legacyCfg.SetTimeout(5 * time.Minute)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -739,6 +752,7 @@ func main() {
|
|||||||
"password": "<PASSWORD>",
|
"password": "<PASSWORD>",
|
||||||
"decortUrl": "https://mr4.digitalenergy.online",
|
"decortUrl": "https://mr4.digitalenergy.online",
|
||||||
"retries": 5,
|
"retries": 5,
|
||||||
|
"timeout": "5m",
|
||||||
"sslSkipVerify": true
|
"sslSkipVerify": true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -749,6 +763,7 @@ username: <USERNAME>
|
|||||||
password: <PASSWORD>
|
password: <PASSWORD>
|
||||||
decortUrl: https://mr4.digitalenergy.online
|
decortUrl: https://mr4.digitalenergy.online
|
||||||
retries: 5
|
retries: 5
|
||||||
|
timeout: 5m
|
||||||
sslSkipVerify: true
|
sslSkipVerify: true
|
||||||
```
|
```
|
||||||
### Создание legacy клиента
|
### Создание legacy клиента
|
||||||
@@ -774,6 +789,8 @@ func main() {
|
|||||||
Retries: 5,
|
Retries: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
legacyCfg.SetTimeout(5 * time.Minute)
|
||||||
|
|
||||||
// Создание клиента
|
// Создание клиента
|
||||||
legacyClient := decort.NewLegacy(cfg)
|
legacyClient := decort.NewLegacy(cfg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
@@ -44,6 +45,15 @@ type Config struct {
|
|||||||
// Skip verify, true by default
|
// Skip verify, true by default
|
||||||
// Required: false
|
// Required: false
|
||||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
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.
|
// ParseConfigJSON parses Config from specified JSON-formatted file.
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
@@ -38,6 +39,15 @@ type LegacyConfig struct {
|
|||||||
// Skip verify, true by default
|
// Skip verify, true by default
|
||||||
// Required: false
|
// Required: false
|
||||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
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.
|
// 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 (
|
require (
|
||||||
github.com/go-playground/validator/v10 v10.11.2
|
github.com/go-playground/validator/v10 v10.11.2
|
||||||
github.com/google/go-querystring v1.1.0
|
github.com/google/go-querystring v1.1.0
|
||||||
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.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
|
github.com/leodido/go-urn v1.2.1 // indirect
|
||||||
golang.org/x/crypto v0.5.0 // indirect
|
golang.org/x/crypto v0.5.0 // indirect
|
||||||
golang.org/x/sys v0.4.0 // indirect
|
golang.org/x/sys v0.4.0 // indirect
|
||||||
golang.org/x/text v0.6.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.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
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-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 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
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 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
|
||||||
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
|
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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
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/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.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
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/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
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 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.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 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
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},
|
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
},
|
},
|
||||||
|
|
||||||
Timeout: 5 * time.Minute,
|
Timeout: cfg.Timeout.Get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||||
)
|
)
|
||||||
@@ -28,6 +27,6 @@ func NewLegacyHttpClient(cfg config.LegacyConfig) *http.Client {
|
|||||||
decortURL: cfg.DecortURL,
|
decortURL: cfg.DecortURL,
|
||||||
},
|
},
|
||||||
|
|
||||||
Timeout: 5 * time.Minute,
|
Timeout: cfg.Timeout.Get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,29 +7,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
once sync.Once
|
once sync.Once
|
||||||
instance *DecortValidator
|
decortValidator = validator.New()
|
||||||
)
|
)
|
||||||
|
|
||||||
type DecortValidator struct {
|
|
||||||
decortValidator *validator.Validate
|
|
||||||
}
|
|
||||||
|
|
||||||
// getDecortValidator returns singleton instance of DecortValidator.
|
// getDecortValidator returns singleton instance of DecortValidator.
|
||||||
func getDecortValidator() *validator.Validate {
|
func getDecortValidator() *validator.Validate {
|
||||||
if instance == nil {
|
once.Do(func() {
|
||||||
once.Do(func() {
|
err := registerAllValidators(decortValidator)
|
||||||
instance = new(DecortValidator)
|
if err != nil {
|
||||||
instance.decortValidator = validator.New()
|
panic(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
err := registerAllValidators(instance.decortValidator)
|
return decortValidator
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance.decortValidator
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// registerAllValidators registers all custom validators in 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
|
// If true send emails when a user is granted access to resources
|
||||||
// Required: false
|
// Required: false
|
||||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty" json:"sendAccessEmails,omitempty"`
|
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
|
||||||
|
|
||||||
// Limit (positive) or disable (0) GPU resources
|
// Limit (positive) or disable (0) GPU resources
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ type UpdateRequest struct {
|
|||||||
|
|
||||||
// If true send emails when a user is granted access to resources
|
// If true send emails when a user is granted access to resources
|
||||||
// Required: false
|
// Required: false
|
||||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty" json:"sendAccessEmails,omitempty"`
|
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
|
||||||
|
|
||||||
// Limit (positive) or disable (0) GPU resources
|
// Limit (positive) or disable (0) GPU resources
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ type CreateTemplateRequest struct {
|
|||||||
// Name to assign to the template being created
|
// Name to assign to the template being created
|
||||||
// Required: true
|
// Required: true
|
||||||
Name string `url:"name" json:"name" validate:"required"`
|
Name string `url:"name" json:"name" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
// Async API call
|
type wrapperCreateTemplateRequest struct {
|
||||||
// For async call use CreateTemplateAsync
|
CreateTemplateRequest
|
||||||
// For sync call use CreateTemplate
|
|
||||||
// Required: true
|
Async bool `url:"async"`
|
||||||
async bool `url:"async"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateTemplate create template from compute instance
|
// CreateTemplate create template from compute instance
|
||||||
@@ -35,11 +35,14 @@ func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
req.async = false
|
reqWrapped := wrapperCreateTemplateRequest{
|
||||||
|
CreateTemplateRequest: req,
|
||||||
|
Async: false,
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudapi/compute/createTemplate"
|
url := "/cloudapi/compute/createTemplate"
|
||||||
|
|
||||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
@@ -61,11 +64,14 @@ func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequ
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
req.async = true
|
reqWrapped := wrapperCreateTemplateRequest{
|
||||||
|
CreateTemplateRequest: req,
|
||||||
|
Async: true,
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudapi/compute/createTemplate"
|
url := "/cloudapi/compute/createTemplate"
|
||||||
|
|
||||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,9 @@ type PFWAddRequest struct {
|
|||||||
PublicPortStart uint64 `url:"publicPortStart" json:"publicPortStart" validate:"required"`
|
PublicPortStart uint64 `url:"publicPortStart" json:"publicPortStart" validate:"required"`
|
||||||
|
|
||||||
// End port number (inclusive) for the ranged rule
|
// End port number (inclusive) for the ranged rule
|
||||||
|
// Default value: -1
|
||||||
// Required: false
|
// Required: false
|
||||||
PublicPortEnd uint64 `url:"publicPortEnd,omitempty" json:"publicPortEnd,omitempty"`
|
PublicPortEnd int64 `url:"publicPortEnd,omitempty" json:"publicPortEnd,omitempty"`
|
||||||
|
|
||||||
// Internal base port number
|
// Internal base port number
|
||||||
// Required: true
|
// Required: true
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ type CreateRequest struct {
|
|||||||
// Create Kubernetes cluster with masters nodes behind load balancer if true.
|
// Create Kubernetes cluster with masters nodes behind load balancer if true.
|
||||||
// Otherwise give all cluster nodes direct external addresses from selected ExtNet
|
// Otherwise give all cluster nodes direct external addresses from selected ExtNet
|
||||||
// Required: false
|
// Required: false
|
||||||
WithLB bool `url:"withLB,omitempty" json:"withLB,omitempty"`
|
WithLB bool `url:"withLB" json:"withLB"`
|
||||||
|
|
||||||
// Text description of this Kubernetes cluster
|
// Text description of this Kubernetes cluster
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Request struct for disable/enable kubernetes cluster
|
// Request struct for disable/enable kubernetes cluster
|
||||||
type DisabelEnableRequest struct {
|
type DisableEnableRequest struct {
|
||||||
// Kubernetes cluster ID
|
// Kubernetes cluster ID
|
||||||
// Required: true
|
// Required: true
|
||||||
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
K8SID uint64 `url:"k8sId" json:"k8sId" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable disables kubernetes cluster by ID
|
// 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)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
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
|
// 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)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
|||||||
@@ -2,9 +2,8 @@ package k8s
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,11 +23,11 @@ type WorkerAddRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WorkerAdd add worker nodes to a Kubernetes cluster
|
// 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)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
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)
|
res, err := k8s.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
if err != nil {
|
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 {
|
if err != nil {
|
||||||
return false, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|||||||
@@ -39,11 +39,11 @@ type NATRuleAddRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NATRuleAdd create NAT (port forwarding) rule on VINS
|
// NATRuleAdd create NAT (port forwarding) rule on VINS
|
||||||
func (v VINS) NATRuleAdd(ctx context.Context, req NATRuleAddRequest) (bool, error) {
|
func (v VINS) NATRuleAdd(ctx context.Context, req NATRuleAddRequest) (uint64, error) {
|
||||||
err := validators.ValidateRequest(req)
|
err := validators.ValidateRequest(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
for _, validationError := range validators.GetErrors(err) {
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
return false, validators.ValidationError(validationError)
|
return 0, validators.ValidationError(validationError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,12 +51,12 @@ func (v VINS) NATRuleAdd(ctx context.Context, req NATRuleAddRequest) (bool, erro
|
|||||||
|
|
||||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
result, err := strconv.ParseUint(string(res), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ type NATRuleDelRequest struct {
|
|||||||
// ID of the rule to delete.
|
// ID of the rule to delete.
|
||||||
// Pass -1 to clear all rules at once
|
// Pass -1 to clear all rules at once
|
||||||
// Required: true
|
// Required: true
|
||||||
RuleID uint64 `url:"ruleId" json:"ruleId" validate:"required"`
|
RuleID int64 `url:"ruleId" json:"ruleId" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NATRuleDel delete NAT (port forwarding) rule on VINS
|
// NATRuleDel delete NAT (port forwarding) rule on VINS
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ type CreateRequest struct {
|
|||||||
|
|
||||||
// If true send emails when a user is granted access to resources
|
// If true send emails when a user is granted access to resources
|
||||||
// Required: false
|
// Required: false
|
||||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty" json:"sendAccessEmails,omitempty"`
|
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
|
||||||
|
|
||||||
// Limit (positive) or disable (0) GPU resources
|
// Limit (positive) or disable (0) GPU resources
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ type UpdateRequest struct {
|
|||||||
|
|
||||||
// If true send emails when a user is granted access to resources
|
// If true send emails when a user is granted access to resources
|
||||||
// Required: false
|
// Required: false
|
||||||
SendAccessEmails bool `url:"sendAccessEmails,omitempty" json:"sendAccessEmails,omitempty"`
|
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
|
||||||
|
|
||||||
// Limit (positive) or disable (0) GPU resources
|
// Limit (positive) or disable (0) GPU resources
|
||||||
// Required: false
|
// Required: false
|
||||||
|
|||||||
8
pkg/cloudbroker/apiaccess.go
Normal file
8
pkg/cloudbroker/apiaccess.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package cloudbroker
|
||||||
|
|
||||||
|
import "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/apiaccess"
|
||||||
|
|
||||||
|
// Accessing the APIAccess method group
|
||||||
|
func (cb *CloudBroker) APIAccess() *apiaccess.APIAccess {
|
||||||
|
return apiaccess.New(cb.client)
|
||||||
|
}
|
||||||
43
pkg/cloudbroker/apiaccess/api_find.go
Normal file
43
pkg/cloudbroker/apiaccess/api_find.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for finding apiaccess groups.
|
||||||
|
type APIFindRequest struct {
|
||||||
|
// API function to find
|
||||||
|
// Example: cloudbroker/k8s/create
|
||||||
|
// Required: true
|
||||||
|
APIName string `url:"apiName" json:"apiName" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// APIFind outputs a list of apiaccess groups that mention the specified API function.
|
||||||
|
func (a APIAccess) APIFind(ctx context.Context, req APIFindRequest) ([]uint64, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/apiaccess/apiFind"
|
||||||
|
|
||||||
|
list := make([]uint64, 0)
|
||||||
|
|
||||||
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
15
pkg/cloudbroker/apiaccess/apiaccess.go
Normal file
15
pkg/cloudbroker/apiaccess/apiaccess.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||||
|
|
||||||
|
// Structure for creating request to APIAccess
|
||||||
|
type APIAccess struct {
|
||||||
|
client interfaces.Caller
|
||||||
|
}
|
||||||
|
|
||||||
|
// Builder for APIAccess endpoints
|
||||||
|
func New(client interfaces.Caller) *APIAccess {
|
||||||
|
return &APIAccess{
|
||||||
|
client: client,
|
||||||
|
}
|
||||||
|
}
|
||||||
69
pkg/cloudbroker/apiaccess/apis_exclude.go
Normal file
69
pkg/cloudbroker/apiaccess/apis_exclude.go
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for removing api from access group.
|
||||||
|
type APIsExcludeRequest struct {
|
||||||
|
// APIAccess group ID
|
||||||
|
// Required: true
|
||||||
|
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
|
||||||
|
|
||||||
|
// APIs to remove from APIAccess group
|
||||||
|
// Required: true
|
||||||
|
APIs APIsEndpoints `url:"-" json:"-" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type wrapperAPIsExcludeRequest struct {
|
||||||
|
APIsExcludeRequest
|
||||||
|
|
||||||
|
APIString string `url:"apis"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// APIsExclude removes the listed API functions from the specified apiaccess group.
|
||||||
|
func (a APIAccess) APIsExclude(ctx context.Context, req APIsExcludeRequest) (*APIsEndpoints, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/apiaccess/apisExclude"
|
||||||
|
|
||||||
|
info := APIsEndpoints{}
|
||||||
|
|
||||||
|
apiJSON, err := json.Marshal(&req.APIs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
apiJSONPretty, err := json.MarshalIndent(&req.APIs, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fmt.Println(string(apiJSONPretty))
|
||||||
|
|
||||||
|
reqWrapped := wrapperAPIsExcludeRequest{
|
||||||
|
APIsExcludeRequest: req,
|
||||||
|
APIString: string(apiJSON),
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
62
pkg/cloudbroker/apiaccess/apis_include.go
Normal file
62
pkg/cloudbroker/apiaccess/apis_include.go
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for adding api to access group.
|
||||||
|
type APIsIncludeRequest struct {
|
||||||
|
// APIAccess group ID.
|
||||||
|
// Required: true
|
||||||
|
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
|
||||||
|
|
||||||
|
// APIs to add to APIAccess group.
|
||||||
|
// Required: true
|
||||||
|
APIs APIsEndpoints `url:"-" json:"-" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type wrapperAPIsIncludeRequest struct {
|
||||||
|
APIsIncludeRequest
|
||||||
|
|
||||||
|
APIString string `url:"apis"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// APIsInclude adds the listed API functions to the specified apiaccess group.
|
||||||
|
func (a APIAccess) APIsInclude(ctx context.Context, req APIsIncludeRequest) (*APIsEndpoints, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/apiaccess/apisInclude"
|
||||||
|
|
||||||
|
info := APIsEndpoints{}
|
||||||
|
|
||||||
|
apiJSON, err := json.Marshal(&req.APIs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperAPIsIncludeRequest{
|
||||||
|
APIsIncludeRequest: req,
|
||||||
|
APIString: string(apiJSON),
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
44
pkg/cloudbroker/apiaccess/copy.go
Normal file
44
pkg/cloudbroker/apiaccess/copy.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for copying apiaccess group.
|
||||||
|
type CopyRequest struct {
|
||||||
|
// ID of the API access group to make copy from
|
||||||
|
// Required: true
|
||||||
|
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
|
||||||
|
|
||||||
|
// Name of the target API access group, which will be created on successful copy
|
||||||
|
// Required: true
|
||||||
|
Name string `url:"name" json:"name" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy creates a copy of the specified apiaccess group with a new name (and a new unique ID).
|
||||||
|
func (a APIAccess) Copy(ctx context.Context, req CopyRequest) (uint64, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return 0, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/apiaccess/copy"
|
||||||
|
|
||||||
|
res, err := a.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
|
||||||
|
}
|
||||||
44
pkg/cloudbroker/apiaccess/create.go
Normal file
44
pkg/cloudbroker/apiaccess/create.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for creating apiaccess group.
|
||||||
|
type CreateRequest struct {
|
||||||
|
// Name of this apiaccess group.
|
||||||
|
// Required: true
|
||||||
|
Name string `url:"name" json:"name" validate:"required"`
|
||||||
|
|
||||||
|
// Description of this apiaccess group.
|
||||||
|
// Required: false
|
||||||
|
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create creates apiaccess group.
|
||||||
|
func (a APIAccess) Create(ctx context.Context, req CreateRequest) (uint64, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return 0, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/apiaccess/create"
|
||||||
|
|
||||||
|
res, err := a.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
|
||||||
|
}
|
||||||
44
pkg/cloudbroker/apiaccess/delete.go
Normal file
44
pkg/cloudbroker/apiaccess/delete.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for deleting apiaccess group.
|
||||||
|
type DeleteRequest struct {
|
||||||
|
// APIAccess group ID.
|
||||||
|
// Required: true
|
||||||
|
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
|
||||||
|
|
||||||
|
// Set True to delete apiaccess group with attached users.
|
||||||
|
// Required: false
|
||||||
|
Force bool `url:"force,omitempty" json:"force,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete deletes apiaccess group
|
||||||
|
func (a APIAccess) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/apiaccess/delete"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
44
pkg/cloudbroker/apiaccess/desc_update.go
Normal file
44
pkg/cloudbroker/apiaccess/desc_update.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for updating apiaccess group description.
|
||||||
|
type DescUpdateRequest struct {
|
||||||
|
// APIAccess group ID.
|
||||||
|
// Required: true
|
||||||
|
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
|
||||||
|
|
||||||
|
// New description to set for the apiaccess group.
|
||||||
|
// Required: true
|
||||||
|
Description string `url:"desc" json:"desc" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescUpdate sets a new text description of the apiaccess group.
|
||||||
|
func (a APIAccess) DescUpdate(ctx context.Context, req DescUpdateRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/apiaccess/descUpdate"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
42
pkg/cloudbroker/apiaccess/get.go
Normal file
42
pkg/cloudbroker/apiaccess/get.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for getting apiaccess group.
|
||||||
|
type GetRequest struct {
|
||||||
|
// APIAccess group ID.
|
||||||
|
// Required: true
|
||||||
|
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get gets apiaccess group.
|
||||||
|
func (a APIAccess) Get(ctx context.Context, req GetRequest) (*ItemAPIAccess, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/apiaccess/get"
|
||||||
|
|
||||||
|
info := ItemAPIAccess{}
|
||||||
|
|
||||||
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
26
pkg/cloudbroker/apiaccess/get_full.go
Normal file
26
pkg/cloudbroker/apiaccess/get_full.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetFull gets full current endpoints dictionary
|
||||||
|
func (a APIAccess) GetFull(ctx context.Context) (*APIsEndpoints, error) {
|
||||||
|
url := "/cloudbroker/apiaccess/getFull"
|
||||||
|
|
||||||
|
info := APIsEndpoints{}
|
||||||
|
|
||||||
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
26
pkg/cloudbroker/apiaccess/get_pre_groups.go
Normal file
26
pkg/cloudbroker/apiaccess/get_pre_groups.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetPreGroups gets list of pre default groups from spec
|
||||||
|
func (a APIAccess) GetPreGroups(ctx context.Context) (map[string]APIsEndpoints, error) {
|
||||||
|
url := "/cloudbroker/apiaccess/getPreGroups"
|
||||||
|
|
||||||
|
info := make(map[string]APIsEndpoints)
|
||||||
|
|
||||||
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return info, nil
|
||||||
|
}
|
||||||
70
pkg/cloudbroker/apiaccess/list.go
Normal file
70
pkg/cloudbroker/apiaccess/list.go
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for getting list of all non deleted apiaccess instances.
|
||||||
|
type ListRequest struct {
|
||||||
|
// Find by ID
|
||||||
|
// Required: false
|
||||||
|
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by name apiaccess
|
||||||
|
// Required: false
|
||||||
|
Name string `url:"name,omitempty" json:"name,omitempty"`
|
||||||
|
|
||||||
|
// Find by status apiaccess
|
||||||
|
// Required: false
|
||||||
|
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||||
|
|
||||||
|
// Find by created actor
|
||||||
|
// Required: false
|
||||||
|
CreatedBy string `url:"createdBy,omitempty" json:"createdBy,omitempty"`
|
||||||
|
|
||||||
|
// Find by created after time (unix timestamp)
|
||||||
|
// Required: false
|
||||||
|
CreatedAfter uint64 `url:"createdAfter,omitempty" json:"createdAfter,omitempty"`
|
||||||
|
|
||||||
|
// Find by created before time (unix timestamp)
|
||||||
|
// Required: false
|
||||||
|
CreatedBefore uint64 `url:"createdBefore,omitempty" json:"createdBefore,omitempty"`
|
||||||
|
|
||||||
|
// Page number
|
||||||
|
// Required: false
|
||||||
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|
||||||
|
// Page size, maximum - 100
|
||||||
|
// Required: false
|
||||||
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// List gets list of all non deleted apiaccess instances.
|
||||||
|
func (a APIAccess) List(ctx context.Context, req ListRequest) (*ListAPIAccess, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/apiaccess/list"
|
||||||
|
|
||||||
|
info := ListAPIAccess{}
|
||||||
|
|
||||||
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
46
pkg/cloudbroker/apiaccess/list_deleted.go
Normal file
46
pkg/cloudbroker/apiaccess/list_deleted.go
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for getting list of all deleted apiaccess instances.
|
||||||
|
type ListDeletedRequest struct {
|
||||||
|
// Page number.
|
||||||
|
// Required: false
|
||||||
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|
||||||
|
// Page size.
|
||||||
|
// Required: false
|
||||||
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListDeleted gets list of all deleted apiaccess instances.
|
||||||
|
func (a APIAccess) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListAPIAccess, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/apiaccess/listDeleted"
|
||||||
|
|
||||||
|
info := ListAPIAccess{}
|
||||||
|
|
||||||
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
182
pkg/cloudbroker/apiaccess/models.go
Normal file
182
pkg/cloudbroker/apiaccess/models.go
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
type ItemAPIAccess struct {
|
||||||
|
// APIs
|
||||||
|
APIs APIsEndpoints `json:"apis"`
|
||||||
|
|
||||||
|
// Created by
|
||||||
|
CreatedBy string `json:"createdBy"`
|
||||||
|
|
||||||
|
// Created time
|
||||||
|
CreatedTime uint64 `json:"createdTime"`
|
||||||
|
|
||||||
|
// Is default
|
||||||
|
Default bool `json:"default"`
|
||||||
|
|
||||||
|
// Deleted by
|
||||||
|
DeletedBy string `json:"deletedBy"`
|
||||||
|
|
||||||
|
// Deleted time
|
||||||
|
DeletedTime uint64 `json:"deletedTime"`
|
||||||
|
|
||||||
|
// Description
|
||||||
|
Description string `json:"decs"`
|
||||||
|
|
||||||
|
// GID
|
||||||
|
GID uint64 `json:"gid"`
|
||||||
|
|
||||||
|
// GUID
|
||||||
|
GUID uint64 `json:"guid"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
// Milestones
|
||||||
|
Milestones uint64 `json:"milestones"`
|
||||||
|
|
||||||
|
// Name
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Is protected
|
||||||
|
Protected bool `json:"protected"`
|
||||||
|
|
||||||
|
// Status
|
||||||
|
Status string `json:"status"`
|
||||||
|
|
||||||
|
//Updated by
|
||||||
|
UpdatedBy string `json:"updatedBy"`
|
||||||
|
|
||||||
|
// Updated time
|
||||||
|
UpdatedTime uint64 `json:"updatedTime"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListAPIAccess struct {
|
||||||
|
Data []ItemAPIAccess `json:"data"`
|
||||||
|
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type APIsEndpoints struct {
|
||||||
|
// CloudAPI endpoints
|
||||||
|
CloudAPI CloudAPIEndpoints `json:"cloudapi,omitempty"`
|
||||||
|
|
||||||
|
// CloudBroker endpoints
|
||||||
|
CloudBroker CloudBrokerEndpoints `json:"cloudbroker,omitempty"`
|
||||||
|
|
||||||
|
// LibCloud endpoints
|
||||||
|
LibCloud LibCloudEndpoints `json:"libcloud,omitempty"`
|
||||||
|
|
||||||
|
// System endpoints
|
||||||
|
System SystemEndpoints `json:"system,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CloudAPIEndpoints struct {
|
||||||
|
Account []string `json:"account,omitempty"`
|
||||||
|
BService []string `json:"bservice,omitempty"`
|
||||||
|
CloudSpace []string `json:"cloudspace,omitempty"`
|
||||||
|
Compute []string `json:"compute,omitempty"`
|
||||||
|
ComputeCI []string `json:"computeci,omitempty"`
|
||||||
|
Disks []string `json:"disks,omitempty"`
|
||||||
|
ExtNet []string `json:"extnet,omitempty"`
|
||||||
|
FLIPGroup []string `json:"flipgroup,omitempty"`
|
||||||
|
GPU []string `json:"gpu,omitempty"`
|
||||||
|
Image []string `json:"image,omitempty"`
|
||||||
|
K8CI []string `json:"k8ci,omitempty"`
|
||||||
|
K8S []string `json:"k8s,omitempty"`
|
||||||
|
KVMPPC []string `json:"kvmppc,omitempty"`
|
||||||
|
KVMX86 []string `json:"kvmx86,omitempty"`
|
||||||
|
LB []string `json:"lb,omitempty"`
|
||||||
|
Loactions []string `json:"locations,omitempty"`
|
||||||
|
Machine []string `json:"machine,omitempty"`
|
||||||
|
Openshift []string `json:"openshift,omitempty"`
|
||||||
|
OpenshiftCI []string `json:"openshiftci,omitempty"`
|
||||||
|
PCIDevice []string `json:"pcidevice,omitempty"`
|
||||||
|
PortForwarding []string `json:"portforwarding,omitempty"`
|
||||||
|
Prometheus []string `json:"prometheus,omitempty"`
|
||||||
|
RG []string `json:"rg,omitempty"`
|
||||||
|
Sizes []string `json:"sizes,omitempty"`
|
||||||
|
Tasks []string `json:"tasks,omitempty"`
|
||||||
|
User []string `json:"user,omitempty"`
|
||||||
|
VGPU []string `json:"vgpu,omitempty"`
|
||||||
|
VINS []string `json:"vins,omitempty"`
|
||||||
|
All bool `json:"ALL,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CloudBrokerEndpoints struct {
|
||||||
|
Account []string `json:"account,omitempty"`
|
||||||
|
APIAccess []string `json:"apiaccess,omitempty"`
|
||||||
|
Audit []string `json:"audit,omitempty"`
|
||||||
|
AuditBeat []string `json:"auditbeat,omitempty"`
|
||||||
|
AuditCollector []string `json:"auditcollector,omitempty"`
|
||||||
|
BackupCreator []string `json:"backupcreator,omitempty"`
|
||||||
|
BService []string `json:"bservice,omitempty"`
|
||||||
|
CloudSpace []string `json:"cloudspace,omitempty"`
|
||||||
|
Compute []string `json:"compute,omitempty"`
|
||||||
|
ComputeCI []string `json:"computeci,omitempty"`
|
||||||
|
Desnode []string `json:"desnode,omitempty"`
|
||||||
|
Diagnostics []string `json:"diagnostics,omitempty"`
|
||||||
|
Disks []string `json:"disks,omitempty"`
|
||||||
|
Eco []string `json:"eco,omitempty"`
|
||||||
|
ExtNet []string `json:"extnet,omitempty"`
|
||||||
|
FlIPgroup []string `json:"flipgroup,omitempty"`
|
||||||
|
Grid []string `json:"grid,omitempty"`
|
||||||
|
Group []string `json:"group,omitempty"`
|
||||||
|
Health []string `json:"health,omitempty"`
|
||||||
|
IaaS []string `json:"iaas,omitempty"`
|
||||||
|
Image []string `json:"image,omitempty"`
|
||||||
|
Job []string `json:"job,omitempty"`
|
||||||
|
K8CI []string `json:"k8ci,omitempty"`
|
||||||
|
K8S []string `json:"k8s,omitempty"`
|
||||||
|
KVMPPC []string `json:"kvmppc,omitempty"`
|
||||||
|
KVMX86 []string `json:"kvmx86,omitempty"`
|
||||||
|
LB []string `json:"lb,omitempty"`
|
||||||
|
Machine []string `json:"machine,omitempty"`
|
||||||
|
Metering []string `json:"metering,omitempty"`
|
||||||
|
Milestones []string `json:"milestones,omitempty"`
|
||||||
|
Node []string `json:"node,omitempty"`
|
||||||
|
Openshift []string `json:"openshift,omitempty"`
|
||||||
|
OpenshiftCI []string `json:"openshiftci,omitempty"`
|
||||||
|
Ovsnode []string `json:"ovsnode,omitempty"`
|
||||||
|
PCIDevice []string `json:"pcidevice,omitempty"`
|
||||||
|
PGPU []string `json:"pgpu,omitempty"`
|
||||||
|
Prometheus []string `json:"prometheus,omitempty"`
|
||||||
|
QOS []string `json:"qos,omitempty"`
|
||||||
|
Resmon []string `json:"resmon,omitempty"`
|
||||||
|
RG []string `json:"rg,omitempty"`
|
||||||
|
Sep []string `json:"sep,omitempty"`
|
||||||
|
Stack []string `json:"stack,omitempty"`
|
||||||
|
Tasks []string `json:"tasks,omitempty"`
|
||||||
|
TLock []string `json:"tlock,omitempty"`
|
||||||
|
User []string `json:"user,omitempty"`
|
||||||
|
VGPU []string `json:"vgpu,omitempty"`
|
||||||
|
VINS []string `json:"vins,omitempty"`
|
||||||
|
VNFDev []string `json:"vnfdev,omitempty"`
|
||||||
|
ZeroAccess []string `json:"zeroaccess,omitempty"`
|
||||||
|
All bool `json:"ALL,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LibCloudEndpoints struct {
|
||||||
|
Libvirt []string `json:"libvirt,omitempty"`
|
||||||
|
All bool `json:"ALL,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SystemEndpoints struct {
|
||||||
|
AgentController []string `json:"agentcontroller,omitempty"`
|
||||||
|
Alerts []string `json:"alerts,omitempty"`
|
||||||
|
Audits []string `json:"audits,omitempty"`
|
||||||
|
ContentManager []string `json:"contentmanager,omitempty"`
|
||||||
|
DocGenerator []string `json:"docgenerator,omitempty"`
|
||||||
|
EmailSender []string `json:"emailsender,omitempty"`
|
||||||
|
ErrorConditionHandler []string `json:"errorconditionhandler,omitempty"`
|
||||||
|
GridManager []string `json:"gridmanager,omitempty"`
|
||||||
|
Health []string `json:"health,omitempty"`
|
||||||
|
Info []string `json:"info,omitempty"`
|
||||||
|
InfoMGR []string `json:"infomgr,omitempty"`
|
||||||
|
Job []string `json:"job,omitempty"`
|
||||||
|
Log []string `json:"log,omitempty"`
|
||||||
|
Logo []string `json:"logo,omitempty"`
|
||||||
|
Oauth []string `json:"oauth,omitempty"`
|
||||||
|
Task []string `json:"task,omitempty"`
|
||||||
|
UserManager []string `json:"usermanager,omitempty"`
|
||||||
|
All bool `json:"ALL,omitempty"`
|
||||||
|
}
|
||||||
40
pkg/cloudbroker/apiaccess/set_default.go
Normal file
40
pkg/cloudbroker/apiaccess/set_default.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reqeust struct for setting default apiaccess group.
|
||||||
|
type SetDefaultRequest struct {
|
||||||
|
// APIAccess group ID
|
||||||
|
// Required: true
|
||||||
|
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDefault sets current apiaccess group default.
|
||||||
|
func (a APIAccess) SetDefault(ctx context.Context, req SetDefaultRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/apiaccess/setDefault"
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
45
pkg/cloudbroker/apiaccess/subtract.go
Normal file
45
pkg/cloudbroker/apiaccess/subtract.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for subtracting.
|
||||||
|
type SubtractRequest struct {
|
||||||
|
// ID of the API access group to subtract from. This group will contain the difference.
|
||||||
|
MinuendID uint64 `url:"minuendId" json:"minuendId" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the API access group which is subtracted. This group is unchanged.
|
||||||
|
SubtrahendID uint64 `url:"subtrahendId" json:"subtrahendId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subtract removes such APIs from MinuendID that match APIs from SubtrahendID.
|
||||||
|
func (a APIAccess) Subtruct(ctx context.Context, req SubtractRequest) (*APIsEndpoints, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/apiaccess/subtract"
|
||||||
|
|
||||||
|
info := APIsEndpoints{}
|
||||||
|
|
||||||
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
47
pkg/cloudbroker/apiaccess/union.go
Normal file
47
pkg/cloudbroker/apiaccess/union.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for union.
|
||||||
|
type UnionRequest struct {
|
||||||
|
// Recipient apiaccess group ID
|
||||||
|
// Required: true
|
||||||
|
RecipientID uint64 `url:"recipientId" json:"recipientId" validate:"required"`
|
||||||
|
|
||||||
|
// Donor apiaccess group ID
|
||||||
|
// Required: true
|
||||||
|
DonorID uint64 `url:"donorId" json:"donorId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Combines the API list of group #1 ("recipient") and group #2 ("donor"),
|
||||||
|
// writing the result to group #1 and avoiding duplicates in the list
|
||||||
|
func (a APIAccess) Union(ctx context.Context, req UnionRequest) (*APIsEndpoints, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/apiaccess/union"
|
||||||
|
|
||||||
|
info := APIsEndpoints{}
|
||||||
|
|
||||||
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
62
pkg/cloudbroker/apiaccess/update.go
Normal file
62
pkg/cloudbroker/apiaccess/update.go
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for updating apis of apiaccess group.
|
||||||
|
type UpdateRequest struct {
|
||||||
|
// APIAccess group ID
|
||||||
|
// Required: true
|
||||||
|
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
|
||||||
|
|
||||||
|
// APIs to remove from APIAccess group
|
||||||
|
// Required: false
|
||||||
|
APIs APIsEndpoints `url:"-" json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type wrapperUpdateRequest struct {
|
||||||
|
UpdateRequest
|
||||||
|
|
||||||
|
APIString string `url:"apis"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update updates apis of apiaccess group.
|
||||||
|
func (a APIAccess) Update(ctx context.Context, req UpdateRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/apiaccess/update"
|
||||||
|
|
||||||
|
reqWrapped := wrapperUpdateRequest{
|
||||||
|
UpdateRequest: req,
|
||||||
|
}
|
||||||
|
|
||||||
|
apiJSON, err := json.Marshal(&req.APIs)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped.APIString = string(apiJSON)
|
||||||
|
|
||||||
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := strconv.ParseBool(string(res))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
42
pkg/cloudbroker/apiaccess/user_list.go
Normal file
42
pkg/cloudbroker/apiaccess/user_list.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package apiaccess
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for getting a list of users currently included in the specified group.
|
||||||
|
type UserListRequest struct {
|
||||||
|
// APIAccess group ID
|
||||||
|
// Required: true
|
||||||
|
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserList gets a list of users currently included in the specified group.
|
||||||
|
func (a APIAccess) UserList(ctx context.Context, req UserListRequest) ([]string, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/apiaccess/userList"
|
||||||
|
|
||||||
|
list := make([]string, 0)
|
||||||
|
|
||||||
|
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
88
pkg/cloudbroker/backup/create_disk_backup.go
Normal file
88
pkg/cloudbroker/backup/create_disk_backup.go
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
package backup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type wrapperCreateDiskBackupRequest struct {
|
||||||
|
CreateDiskBackupRequest
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperCreateDiskBackupRequest{
|
||||||
|
CreateDiskBackupRequest: req,
|
||||||
|
Async: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/createDiskBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperCreateDiskBackupRequest{
|
||||||
|
CreateDiskBackupRequest: req,
|
||||||
|
Async: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/createDiskBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := strings.ReplaceAll(string(res), "\"", "")
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
90
pkg/cloudbroker/backup/create_disks_backup.go
Normal file
90
pkg/cloudbroker/backup/create_disks_backup.go
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
package backup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type wrapperCreateDisksBackupRequest struct {
|
||||||
|
CreateDisksBackupRequest
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperCreateDisksBackupRequest{
|
||||||
|
CreateDisksBackupRequest: req,
|
||||||
|
Async: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/createDisksBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperCreateDisksBackupRequest{
|
||||||
|
CreateDisksBackupRequest: req,
|
||||||
|
Async: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/createDisksBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := strings.ReplaceAll(string(res), "\"", "")
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
80
pkg/cloudbroker/backup/delete_disk_backup.go
Normal file
80
pkg/cloudbroker/backup/delete_disk_backup.go
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
package backup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type wrapperDeleteDiskBackupRequest struct {
|
||||||
|
DeleteDiskBackupRequest
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperDeleteDiskBackupRequest{
|
||||||
|
DeleteDiskBackupRequest: req,
|
||||||
|
Async: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/deleteDiskBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperDeleteDiskBackupRequest{
|
||||||
|
DeleteDiskBackupRequest: req,
|
||||||
|
Async: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/deleteDiskBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
|
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
|
||||||
88
pkg/cloudbroker/backup/restore_disk_from_backup.go
Normal file
88
pkg/cloudbroker/backup/restore_disk_from_backup.go
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
package backup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type wrapperRestoreDiskFromBackupRequest struct {
|
||||||
|
RestoreDiskFromBackupRequest
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperRestoreDiskFromBackupRequest{
|
||||||
|
RestoreDiskFromBackupRequest: req,
|
||||||
|
Async: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/restoreDiskFromBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperRestoreDiskFromBackupRequest{
|
||||||
|
RestoreDiskFromBackupRequest: req,
|
||||||
|
Async: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/restoreDiskFromBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := strings.ReplaceAll(string(res), "\"", "")
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
93
pkg/cloudbroker/backup/restore_disks_from_backup.go
Normal file
93
pkg/cloudbroker/backup/restore_disks_from_backup.go
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
package backup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type wrapperRestoreDisksFromBackupRequest struct {
|
||||||
|
RestoreDisksFromBackupRequest
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperRestoreDisksFromBackupRequest{
|
||||||
|
RestoreDisksFromBackupRequest: req,
|
||||||
|
Async: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/restoreDisksFromBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqWrapped := wrapperRestoreDisksFromBackupRequest{
|
||||||
|
RestoreDisksFromBackupRequest: req,
|
||||||
|
Async: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/backup/restoreDisksFromBackup"
|
||||||
|
|
||||||
|
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := strings.ReplaceAll(string(res), "\"", "")
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
@@ -22,12 +22,12 @@ type CreateTemplateRequest struct {
|
|||||||
// Reason for action
|
// Reason for action
|
||||||
// Required: false
|
// Required: false
|
||||||
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// Async API call
|
type wrapperCreateTemplateRequest struct {
|
||||||
// For async call use CreateTemplateAsync
|
CreateTemplateRequest
|
||||||
// For sync call use CreateTemplate
|
|
||||||
// Required: true
|
Async bool `url:"async"`
|
||||||
async bool `url:"async"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateTemplateAsync create template from compute instance
|
// CreateTemplateAsync create template from compute instance
|
||||||
@@ -39,11 +39,14 @@ func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequ
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
req.async = true
|
reqWrapped := wrapperCreateTemplateRequest{
|
||||||
|
CreateTemplateRequest: req,
|
||||||
|
Async: true,
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudbroker/compute/createTemplate"
|
url := "/cloudbroker/compute/createTemplate"
|
||||||
|
|
||||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -62,11 +65,14 @@ func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
req.async = false
|
reqWrapped := wrapperCreateTemplateRequest{
|
||||||
|
CreateTemplateRequest: req,
|
||||||
|
Async: false,
|
||||||
|
}
|
||||||
|
|
||||||
url := "/cloudbroker/compute/createTemplate"
|
url := "/cloudbroker/compute/createTemplate"
|
||||||
|
|
||||||
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,9 @@ type PFWAddRequest struct {
|
|||||||
PublicPortStart uint64 `url:"publicPortStart" json:"publicPortStart" validate:"required"`
|
PublicPortStart uint64 `url:"publicPortStart" json:"publicPortStart" validate:"required"`
|
||||||
|
|
||||||
// End port number (inclusive) for the ranged rule
|
// End port number (inclusive) for the ranged rule
|
||||||
|
// Default value: -1
|
||||||
// Required: false
|
// Required: false
|
||||||
PublicPortEnd uint64 `url:"publicPortEnd,omitempty" json:"publicPortEnd,omitempty"`
|
PublicPortEnd int64 `url:"publicPortEnd,omitempty" json:"publicPortEnd,omitempty"`
|
||||||
|
|
||||||
// Internal base port number
|
// Internal base port number
|
||||||
// Required: true
|
// Required: true
|
||||||
|
|||||||
8
pkg/cloudbroker/group.go
Normal file
8
pkg/cloudbroker/group.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package cloudbroker
|
||||||
|
|
||||||
|
import "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/group"
|
||||||
|
|
||||||
|
// Accessing the Group method group
|
||||||
|
func (cb *CloudBroker) Group() *group.Group {
|
||||||
|
return group.New(cb.client)
|
||||||
|
}
|
||||||
42
pkg/cloudbroker/group/get.go
Normal file
42
pkg/cloudbroker/group/get.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package group
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reuqest struct for getting details of the specified group.
|
||||||
|
type GetRequest struct {
|
||||||
|
// Group ID
|
||||||
|
// Required: true
|
||||||
|
GroupID string `url:"groupId" json:"groupId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get gets details of the specified group.
|
||||||
|
func (g Group) Get(ctx context.Context, req GetRequest) (*ItemGroup, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/group/get"
|
||||||
|
|
||||||
|
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := ItemGroup{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
15
pkg/cloudbroker/group/group.go
Normal file
15
pkg/cloudbroker/group/group.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package group
|
||||||
|
|
||||||
|
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||||
|
|
||||||
|
// Structure for creating request to group
|
||||||
|
type Group struct {
|
||||||
|
client interfaces.Caller
|
||||||
|
}
|
||||||
|
|
||||||
|
// Builder for group endpoints
|
||||||
|
func New(client interfaces.Caller) *Group {
|
||||||
|
return &Group{
|
||||||
|
client: client,
|
||||||
|
}
|
||||||
|
}
|
||||||
57
pkg/cloudbroker/group/list.go
Normal file
57
pkg/cloudbroker/group/list.go
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package group
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for getting list of group instances.
|
||||||
|
type ListRequest struct {
|
||||||
|
// Find by id.
|
||||||
|
// Requires: false
|
||||||
|
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by list users.
|
||||||
|
// Required: false
|
||||||
|
User string `url:"user,omitempty" json:"user,omitempty"`
|
||||||
|
|
||||||
|
// Page number.
|
||||||
|
// Required: false
|
||||||
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|
||||||
|
// Page size, maximum - 100.
|
||||||
|
// Required: false
|
||||||
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||||
|
|
||||||
|
// Find by active True or False.
|
||||||
|
// Required: true
|
||||||
|
Active bool `url:"active" json:"active" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g Group) List(ctx context.Context, req ListRequest) (*ListGroups, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/group/list"
|
||||||
|
|
||||||
|
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := ListGroups{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
42
pkg/cloudbroker/group/models.go
Normal file
42
pkg/cloudbroker/group/models.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package group
|
||||||
|
|
||||||
|
type ItemGroup struct {
|
||||||
|
// CKey
|
||||||
|
CKey string `json:"_ckey"`
|
||||||
|
|
||||||
|
// Meta
|
||||||
|
Meta []interface{} `json:"meta"`
|
||||||
|
|
||||||
|
// Is active
|
||||||
|
Actice bool `json:"active"`
|
||||||
|
|
||||||
|
// Description
|
||||||
|
Description string `json:"description"`
|
||||||
|
|
||||||
|
// Domain
|
||||||
|
Domain string `json:"domain"`
|
||||||
|
|
||||||
|
// GID
|
||||||
|
GID uint64 `json:"gid"`
|
||||||
|
|
||||||
|
// GUID
|
||||||
|
GUID string `json:"guid"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID string
|
||||||
|
|
||||||
|
// Last check
|
||||||
|
LastCheck uint64 `json:"lastcheck"`
|
||||||
|
|
||||||
|
// Roles
|
||||||
|
Roles []interface{} `json:"roles"`
|
||||||
|
|
||||||
|
// Users
|
||||||
|
Users []string `json:"users"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListGroups struct {
|
||||||
|
Data []ItemGroup `json:"data"`
|
||||||
|
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
7
pkg/cloudbroker/user.go
Normal file
7
pkg/cloudbroker/user.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package cloudbroker
|
||||||
|
|
||||||
|
import "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/user"
|
||||||
|
|
||||||
|
func (cb *CloudBroker) User() *user.User {
|
||||||
|
return user.New(cb.client)
|
||||||
|
}
|
||||||
43
pkg/cloudbroker/user/api_list.go
Normal file
43
pkg/cloudbroker/user/api_list.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for getting API list.
|
||||||
|
type APIListRequest struct {
|
||||||
|
// ID of the user.
|
||||||
|
// Required: true
|
||||||
|
UserID string `url:"userId" json:"userId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// APIList gets a list of all API functions that a given user has
|
||||||
|
// access to according to their apiaccess group membership.
|
||||||
|
func (u User) APIList(ctx context.Context, req APIListRequest) (*APIsEndpoints, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/user/apiList"
|
||||||
|
|
||||||
|
info := APIsEndpoints{}
|
||||||
|
|
||||||
|
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &info)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &info, nil
|
||||||
|
}
|
||||||
44
pkg/cloudbroker/user/apiaccess_join.go
Normal file
44
pkg/cloudbroker/user/apiaccess_join.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for joining user into apiaccess group.
|
||||||
|
type APIAccessJoinRequest struct {
|
||||||
|
// ID of the user whose membership will be updated.
|
||||||
|
// Required: true
|
||||||
|
UserID string `url:"userId" json:"userId" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the API access group to join
|
||||||
|
// Required: true
|
||||||
|
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// APIAccessJoin joins user into apiaccess group.
|
||||||
|
func (u User) APIAccessJoin(ctx context.Context, req APIAccessJoinRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/user/apiaccessJoin"
|
||||||
|
|
||||||
|
res, err := u.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
|
||||||
|
}
|
||||||
44
pkg/cloudbroker/user/apiaccess_leave.go
Normal file
44
pkg/cloudbroker/user/apiaccess_leave.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for leaving user from apiaccess group.
|
||||||
|
type APIAccessLeaveRequest struct {
|
||||||
|
// ID of the user whose membership will be updated.
|
||||||
|
// Required: true
|
||||||
|
UserID string `url:"userId" json:"userId" validate:"required"`
|
||||||
|
|
||||||
|
// ID of the API access group to leave.
|
||||||
|
// Required: true
|
||||||
|
APIAccessID uint64 `url:"apiaccessId" json:"apiaccessId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// APIAccessLeave leaves user from apiaccess group.
|
||||||
|
func (u User) APIAccessLeave(ctx context.Context, req APIAccessLeaveRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/user/apiaccessLeave"
|
||||||
|
|
||||||
|
res, err := u.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
|
||||||
|
}
|
||||||
44
pkg/cloudbroker/user/apiaccess_list.go
Normal file
44
pkg/cloudbroker/user/apiaccess_list.go
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for showing list of dicts with information about
|
||||||
|
// apiaccess groups contains to the user.
|
||||||
|
type APIAccessListRequest struct {
|
||||||
|
// ID of the user to list API access groups for.
|
||||||
|
// Required: true
|
||||||
|
UserID string `url:"userId" json:"userId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// APIAccessList shows list of dicts with information about apiaccess groups contains to the user.
|
||||||
|
func (u User) APIAccessList(ctx context.Context, req APIAccessListRequest) (ListAPIAccess, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/user/apiaccessList"
|
||||||
|
|
||||||
|
list := ListAPIAccess{}
|
||||||
|
|
||||||
|
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
56
pkg/cloudbroker/user/create.go
Normal file
56
pkg/cloudbroker/user/create.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for creating a user.
|
||||||
|
type CreateRequest struct {
|
||||||
|
// ID of user.
|
||||||
|
// Required: true
|
||||||
|
Username string `url:"username" json:"username" validate:"required"`
|
||||||
|
|
||||||
|
// Email addresses of the user.
|
||||||
|
// Required: true
|
||||||
|
EmailAddress []string `url:"emailaddress" json:"emailaddress" validate:"required"`
|
||||||
|
|
||||||
|
// Password of user
|
||||||
|
// Required: false
|
||||||
|
Password string `url:"password,omitempty" json:"password,omitempty"`
|
||||||
|
|
||||||
|
// List of groups this user belongs to.
|
||||||
|
// Required: false
|
||||||
|
Groups []string `url:"groups,omitempty" json:"groups,omitempty"`
|
||||||
|
|
||||||
|
// List of apiaccess groups this user belongs to.
|
||||||
|
// Required: false
|
||||||
|
APIAccess []uint64 `url:"apiaccess,omitempty" json:"apiaccess,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create creates a user.
|
||||||
|
func (u User) Create(ctx context.Context, req CreateRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/user/create"
|
||||||
|
|
||||||
|
res, err := u.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
|
||||||
|
}
|
||||||
40
pkg/cloudbroker/user/delete.go
Normal file
40
pkg/cloudbroker/user/delete.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for deleting a user.
|
||||||
|
type DeleteRequest struct {
|
||||||
|
// ID of user.
|
||||||
|
// Required: true
|
||||||
|
Username string `url:"username" json:"username" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete deletes a user.
|
||||||
|
func (u User) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/user/delete"
|
||||||
|
|
||||||
|
res, err := u.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
|
||||||
|
}
|
||||||
42
pkg/cloudbroker/user/delete_by_guid.go
Normal file
42
pkg/cloudbroker/user/delete_by_guid.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for deleting a user using user's GUID.
|
||||||
|
type DeleteByGUIDRequest struct {
|
||||||
|
// GUID of user.
|
||||||
|
// Required: true
|
||||||
|
GUID string `url:"userguid" json:"userguid" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteByGUID deletes a user using user's GUID.
|
||||||
|
// Note: This actor can also be called using username instead of guid to workaround CBGrid
|
||||||
|
// allowing userguid or username.
|
||||||
|
func (u User) DeleteByGUID(ctx context.Context, req DeleteByGUIDRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/user/deleteByGuid"
|
||||||
|
|
||||||
|
res, err := u.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
|
||||||
|
}
|
||||||
39
pkg/cloudbroker/user/delete_users.go
Normal file
39
pkg/cloudbroker/user/delete_users.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for bulk delete a list of users.
|
||||||
|
type DeleteUsersRequest struct {
|
||||||
|
// List of user ids
|
||||||
|
UserIDs string
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteUsers bulk delete a list of users.
|
||||||
|
func (u User) DeleteUsers(ctx context.Context, req DeleteUsersRequest) (bool, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return false, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/user/deleteUsers"
|
||||||
|
|
||||||
|
res, err := u.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
|
||||||
|
}
|
||||||
42
pkg/cloudbroker/user/get.go
Normal file
42
pkg/cloudbroker/user/get.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for getting user details.
|
||||||
|
type GetRequest struct {
|
||||||
|
// ID of the user.
|
||||||
|
// Required: true
|
||||||
|
UserID string `url:"userId" json:"userId" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get gets user details.
|
||||||
|
func (u User) Get(ctx context.Context, req GetRequest) (*ItemUser, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/user/get"
|
||||||
|
|
||||||
|
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
item := ItemUser{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &item)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &item, nil
|
||||||
|
}
|
||||||
50
pkg/cloudbroker/user/get_audit.go
Normal file
50
pkg/cloudbroker/user/get_audit.go
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for getting user's audits.
|
||||||
|
type GetAuditRequest struct {
|
||||||
|
// Name of user (get audits for current user if set to empty).
|
||||||
|
// Required: false
|
||||||
|
Username string `url:"username,omitempty" json:"username,omitempty"`
|
||||||
|
|
||||||
|
// Page number.
|
||||||
|
// Required: false
|
||||||
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|
||||||
|
// Page size, maximum - 100.
|
||||||
|
// Required: false
|
||||||
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAudits gets user's audits.
|
||||||
|
func (u User) GetAudit(ctx context.Context, req GetAuditRequest) (ListAudits, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/user/getAudit"
|
||||||
|
|
||||||
|
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
list := ListAudits{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
47
pkg/cloudbroker/user/get_matching_usernames.go
Normal file
47
pkg/cloudbroker/user/get_matching_usernames.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for getting a list of the matching usernames for a given string.
|
||||||
|
type GetMatchingUsernamesRequest struct {
|
||||||
|
// Regex of the usernames to searched for.
|
||||||
|
// Required: true
|
||||||
|
UsernameRegex string `url:"usernameregex" json:"usernameregex" validate:"required"`
|
||||||
|
|
||||||
|
// The number of usernames to return.
|
||||||
|
// Required: true
|
||||||
|
Limit uint64 `url:"limit" json:"limit" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMatchingUsernames gets a list of the matching usernames for a given string.
|
||||||
|
func (u User) GetMatchingUsernames(ctx context.Context, req GetMatchingUsernamesRequest) (ListMatchingUsernames, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/user/getMatchingUsernames"
|
||||||
|
|
||||||
|
list := ListMatchingUsernames{}
|
||||||
|
|
||||||
|
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
58
pkg/cloudbroker/user/list.go
Normal file
58
pkg/cloudbroker/user/list.go
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Request struct for getting all non deleted user instances.
|
||||||
|
type ListRequest struct {
|
||||||
|
// Find by ID.
|
||||||
|
// Required: false
|
||||||
|
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
||||||
|
|
||||||
|
// Find by active. True or False.
|
||||||
|
// Required: false
|
||||||
|
Active bool `url:"active,omitempty" json:"active,omitempty"`
|
||||||
|
|
||||||
|
// Find by serviceaccount. True or False.
|
||||||
|
// Required: false
|
||||||
|
ServiceAccount bool `url:"serviceaccount,omitempty" json:"serviceaccount,omitempty"`
|
||||||
|
|
||||||
|
// Page number.
|
||||||
|
// Required: false
|
||||||
|
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
||||||
|
|
||||||
|
// Page size, maximum - 100.
|
||||||
|
// Required: false
|
||||||
|
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// List gets all non deleted user instances.
|
||||||
|
func (u User) List(ctx context.Context, req ListRequest) (*ListUsers, error) {
|
||||||
|
err := validators.ValidateRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
for _, validationError := range validators.GetErrors(err) {
|
||||||
|
return nil, validators.ValidationError(validationError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url := "/cloudbroker/user/list"
|
||||||
|
|
||||||
|
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
list := ListUsers{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(res, &list)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &list, nil
|
||||||
|
}
|
||||||
276
pkg/cloudbroker/user/models.go
Normal file
276
pkg/cloudbroker/user/models.go
Normal file
@@ -0,0 +1,276 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
type ItemUser struct {
|
||||||
|
// CKey
|
||||||
|
CKey string `json:"_ckey"`
|
||||||
|
|
||||||
|
// Meta
|
||||||
|
Meta []interface{} `json:"_meta"`
|
||||||
|
|
||||||
|
// Is active
|
||||||
|
Active bool `json:"active"`
|
||||||
|
|
||||||
|
// APIAccess
|
||||||
|
APIAccess []uint64 `json:"apiaccess"`
|
||||||
|
|
||||||
|
// AuthKey
|
||||||
|
AuthKey string `json:"authkey"`
|
||||||
|
|
||||||
|
// AuthKeys
|
||||||
|
AuthKeys []interface{}
|
||||||
|
|
||||||
|
// Data
|
||||||
|
Data string `json:"data"`
|
||||||
|
|
||||||
|
// Description
|
||||||
|
Description string `json:"description"`
|
||||||
|
|
||||||
|
// Domain
|
||||||
|
Domain string `json:"domain"`
|
||||||
|
|
||||||
|
// Emails
|
||||||
|
Emails []string `json:"emails"`
|
||||||
|
|
||||||
|
// GID
|
||||||
|
GID uint64 `json:"gid"`
|
||||||
|
|
||||||
|
// Groups
|
||||||
|
Groups []string `json:"groups"`
|
||||||
|
|
||||||
|
// GUID
|
||||||
|
GUID string `json:"guid"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID string `json:"id"`
|
||||||
|
|
||||||
|
// LastCheck
|
||||||
|
LastCheck uint64 `json:"lastcheck"`
|
||||||
|
|
||||||
|
// Mobile
|
||||||
|
Mobile []interface{} `json:"mobile"`
|
||||||
|
|
||||||
|
// Password
|
||||||
|
Password string `json:"password"`
|
||||||
|
|
||||||
|
// Protected
|
||||||
|
Protected bool `json:"protected"`
|
||||||
|
|
||||||
|
// Roles
|
||||||
|
Roles []interface{} `json:"roles"`
|
||||||
|
|
||||||
|
// ServiceAccount
|
||||||
|
ServiceAccount bool `json:"serviceaccount"`
|
||||||
|
|
||||||
|
// XMPP
|
||||||
|
XMPP []interface{} `json:"xmpp"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListUsers struct {
|
||||||
|
Data []ItemUser `json:"data"`
|
||||||
|
|
||||||
|
EntryCount uint64 `json:"entryCount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ItemAPIAccess struct {
|
||||||
|
// Description
|
||||||
|
Description string `json:"desc"`
|
||||||
|
|
||||||
|
// ID
|
||||||
|
ID uint64 `json:"id"`
|
||||||
|
|
||||||
|
// Name
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListAPIAccess []ItemAPIAccess
|
||||||
|
|
||||||
|
type ItemMatchingUsername struct {
|
||||||
|
// Gravatar URL
|
||||||
|
GravatarURL string `json:"gravatarurl"`
|
||||||
|
|
||||||
|
// Username
|
||||||
|
Username string `json:"username"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListMatchingUsernames []ItemMatchingUsername
|
||||||
|
|
||||||
|
type ItemAudit struct {
|
||||||
|
// Call
|
||||||
|
Call string `json:"Call"`
|
||||||
|
|
||||||
|
// Response time
|
||||||
|
ResponseTime ResponseTime `json:"Response Time"`
|
||||||
|
|
||||||
|
// StatusCode
|
||||||
|
StatusCode StatusCode `json:"Status Code"`
|
||||||
|
|
||||||
|
// Time
|
||||||
|
Time float64 `json:"Time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListAudits []ItemAudit
|
||||||
|
|
||||||
|
type ResponseTime float64
|
||||||
|
|
||||||
|
func (r *ResponseTime) UnmarshalJSON(b []byte) error {
|
||||||
|
if string(b) == "null" {
|
||||||
|
*r = ResponseTime(-1)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := strconv.ParseFloat(string(b), 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*r = ResponseTime(res)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type StatusCode int64
|
||||||
|
|
||||||
|
func (s *StatusCode) UnmarshalJSON(b []byte) error {
|
||||||
|
if string(b) == "null" {
|
||||||
|
*s = StatusCode(-1)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := strconv.ParseInt(string(b), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*s = StatusCode(res)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type APIsEndpoints struct {
|
||||||
|
// CloudAPI endpoints
|
||||||
|
CloudAPI CloudAPIEndpoints `json:"cloudapi,omitempty"`
|
||||||
|
|
||||||
|
// CloudBroker endpoints
|
||||||
|
CloudBroker CloudBrokerEndpoints `json:"cloudbroker,omitempty"`
|
||||||
|
|
||||||
|
// LibCloud endpoints
|
||||||
|
LibCloud LibCloudEndpoints `json:"libcloud,omitempty"`
|
||||||
|
|
||||||
|
// System endpoints
|
||||||
|
System SystemEndpoints `json:"system,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CloudAPIEndpoints struct {
|
||||||
|
Account []string `json:"account,omitempty"`
|
||||||
|
BService []string `json:"bservice,omitempty"`
|
||||||
|
CloudSpace []string `json:"cloudspace,omitempty"`
|
||||||
|
Compute []string `json:"compute,omitempty"`
|
||||||
|
ComputeCI []string `json:"computeci,omitempty"`
|
||||||
|
Disks []string `json:"disks,omitempty"`
|
||||||
|
ExtNet []string `json:"extnet,omitempty"`
|
||||||
|
FLIPGroup []string `json:"flipgroup,omitempty"`
|
||||||
|
GPU []string `json:"gpu,omitempty"`
|
||||||
|
Image []string `json:"image,omitempty"`
|
||||||
|
K8CI []string `json:"k8ci,omitempty"`
|
||||||
|
K8S []string `json:"k8s,omitempty"`
|
||||||
|
KVMPPC []string `json:"kvmppc,omitempty"`
|
||||||
|
KVMX86 []string `json:"kvmx86,omitempty"`
|
||||||
|
LB []string `json:"lb,omitempty"`
|
||||||
|
Loactions []string `json:"locations,omitempty"`
|
||||||
|
Machine []string `json:"machine,omitempty"`
|
||||||
|
Openshift []string `json:"openshift,omitempty"`
|
||||||
|
OpenshiftCI []string `json:"openshiftci,omitempty"`
|
||||||
|
PCIDevice []string `json:"pcidevice,omitempty"`
|
||||||
|
PortForwarding []string `json:"portforwarding,omitempty"`
|
||||||
|
Prometheus []string `json:"prometheus,omitempty"`
|
||||||
|
RG []string `json:"rg,omitempty"`
|
||||||
|
Sizes []string `json:"sizes,omitempty"`
|
||||||
|
Tasks []string `json:"tasks,omitempty"`
|
||||||
|
User []string `json:"user,omitempty"`
|
||||||
|
VGPU []string `json:"vgpu,omitempty"`
|
||||||
|
VINS []string `json:"vins,omitempty"`
|
||||||
|
All bool `json:"ALL,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CloudBrokerEndpoints struct {
|
||||||
|
Account []string `json:"account,omitempty"`
|
||||||
|
APIAccess []string `json:"apiaccess,omitempty"`
|
||||||
|
Audit []string `json:"audit,omitempty"`
|
||||||
|
AuditBeat []string `json:"auditbeat,omitempty"`
|
||||||
|
AuditCollector []string `json:"auditcollector,omitempty"`
|
||||||
|
BackupCreator []string `json:"backupcreator,omitempty"`
|
||||||
|
BService []string `json:"bservice,omitempty"`
|
||||||
|
CloudSpace []string `json:"cloudspace,omitempty"`
|
||||||
|
Compute []string `json:"compute,omitempty"`
|
||||||
|
ComputeCI []string `json:"computeci,omitempty"`
|
||||||
|
Desnode []string `json:"desnode,omitempty"`
|
||||||
|
Diagnostics []string `json:"diagnostics,omitempty"`
|
||||||
|
Disks []string `json:"disks,omitempty"`
|
||||||
|
Eco []string `json:"eco,omitempty"`
|
||||||
|
ExtNet []string `json:"extnet,omitempty"`
|
||||||
|
FlIPgroup []string `json:"flipgroup,omitempty"`
|
||||||
|
Grid []string `json:"grid,omitempty"`
|
||||||
|
Group []string `json:"group,omitempty"`
|
||||||
|
Health []string `json:"health,omitempty"`
|
||||||
|
IaaS []string `json:"iaas,omitempty"`
|
||||||
|
Image []string `json:"image,omitempty"`
|
||||||
|
Job []string `json:"job,omitempty"`
|
||||||
|
K8CI []string `json:"k8ci,omitempty"`
|
||||||
|
K8S []string `json:"k8s,omitempty"`
|
||||||
|
KVMPPC []string `json:"kvmppc,omitempty"`
|
||||||
|
KVMX86 []string `json:"kvmx86,omitempty"`
|
||||||
|
LB []string `json:"lb,omitempty"`
|
||||||
|
Machine []string `json:"machine,omitempty"`
|
||||||
|
Metering []string `json:"metering,omitempty"`
|
||||||
|
Milestones []string `json:"milestones,omitempty"`
|
||||||
|
Node []string `json:"node,omitempty"`
|
||||||
|
Openshift []string `json:"openshift,omitempty"`
|
||||||
|
OpenshiftCI []string `json:"openshiftci,omitempty"`
|
||||||
|
Ovsnode []string `json:"ovsnode,omitempty"`
|
||||||
|
PCIDevice []string `json:"pcidevice,omitempty"`
|
||||||
|
PGPU []string `json:"pgpu,omitempty"`
|
||||||
|
Prometheus []string `json:"prometheus,omitempty"`
|
||||||
|
QOS []string `json:"qos,omitempty"`
|
||||||
|
Resmon []string `json:"resmon,omitempty"`
|
||||||
|
RG []string `json:"rg,omitempty"`
|
||||||
|
Sep []string `json:"sep,omitempty"`
|
||||||
|
Stack []string `json:"stack,omitempty"`
|
||||||
|
Tasks []string `json:"tasks,omitempty"`
|
||||||
|
TLock []string `json:"tlock,omitempty"`
|
||||||
|
User []string `json:"user,omitempty"`
|
||||||
|
VGPU []string `json:"vgpu,omitempty"`
|
||||||
|
VINS []string `json:"vins,omitempty"`
|
||||||
|
VNFDev []string `json:"vnfdev,omitempty"`
|
||||||
|
ZeroAccess []string `json:"zeroaccess,omitempty"`
|
||||||
|
All bool `json:"ALL,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type LibCloudEndpoints struct {
|
||||||
|
Libvirt []string `json:"libvirt,omitempty"`
|
||||||
|
All bool `json:"ALL,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SystemEndpoints struct {
|
||||||
|
AgentController []string `json:"agentcontroller,omitempty"`
|
||||||
|
Alerts []string `json:"alerts,omitempty"`
|
||||||
|
Audits []string `json:"audits,omitempty"`
|
||||||
|
ContentManager []string `json:"contentmanager,omitempty"`
|
||||||
|
DocGenerator []string `json:"docgenerator,omitempty"`
|
||||||
|
EmailSender []string `json:"emailsender,omitempty"`
|
||||||
|
ErrorConditionHandler []string `json:"errorconditionhandler,omitempty"`
|
||||||
|
GridManager []string `json:"gridmanager,omitempty"`
|
||||||
|
Health []string `json:"health,omitempty"`
|
||||||
|
Info []string `json:"info,omitempty"`
|
||||||
|
InfoMGR []string `json:"infomgr,omitempty"`
|
||||||
|
Job []string `json:"job,omitempty"`
|
||||||
|
Log []string `json:"log,omitempty"`
|
||||||
|
Logo []string `json:"logo,omitempty"`
|
||||||
|
Oauth []string `json:"oauth,omitempty"`
|
||||||
|
Task []string `json:"task,omitempty"`
|
||||||
|
UserManager []string `json:"usermanager,omitempty"`
|
||||||
|
All bool `json:"ALL,omitempty"`
|
||||||
|
}
|
||||||
15
pkg/cloudbroker/user/user.go
Normal file
15
pkg/cloudbroker/user/user.go
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||||
|
|
||||||
|
// Structure for creating request to User
|
||||||
|
type User struct {
|
||||||
|
client interfaces.Caller
|
||||||
|
}
|
||||||
|
|
||||||
|
// Builder for User endpoints
|
||||||
|
func New(client interfaces.Caller) *User {
|
||||||
|
return &User{
|
||||||
|
client: client,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"appId": "<APP_ID>",
|
"appId": "<APP_ID>",
|
||||||
"appSecret": "<APP_SECRET>",
|
"appSecret": "<APP_SECRET>",
|
||||||
"ssoUrl": "https://sso.digitalenergy.online",
|
"ssoUrl": "https://sso.digitalenergy.online",
|
||||||
"decortUrl": "https://mr4.digitalenergy.online",
|
"decortUrl": "https://mr4.digitalenergy.online",
|
||||||
"retries": 5,
|
"retries": 5,
|
||||||
"sslSkipVerify": false
|
"timeout": "5m",
|
||||||
|
"sslSkipVerify": false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,4 +3,5 @@ appSecret: <APP_SECRET>
|
|||||||
ssoUrl: https://sso.digitalenergy.online
|
ssoUrl: https://sso.digitalenergy.online
|
||||||
decortUrl: https://mr4.digitalenergy.online
|
decortUrl: https://mr4.digitalenergy.online
|
||||||
retries: 5
|
retries: 5
|
||||||
|
timeout: 5m
|
||||||
sslSkipVerify: false
|
sslSkipVerify: false
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"username": "<USERNAME>",
|
"username": "<USERNAME>",
|
||||||
"password": "<PASSWORD>",
|
"password": "<PASSWORD>",
|
||||||
"decortUrl": "https://mr4.digitalenergy.online",
|
"decortUrl": "https://mr4.digitalenergy.online",
|
||||||
"retries": 5,
|
"retries": 5,
|
||||||
"sslSkipVerify": true
|
"timeout": "5m",
|
||||||
|
"sslSkipVerify": true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,4 +2,5 @@ username: <USERNAME>
|
|||||||
password: <PASSWORD>
|
password: <PASSWORD>
|
||||||
decortUrl: https://mr4.digitalenergy.online
|
decortUrl: https://mr4.digitalenergy.online
|
||||||
retries: 5
|
retries: 5
|
||||||
|
timeout: 5m
|
||||||
sslSkipVerify: true
|
sslSkipVerify: true
|
||||||
|
|||||||
Reference in New Issue
Block a user