Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a85ad3acd5 | |||
| 823dfb49bc | |||
| e6440bc4a3 | |||
| 84c0248019 | |||
| 4120cd2b1a | |||
| b666789c7d | |||
| b069c31745 | |||
| 2953ef0a85 | |||
| 50a4d5ade2 | |||
| 1575b75fa6 | |||
| 35fa4af0d6 | |||
| d3e6309ef8 | |||
| 78a4152471 | |||
| 3e55195831 | |||
| 9f5e76aee4 | |||
| df8b045e77 | |||
| 4d9b8fc9d8 | |||
| e8270453cc | |||
| 7de095302b | |||
| a3711057ba | |||
| 1c59ca338a | |||
| f1529c9aac | |||
| 040235f92f |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
cmd/
|
||||
.idea/
|
||||
.vscode/
|
||||
.vscode/
|
||||
.fleet/
|
||||
.DS_Store
|
||||
|
||||
164
CHANGELOG.md
164
CHANGELOG.md
@@ -1,162 +1,4 @@
|
||||
## Version 1.5.0
|
||||
## Version 1.7.1
|
||||
|
||||
### Feature
|
||||
|
||||
- Updated lists responses models in:
|
||||
- - cloudapi/account/list
|
||||
- - cloudbroker/account/list
|
||||
- - cloudapi/bservice/list
|
||||
- - cloudapi/compute/list
|
||||
- - cloudbroker/compute/list
|
||||
- - cloudapi/computeci/list
|
||||
- - cloudapi/disks/list
|
||||
- - cloudbroker/disks/list
|
||||
- - cloudapi/extnet/list
|
||||
- - cloudbroker/extnet/list
|
||||
- - cloudapi/flipgroup/list
|
||||
- - cloudapi/image/list
|
||||
- - cloudbroker/image/list
|
||||
- - cloudapi/k8ci/list
|
||||
- - cloudbroker/k8ci/list
|
||||
- - cloudapi/k8s/list
|
||||
- - cloudapi/k8s/listDeleted
|
||||
- - cloudbroker/k8s/list
|
||||
- - cloudbroker/k8s/listDeleted
|
||||
- - cloudapi/tasks/list
|
||||
- - cloudbroker/tasks/list
|
||||
- - cloudapi/rg/list
|
||||
- - cloudbroker/rg/list
|
||||
- - cloudapi/vins/list
|
||||
- - cloudbroker/vins/list
|
||||
- - cloudapi/account/listDeleted
|
||||
- - cloudapi/account/listCompute
|
||||
- - cloudapi/account/listDisks
|
||||
- - cloudapi/account/listFlipGroups
|
||||
- - cloudapi/account/listRG
|
||||
- - cloudapi/account/listVINS
|
||||
- - cloudapi/compute/listDeleted
|
||||
- - cloudapi/disks/listDeleted
|
||||
- - cloudapi/disks/listTypes
|
||||
- - cloudapi/k8ci/listDeleted
|
||||
- - cloudapi/lb/list
|
||||
- - cloudapi/lb/listDeleted
|
||||
- - cloudbroker/lb/list
|
||||
- - cloudbroker/lb/listDeleted
|
||||
- - cloudapi/rg/listComputes
|
||||
- - cloudapi/rg/listDeleted
|
||||
- - cloudapi/rg/listLb
|
||||
- - cloudapi/rg/listPFW
|
||||
- - cloudapi/rg/listVins
|
||||
- - cloudapi/vins/listDeleted
|
||||
- - cloudbroker/account/listComputes
|
||||
- - cloudbroker/account/listDeleted
|
||||
- - cloudbroker/account/listDisks
|
||||
- - cloudbroker/account/listFlipGroups
|
||||
- - cloudbroker/account/listRG
|
||||
- - cloudbroker/account/listVINS
|
||||
- - cloudbroker/compute/listDeleted
|
||||
- - cloudapi/compute/listPciDevice
|
||||
- - cloudbroker/compute/listPciDevice
|
||||
- - cloudapi/compute/listVGpu
|
||||
- - cloudbroker/compute/listVGpu
|
||||
- - cloudbroker/disks/listTypes
|
||||
- - cloudbroker/grid/list
|
||||
- - cloudbroker/grid/listEmails
|
||||
- - cloudbroker/k8ci/listDeleted
|
||||
- - cloudbroker/pcidevice/list
|
||||
- - cloudbroker/rg/affinityGroupsList
|
||||
- - cloudbroker/rg/listDeleted
|
||||
- - cloudbroker/rg/listComputes
|
||||
- - cloudbroker/rg/listLB
|
||||
- - cloudbroker/rg/listPfw
|
||||
- - cloudbroker/rg/listResourceConsumption
|
||||
- - cloudbroker/rg/listVins
|
||||
- - cloudbroker/sep/list
|
||||
- - cloudbroker/vgpu/list
|
||||
- - cloudbroker/vins/extnetList
|
||||
- - cloudbroker/vins/IpList
|
||||
- - cloudbroker/vins/natRuleList
|
||||
- - cloudapi/account/listTemplates
|
||||
- - cloudapi/compute/pfwList
|
||||
- - cloudapi/compute/sanpshotList
|
||||
- - cloudapi/compute/userList
|
||||
- - cloudapi/vins/extnetList
|
||||
- - cloudapi/vins/ipList
|
||||
- - cloudapi/vins/natRuleList
|
||||
- - cloudapi/sizes/list
|
||||
- - cloudapi/rg/affinityGroupsList
|
||||
- - cloudapi/extnet/listComputes
|
||||
|
||||
- Added new endpoints:
|
||||
- - cloudapi/rg/getResourceConsumption
|
||||
- - cloudapi/rg/listResourceConsumption
|
||||
- - cloudbroker/rg/getResourceConsumption
|
||||
- - cloudbroker/rg/listResourceConsumption
|
||||
- - cloudapi/account/getResourceConsumption
|
||||
- - cloudapi/account/listResourceConsumption
|
||||
- - cloudbroker/account/getResourceConsumption
|
||||
- - cloudbroker/account/listResourceConsumption
|
||||
- - cloudbroker/grid/getResourceConsumption
|
||||
- - cloudbroker/grid/listResourceConsumption
|
||||
- - cloudapi/compute/getCustomFields
|
||||
- - cloudapi/compute/deleteCustomFields
|
||||
- - cloudapi/compute/setCustomFields
|
||||
|
||||
- Added field CU_DM to ResourceLimits model (account, rg)
|
||||
|
||||
- Added field ReferenceID to SnapshotExtended model in cloudapi/compute/get
|
||||
|
||||
- Added field Interfaces in requests:
|
||||
- - cloudapi/kvmppc/create
|
||||
- - cloudapi/kvmppc/createBlank
|
||||
- - cloudapi/kvmx86/create
|
||||
- - cloudapi/kvmx86/createBlank
|
||||
- - cloudbroker/kvmppc/create
|
||||
- - cloudbroker/kvmppc/createBlank
|
||||
- - cloudbroker/kvmx86/create
|
||||
- - cloudbroker/kvmx86/createBlank
|
||||
|
||||
- Added UpdatedBy field to task model in cloudbroker/task/get
|
||||
|
||||
- Made optional fields in requests:
|
||||
- - Reason (cloudbroker/account/delete)
|
||||
- - Reason (cloudbroker/account/restore)
|
||||
- - Gateway (cloudbroker/extnet/create)
|
||||
- - Reason (cloudbroker/image/delete)
|
||||
- - Num (cloudapi/k8s/workerAdd)
|
||||
- - NetID (cloudbroker/vins/extnetConnect)
|
||||
|
||||
- Updated cloudapi/rg/get model
|
||||
|
||||
- Deleted field Username from cloudbroker/account/update request
|
||||
|
||||
- Deleted field EmailAddress from cloudbroker/account/update request
|
||||
|
||||
- Added field DiskType to cloudbroker/compute/diskAttach request
|
||||
|
||||
- Added field Reason to cloudbroker/compute/diskQos request
|
||||
|
||||
- Added field Enabled to cloudbroker/compute/netAttach response model
|
||||
|
||||
- Added field CPUAllocationRatio to cloudbroker/image/listStacks response model
|
||||
|
||||
- Added field Descr to cloudbroker/image/listStacks response model
|
||||
|
||||
- Added field MemAllocationRatio to cloudbroker/image/listStacks response model
|
||||
|
||||
- Updated cloudapi/k8s/workersGroupByName response model
|
||||
|
||||
- Deleted field LBImageID from cloudbroker/k8ci/create request
|
||||
|
||||
- Deleted field ImageID from cloudbroker/lb/create request
|
||||
|
||||
- Deleted field Reason from cloudbroker/vins/extnetList request
|
||||
|
||||
- Added field CustomFields to cloudapi/kvmx86/create request
|
||||
|
||||
- Added field Driver to cloudapi/kvmx86/create request
|
||||
|
||||
- Added field Driver to cloudapi/kvmx86/createBlank request
|
||||
|
||||
### Bugfix
|
||||
- Changed the Excluded field type in cloudbroker/extnet/get response model
|
||||
## Bugfix
|
||||
- Fix panic in clients
|
||||
|
||||
327
README.md
327
README.md
@@ -10,6 +10,8 @@ Decort SDK - это библиотека, написанная на языке G
|
||||
- Версия 1.3.x Decort-SDK соответствует 3.8.5 версии платформы
|
||||
- Версия 1.4.x Decort-SDK соответствует 3.8.6 версии платформы
|
||||
- Версия 1.5.x Decort-SDK соответствует 3.8.7 версии платформы
|
||||
- Версия 1.6.x Decort-SDK соответствует 3.8.8 версии платформы
|
||||
- Версия 1.7.х Decort-SDK соответствует 3.8.9 версии платформы
|
||||
|
||||
## Оглавление
|
||||
|
||||
@@ -62,12 +64,11 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
||||
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
|
||||
- `BService` - управление группами виртуальных машин (computes);
|
||||
- `Compute` - управление виртуальными машинами (индивидуально);
|
||||
- `ComputeCI` - управление конвейром для создания виртуальных машин;
|
||||
- `Disks` - управление виртуальными дисками;
|
||||
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
|
||||
- `FLIPgroup` - управление группами "плавающими" ip - адресами;
|
||||
- `Image` - управление образами операционных систем;
|
||||
- `K8CI` - управление конвейром для создания кластера;
|
||||
- `K8CI` - получение информации о конвейере для создания кластера;
|
||||
- `K8S` - управление кластерами kubernetes;
|
||||
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
|
||||
- `KVMx86` - создание виртуальной машины x86;
|
||||
@@ -75,6 +76,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
||||
- `Locations` - получение информации о grid площадки;
|
||||
- `RG` - управление ресурсными группами аккаунта;
|
||||
- `Sizes` - получение информации о потребляемых ресурсах виртуальными машинами и дисками;
|
||||
- `Stack` - получение информации о вычислительных узлах;
|
||||
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
|
||||
- `VINS` - управление виртуальными изолированными сетями.
|
||||
|
||||
@@ -84,30 +86,39 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
||||
Данная группа ручек позволяет выполнять следующие операции в платформе:
|
||||
|
||||
- `Account` - управление аккаунтами - внутренними учетными записями платформы, которые являются владельцами вычислительных ресурсов;
|
||||
- `APIAccess` - управление доступом к API и его объектам;
|
||||
- `Backup` - управление резервным копированием;
|
||||
- `Compute` - управление виртуальными машинами (индивидуально);
|
||||
- `Disks` - управление виртуальными дисками;
|
||||
- `ExtNet` - управление виртуальными сетями, отвечающими за внешний доступ;
|
||||
- `FLIPGroup` - управление группами с «плавающими» ip адресами;
|
||||
- `Grid` - управление площадками;
|
||||
- `Group` - управление группами пользователей;
|
||||
- `Image` - управление образами операционных систем;
|
||||
- `K8CI` - управление конвейром для создания кластера;
|
||||
- `K8S` - управление кластерами kubernetes;
|
||||
- `KVMPPC` - создание виртуальной машины Power PC (IBM);
|
||||
- `KVMx86` - создание виртуальной машины x86;
|
||||
- `LB` - управление балансировщиками нагрузки;
|
||||
- `PCIDevice` - управление устройствами;
|
||||
- `RG` - управление ресурсными группами аккаунта;
|
||||
- `SEP` - управление storage endpoint (sep);
|
||||
- `Stack` - получение информации о вычислительных узлах;
|
||||
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
|
||||
- `User` - управление пользователями (индивидуально);
|
||||
- `VGPU` - управление виртуальными графическими процессорами;
|
||||
- `VINS` - управление виртуальными изолированными сетями.
|
||||
|
||||
## Работа с библиотекой
|
||||
|
||||
Алгоритм работы с библиотекой выглядит следующим образом:
|
||||
|
||||
1. Настройка конфигурации клиента.
|
||||
2. Парсинг конфигурации из файла.
|
||||
3. Создание клиента.
|
||||
4. Создание структуры запроса.
|
||||
5. Выполнение запроса.
|
||||
1. Выполнение одного из действий:
|
||||
- настройка конфигурации клиента;
|
||||
- парсинг конфигурации из файла.
|
||||
2. Создание клиента.
|
||||
3. Создание структуры запроса.
|
||||
4. Выполнение запроса.
|
||||
|
||||
### Настройка конфигурации клиента
|
||||
|
||||
@@ -120,7 +131,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата |
|
||||
| Token | string | Нет | JWT токен |
|
||||
|
||||
#### Пример конфигурации клиента
|
||||
@@ -231,7 +242,6 @@ func main() {
|
||||
- `pkg/cloudapi/account` - для `Account`
|
||||
- `pkg/cloudapi/bservice` - для `Basic Service`
|
||||
- `pkg/cloudapi/compute` - для `Compute`
|
||||
- `pkg/cloudapi/computeci` - для `ComputeCI`
|
||||
- `pkg/cloudapi/disks` - для `Disks`
|
||||
- `pkg/cloudapi/extnet` - для `ExtNet`
|
||||
- `pkg/cloudapi/flipgroup` - для `FLIPGroup`
|
||||
@@ -243,24 +253,33 @@ func main() {
|
||||
- `pkg/cloudapi/lb` - для `LB`
|
||||
- `pkg/cloudapi/locations` - для `Locations`
|
||||
- `pkg/cloudapi/rg` - для `RG`
|
||||
- `pkg/cloudapi/sizes` - для `RG`
|
||||
- `pkg/cloudapi/sizes` - для `Sizes`
|
||||
- `pkg/cloudapi/stack` - для `Stack`
|
||||
- `pkg/cloudapi/tasks` - для `Tasks`
|
||||
- `pkg/cloudapi/vins` - для `VINS`
|
||||
- **cloudbroker**:
|
||||
- `pkg/cloudbroker/account` - для `Account`
|
||||
- `pkg/cloudbroker/apiaccess` - для `APIAccess`
|
||||
- `pkg/cloudbroker/backup` - для `Backup`
|
||||
- `pkg/cloudbroker/compute` - для `Compute`
|
||||
- `pkg/cloudbroker/disks` - для `Disks`
|
||||
- `pkg/cloudbroker/extnet` - для `ExtNet`
|
||||
- `pkg/cloudbroker/flipgroup` - для `FLIPGroup`
|
||||
- `pkg/cloudbroker/grid` - для `Grid`
|
||||
- `pkg/cloudbroker/group` - для `Group`
|
||||
- `pkg/cloudbroker/image` - для `Image`
|
||||
- `pkg/cloudbroker/k8ci` - для `K8CI`
|
||||
- `pkg/cloudbroker/k8s` - для `K8S`
|
||||
- `pkg/cloudbroker/kvmppc` - для `KVMPPC`
|
||||
- `pkg/cloudbroker/kvmx86` - для `KVMX86`
|
||||
- `pkg/cloudbroker/lb` - для `LB`
|
||||
- `pkg/cloudbroker/pcidevice` - для `PCIDevice`
|
||||
- `pkg/cloudbroker/rg` - для `RG`
|
||||
- `pkg/cloudbroker/sep` - для `SEP`
|
||||
- `pkg/cloudbroker/stack` - для `Stack`
|
||||
- `pkg/cloudbroker/tasks` - для `Tasks`
|
||||
- `pkg/cloudbroker/user` - для `User`
|
||||
- `pkg/cloudbroker/vgpu` - для `VGPU`
|
||||
- `pkg/cloudbroker/vins` - для `VINS`
|
||||
|
||||
Все поля структуры имеют описание, в которых содержится:
|
||||
@@ -397,7 +416,7 @@ func main() {
|
||||
|
||||
Чтобы выполнить запрос, необходимо:
|
||||
|
||||
1. Вызвать у клиента метод, отвечаеющий за определение группы API для взаимодействия, это может быть `.CloudAPI()`, либо `.CloudBroker()`. Данные методы возвращаеют соответствующие структуры, с помощью которых можно соверать запросы.
|
||||
1. Вызвать у клиента метод, отвечаеющий за определение группы API для взаимодействия, это может быть `.CloudAPI()`, либо `.CloudBroker()`. Данные методы возвращаеют соответствующие структуры, с помощью которых можно совершать запросы.
|
||||
2. Вызвать у возвращенной структуры метод, определяющий группу ручек для взаимодействия.
|
||||
|
||||
Доступные методы для `.CloudAPI()`:
|
||||
@@ -405,7 +424,6 @@ func main() {
|
||||
- `.Account()` - для работы с `Account`
|
||||
- `.BService()` - для работы с `BService`
|
||||
- `.Compute()` - для работы с `Compute`
|
||||
- `.ComputeCI()` - для работы с `ComputeCI`
|
||||
- `.Disks()` - для работы с `Disks`
|
||||
- `.ExtNet()` - для работы с `ExtNet`
|
||||
- `.FLIPgroup()` - для работы с `FLIPGroup`
|
||||
@@ -418,37 +436,46 @@ func main() {
|
||||
- `.Locations()` - для работы с `Locations`
|
||||
- `.RG()` - для работы с `RG`
|
||||
- `.Sizes()` - для работы с `Sizes`
|
||||
- `.Stack()` - для работы с `Stack`
|
||||
- `.Tasks()` - для работы с `Tasks`
|
||||
- `.VINS()` - для работы с `VINS`
|
||||
|
||||
Доступные методы для `.CloudBroker()`:
|
||||
|
||||
- `.Account()` - для работы с `Account`
|
||||
- `.APIAccess()` - для работы с `APIAccess`
|
||||
- `.Backup()` - для работы с `Backup`
|
||||
- `.Compute()` - для работы с `Compute`
|
||||
- `.Disks()` - для работы с `Disks`
|
||||
- `.ExtNet()` - для работы с `ExtNet`
|
||||
- `.FLIPGroup()` - для работы с `FLIPGroup`
|
||||
- `.Grid()` - для работы с `Grid`
|
||||
- `.Group()` - для работы с `Group`
|
||||
- `.Image()` - для работы с `Image`
|
||||
- `.K8CI()` - для работы с `K8CI`
|
||||
- `.K8S()` - для работы с `K8S`
|
||||
- `.KVMPPC()` - для работы с `KVMPPC`
|
||||
- `.KVMx86()` - для работы с `KVMX86`
|
||||
- `.LB()` - для работы с `LB`
|
||||
- `.PCIDevice()` - для работы с `PCIDevice`
|
||||
- `.RG()` - для работы с `RG`
|
||||
- `.SEP()` - для работы с `SEP`
|
||||
- `.Stack()` - для работы с `Stack`
|
||||
- `.Tasks()` - для работы с `Tasks`
|
||||
- `.User()` - для работы с `User`
|
||||
- `.VGPU()` - для работы с `VGPU`
|
||||
- `.VINS()` - для работы с `VINS`
|
||||
|
||||
3. Вызвать метод, отвечающий за выполнение запроса и передать в него:
|
||||
|
||||
- контекст;
|
||||
- структуру запроса.
|
||||
У кождой группы ручек API имеются свои доступные методы, которые определяются платформой.
|
||||
У каждой группы ручек API имеются свои доступные методы, которые определяются платформой.
|
||||
|
||||
4. Обработать результат и ошибки.
|
||||
|
||||
Т.к. все вызовы методов идут последовательно, можно их объеденить в конвейер:
|
||||
Общий вид вонвейра будет выглядеть так:
|
||||
Общий вид конвейера будет выглядеть так:
|
||||
|
||||
```go
|
||||
client.<API>.<группа>.<метод>
|
||||
@@ -501,6 +528,56 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
Для запросов Get и List реализованы запросы GetRaw и ListRaw, которые возвращают ответ не в виде соответствующей структуры, а в виде массива байт (JSON).
|
||||
Выполнение таких запросов происходит аналогично.
|
||||
|
||||
#### Пример выполнения GetRaw и ListRaw запросов
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"fmt"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Настройка конфигурации
|
||||
cfg := config.Config{
|
||||
AppID: "<APPID>",
|
||||
AppSecret: "<APPSECRET>",
|
||||
SSOURL: "https://sso.digitalenergy.online",
|
||||
DecortURL: "https://mr4.digitalenergy.online",
|
||||
Retries: 5,
|
||||
}
|
||||
|
||||
// Создание клиента
|
||||
client := decort.New(cfg)
|
||||
|
||||
// 1. Создание структуры запроса GetRequest на получение информации об аккаунте и выполнение GetRaw запроса с помощью конвейера
|
||||
req1 := account.GetRequest{
|
||||
AccountID: 123,
|
||||
}
|
||||
res1, err := client.CloudAPI().Account().GetRaw(context.Background(), req1)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(string(res1))
|
||||
|
||||
// 2. Создание структуры запроса ListRequest на получение информации об аккаунтах и выполнение ListRaw запроса с помощью конвейера
|
||||
req2 := account.ListRequest{}
|
||||
res2, err := client.CloudAPI().Account().ListRaw(context.Background(), req2)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(string(res2))
|
||||
}
|
||||
```
|
||||
|
||||
### Фильтрация
|
||||
|
||||
Для каждого `ListRequest` в SDK есть группа функций для фильтрации ответа платформы. Для того чтобы произвести фильтрацию по заданным полям, достаточно описать анонимную функцию (предикат) в `.FilterFunc()`, например:
|
||||
@@ -690,6 +767,52 @@ func main() {
|
||||
|
||||
```
|
||||
|
||||
### Получение списка уникальных идентификаторов (ID) объекта
|
||||
|
||||
Для всех структур, имеющих поля со списками объектов с уникальными числовыми идентификаторами (ID), добавлены методы IDs(), возвращающие массивы уникальных идентификаторов объектов в этих списках.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"fmt"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Настройка конфигурации
|
||||
cfg := config.Config{
|
||||
AppID: "<APPID>",
|
||||
AppSecret: "<APPSECRET>",
|
||||
SSOURL: "https://sso.digitalenergy.online",
|
||||
DecortURL: "https://mr4.digitalenergy.online",
|
||||
Retries: 5,
|
||||
}
|
||||
|
||||
// Создание клиента
|
||||
client := decort.New(cfg)
|
||||
|
||||
// Создание структуры запроса GetRequest на получение информации о сервисе и выполнение запроса с помощью конвейера
|
||||
req := bservice.GetRequest{
|
||||
ServiceID: 123,
|
||||
}
|
||||
res, err := client.CloudAPI().BService().Get(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Получение списков ID ComputeIDs и GroupIDs экземпляра res типа RecordBasicService по полям Computes и Groups, соответственно
|
||||
computeIDs := res.Computes.IDs()
|
||||
groupIDs := res.Groups.IDs()
|
||||
fmt.Println(computeIDs)
|
||||
fmt.Println(groupIDs)
|
||||
}
|
||||
```
|
||||
|
||||
## Работа с legacy клиентом
|
||||
|
||||
Работа с legacy клиентом применяется для пользователей, которые не используют для авторизации decs3o.
|
||||
@@ -705,7 +828,7 @@ func main() {
|
||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата |
|
||||
| Token | string | Нет | JWT токен |
|
||||
|
||||
#### Пример конфигурации legacy клиента
|
||||
@@ -814,6 +937,7 @@ func main() {
|
||||
legacyCfg := config.LegacyConfig{
|
||||
Username: "<USERNAME>",
|
||||
Password: "<PASSWORD>",
|
||||
Domain: "dynamix",
|
||||
DecortURL: "https://mr4.digitalenergy.online",
|
||||
Retries: 5,
|
||||
}
|
||||
@@ -839,3 +963,176 @@ func main() {
|
||||
|
||||
fmt.Println(res)
|
||||
}
|
||||
```
|
||||
|
||||
## Работа с BVS клиентом
|
||||
|
||||
Работа с BVS клиентом применяется для пользователей, которые используют для авторизации BVS.
|
||||
|
||||
### Настройка конфигурации BVS клиента
|
||||
|
||||
Сначала, необходимо создать переменную конфигурации клиента. Конфигурация состоит как из обязательных, так и необязательных полей.
|
||||
|
||||
| Поле | Тип | Обязательный | Описание |
|
||||
| ------------- | ------ | ------------ | ------------------------------------------------------------------ |
|
||||
| Username | string | Да | username legacy пользователя |
|
||||
| Password | string | Да | пароль legacy пользователя |
|
||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||
| SSOURL | string | Да | URL адрес сервиса аутентификации и авторизации |
|
||||
| Domain | string | Да | Имя домена |
|
||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата |
|
||||
|
||||
|
||||
#### Пример конфигурации BVS клиента
|
||||
|
||||
```go
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||
)
|
||||
|
||||
func main(){
|
||||
// Настройка конфигурации
|
||||
BvsCfg := config.BVSConfig{
|
||||
AppID: "<APP_ID>",
|
||||
AppSecret: "<APP_SECRET>",
|
||||
Username: "<USERNAME>",
|
||||
Password: "<PASSWORD>",
|
||||
SSOURL: "https://bvs-delta.qa.loc:8443"
|
||||
DecortURL: "https://delta.qa.loc",
|
||||
Domain: "dynamix"
|
||||
Retries: 5,
|
||||
}
|
||||
|
||||
BvsCfg.SetTimeout(5 * time.Minute)
|
||||
}
|
||||
```
|
||||
|
||||
#### Парсинг BVS конфигурации из файла
|
||||
|
||||
Также возможно создать переменную конфигурации из JSON или YAML файла, используя функцию `ParseConfigBVSJSON` (или `ParseConfigBVSYAML`) из пакета config.
|
||||
<br>
|
||||
*См. пример файлов конфигурации ниже и в директории `samples/`.*
|
||||
|
||||
```go
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Парсинг конфигурации из YAML-файла
|
||||
BVSCfg := config.ParseConfigBVSYAML("<PATH>")
|
||||
}
|
||||
```
|
||||
|
||||
#### Пример BVS JSON конфигурации
|
||||
|
||||
```json
|
||||
{
|
||||
"username": "<USERNAME>",
|
||||
"password": "<PASSWORD>",
|
||||
"appId": "<APP_ID>",
|
||||
"appSecret": "<APP_SECRET>",
|
||||
"ssoUrl": "https://bvs-delta.qa.loc:8443",
|
||||
"decortUrl": "https://delta.qa.loc",
|
||||
"domain": "dynamix",
|
||||
"retries": 5,
|
||||
"timeout": "5m",
|
||||
"sslSkipVerify": false
|
||||
}
|
||||
```
|
||||
|
||||
#### Пример BVS YAML конфигурации
|
||||
```yaml
|
||||
username: <USERNAME>
|
||||
password: <PASSWORD>
|
||||
appId: <APP_ID>
|
||||
appSecret: <APP_SECRET>
|
||||
ssoUrl: https://bvs-delta.qa.loc:8443
|
||||
decortUrl: https://delta.qa.loc
|
||||
domain: dynamix,
|
||||
retries: 5
|
||||
timeout: 5m
|
||||
sslSkipVerify: false
|
||||
```
|
||||
### Создание BVS клиента
|
||||
|
||||
Создание клиента происходит с помощью функции-строителя `NewBVS` из основного пакета `decort-sdk`, для избежания проблем с именами, пакету можно присвоить алиас `decort`. Функция принимает конфигурацию, возвращает структуру `DecortClient`, с помощью которой можно взаимодействовать с платформой.
|
||||
|
||||
#### Пример создания BVS клиента
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Настройка конфигурации
|
||||
BVSCfg := config.BVSConfig{
|
||||
Username: "<USERNAME>",
|
||||
Password: "<PASSWORD>",
|
||||
AppID: "<APPID>",
|
||||
AppSecret: "<APPSECRET>",
|
||||
SSOURL: "https://bvs-delta.qa.loc:8443"
|
||||
DecortURL: "https://mr4.digitalenergy.online",
|
||||
Domain: "dynamix",
|
||||
Retries: 5,
|
||||
}
|
||||
|
||||
BVSCfg.SetTimeout(5 * time.Minute)
|
||||
|
||||
// Создание клиента
|
||||
BVSClient := decort.NewBVS(cfg)
|
||||
}
|
||||
```
|
||||
|
||||
#### Пример выполнения запроса
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||
decort "repository.basistech.ru/BASIS/decort-golang-sdk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Настройка конфигурации
|
||||
BVSCfg := config.config.BVSConfig{
|
||||
Username: "<USERNAME>",
|
||||
Password: "<PASSWORD>",
|
||||
AppID: "<APPID>",
|
||||
AppSecret: "<APPSECRET>",
|
||||
SSOURL: "https://bvs-delta.qa.loc:8443"
|
||||
DecortURL: "https://mr4.digitalenergy.online",
|
||||
Domain: "dynamix",
|
||||
Retries: 5,
|
||||
}
|
||||
|
||||
// Создание клиента
|
||||
BVSClient := decort.NewBVS(cfg)
|
||||
|
||||
// Создание структуры запроса
|
||||
// CreateRequest - реквест на создание виртуальной машины
|
||||
req := kvmx86.CreateRequest{
|
||||
RGID: 123,
|
||||
Name: "compute",
|
||||
CPU: 4,
|
||||
RAM: 4096,
|
||||
ImageID: 321,
|
||||
}
|
||||
|
||||
// Выполнение запроса
|
||||
res, err := client.CloudAPI().KVMX86().Create(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(res)
|
||||
}
|
||||
360
client.go
360
client.go
@@ -1,24 +1,36 @@
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/client"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
||||
k8s_ca "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
||||
k8s_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
|
||||
)
|
||||
|
||||
const restmachine = "/restmachine"
|
||||
|
||||
// HTTP-client for platform
|
||||
type DecortClient struct {
|
||||
decortURL string
|
||||
client *http.Client
|
||||
decortURL string
|
||||
client *http.Client
|
||||
cfg config.Config
|
||||
expiryTime time.Time
|
||||
mutex *sync.Mutex
|
||||
}
|
||||
|
||||
// Сlient builder
|
||||
@@ -27,9 +39,25 @@ func New(cfg config.Config) *DecortClient {
|
||||
cfg.Retries = 5
|
||||
}
|
||||
|
||||
var expiryTime time.Time
|
||||
|
||||
if cfg.Token != "" {
|
||||
expiryTime = time.Now().AddDate(0, 0, 1)
|
||||
}
|
||||
|
||||
return &DecortClient{
|
||||
decortURL: cfg.DecortURL,
|
||||
client: client.NewHttpClient(cfg),
|
||||
client: &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
//nolint:gosec
|
||||
InsecureSkipVerify: cfg.SSLSkipVerify,
|
||||
},
|
||||
},
|
||||
},
|
||||
cfg: cfg,
|
||||
expiryTime: expiryTime,
|
||||
mutex: &sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,18 +73,33 @@ func (dc *DecortClient) CloudBroker() *cloudbroker.CloudBroker {
|
||||
|
||||
// DecortApiCall method for sending requests to the platform
|
||||
func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
||||
values, err := query.Values(params)
|
||||
k8sCaCreateReq, okCa := params.(k8s_ca.CreateRequest)
|
||||
k8sCbCreateReq, okCb := params.(k8s_cb.CreateRequest)
|
||||
var body *bytes.Buffer
|
||||
var ctype string
|
||||
|
||||
if okCa {
|
||||
body, ctype = createK8sCloudApi(k8sCaCreateReq)
|
||||
} else if okCb {
|
||||
body, ctype = createK8sCloudBroker(k8sCbCreateReq)
|
||||
} else {
|
||||
values, err := query.Values(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
body = bytes.NewBufferString(values.Encode())
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+restmachine+url, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
body := strings.NewReader(values.Encode())
|
||||
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+"/restmachine"+url, body)
|
||||
if err != nil {
|
||||
if err = dc.getToken(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := dc.client.Do(req)
|
||||
resp, err := dc.do(req, ctype)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -73,3 +116,296 @@ func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, p
|
||||
|
||||
return respBytes, nil
|
||||
}
|
||||
|
||||
func (dc *DecortClient) getToken(ctx context.Context) error {
|
||||
dc.mutex.Lock()
|
||||
defer dc.mutex.Unlock()
|
||||
|
||||
if dc.cfg.Token == "" || time.Now().After(dc.expiryTime) {
|
||||
body := fmt.Sprintf("grant_type=client_credentials&client_id=%s&client_secret=%s&response_type=id_token", dc.cfg.AppID, dc.cfg.AppSecret)
|
||||
bodyReader := strings.NewReader(body)
|
||||
|
||||
dc.cfg.SSOURL = strings.TrimSuffix(dc.cfg.SSOURL, "/")
|
||||
|
||||
req, _ := http.NewRequestWithContext(ctx, "POST", dc.cfg.SSOURL+"/v1/oauth/access_token", bodyReader)
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
resp, err := dc.client.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot get token: %w", err)
|
||||
}
|
||||
|
||||
tokenBytes, _ := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return fmt.Errorf("cannot get token: %s", tokenBytes)
|
||||
}
|
||||
|
||||
token := string(tokenBytes)
|
||||
|
||||
dc.cfg.Token = token
|
||||
dc.expiryTime = time.Now().AddDate(0, 0, 1)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dc *DecortClient) do(req *http.Request, ctype string) (*http.Response, error) {
|
||||
if ctype != "" {
|
||||
req.Header.Add("Content-Type", ctype)
|
||||
} else {
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
}
|
||||
|
||||
req.Header.Add("Authorization", "bearer "+dc.cfg.Token)
|
||||
req.Header.Set("Accept", "application/json")
|
||||
|
||||
// var resp *http.Response
|
||||
// var err error
|
||||
buf, _ := io.ReadAll(req.Body)
|
||||
|
||||
// for i := uint64(0); i < dc.cfg.Retries; i++ {
|
||||
// req = req.Clone(req.Context())
|
||||
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||
resp, err := dc.client.Do(req)
|
||||
if err == nil {
|
||||
if resp.StatusCode == 200 {
|
||||
return resp, err
|
||||
}
|
||||
}
|
||||
// }
|
||||
respBytes, _ := io.ReadAll(resp.Body)
|
||||
err = fmt.Errorf("%s", respBytes)
|
||||
resp.Body.Close()
|
||||
|
||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||
}
|
||||
|
||||
func createK8sCloudApi(req k8s_ca.CreateRequest) (*bytes.Buffer, string) {
|
||||
reqBody := &bytes.Buffer{}
|
||||
writer := multipart.NewWriter(reqBody)
|
||||
if req.OidcCertificate != "" {
|
||||
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
|
||||
_, _ = io.Copy(part, strings.NewReader(req.OidcCertificate))
|
||||
}
|
||||
|
||||
_ = writer.WriteField("name", req.Name)
|
||||
_ = writer.WriteField("rgId", strconv.FormatUint(req.RGID, 10))
|
||||
_ = writer.WriteField("k8ciId", strconv.FormatUint(req.K8SCIID, 10))
|
||||
_ = writer.WriteField("workerGroupName", req.WorkerGroupName)
|
||||
_ = writer.WriteField("networkPlugin", req.NetworkPlugin)
|
||||
|
||||
if req.MasterSEPID != 0 {
|
||||
_ = writer.WriteField("masterSepId", strconv.FormatUint(req.MasterSEPID, 10))
|
||||
}
|
||||
if req.MasterSEPPool != "" {
|
||||
_ = writer.WriteField("masterSepPool", req.MasterSEPPool)
|
||||
}
|
||||
if req.WorkerSEPID != 0 {
|
||||
_ = writer.WriteField("workerSepId", strconv.FormatUint(req.WorkerSEPID, 10))
|
||||
}
|
||||
if req.WorkerSEPPool != "" {
|
||||
_ = writer.WriteField("workerSepPool", req.WorkerSEPPool)
|
||||
}
|
||||
|
||||
if req.Labels != nil {
|
||||
for _, v := range req.Labels {
|
||||
_ = writer.WriteField("labels", v)
|
||||
}
|
||||
}
|
||||
if req.Taints != nil {
|
||||
for _, v := range req.Taints {
|
||||
_ = writer.WriteField("taints", v)
|
||||
}
|
||||
}
|
||||
if req.Annotations != nil {
|
||||
for _, v := range req.Annotations {
|
||||
_ = writer.WriteField("annotations", v)
|
||||
}
|
||||
}
|
||||
|
||||
if req.MasterCPU != 0 {
|
||||
_ = writer.WriteField("masterCpu", strconv.FormatUint(uint64(req.MasterCPU), 10))
|
||||
}
|
||||
if req.MasterNum != 0 {
|
||||
_ = writer.WriteField("masterNum", strconv.FormatUint(uint64(req.MasterNum), 10))
|
||||
}
|
||||
if req.MasterRAM != 0 {
|
||||
_ = writer.WriteField("masterRam", strconv.FormatUint(uint64(req.MasterRAM), 10))
|
||||
}
|
||||
if req.MasterDisk != 0 {
|
||||
_ = writer.WriteField("masterDisk", strconv.FormatUint(uint64(req.MasterDisk), 10))
|
||||
}
|
||||
if req.WorkerCPU != 0 {
|
||||
_ = writer.WriteField("workerCpu", strconv.FormatUint(uint64(req.WorkerCPU), 10))
|
||||
}
|
||||
if req.WorkerNum != 0 {
|
||||
_ = writer.WriteField("workerNum", strconv.FormatUint(uint64(req.WorkerNum), 10))
|
||||
}
|
||||
if req.WorkerRAM != 0 {
|
||||
_ = writer.WriteField("workerRam", strconv.FormatUint(uint64(req.WorkerRAM), 10))
|
||||
}
|
||||
if req.WorkerDisk != 0 {
|
||||
_ = writer.WriteField("workerDisk", strconv.FormatUint(uint64(req.WorkerDisk), 10))
|
||||
}
|
||||
if req.ExtNetID != 0 {
|
||||
_ = writer.WriteField("extnetId", strconv.FormatUint(req.ExtNetID, 10))
|
||||
}
|
||||
if req.VinsId != 0 {
|
||||
_ = writer.WriteField("vinsId", strconv.FormatUint(req.VinsId, 10))
|
||||
}
|
||||
if !req.WithLB {
|
||||
_ = writer.WriteField("withLB", strconv.FormatBool(req.WithLB))
|
||||
}
|
||||
|
||||
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(req.HighlyAvailable))
|
||||
|
||||
if req.AdditionalSANs != nil {
|
||||
for _, v := range req.AdditionalSANs {
|
||||
_ = writer.WriteField("additionalSANs", v)
|
||||
}
|
||||
}
|
||||
if req.InitConfiguration != "" {
|
||||
_ = writer.WriteField("initConfiguration", req.InitConfiguration)
|
||||
}
|
||||
if req.ClusterConfiguration != "" {
|
||||
_ = writer.WriteField("clusterConfiguration", req.ClusterConfiguration)
|
||||
}
|
||||
if req.KubeletConfiguration != "" {
|
||||
_ = writer.WriteField("kubeletConfiguration", req.KubeletConfiguration)
|
||||
}
|
||||
if req.KubeProxyConfiguration != "" {
|
||||
_ = writer.WriteField("kubeProxyConfiguration", req.KubeProxyConfiguration)
|
||||
}
|
||||
if req.JoinConfiguration != "" {
|
||||
_ = writer.WriteField("joinConfiguration", req.JoinConfiguration)
|
||||
}
|
||||
if req.Description != "" {
|
||||
_ = writer.WriteField("desc", req.Description)
|
||||
}
|
||||
if req.UserData != "" {
|
||||
_ = writer.WriteField("userData", req.UserData)
|
||||
}
|
||||
|
||||
_ = writer.WriteField("extnetOnly", strconv.FormatBool(req.ExtNetOnly))
|
||||
|
||||
ct := writer.FormDataContentType()
|
||||
writer.Close()
|
||||
|
||||
return reqBody, ct
|
||||
}
|
||||
|
||||
func createK8sCloudBroker(req k8s_cb.CreateRequest) (*bytes.Buffer, string) {
|
||||
reqBody := &bytes.Buffer{}
|
||||
writer := multipart.NewWriter(reqBody)
|
||||
if req.OidcCertificate != "" {
|
||||
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
|
||||
_, _ = io.Copy(part, strings.NewReader(req.OidcCertificate))
|
||||
}
|
||||
|
||||
_ = writer.WriteField("name", req.Name)
|
||||
_ = writer.WriteField("rgId", strconv.FormatUint(req.RGID, 10))
|
||||
_ = writer.WriteField("k8ciId", strconv.FormatUint(req.K8CIID, 10))
|
||||
_ = writer.WriteField("workerGroupName", req.WorkerGroupName)
|
||||
_ = writer.WriteField("networkPlugin", req.NetworkPlugin)
|
||||
|
||||
if req.MasterSEPID != 0 {
|
||||
_ = writer.WriteField("masterSepId", strconv.FormatUint(req.MasterSEPID, 10))
|
||||
}
|
||||
if req.MasterSEPPool != "" {
|
||||
_ = writer.WriteField("masterSepPool", req.MasterSEPPool)
|
||||
}
|
||||
if req.WorkerSEPID != 0 {
|
||||
_ = writer.WriteField("workerSepId", strconv.FormatUint(req.WorkerSEPID, 10))
|
||||
}
|
||||
if req.WorkerSEPPool != "" {
|
||||
_ = writer.WriteField("workerSepPool", req.WorkerSEPPool)
|
||||
}
|
||||
|
||||
if req.Labels != nil {
|
||||
for _, v := range req.Labels {
|
||||
_ = writer.WriteField("labels", v)
|
||||
}
|
||||
}
|
||||
if req.Taints != nil {
|
||||
for _, v := range req.Taints {
|
||||
_ = writer.WriteField("taints", v)
|
||||
}
|
||||
}
|
||||
if req.Annotations != nil {
|
||||
for _, v := range req.Annotations {
|
||||
_ = writer.WriteField("annotations", v)
|
||||
}
|
||||
}
|
||||
|
||||
if req.MasterCPU != 0 {
|
||||
_ = writer.WriteField("masterCpu", strconv.FormatUint(req.MasterCPU, 10))
|
||||
}
|
||||
if req.MasterNum != 0 {
|
||||
_ = writer.WriteField("masterNum", strconv.FormatUint(req.MasterNum, 10))
|
||||
}
|
||||
if req.MasterRAM != 0 {
|
||||
_ = writer.WriteField("masterRam", strconv.FormatUint(req.MasterRAM, 10))
|
||||
}
|
||||
if req.MasterDisk != 0 {
|
||||
_ = writer.WriteField("masterDisk", strconv.FormatUint(req.MasterDisk, 10))
|
||||
}
|
||||
if req.WorkerCPU != 0 {
|
||||
_ = writer.WriteField("workerCpu", strconv.FormatUint(req.WorkerCPU, 10))
|
||||
}
|
||||
if req.WorkerNum != 0 {
|
||||
_ = writer.WriteField("workerNum", strconv.FormatUint(req.WorkerNum, 10))
|
||||
}
|
||||
if req.WorkerRAM != 0 {
|
||||
_ = writer.WriteField("workerRam", strconv.FormatUint(req.WorkerRAM, 10))
|
||||
}
|
||||
if req.WorkerDisk != 0 {
|
||||
_ = writer.WriteField("workerDisk", strconv.FormatUint(req.WorkerDisk, 10))
|
||||
}
|
||||
if req.ExtNetID != 0 {
|
||||
_ = writer.WriteField("extnetId", strconv.FormatUint(req.ExtNetID, 10))
|
||||
}
|
||||
if req.VinsId != 0 {
|
||||
_ = writer.WriteField("vinsId", strconv.FormatUint(req.VinsId, 10))
|
||||
}
|
||||
if !req.WithLB {
|
||||
_ = writer.WriteField("withLB", strconv.FormatBool(req.WithLB))
|
||||
}
|
||||
|
||||
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(req.HighlyAvailable))
|
||||
|
||||
if req.AdditionalSANs != nil {
|
||||
for _, v := range req.AdditionalSANs {
|
||||
_ = writer.WriteField("additionalSANs", v)
|
||||
}
|
||||
}
|
||||
if req.InitConfiguration != "" {
|
||||
_ = writer.WriteField("initConfiguration", req.InitConfiguration)
|
||||
}
|
||||
if req.ClusterConfiguration != "" {
|
||||
_ = writer.WriteField("clusterConfiguration", req.ClusterConfiguration)
|
||||
}
|
||||
if req.KubeletConfiguration != "" {
|
||||
_ = writer.WriteField("kubeletConfiguration", req.KubeletConfiguration)
|
||||
}
|
||||
if req.KubeProxyConfiguration != "" {
|
||||
_ = writer.WriteField("kubeProxyConfiguration", req.KubeProxyConfiguration)
|
||||
}
|
||||
if req.JoinConfiguration != "" {
|
||||
_ = writer.WriteField("joinConfiguration", req.JoinConfiguration)
|
||||
}
|
||||
if req.Description != "" {
|
||||
_ = writer.WriteField("desc", req.Description)
|
||||
}
|
||||
if req.UserData != "" {
|
||||
_ = writer.WriteField("userData", req.UserData)
|
||||
}
|
||||
|
||||
_ = writer.WriteField("extnetOnly", strconv.FormatBool(req.ExtNetOnly))
|
||||
|
||||
ct := writer.FormDataContentType()
|
||||
|
||||
writer.Close()
|
||||
return reqBody, ct
|
||||
}
|
||||
|
||||
401
client_bvs.go
Normal file
401
client_bvs.go
Normal file
@@ -0,0 +1,401 @@
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
||||
k8s_ca "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
||||
k8s_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
|
||||
)
|
||||
|
||||
// HTTP-client for platform
|
||||
type BVSDecortClient struct {
|
||||
client *http.Client
|
||||
cfg config.BVSConfig
|
||||
mutex *sync.Mutex
|
||||
decortURL string
|
||||
}
|
||||
|
||||
// Сlient builder
|
||||
func NewBVS(cfg config.BVSConfig) *BVSDecortClient {
|
||||
if cfg.Retries == 0 {
|
||||
cfg.Retries = 5
|
||||
}
|
||||
|
||||
return &BVSDecortClient{
|
||||
decortURL: cfg.DecortURL,
|
||||
client: &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
//nolint:gosec
|
||||
InsecureSkipVerify: cfg.SSLSkipVerify,
|
||||
},
|
||||
},
|
||||
},
|
||||
cfg: cfg,
|
||||
mutex: &sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
// CloudAPI builder
|
||||
func (bdc *BVSDecortClient) CloudAPI() *cloudapi.CloudAPI {
|
||||
return cloudapi.New(bdc)
|
||||
}
|
||||
|
||||
// CloudBroker builder
|
||||
func (bdc *BVSDecortClient) CloudBroker() *cloudbroker.CloudBroker {
|
||||
return cloudbroker.New(bdc)
|
||||
}
|
||||
|
||||
// DecortApiCall method for sending requests to the platform
|
||||
func (bdc *BVSDecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
||||
k8sCaCreateReq, okCa := params.(k8s_ca.CreateRequest)
|
||||
k8sCbCreateReq, okCb := params.(k8s_cb.CreateRequest)
|
||||
var body *bytes.Buffer
|
||||
var ctype string
|
||||
|
||||
if okCa {
|
||||
body, ctype = createK8sCloudApiBVS(k8sCaCreateReq)
|
||||
} else if okCb {
|
||||
body, ctype = createK8sCloudBrokerBVS(k8sCbCreateReq)
|
||||
} else {
|
||||
values, err := query.Values(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
body = bytes.NewBufferString(values.Encode())
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, method, bdc.decortURL+restmachine+url, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = bdc.getToken(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := bdc.do(req, ctype)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
respBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, errors.New(string(respBytes))
|
||||
}
|
||||
|
||||
return respBytes, nil
|
||||
}
|
||||
|
||||
func (bdc *BVSDecortClient) getToken(ctx context.Context) error {
|
||||
bdc.mutex.Lock()
|
||||
defer bdc.mutex.Unlock()
|
||||
|
||||
if !bdc.cfg.Token.Valid() {
|
||||
|
||||
body := fmt.Sprintf("grant_type=password&client_id=%s&client_secret=%s&username=%s&password=%s&response_type=token&scope=openid", bdc.cfg.AppID, bdc.cfg.AppSecret, bdc.cfg.Username, bdc.cfg.Password)
|
||||
bodyReader := strings.NewReader(body)
|
||||
|
||||
bdc.cfg.SSOURL = strings.TrimSuffix(bdc.cfg.SSOURL, "/")
|
||||
|
||||
req, _ := http.NewRequestWithContext(ctx, "POST", bdc.cfg.SSOURL+"/realms/"+bdc.cfg.Domain+"/protocol/openid-connect/token", bodyReader)
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
resp, err := bdc.client.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot get token: %w", err)
|
||||
}
|
||||
|
||||
tokenBytes, _ := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return fmt.Errorf("cannot get token: %s", tokenBytes)
|
||||
}
|
||||
|
||||
err = json.Unmarshal(tokenBytes, &bdc.cfg.Token)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot unmarshal token: %s", tokenBytes)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (bdc *BVSDecortClient) do(req *http.Request, ctype string) (*http.Response, error) {
|
||||
if ctype != "" {
|
||||
req.Header.Add("Content-Type", ctype)
|
||||
} else {
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
}
|
||||
bdc.cfg.Token.SetAuthHeader(req)
|
||||
req.Header.Set("Accept", "application/json")
|
||||
|
||||
// var resp *http.Response
|
||||
// var err error
|
||||
buf, _ := io.ReadAll(req.Body)
|
||||
|
||||
// for i := uint64(0); i < bdc.cfg.Retries; i++ {
|
||||
// req = req.Clone(req.Context())
|
||||
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||
resp, err := bdc.client.Do(req)
|
||||
if err == nil {
|
||||
if resp.StatusCode == 200 {
|
||||
return resp, err
|
||||
}
|
||||
}
|
||||
// }
|
||||
respBytes, _ := io.ReadAll(resp.Body)
|
||||
err = fmt.Errorf("%s", respBytes)
|
||||
resp.Body.Close()
|
||||
|
||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||
}
|
||||
|
||||
func createK8sCloudApiBVS(req k8s_ca.CreateRequest) (*bytes.Buffer, string) {
|
||||
reqBody := &bytes.Buffer{}
|
||||
writer := multipart.NewWriter(reqBody)
|
||||
if req.OidcCertificate != "" {
|
||||
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
|
||||
_, _ = io.Copy(part, strings.NewReader(req.OidcCertificate))
|
||||
}
|
||||
|
||||
_ = writer.WriteField("name", req.Name)
|
||||
_ = writer.WriteField("rgId", strconv.FormatUint(req.RGID, 10))
|
||||
_ = writer.WriteField("k8ciId", strconv.FormatUint(req.K8SCIID, 10))
|
||||
_ = writer.WriteField("workerGroupName", req.WorkerGroupName)
|
||||
_ = writer.WriteField("networkPlugin", req.NetworkPlugin)
|
||||
|
||||
if req.MasterSEPID != 0 {
|
||||
_ = writer.WriteField("masterSepId", strconv.FormatUint(req.MasterSEPID, 10))
|
||||
}
|
||||
if req.MasterSEPPool != "" {
|
||||
_ = writer.WriteField("masterSepPool", req.MasterSEPPool)
|
||||
}
|
||||
if req.WorkerSEPID != 0 {
|
||||
_ = writer.WriteField("workerSepId", strconv.FormatUint(req.WorkerSEPID, 10))
|
||||
}
|
||||
if req.WorkerSEPPool != "" {
|
||||
_ = writer.WriteField("workerSepPool", req.WorkerSEPPool)
|
||||
}
|
||||
|
||||
if req.Labels != nil {
|
||||
for _, v := range req.Labels {
|
||||
_ = writer.WriteField("labels", v)
|
||||
}
|
||||
}
|
||||
if req.Taints != nil {
|
||||
for _, v := range req.Taints {
|
||||
_ = writer.WriteField("taints", v)
|
||||
}
|
||||
}
|
||||
if req.Annotations != nil {
|
||||
for _, v := range req.Annotations {
|
||||
_ = writer.WriteField("annotations", v)
|
||||
}
|
||||
}
|
||||
|
||||
if req.MasterCPU != 0 {
|
||||
_ = writer.WriteField("masterCpu", strconv.FormatUint(uint64(req.MasterCPU), 10))
|
||||
}
|
||||
if req.MasterNum != 0 {
|
||||
_ = writer.WriteField("masterNum", strconv.FormatUint(uint64(req.MasterNum), 10))
|
||||
}
|
||||
if req.MasterRAM != 0 {
|
||||
_ = writer.WriteField("masterRam", strconv.FormatUint(uint64(req.MasterRAM), 10))
|
||||
}
|
||||
if req.MasterDisk != 0 {
|
||||
_ = writer.WriteField("masterDisk", strconv.FormatUint(uint64(req.MasterDisk), 10))
|
||||
}
|
||||
if req.WorkerCPU != 0 {
|
||||
_ = writer.WriteField("workerCpu", strconv.FormatUint(uint64(req.WorkerCPU), 10))
|
||||
}
|
||||
if req.WorkerNum != 0 {
|
||||
_ = writer.WriteField("workerNum", strconv.FormatUint(uint64(req.WorkerNum), 10))
|
||||
}
|
||||
if req.WorkerRAM != 0 {
|
||||
_ = writer.WriteField("workerRam", strconv.FormatUint(uint64(req.WorkerRAM), 10))
|
||||
}
|
||||
if req.WorkerDisk != 0 {
|
||||
_ = writer.WriteField("workerDisk", strconv.FormatUint(uint64(req.WorkerDisk), 10))
|
||||
}
|
||||
if req.ExtNetID != 0 {
|
||||
_ = writer.WriteField("extnetId", strconv.FormatUint(req.ExtNetID, 10))
|
||||
}
|
||||
if req.VinsId != 0 {
|
||||
_ = writer.WriteField("vinsId", strconv.FormatUint(req.VinsId, 10))
|
||||
}
|
||||
if !req.WithLB {
|
||||
_ = writer.WriteField("withLB", strconv.FormatBool(req.WithLB))
|
||||
}
|
||||
|
||||
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(req.HighlyAvailable))
|
||||
|
||||
if req.AdditionalSANs != nil {
|
||||
for _, v := range req.AdditionalSANs {
|
||||
_ = writer.WriteField("additionalSANs", v)
|
||||
}
|
||||
}
|
||||
if req.InitConfiguration != "" {
|
||||
_ = writer.WriteField("initConfiguration", req.InitConfiguration)
|
||||
}
|
||||
if req.ClusterConfiguration != "" {
|
||||
_ = writer.WriteField("clusterConfiguration", req.ClusterConfiguration)
|
||||
}
|
||||
if req.KubeletConfiguration != "" {
|
||||
_ = writer.WriteField("kubeletConfiguration", req.KubeletConfiguration)
|
||||
}
|
||||
if req.KubeProxyConfiguration != "" {
|
||||
_ = writer.WriteField("kubeProxyConfiguration", req.KubeProxyConfiguration)
|
||||
}
|
||||
if req.JoinConfiguration != "" {
|
||||
_ = writer.WriteField("joinConfiguration", req.JoinConfiguration)
|
||||
}
|
||||
if req.Description != "" {
|
||||
_ = writer.WriteField("desc", req.Description)
|
||||
}
|
||||
if req.UserData != "" {
|
||||
_ = writer.WriteField("userData", req.UserData)
|
||||
}
|
||||
|
||||
_ = writer.WriteField("extnetOnly", strconv.FormatBool(req.ExtNetOnly))
|
||||
|
||||
ct := writer.FormDataContentType()
|
||||
writer.Close()
|
||||
|
||||
return reqBody, ct
|
||||
}
|
||||
|
||||
func createK8sCloudBrokerBVS(req k8s_cb.CreateRequest) (*bytes.Buffer, string) {
|
||||
reqBody := &bytes.Buffer{}
|
||||
writer := multipart.NewWriter(reqBody)
|
||||
if req.OidcCertificate != "" {
|
||||
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
|
||||
_, _ = io.Copy(part, strings.NewReader(req.OidcCertificate))
|
||||
}
|
||||
|
||||
_ = writer.WriteField("name", req.Name)
|
||||
_ = writer.WriteField("rgId", strconv.FormatUint(req.RGID, 10))
|
||||
_ = writer.WriteField("k8ciId", strconv.FormatUint(req.K8CIID, 10))
|
||||
_ = writer.WriteField("workerGroupName", req.WorkerGroupName)
|
||||
_ = writer.WriteField("networkPlugin", req.NetworkPlugin)
|
||||
|
||||
if req.MasterSEPID != 0 {
|
||||
_ = writer.WriteField("masterSepId", strconv.FormatUint(req.MasterSEPID, 10))
|
||||
}
|
||||
if req.MasterSEPPool != "" {
|
||||
_ = writer.WriteField("masterSepPool", req.MasterSEPPool)
|
||||
}
|
||||
if req.WorkerSEPID != 0 {
|
||||
_ = writer.WriteField("workerSepId", strconv.FormatUint(req.WorkerSEPID, 10))
|
||||
}
|
||||
if req.WorkerSEPPool != "" {
|
||||
_ = writer.WriteField("workerSepPool", req.WorkerSEPPool)
|
||||
}
|
||||
|
||||
if req.Labels != nil {
|
||||
for _, v := range req.Labels {
|
||||
_ = writer.WriteField("labels", v)
|
||||
}
|
||||
}
|
||||
if req.Taints != nil {
|
||||
for _, v := range req.Taints {
|
||||
_ = writer.WriteField("taints", v)
|
||||
}
|
||||
}
|
||||
if req.Annotations != nil {
|
||||
for _, v := range req.Annotations {
|
||||
_ = writer.WriteField("annotations", v)
|
||||
}
|
||||
}
|
||||
|
||||
if req.MasterCPU != 0 {
|
||||
_ = writer.WriteField("masterCpu", strconv.FormatUint(req.MasterCPU, 10))
|
||||
}
|
||||
if req.MasterNum != 0 {
|
||||
_ = writer.WriteField("masterNum", strconv.FormatUint(req.MasterNum, 10))
|
||||
}
|
||||
if req.MasterRAM != 0 {
|
||||
_ = writer.WriteField("masterRam", strconv.FormatUint(req.MasterRAM, 10))
|
||||
}
|
||||
if req.MasterDisk != 0 {
|
||||
_ = writer.WriteField("masterDisk", strconv.FormatUint(req.MasterDisk, 10))
|
||||
}
|
||||
if req.WorkerCPU != 0 {
|
||||
_ = writer.WriteField("workerCpu", strconv.FormatUint(req.WorkerCPU, 10))
|
||||
}
|
||||
if req.WorkerNum != 0 {
|
||||
_ = writer.WriteField("workerNum", strconv.FormatUint(req.WorkerNum, 10))
|
||||
}
|
||||
if req.WorkerRAM != 0 {
|
||||
_ = writer.WriteField("workerRam", strconv.FormatUint(req.WorkerRAM, 10))
|
||||
}
|
||||
if req.WorkerDisk != 0 {
|
||||
_ = writer.WriteField("workerDisk", strconv.FormatUint(req.WorkerDisk, 10))
|
||||
}
|
||||
if req.ExtNetID != 0 {
|
||||
_ = writer.WriteField("extnetId", strconv.FormatUint(req.ExtNetID, 10))
|
||||
}
|
||||
if req.VinsId != 0 {
|
||||
_ = writer.WriteField("vinsId", strconv.FormatUint(req.VinsId, 10))
|
||||
}
|
||||
if !req.WithLB {
|
||||
_ = writer.WriteField("withLB", strconv.FormatBool(req.WithLB))
|
||||
}
|
||||
|
||||
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(req.HighlyAvailable))
|
||||
|
||||
if req.AdditionalSANs != nil {
|
||||
for _, v := range req.AdditionalSANs {
|
||||
_ = writer.WriteField("additionalSANs", v)
|
||||
}
|
||||
}
|
||||
if req.InitConfiguration != "" {
|
||||
_ = writer.WriteField("initConfiguration", req.InitConfiguration)
|
||||
}
|
||||
if req.ClusterConfiguration != "" {
|
||||
_ = writer.WriteField("clusterConfiguration", req.ClusterConfiguration)
|
||||
}
|
||||
if req.KubeletConfiguration != "" {
|
||||
_ = writer.WriteField("kubeletConfiguration", req.KubeletConfiguration)
|
||||
}
|
||||
if req.KubeProxyConfiguration != "" {
|
||||
_ = writer.WriteField("kubeProxyConfiguration", req.KubeProxyConfiguration)
|
||||
}
|
||||
if req.JoinConfiguration != "" {
|
||||
_ = writer.WriteField("joinConfiguration", req.JoinConfiguration)
|
||||
}
|
||||
if req.Description != "" {
|
||||
_ = writer.WriteField("desc", req.Description)
|
||||
}
|
||||
if req.UserData != "" {
|
||||
_ = writer.WriteField("userData", req.UserData)
|
||||
}
|
||||
|
||||
_ = writer.WriteField("extnetOnly", strconv.FormatBool(req.ExtNetOnly))
|
||||
|
||||
ct := writer.FormDataContentType()
|
||||
|
||||
writer.Close()
|
||||
return reqBody, ct
|
||||
}
|
||||
@@ -42,7 +42,7 @@ type Config struct {
|
||||
// Required: false
|
||||
Retries uint64 `json:"retries" yaml:"retries"`
|
||||
|
||||
// Skip verify, true by default
|
||||
// Skip verify
|
||||
// Required: false
|
||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||
|
||||
@@ -72,9 +72,7 @@ func ParseConfigJSON(path string) (Config, error) {
|
||||
|
||||
err = validators.ValidateConfig(config)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return Config{}, validators.ValidationError(validationError)
|
||||
}
|
||||
return Config{}, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
return config, nil
|
||||
@@ -96,9 +94,7 @@ func ParseConfigYAML(path string) (Config, error) {
|
||||
|
||||
err = validators.ValidateConfig(config)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return Config{}, validators.ValidationError(validationError)
|
||||
}
|
||||
return Config{}, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
return config, nil
|
||||
|
||||
116
config/config_bvs.go
Normal file
116
config/config_bvs.go
Normal file
@@ -0,0 +1,116 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"golang.org/x/oauth2"
|
||||
"gopkg.in/yaml.v3"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
type BVSConfig struct {
|
||||
// ServiceAccount username
|
||||
// Required: true
|
||||
// Example : "osh_mikoev"
|
||||
Username string `json:"username" yaml:"username" validate:"required"`
|
||||
|
||||
// ServiceAccount password
|
||||
// Required: true
|
||||
// Example: "[1o>hYkjnJr)HI78q7t&#%8Lm"
|
||||
Password string `json:"password" yaml:"password" validate:"required"`
|
||||
|
||||
// Domain name
|
||||
// Required: true
|
||||
// Example: "dynamix"
|
||||
Domain string `json:"domain" yaml:"domain"`
|
||||
|
||||
// Application (client) identifier for authorization
|
||||
// in the cloud platform controller in oauth2 mode.
|
||||
// Required: true
|
||||
// Example: "ewqfrvea7s890avw804389qwguf234h0otfi3w4eiu"
|
||||
AppID string `json:"appId" yaml:"appId" validate:"required"`
|
||||
|
||||
// Application (client) secret code for authorization
|
||||
// in the cloud platform controller in oauth2 mode.
|
||||
// Example: "frvet09rvesfis0c9erv9fsov0vsdfi09ovds0f"
|
||||
AppSecret string `json:"appSecret" yaml:"appSecret" validate:"required"`
|
||||
|
||||
// Platform authentication service address
|
||||
// Required: true
|
||||
// Example: "https://sso.digitalenergy.online"
|
||||
SSOURL string `json:"ssoUrl" yaml:"ssoUrl" validate:"url"`
|
||||
|
||||
// The address of the platform on which the actions are planned
|
||||
// Required: true
|
||||
// Example: "https://mr4.digitalenergy.online"
|
||||
DecortURL string `json:"decortUrl" yaml:"decortUrl" validate:"url"`
|
||||
|
||||
// JWT platform token
|
||||
// Required: false
|
||||
// Example: "qwqwdfwv68979we0q9bfv7e9sbvd89798qrwv97ff"
|
||||
Token oauth2.Token `json:"token" yaml:"token"`
|
||||
|
||||
// Amount platform request attempts
|
||||
// Default value: 5
|
||||
// Required: false
|
||||
Retries uint64 `json:"retries" yaml:"retries"`
|
||||
|
||||
// Skip verify
|
||||
// Required: false
|
||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||
|
||||
// HTTP client timeout, unlimited if left empty
|
||||
// Required: false
|
||||
Timeout Duration `json:"timeout" yaml:"timeout"`
|
||||
}
|
||||
|
||||
// SetTimeout is used to set HTTP client timeout.
|
||||
func (c *BVSConfig) SetTimeout(dur time.Duration) {
|
||||
c.Timeout = Duration(dur)
|
||||
}
|
||||
|
||||
// ParseConfigJSON parses Config from specified JSON-formatted file.
|
||||
func ParseConfigBVSJSON(path string) (BVSConfig, error) {
|
||||
file, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return BVSConfig{}, err
|
||||
}
|
||||
|
||||
var config BVSConfig
|
||||
|
||||
err = json.Unmarshal(file, &config)
|
||||
if err != nil {
|
||||
return BVSConfig{}, err
|
||||
}
|
||||
|
||||
err = validators.ValidateConfig(config)
|
||||
if err != nil {
|
||||
return BVSConfig{}, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// ParseConfigYAML parses Config from specified YAML-formatted file.
|
||||
func ParseConfigBVSYAML(path string) (BVSConfig, error) {
|
||||
file, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return BVSConfig{}, err
|
||||
}
|
||||
|
||||
var config BVSConfig
|
||||
|
||||
err = yaml.Unmarshal(file, &config)
|
||||
if err != nil {
|
||||
return BVSConfig{}, err
|
||||
}
|
||||
|
||||
err = validators.ValidateConfig(config)
|
||||
if err != nil {
|
||||
return BVSConfig{}, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
@@ -36,7 +36,7 @@ type LegacyConfig struct {
|
||||
// Required: false
|
||||
Retries uint64 `json:"retries" yaml:"retries"`
|
||||
|
||||
// Skip verify, true by default
|
||||
// Skip verify
|
||||
// Required: false
|
||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||
|
||||
@@ -66,9 +66,7 @@ func ParseLegacyConfigJSON(path string) (LegacyConfig, error) {
|
||||
|
||||
err = validators.ValidateConfig(config)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return LegacyConfig{}, validators.ValidationError(validationError)
|
||||
}
|
||||
return LegacyConfig{}, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
return config, nil
|
||||
@@ -90,9 +88,7 @@ func ParseLegacyConfigYAML(path string) (LegacyConfig, error) {
|
||||
|
||||
err = validators.ValidateConfig(config)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return LegacyConfig{}, validators.ValidationError(validationError)
|
||||
}
|
||||
return LegacyConfig{}, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
return config, nil
|
||||
|
||||
@@ -23,7 +23,7 @@ func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
*d = Duration(tmp)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("Invalid duration %v", value)
|
||||
return fmt.Errorf("invalid duration %v", value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func (d *Duration) UnmarshalJSON(b []byte) error {
|
||||
*d = Duration(tmp)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("Invalid duration %v", value)
|
||||
return fmt.Errorf("invalid duration %v", value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
11
go.mod
11
go.mod
@@ -5,15 +5,20 @@ go 1.20
|
||||
require (
|
||||
github.com/go-playground/validator/v10 v10.11.2
|
||||
github.com/google/go-querystring v1.1.0
|
||||
golang.org/x/oauth2 v0.13.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
golang.org/x/crypto v0.5.0 // indirect
|
||||
golang.org/x/sys v0.4.0 // indirect
|
||||
golang.org/x/text v0.6.0 // indirect
|
||||
golang.org/x/crypto v0.14.0 // indirect
|
||||
golang.org/x/net v0.16.0 // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
golang.org/x/text v0.13.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
)
|
||||
|
||||
35
go.sum
35
go.sum
@@ -8,8 +8,13 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU=
|
||||
github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s=
|
||||
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||
@@ -23,13 +28,29 @@ github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUA
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
|
||||
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
|
||||
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
|
||||
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
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/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
|
||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.16.0 h1:7eBu7KsSvFDtSXUIDbh3aqlK4DPsZ1rByC8PFfBThos=
|
||||
golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||
golang.org/x/oauth2 v0.13.0 h1:jDDenyj+WgFtmV3zYVoi8aE2BwtXFLWOA67ZfNWftiY=
|
||||
golang.org/x/oauth2 v0.13.0/go.mod h1:/JMhi4ZRXAf4HG9LiNmxvk+45+96RUlVThiH8FzNBn0=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
|
||||
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
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=
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||
)
|
||||
|
||||
func NewHttpClient(cfg config.Config) *http.Client {
|
||||
|
||||
transCfg := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
//nolint:gosec
|
||||
InsecureSkipVerify: cfg.SSLSkipVerify,
|
||||
},
|
||||
}
|
||||
|
||||
var expiredTime time.Time
|
||||
|
||||
if cfg.Token != "" {
|
||||
expiredTime = time.Now().AddDate(0, 0, 1)
|
||||
}
|
||||
|
||||
return &http.Client{
|
||||
Transport: &transport{
|
||||
base: transCfg,
|
||||
retries: cfg.Retries,
|
||||
clientID: cfg.AppID,
|
||||
clientSecret: cfg.AppSecret,
|
||||
ssoURL: cfg.SSOURL,
|
||||
token: cfg.Token,
|
||||
expiryTime: expiredTime,
|
||||
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
|
||||
Timeout: cfg.Timeout.Get(),
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||
)
|
||||
|
||||
// NewLegacyHttpClient creates legacy HTTP Client
|
||||
func NewLegacyHttpClient(cfg config.LegacyConfig) *http.Client {
|
||||
transCfg := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
//nolint:gosec
|
||||
InsecureSkipVerify: cfg.SSLSkipVerify,
|
||||
},
|
||||
}
|
||||
|
||||
return &http.Client{
|
||||
Transport: &transportLegacy{
|
||||
base: transCfg,
|
||||
username: url.QueryEscape(cfg.Username),
|
||||
password: url.QueryEscape(cfg.Password),
|
||||
retries: cfg.Retries,
|
||||
token: cfg.Token,
|
||||
decortURL: cfg.DecortURL,
|
||||
},
|
||||
|
||||
Timeout: cfg.Timeout.Get(),
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type transportLegacy struct {
|
||||
base http.RoundTripper
|
||||
username string
|
||||
password string
|
||||
retries uint64
|
||||
token string
|
||||
decortURL string
|
||||
}
|
||||
|
||||
func (t *transportLegacy) RoundTrip(request *http.Request) (*http.Response, error) {
|
||||
if t.token == "" {
|
||||
body := fmt.Sprintf("username=%s&password=%s", t.username, t.password)
|
||||
bodyReader := strings.NewReader(body)
|
||||
|
||||
req, _ := http.NewRequestWithContext(request.Context(), "POST", t.decortURL+"/restmachine/cloudapi/user/authenticate", bodyReader)
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
resp, err := t.base.RoundTrip(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get token: %w", err)
|
||||
}
|
||||
|
||||
tokenBytes, _ := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("unable to get token: %s", tokenBytes)
|
||||
}
|
||||
|
||||
token := string(tokenBytes)
|
||||
t.token = token
|
||||
}
|
||||
|
||||
tokenValue := fmt.Sprintf("&authkey=%s", t.token)
|
||||
tokenReader := strings.NewReader(tokenValue)
|
||||
|
||||
newBody := io.MultiReader(request.Body, tokenReader)
|
||||
|
||||
req, _ := http.NewRequestWithContext(request.Context(), request.Method, request.URL.String(), newBody)
|
||||
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
req.Header.Set("Accept", "application/json")
|
||||
|
||||
var resp *http.Response
|
||||
var err error
|
||||
for i := uint64(0); i < t.retries; i++ {
|
||||
resp, err = t.base.RoundTrip(req)
|
||||
if err == nil {
|
||||
if resp.StatusCode == 200 {
|
||||
return resp, nil
|
||||
}
|
||||
respBytes, _ := io.ReadAll(resp.Body)
|
||||
err = fmt.Errorf("%s", respBytes)
|
||||
resp.Body.Close()
|
||||
}
|
||||
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type transport struct {
|
||||
base http.RoundTripper
|
||||
retries uint64
|
||||
clientID string
|
||||
clientSecret string
|
||||
token string
|
||||
ssoURL string
|
||||
expiryTime time.Time
|
||||
}
|
||||
|
||||
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
if t.token == "" || time.Now().After(t.expiryTime) {
|
||||
body := fmt.Sprintf("grant_type=client_credentials&client_id=%s&client_secret=%s&response_type=id_token", t.clientID, t.clientSecret)
|
||||
bodyReader := strings.NewReader(body)
|
||||
|
||||
t.ssoURL = strings.TrimSuffix(t.ssoURL, "/")
|
||||
|
||||
req, _ := http.NewRequestWithContext(req.Context(), "POST", t.ssoURL+"/v1/oauth/access_token", bodyReader)
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
resp, err := t.base.RoundTrip(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot get token: %w", err)
|
||||
}
|
||||
|
||||
tokenBytes, _ := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("cannot get token: %s", tokenBytes)
|
||||
}
|
||||
|
||||
token := string(tokenBytes)
|
||||
|
||||
t.token = token
|
||||
t.expiryTime = time.Now().AddDate(0, 0, 1)
|
||||
}
|
||||
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
req.Header.Add("Authorization", "bearer "+t.token)
|
||||
req.Header.Set("Accept", "application/json")
|
||||
|
||||
var resp *http.Response
|
||||
var err error
|
||||
for i := uint64(0); i < t.retries; i++ {
|
||||
resp, err = t.base.RoundTrip(req)
|
||||
if err == nil {
|
||||
if resp.StatusCode == 200 {
|
||||
return resp, nil
|
||||
}
|
||||
respBytes, _ := io.ReadAll(resp.Body)
|
||||
err = fmt.Errorf("%s", respBytes)
|
||||
resp.Body.Close()
|
||||
}
|
||||
//logrus.Errorf("Could not execute request: %v. Retrying %d/%d", err, i+1, t.retries)
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||
}
|
||||
41
internal/multierror/join.go
Normal file
41
internal/multierror/join.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package multierror
|
||||
|
||||
func Join(errs ...error) error {
|
||||
n := 0
|
||||
for _, err := range errs {
|
||||
if err != nil {
|
||||
n++
|
||||
}
|
||||
}
|
||||
if n == 0 {
|
||||
return nil
|
||||
}
|
||||
e := &joinError{
|
||||
errs: make([]error, 0, n),
|
||||
}
|
||||
for _, err := range errs {
|
||||
if err != nil {
|
||||
e.errs = append(e.errs, err)
|
||||
}
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
type joinError struct {
|
||||
errs []error
|
||||
}
|
||||
|
||||
func (e *joinError) Error() string {
|
||||
var b []byte
|
||||
for i, err := range e.errs {
|
||||
if i > 0 {
|
||||
b = append(b, '\n')
|
||||
}
|
||||
b = append(b, err.Error()...)
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func (e *joinError) Unwrap() []error {
|
||||
return e.errs
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package validators
|
||||
|
||||
import (
|
||||
"github.com/go-playground/validator/v10"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
// computeDriverValidator is used to validate Driver field in kvmx86/kvmppc create.
|
||||
@@ -263,3 +264,11 @@ func strictLooseValidator(fe validator.FieldLevel) bool {
|
||||
|
||||
return StringInSlice(fieldValue, strictLooseValues)
|
||||
}
|
||||
|
||||
// name workerGroup must be more 3 symbol
|
||||
func workerGroupNameValidator(fe validator.FieldLevel) bool {
|
||||
fieldValue := fe.Field().String()
|
||||
fieldValue = strings.Trim(fieldValue, " ")
|
||||
|
||||
return len(fieldValue) >= 3
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package validators
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/multierror"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
@@ -20,6 +21,14 @@ func ValidationError(fe validator.FieldError) error {
|
||||
return errors.New(errorMessage(fe))
|
||||
}
|
||||
|
||||
func ValidationErrors(fes []validator.FieldError) error {
|
||||
errs := make([]error, 0, len(fes))
|
||||
for _, fe := range fes {
|
||||
errs = append(errs, ValidationError(fe))
|
||||
}
|
||||
return multierror.Join(errs...)
|
||||
}
|
||||
|
||||
//nolint:errorlint
|
||||
func GetErrors(err error) validator.ValidationErrors {
|
||||
return err.(validator.ValidationErrors)
|
||||
|
||||
@@ -127,6 +127,12 @@ func errorMessage(fe validator.FieldError) string {
|
||||
fe.Field(),
|
||||
joinValues(flipgroupClientTypeValues))
|
||||
|
||||
// k8s Validators
|
||||
case "workerGroupName":
|
||||
return fmt.Sprintf("%s %s must be more 3 symbol",
|
||||
prefix,
|
||||
fe.Field())
|
||||
|
||||
// KVM_X86/KVM_PPC Validators
|
||||
case "kvmNetType":
|
||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
||||
|
||||
@@ -180,5 +180,10 @@ func registerAllValidators(validate *validator.Validate) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = validate.RegisterValidation("workerGroupName", workerGroupNameValidator)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
360
legacy-client.go
360
legacy-client.go
@@ -1,23 +1,35 @@
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/client"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
||||
k8s_ca "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
||||
k8s_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
|
||||
)
|
||||
|
||||
// Legacy HTTP-client for platform
|
||||
type LegacyDecortClient struct {
|
||||
decortURL string
|
||||
client *http.Client
|
||||
decortURL string
|
||||
client *http.Client
|
||||
cfg config.LegacyConfig
|
||||
expiryTime time.Time
|
||||
mutex *sync.Mutex
|
||||
}
|
||||
|
||||
// Legacy client builder
|
||||
@@ -26,9 +38,25 @@ func NewLegacy(cfg config.LegacyConfig) *LegacyDecortClient {
|
||||
cfg.Retries = 5
|
||||
}
|
||||
|
||||
var expiryTime time.Time
|
||||
|
||||
if cfg.Token != "" {
|
||||
expiryTime = time.Now().AddDate(0, 0, 1)
|
||||
}
|
||||
|
||||
return &LegacyDecortClient{
|
||||
decortURL: cfg.DecortURL,
|
||||
client: client.NewLegacyHttpClient(cfg),
|
||||
client: &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
//nolint:gosec
|
||||
InsecureSkipVerify: cfg.SSLSkipVerify,
|
||||
},
|
||||
},
|
||||
},
|
||||
cfg: cfg,
|
||||
expiryTime: expiryTime,
|
||||
mutex: &sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,18 +72,34 @@ func (ldc *LegacyDecortClient) CloudBroker() *cloudbroker.CloudBroker {
|
||||
|
||||
// DecortApiCall method for sending requests to the platform
|
||||
func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
||||
values, err := query.Values(params)
|
||||
if err := ldc.getToken(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8sCaCreateReq, okCa := params.(k8s_ca.CreateRequest)
|
||||
k8sCbCreateReq, okCb := params.(k8s_cb.CreateRequest)
|
||||
|
||||
var body *bytes.Buffer
|
||||
var ctype string
|
||||
|
||||
if okCa {
|
||||
body, ctype = createK8sCloudApiLegacy(k8sCaCreateReq, ldc.cfg.Token)
|
||||
} else if okCb {
|
||||
body, ctype = createK8sCloudBrokerLegacy(k8sCbCreateReq, ldc.cfg.Token)
|
||||
} else {
|
||||
values, err := query.Values(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
body = bytes.NewBufferString(values.Encode() + fmt.Sprintf("&authkey=%s", ldc.cfg.Token))
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+restmachine+url, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
body := strings.NewReader(values.Encode())
|
||||
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+"/restmachine"+url, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := ldc.client.Do(req)
|
||||
resp, err := ldc.do(req, ctype)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -72,3 +116,295 @@ func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url st
|
||||
|
||||
return respBytes, nil
|
||||
}
|
||||
|
||||
func (ldc *LegacyDecortClient) getToken(ctx context.Context) error {
|
||||
ldc.mutex.Lock()
|
||||
defer ldc.mutex.Unlock()
|
||||
|
||||
if ldc.cfg.Token == "" || time.Now().After(ldc.expiryTime) {
|
||||
body := fmt.Sprintf("username=%s&password=%s", url.QueryEscape(ldc.cfg.Username), url.QueryEscape(ldc.cfg.Password))
|
||||
bodyReader := strings.NewReader(body)
|
||||
|
||||
req, _ := http.NewRequestWithContext(ctx, "POST", ldc.cfg.DecortURL+"/restmachine/cloudapi/user/authenticate", bodyReader)
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
resp, err := ldc.client.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to get token: %w", err)
|
||||
}
|
||||
|
||||
tokenBytes, _ := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return fmt.Errorf("unable to get token: %s", tokenBytes)
|
||||
}
|
||||
|
||||
token := string(tokenBytes)
|
||||
ldc.cfg.Token = token
|
||||
ldc.expiryTime = time.Now().AddDate(0, 0, 1)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ldc *LegacyDecortClient) do(req *http.Request, ctype string) (*http.Response, error) {
|
||||
if ctype != "" {
|
||||
req.Header.Add("Content-Type", ctype)
|
||||
} else {
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
}
|
||||
req.Header.Set("Accept", "application/json")
|
||||
|
||||
// var resp *http.Response
|
||||
// var err error
|
||||
buf, _ := io.ReadAll(req.Body)
|
||||
|
||||
// for i := uint64(0); i < ldc.cfg.Retries; i++ {
|
||||
// req = req.Clone(req.Context())
|
||||
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||
resp, err := ldc.client.Do(req)
|
||||
if err == nil {
|
||||
if resp.StatusCode == 200 {
|
||||
return resp, err
|
||||
}
|
||||
}
|
||||
// }
|
||||
respBytes, _ := io.ReadAll(resp.Body)
|
||||
err = fmt.Errorf("%s", respBytes)
|
||||
resp.Body.Close()
|
||||
|
||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||
}
|
||||
|
||||
func createK8sCloudApiLegacy(req k8s_ca.CreateRequest, token string) (*bytes.Buffer, string) {
|
||||
reqBody := &bytes.Buffer{}
|
||||
writer := multipart.NewWriter(reqBody)
|
||||
if req.OidcCertificate != "" {
|
||||
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
|
||||
_, _ = io.Copy(part, strings.NewReader(req.OidcCertificate))
|
||||
}
|
||||
|
||||
_ = writer.WriteField("name", req.Name)
|
||||
_ = writer.WriteField("rgId", strconv.FormatUint(req.RGID, 10))
|
||||
_ = writer.WriteField("k8ciId", strconv.FormatUint(req.K8SCIID, 10))
|
||||
_ = writer.WriteField("workerGroupName", req.WorkerGroupName)
|
||||
_ = writer.WriteField("networkPlugin", req.NetworkPlugin)
|
||||
|
||||
if req.MasterSEPID != 0 {
|
||||
_ = writer.WriteField("masterSepId", strconv.FormatUint(req.MasterSEPID, 10))
|
||||
}
|
||||
if req.MasterSEPPool != "" {
|
||||
_ = writer.WriteField("masterSepPool", req.MasterSEPPool)
|
||||
}
|
||||
if req.WorkerSEPID != 0 {
|
||||
_ = writer.WriteField("workerSepId", strconv.FormatUint(req.WorkerSEPID, 10))
|
||||
}
|
||||
if req.WorkerSEPPool != "" {
|
||||
_ = writer.WriteField("workerSepPool", req.WorkerSEPPool)
|
||||
}
|
||||
|
||||
if req.Labels != nil {
|
||||
for _, v := range req.Labels {
|
||||
_ = writer.WriteField("labels", v)
|
||||
}
|
||||
}
|
||||
if req.Taints != nil {
|
||||
for _, v := range req.Taints {
|
||||
_ = writer.WriteField("taints", v)
|
||||
}
|
||||
}
|
||||
if req.Annotations != nil {
|
||||
for _, v := range req.Annotations {
|
||||
_ = writer.WriteField("annotations", v)
|
||||
}
|
||||
}
|
||||
|
||||
if req.MasterCPU != 0 {
|
||||
_ = writer.WriteField("masterCpu", strconv.FormatUint(uint64(req.MasterCPU), 10))
|
||||
}
|
||||
if req.MasterNum != 0 {
|
||||
_ = writer.WriteField("masterNum", strconv.FormatUint(uint64(req.MasterNum), 10))
|
||||
}
|
||||
if req.MasterRAM != 0 {
|
||||
_ = writer.WriteField("masterRam", strconv.FormatUint(uint64(req.MasterRAM), 10))
|
||||
}
|
||||
if req.MasterDisk != 0 {
|
||||
_ = writer.WriteField("masterDisk", strconv.FormatUint(uint64(req.MasterDisk), 10))
|
||||
}
|
||||
if req.WorkerCPU != 0 {
|
||||
_ = writer.WriteField("workerCpu", strconv.FormatUint(uint64(req.WorkerCPU), 10))
|
||||
}
|
||||
if req.WorkerNum != 0 {
|
||||
_ = writer.WriteField("workerNum", strconv.FormatUint(uint64(req.WorkerNum), 10))
|
||||
}
|
||||
if req.WorkerRAM != 0 {
|
||||
_ = writer.WriteField("workerRam", strconv.FormatUint(uint64(req.WorkerRAM), 10))
|
||||
}
|
||||
if req.WorkerDisk != 0 {
|
||||
_ = writer.WriteField("workerDisk", strconv.FormatUint(uint64(req.WorkerDisk), 10))
|
||||
}
|
||||
if req.ExtNetID != 0 {
|
||||
_ = writer.WriteField("extnetId", strconv.FormatUint(req.ExtNetID, 10))
|
||||
}
|
||||
if req.VinsId != 0 {
|
||||
_ = writer.WriteField("vinsId", strconv.FormatUint(req.VinsId, 10))
|
||||
}
|
||||
if !req.WithLB {
|
||||
_ = writer.WriteField("withLB", strconv.FormatBool(req.WithLB))
|
||||
}
|
||||
|
||||
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(req.HighlyAvailable))
|
||||
|
||||
if req.AdditionalSANs != nil {
|
||||
for _, v := range req.AdditionalSANs {
|
||||
_ = writer.WriteField("additionalSANs", v)
|
||||
}
|
||||
}
|
||||
if req.InitConfiguration != "" {
|
||||
_ = writer.WriteField("initConfiguration", req.InitConfiguration)
|
||||
}
|
||||
if req.ClusterConfiguration != "" {
|
||||
_ = writer.WriteField("clusterConfiguration", req.ClusterConfiguration)
|
||||
}
|
||||
if req.KubeletConfiguration != "" {
|
||||
_ = writer.WriteField("kubeletConfiguration", req.KubeletConfiguration)
|
||||
}
|
||||
if req.KubeProxyConfiguration != "" {
|
||||
_ = writer.WriteField("kubeProxyConfiguration", req.KubeProxyConfiguration)
|
||||
}
|
||||
if req.JoinConfiguration != "" {
|
||||
_ = writer.WriteField("joinConfiguration", req.JoinConfiguration)
|
||||
}
|
||||
if req.Description != "" {
|
||||
_ = writer.WriteField("desc", req.Description)
|
||||
}
|
||||
if req.UserData != "" {
|
||||
_ = writer.WriteField("userData", req.UserData)
|
||||
}
|
||||
|
||||
_ = writer.WriteField("extnetOnly", strconv.FormatBool(req.ExtNetOnly))
|
||||
|
||||
_ = writer.WriteField("authkey", token)
|
||||
|
||||
ct := writer.FormDataContentType()
|
||||
writer.Close()
|
||||
|
||||
return reqBody, ct
|
||||
}
|
||||
|
||||
func createK8sCloudBrokerLegacy(req k8s_cb.CreateRequest, token string) (*bytes.Buffer, string) {
|
||||
reqBody := &bytes.Buffer{}
|
||||
writer := multipart.NewWriter(reqBody)
|
||||
if req.OidcCertificate != "" {
|
||||
part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt")
|
||||
_, _ = io.Copy(part, strings.NewReader(req.OidcCertificate))
|
||||
}
|
||||
|
||||
_ = writer.WriteField("name", req.Name)
|
||||
_ = writer.WriteField("rgId", strconv.FormatUint(req.RGID, 10))
|
||||
_ = writer.WriteField("k8ciId", strconv.FormatUint(req.K8CIID, 10))
|
||||
_ = writer.WriteField("workerGroupName", req.WorkerGroupName)
|
||||
_ = writer.WriteField("networkPlugin", req.NetworkPlugin)
|
||||
|
||||
if req.MasterSEPID != 0 {
|
||||
_ = writer.WriteField("masterSepId", strconv.FormatUint(req.MasterSEPID, 10))
|
||||
}
|
||||
if req.MasterSEPPool != "" {
|
||||
_ = writer.WriteField("masterSepPool", req.MasterSEPPool)
|
||||
}
|
||||
if req.WorkerSEPID != 0 {
|
||||
_ = writer.WriteField("workerSepId", strconv.FormatUint(req.WorkerSEPID, 10))
|
||||
}
|
||||
if req.WorkerSEPPool != "" {
|
||||
_ = writer.WriteField("workerSepPool", req.WorkerSEPPool)
|
||||
}
|
||||
|
||||
if req.Labels != nil {
|
||||
for _, v := range req.Labels {
|
||||
_ = writer.WriteField("labels", v)
|
||||
}
|
||||
}
|
||||
if req.Taints != nil {
|
||||
for _, v := range req.Taints {
|
||||
_ = writer.WriteField("taints", v)
|
||||
}
|
||||
}
|
||||
if req.Annotations != nil {
|
||||
for _, v := range req.Annotations {
|
||||
_ = writer.WriteField("annotations", v)
|
||||
}
|
||||
}
|
||||
|
||||
if req.MasterCPU != 0 {
|
||||
_ = writer.WriteField("masterCpu", strconv.FormatUint(req.MasterCPU, 10))
|
||||
}
|
||||
if req.MasterNum != 0 {
|
||||
_ = writer.WriteField("masterNum", strconv.FormatUint(req.MasterNum, 10))
|
||||
}
|
||||
if req.MasterRAM != 0 {
|
||||
_ = writer.WriteField("masterRam", strconv.FormatUint(req.MasterRAM, 10))
|
||||
}
|
||||
if req.MasterDisk != 0 {
|
||||
_ = writer.WriteField("masterDisk", strconv.FormatUint(req.MasterDisk, 10))
|
||||
}
|
||||
if req.WorkerCPU != 0 {
|
||||
_ = writer.WriteField("workerCpu", strconv.FormatUint(req.WorkerCPU, 10))
|
||||
}
|
||||
if req.WorkerNum != 0 {
|
||||
_ = writer.WriteField("workerNum", strconv.FormatUint(req.WorkerNum, 10))
|
||||
}
|
||||
if req.WorkerRAM != 0 {
|
||||
_ = writer.WriteField("workerRam", strconv.FormatUint(req.WorkerRAM, 10))
|
||||
}
|
||||
if req.WorkerDisk != 0 {
|
||||
_ = writer.WriteField("workerDisk", strconv.FormatUint(req.WorkerDisk, 10))
|
||||
}
|
||||
if req.ExtNetID != 0 {
|
||||
_ = writer.WriteField("extnetId", strconv.FormatUint(req.ExtNetID, 10))
|
||||
}
|
||||
if req.VinsId != 0 {
|
||||
_ = writer.WriteField("vinsId", strconv.FormatUint(req.VinsId, 10))
|
||||
}
|
||||
if !req.WithLB {
|
||||
_ = writer.WriteField("withLB", strconv.FormatBool(req.WithLB))
|
||||
}
|
||||
|
||||
_ = writer.WriteField("highlyAvailableLB", strconv.FormatBool(req.HighlyAvailable))
|
||||
|
||||
if req.AdditionalSANs != nil {
|
||||
for _, v := range req.AdditionalSANs {
|
||||
_ = writer.WriteField("additionalSANs", v)
|
||||
}
|
||||
}
|
||||
if req.InitConfiguration != "" {
|
||||
_ = writer.WriteField("initConfiguration", req.InitConfiguration)
|
||||
}
|
||||
if req.ClusterConfiguration != "" {
|
||||
_ = writer.WriteField("clusterConfiguration", req.ClusterConfiguration)
|
||||
}
|
||||
if req.KubeletConfiguration != "" {
|
||||
_ = writer.WriteField("kubeletConfiguration", req.KubeletConfiguration)
|
||||
}
|
||||
if req.KubeProxyConfiguration != "" {
|
||||
_ = writer.WriteField("kubeProxyConfiguration", req.KubeProxyConfiguration)
|
||||
}
|
||||
if req.JoinConfiguration != "" {
|
||||
_ = writer.WriteField("joinConfiguration", req.JoinConfiguration)
|
||||
}
|
||||
if req.Description != "" {
|
||||
_ = writer.WriteField("desc", req.Description)
|
||||
}
|
||||
if req.UserData != "" {
|
||||
_ = writer.WriteField("userData", req.UserData)
|
||||
}
|
||||
|
||||
_ = writer.WriteField("extnetOnly", strconv.FormatBool(req.ExtNetOnly))
|
||||
|
||||
_ = writer.WriteField("authkey", token)
|
||||
|
||||
ct := writer.FormDataContentType()
|
||||
|
||||
writer.Close()
|
||||
return reqBody, ct
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for adding permission to access to account for a user
|
||||
// AddUserRequest struct to add permission to access account for a user
|
||||
type AddUserRequest struct {
|
||||
// ID of account to add to
|
||||
// Required: true
|
||||
@@ -30,9 +30,7 @@ type AddUserRequest struct {
|
||||
func (a Account) AddUser(ctx context.Context, req AddUserRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/addUser"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for give list account audits
|
||||
// AuditsRequest struct to give list of account audits
|
||||
type AuditsRequest struct {
|
||||
// ID of the account
|
||||
// Required: true
|
||||
@@ -19,9 +19,7 @@ type AuditsRequest struct {
|
||||
func (a Account) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/audits"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for creating account
|
||||
// CreateRequest struct for creating account
|
||||
type CreateRequest struct {
|
||||
// Display name
|
||||
// Required: true
|
||||
@@ -56,9 +56,7 @@ type CreateRequest struct {
|
||||
func (a Account) 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)
|
||||
}
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/create"
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete account
|
||||
// DeleteRequest struct to delete account
|
||||
type DeleteRequest struct {
|
||||
// ID of account to delete
|
||||
// Required: true
|
||||
@@ -22,9 +22,7 @@ type DeleteRequest struct {
|
||||
func (a Account) 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)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/delete"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for revoke access to account
|
||||
// DeleteUserRequest struct to revoke access to account
|
||||
type DeleteUserRequest struct {
|
||||
// ID of the account
|
||||
// Required: true
|
||||
@@ -20,16 +20,14 @@ type DeleteUserRequest struct {
|
||||
|
||||
// Recursively revoke access rights from owned cloudspaces and vmachines
|
||||
// Required: false
|
||||
RecursiveDelete bool `url:"recursivedelete,omitempty" json:"recursivedelete,omitempty"`
|
||||
RecursiveDelete bool `url:"recursivedelete" json:"recursivedelete"`
|
||||
}
|
||||
|
||||
// DeleteUser revokes user access from the account
|
||||
func (a Account) DeleteUser(ctx context.Context, req DeleteUserRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/deleteUser"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for change status of account
|
||||
// DisableEnableRequest struct to change status of account
|
||||
type DisableEnableRequest struct {
|
||||
// ID of account
|
||||
// Required: true
|
||||
@@ -19,9 +19,7 @@ type DisableEnableRequest struct {
|
||||
func (a Account) Disable(ctx context.Context, req DisableEnableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/disable"
|
||||
@@ -43,9 +41,7 @@ func (a Account) Disable(ctx context.Context, req DisableEnableRequest) (bool, e
|
||||
func (a Account) Enable(ctx context.Context, req DisableEnableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/enable"
|
||||
|
||||
@@ -8,25 +8,16 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get information about account
|
||||
// GetRequest struct to get information about account
|
||||
type GetRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets account details
|
||||
// Get gets account details as a RecordAccount struct
|
||||
func (a Account) Get(ctx context.Context, req GetRequest) (*RecordAccount, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/get"
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
res, err := a.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -41,3 +32,16 @@ func (a Account) Get(ctx context.Context, req GetRequest) (*RecordAccount, error
|
||||
return &info, nil
|
||||
|
||||
}
|
||||
|
||||
// GetRaw gets account details as an array of bytes
|
||||
func (a Account) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/get"
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for calculate the currently consumed units for all cloudspaces and resource groups in the account
|
||||
// GetConsumedAccountUnitsRequest struct to calculate the currently consumed units for all cloudspaces and resource groups in the account
|
||||
type GetConsumedAccountUnitsRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
@@ -25,9 +25,7 @@ type GetConsumedAccountUnitsRequest struct {
|
||||
func (a Account) GetConsumedAccountUnits(ctx context.Context, req GetConsumedAccountUnitsRequest) (*ResourceLimits, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/getConsumedAccountUnits"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for calculate the currently consumed cloud units of the specified type for all cloudspaces and resource groups in the account
|
||||
// GetConsumedCloudUnitsByTypeRequest struct to calculate the currently consumed cloud units of the specified type for all cloudspaces and resource groups in the account
|
||||
type GetConsumedCloudUnitsByTypeRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
@@ -35,9 +35,7 @@ type GetConsumedCloudUnitsByTypeRequest struct {
|
||||
func (a Account) GetConsumedCloudUnitsByType(ctx context.Context, req GetConsumedCloudUnitsByTypeRequest) (float64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/getConsumedCloudUnitsByType"
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for download the resources tracking files for an account
|
||||
// GetConsumptionRequest struct to download the resources tracking files for an account
|
||||
type GetConsumptionRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
@@ -26,9 +26,7 @@ type GetConsumptionRequest struct {
|
||||
func (a Account) GetConsumption(ctx context.Context, req GetConsumptionRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/getConsumption"
|
||||
@@ -46,9 +44,7 @@ func (a Account) GetConsumption(ctx context.Context, req GetConsumptionRequest)
|
||||
func (a Account) GetConsumptionGet(ctx context.Context, req GetConsumptionRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/getConsumption"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for calculate the reserved units for all cloudspaces and resource groups in the account
|
||||
// GetReservedAccountUnitsRequest struct to calculate the reserved units for all cloudspaces and resource groups in the account
|
||||
type GetReservedAccountUnitsRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
@@ -26,9 +26,7 @@ type GetReservedAccountUnitsRequest struct {
|
||||
func (a Account) GetReservedAccountUnits(ctx context.Context, req GetReservedAccountUnitsRequest) (*ResourceLimits, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/getReservedAccountUnits"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for getting resource consumption
|
||||
// GetResourceConsumptionRequest struct to get resource consumption
|
||||
type GetResourceConsumptionRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
@@ -19,9 +19,7 @@ type GetResourceConsumptionRequest struct {
|
||||
func (a Account) GetResourceConsumption(ctx context.Context, req GetResourceConsumptionRequest) (*RecordResourceConsumption, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/getResourceConsumption"
|
||||
|
||||
73
pkg/cloudapi/account/ids.go
Normal file
73
pkg/cloudapi/account/ids.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package account
|
||||
|
||||
// IDs gets array of AccountIDs from ListAccounts struct
|
||||
func (la ListAccounts) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(la.Data))
|
||||
for _, acc := range la.Data {
|
||||
res = append(res, acc.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of ComputeIDs from ListComputes struct
|
||||
func (lc ListComputes) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lc.Data))
|
||||
for _, c := range lc.Data {
|
||||
res = append(res, c.ComputeID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of DiskIDs from ListDisks struct
|
||||
func (ld ListDisks) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(ld.Data))
|
||||
for _, d := range ld.Data {
|
||||
res = append(res, d.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of FLIPGroupIDs from ListFLIPGroups struct
|
||||
func (fg ListFLIPGroups) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(fg.Data))
|
||||
for _, g := range fg.Data {
|
||||
res = append(res, g.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of AccountIDs from ListResourceConsumption struct
|
||||
func (rc ListResourceConsumption) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(rc.Data))
|
||||
for _, r := range rc.Data {
|
||||
res = append(res, r.AccountID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of RGIDs from ListRG struct
|
||||
func (rg ListRG) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(rg.Data))
|
||||
for _, g := range rg.Data {
|
||||
res = append(res, g.RGID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of TemplateIDs from ListTemplates struct
|
||||
func (lt ListTemplates) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lt.Data))
|
||||
for _, t := range lt.Data {
|
||||
res = append(res, t.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of VINSIDs from ListVINS struct
|
||||
func (lv ListVINS) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lv.Data))
|
||||
for _, v := range lv.Data {
|
||||
res = append(res, v.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list of accounts
|
||||
// ListRequest struct to get list of accounts
|
||||
type ListRequest struct {
|
||||
// Find by ID
|
||||
// Required: false
|
||||
@@ -33,11 +33,9 @@ type ListRequest struct {
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list all accounts the user has access to
|
||||
// List gets a list of all accounts the user has access to a ListAccounts struct
|
||||
func (a Account) List(ctx context.Context, req ListRequest) (*ListAccounts, error) {
|
||||
url := "/cloudapi/account/list"
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
res, err := a.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -51,3 +49,11 @@ func (a Account) List(ctx context.Context, req ListRequest) (*ListAccounts, erro
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets a list of all accounts the user has access to as an array of bytes
|
||||
func (a Account) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
url := "/cloudapi/account/list"
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for a get list compute instances
|
||||
// ListComputesRequest struct to get a list of compute instances
|
||||
type ListComputesRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
@@ -59,9 +59,7 @@ type ListComputesRequest struct {
|
||||
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (*ListComputes, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/listComputes"
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list deleted accounts
|
||||
// ListDeletedRequest struct to get a list of deleted accounts
|
||||
type ListDeletedRequest struct {
|
||||
// Page number
|
||||
// Required: false
|
||||
@@ -29,7 +29,7 @@ type ListDeletedRequest struct {
|
||||
ACL string `url:"acl,omitempty" json:"acl,omitempty"`
|
||||
}
|
||||
|
||||
// ListDeleted gets list all deleted accounts the user has access to
|
||||
// ListDeleted gets list of all deleted accounts the user has access to
|
||||
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListAccounts, error) {
|
||||
url := "/cloudapi/account/listDeleted"
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list deleted disks
|
||||
// ListDisksRequest struct to get a list of deleted disks
|
||||
type ListDisksRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
@@ -43,9 +43,7 @@ type ListDisksRequest struct {
|
||||
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (*ListDisks, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/listDisks"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list FLIPGroups
|
||||
// ListFLIPGroupsRequest struct to get a list of FLIPGroups
|
||||
type ListFLIPGroupsRequest struct {
|
||||
// ID of the account
|
||||
// Required: true
|
||||
@@ -51,9 +51,7 @@ type ListFLIPGroupsRequest struct {
|
||||
func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest) (*ListFLIPGroups, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/listFlipGroups"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list resource groups
|
||||
// ListRGRequest struct to get a list of resource groups
|
||||
type ListRGRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
@@ -43,13 +43,11 @@ type ListRGRequest struct {
|
||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// ListRG gets list all resource groups under specified account, accessible by the user
|
||||
// ListRG gets list of all resource groups under specified account, accessible by the user
|
||||
func (a Account) ListRG(ctx context.Context, req ListRGRequest) (*ListRG, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/listRG"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list templates
|
||||
// ListTemplatesRequest struct to get a list of templates
|
||||
type ListTemplatesRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
@@ -39,13 +39,11 @@ type ListTemplatesRequest struct {
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// ListTemplates gets list templates which can be managed by this account
|
||||
// ListTemplates gets list of templates which can be managed by this account
|
||||
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (*ListTemplates, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/listTemplates"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list VINS
|
||||
// ListVINSRequest struct to get a list of VINS
|
||||
type ListVINSRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
@@ -39,13 +39,11 @@ type ListVINSRequest struct {
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// ListVINS gets list all ViNSes under specified account, accessible by the user
|
||||
// ListVINS gets list of all ViNSes under specified account, accessible by the user
|
||||
func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (*ListVINS, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/listVins"
|
||||
|
||||
@@ -88,7 +88,7 @@ type Resource struct {
|
||||
DiskSize float64 `json:"disksize"`
|
||||
|
||||
// Max disk size
|
||||
DiskSizeMax uint64 `json:"disksizemax"`
|
||||
DiskSizeMax float64 `json:"disksizemax"`
|
||||
|
||||
// Number of External IPs
|
||||
ExtIPs int64 `json:"extips"`
|
||||
@@ -126,10 +126,10 @@ type RecordResourceConsumption struct {
|
||||
// Information about resources
|
||||
type ItemResourceConsumption struct {
|
||||
// Current information about resources
|
||||
Current Resource `json:"Current"`
|
||||
Consumed Resource `json:"consumed"`
|
||||
|
||||
// Reserved information about resources
|
||||
Reserved Resource `json:"Reserved"`
|
||||
Reserved Resource `json:"reserved"`
|
||||
|
||||
// Account ID
|
||||
AccountID uint64 `json:"id"`
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for restore a deleted account
|
||||
// RestoreRequest struct to restore a deleted account
|
||||
type RestoreRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
@@ -17,9 +17,7 @@ type RestoreRequest struct {
|
||||
func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/restore"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for updaate account
|
||||
// UpdateRequest struct to update account
|
||||
type UpdateRequest struct {
|
||||
// ID an account
|
||||
// Required: true
|
||||
@@ -51,9 +51,7 @@ type UpdateRequest struct {
|
||||
func (a Account) 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)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/update"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update user access rights
|
||||
// UpdateUserRequest struct to update user access rights
|
||||
type UpdateUserRequest struct {
|
||||
// ID of the account
|
||||
// Required: true
|
||||
@@ -30,9 +30,7 @@ type UpdateUserRequest struct {
|
||||
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/account/updateUser"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for BasicService
|
||||
// CreateRequest struct for BasicService
|
||||
type CreateRequest struct {
|
||||
// Name of the service
|
||||
// Required: true
|
||||
@@ -31,9 +31,7 @@ type CreateRequest struct {
|
||||
func (b BService) 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)
|
||||
}
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/create"
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete basic service
|
||||
// DeleteRequest struct to delete basic service
|
||||
type DeleteRequest struct {
|
||||
// ID of the BasicService to be delete
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
|
||||
// If set to False, Basic service will be deleted to recycle bin. Otherwise destroyed immediately
|
||||
// Required: false
|
||||
@@ -23,9 +23,7 @@ type DeleteRequest struct {
|
||||
func (b BService) 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)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/delete"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for disable service
|
||||
// DisableRequest struct for disable service
|
||||
type DisableRequest struct {
|
||||
// ID of the service to disable
|
||||
// Required: true
|
||||
@@ -21,9 +21,7 @@ type DisableRequest struct {
|
||||
func (b BService) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/delete"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for disable service
|
||||
// EnableRequest struct to disable service
|
||||
type EnableRequest struct {
|
||||
// ID of the service to enable
|
||||
// Required: true
|
||||
@@ -22,9 +22,7 @@ type EnableRequest struct {
|
||||
func (b BService) Enable(ctx context.Context, req EnableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/enable"
|
||||
|
||||
@@ -8,35 +8,39 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get detailed information about service
|
||||
// GetRequest struct to get detailed information about service
|
||||
type GetRequest struct {
|
||||
// ID of the service to query information
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets detailed specifications for the BasicService.
|
||||
// Get gets detailed specifications for the BasicService as a RecordBasicService struct
|
||||
func (b BService) Get(ctx context.Context, req GetRequest) (*RecordBasicService, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/get"
|
||||
|
||||
bsRaw, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
res, err := b.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordBasicService{}
|
||||
|
||||
err = json.Unmarshal(bsRaw, &info)
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets detailed specifications for the BasicService as an array of bytes
|
||||
func (b BService) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/get"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -8,42 +8,42 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create new compute group within BasicService
|
||||
// GroupAddRequest struct to create new compute group within BasicService
|
||||
type GroupAddRequest struct {
|
||||
// ID of the Basic Service to add a group to
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
|
||||
// Name of the Compute Group to add
|
||||
// Required: true
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
Name string `url:"name" json:"name" validate:"required"`
|
||||
|
||||
// Computes number. Defines how many computes must be there in the group
|
||||
// Required: true
|
||||
Count uint64 `url:"count" json:"count" validate:"required"`
|
||||
Count uint64 `url:"count" json:"count" validate:"required"`
|
||||
|
||||
// Compute CPU number. All computes in the group have the same CPU count
|
||||
// Required: true
|
||||
CPU uint64 `url:"cpu" json:"cpu" validate:"required"`
|
||||
CPU uint64 `url:"cpu" json:"cpu" validate:"required"`
|
||||
|
||||
// Compute RAM volume in MB. All computes in the group have the same RAM volume
|
||||
// Required: true
|
||||
RAM uint64 `url:"ram" json:"ram" validate:"required"`
|
||||
RAM uint64 `url:"ram" json:"ram" validate:"required"`
|
||||
|
||||
// Compute boot disk size in GB
|
||||
// Required: true
|
||||
Disk uint64 `url:"disk" json:"disk" validate:"required"`
|
||||
Disk uint64 `url:"disk" json:"disk" validate:"required"`
|
||||
|
||||
// OS image ID to create computes from
|
||||
// Required: true
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
ImageID uint64 `url:"imageId" json:"imageId" validate:"required"`
|
||||
|
||||
// Compute driver
|
||||
// should be one of:
|
||||
// - KVM_X86
|
||||
// - KVM_PPC
|
||||
// Required: true
|
||||
Driver string `url:"driver" json:"driver" validate:"driver"`
|
||||
Driver string `url:"driver" json:"driver" validate:"driver"`
|
||||
|
||||
// Storage endpoint provider ID
|
||||
// Required: false
|
||||
@@ -68,6 +68,10 @@ type GroupAddRequest struct {
|
||||
// Time of Compute Group readiness
|
||||
// Required: false
|
||||
TimeoutStart uint64 `url:"timeoutStart,omitempty" json:"timeoutStart,omitempty"`
|
||||
|
||||
// Meta data for working group computes, format YAML "user_data": 1111
|
||||
// Required: false
|
||||
UserData string `url:"userData,omitempty" json:"userData,omitempty"`
|
||||
}
|
||||
|
||||
// GroupAdd creates new Compute Group within BasicService.
|
||||
@@ -76,9 +80,7 @@ type GroupAddRequest struct {
|
||||
func (b BService) GroupAdd(ctx context.Context, req GroupAddRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupAdd"
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for remove group compute
|
||||
// GroupComputeRemoveRequest struct to remove group compute
|
||||
type GroupComputeRemoveRequest struct {
|
||||
// ID of the Basic Service
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
|
||||
// ID of the Compute GROUP
|
||||
// Required: true
|
||||
@@ -27,9 +27,7 @@ type GroupComputeRemoveRequest struct {
|
||||
func (b BService) GroupComputeRemove(ctx context.Context, req GroupComputeRemoveRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupComputeRemove"
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get detailed information about Compute Group
|
||||
// GroupGetRequest struct to get detailed information about Compute Group
|
||||
type GroupGetRequest struct {
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
|
||||
// ID of the Compute Group
|
||||
// Required: true
|
||||
@@ -23,9 +23,7 @@ type GroupGetRequest struct {
|
||||
func (b BService) GroupGet(ctx context.Context, req GroupGetRequest) (*RecordGroup, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupGet"
|
||||
|
||||
@@ -8,12 +8,11 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for add parent Compute Group relation emove parent Compute Group
|
||||
// relation to the specified Compute Group
|
||||
// GroupParentAddRequest struct to add parent Compute Group relation to the specified Compute Group
|
||||
type GroupParentAddRequest struct {
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
|
||||
// ID of the Compute Group
|
||||
// Required: true
|
||||
@@ -28,9 +27,7 @@ type GroupParentAddRequest struct {
|
||||
func (b BService) GroupParentAdd(ctx context.Context, req GroupParentAddRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupParentAdd"
|
||||
|
||||
@@ -8,30 +8,28 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for remove parent Compute Group
|
||||
// relation to the specified Compute Group
|
||||
// GroupParentRemoveRequest struct to remove parent Compute Group
|
||||
// relation from the specified Compute Group
|
||||
type GroupParentRemoveRequest struct {
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
|
||||
// ID of the Compute Group
|
||||
// Required: true
|
||||
CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
|
||||
CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
|
||||
|
||||
// ID of the parent Compute Group
|
||||
// to remove from the current Compute Group
|
||||
// Required: true
|
||||
ParentID uint64 `url:"parentId" json:"parentId" validate:"required"`
|
||||
ParentID uint64 `url:"parentId" json:"parentId" validate:"required"`
|
||||
}
|
||||
|
||||
// GroupParentRemove removes parent Compute Group relation to the specified Compute Group
|
||||
func (b BService) GroupParentRemove(ctx context.Context, req GroupParentRemoveRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupParentRemove"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for destroy the specified Compute Group
|
||||
// GroupRemoveRequest struct for destroy the specified Compute Group
|
||||
type GroupRemoveRequest struct {
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
@@ -23,9 +23,7 @@ type GroupRemoveRequest struct {
|
||||
func (b BService) GroupRemove(ctx context.Context, req GroupRemoveRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupRemove"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for resize the group
|
||||
// GroupResizeRequest struct to resize the group
|
||||
type GroupResizeRequest struct {
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
@@ -34,9 +34,7 @@ type GroupResizeRequest struct {
|
||||
func (b BService) GroupResize(ctx context.Context, req GroupResizeRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupResize"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for start the specified Compute Group
|
||||
// GroupStartRequest struct to start the specified Compute Group
|
||||
type GroupStartRequest struct {
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
@@ -23,9 +23,7 @@ type GroupStartRequest struct {
|
||||
func (b BService) GroupStart(ctx context.Context, req GroupStartRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupStart"
|
||||
|
||||
@@ -8,15 +8,15 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for stop the specified Compute Group
|
||||
// GroupStopRequest struct to stop the specified Compute Group
|
||||
type GroupStopRequest struct {
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
|
||||
// ID of the Compute Group to stop
|
||||
// Required: true
|
||||
CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
|
||||
CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
|
||||
|
||||
// Force stop Compute Group
|
||||
// Required: false
|
||||
@@ -27,9 +27,7 @@ type GroupStopRequest struct {
|
||||
func (b BService) GroupStop(ctx context.Context, req GroupStopRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupStop"
|
||||
|
||||
@@ -8,15 +8,15 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update existing Compute group
|
||||
// GroupUpdateRequest struct to update existing Compute group
|
||||
type GroupUpdateRequest struct {
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
||||
|
||||
// ID of the Compute Group
|
||||
// Required: true
|
||||
CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
|
||||
CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
|
||||
|
||||
// Specify non-empty string to update Compute Group name
|
||||
// Required: false
|
||||
@@ -47,9 +47,7 @@ type GroupUpdateRequest struct {
|
||||
func (b BService) GroupUpdate(ctx context.Context, req GroupUpdateRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupUpdate"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update External Network settings
|
||||
// GroupUpdateExtNetRequest struct to update External Network settings
|
||||
type GroupUpdateExtNetRequest struct {
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
@@ -27,9 +27,7 @@ type GroupUpdateExtNetRequest struct {
|
||||
func (b BService) GroupUpdateExtNet(ctx context.Context, req GroupUpdateExtNetRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupUpdateExtnet"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for update VINS settings
|
||||
// GroupUpdateVINSRequest struct to update VINS settings
|
||||
type GroupUpdateVINSRequest struct {
|
||||
// ID of the Basic Service of Compute Group
|
||||
// Required: true
|
||||
@@ -27,9 +27,7 @@ type GroupUpdateVINSRequest struct {
|
||||
func (b BService) GroupUpdateVINS(ctx context.Context, req GroupUpdateVINSRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/groupUpdateVins"
|
||||
|
||||
37
pkg/cloudapi/bservice/ids.go
Normal file
37
pkg/cloudapi/bservice/ids.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package bservice
|
||||
|
||||
// IDs gets array of BasicServiceIDs from ListBasicServices struct
|
||||
func (lbs ListBasicServices) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lbs.Data))
|
||||
for _, bs := range lbs.Data {
|
||||
res = append(res, bs.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of ComputeIDs from ListComputes struct
|
||||
func (lc ListComputes) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lc))
|
||||
for _, c := range lc {
|
||||
res = append(res, c.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of GroupIDs from ListGroups struct
|
||||
func (lg ListGroups) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lg))
|
||||
for _, g := range lg {
|
||||
res = append(res, g.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of GroupComputeIDs from ListGroupComputes struct
|
||||
func (lgc ListGroupComputes) IDs() []uint64 {
|
||||
res := make([]uint64, 0, len(lgc))
|
||||
for _, gc := range lgc {
|
||||
res = append(res, gc.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list BasicService instances
|
||||
// ListRequest struct to get list of BasicService instances
|
||||
type ListRequest struct {
|
||||
// Find by ID
|
||||
// Required: false
|
||||
@@ -49,11 +49,9 @@ type ListRequest struct {
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// List gets list BasicService instances associated with the specified Resource Group
|
||||
// List gets list of BasicService instances associated with the specified Resource Group as a ListBasicServices struct
|
||||
func (b BService) List(ctx context.Context, req ListRequest) (*ListBasicServices, error) {
|
||||
url := "/cloudapi/bservice/list"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
res, err := b.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -67,3 +65,11 @@ func (b BService) List(ctx context.Context, req ListRequest) (*ListBasicServices
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
// ListRaw gets list of BasicService instances associated with the specified Resource Group as an array of bytes
|
||||
func (b BService) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
||||
url := "/cloudapi/bservice/list"
|
||||
|
||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Request struct for get list of deleted BasicService instances
|
||||
// ListDeletedRequest struct to get list of deleted BasicService instances
|
||||
type ListDeletedRequest struct {
|
||||
// ID of the account to query for BasicService instances
|
||||
// Required: false
|
||||
@@ -25,7 +25,7 @@ type ListDeletedRequest struct {
|
||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
||||
}
|
||||
|
||||
// ListDeleted gets list deleted BasicService instances associated with the specified Resource Group
|
||||
// ListDeleted gets list of deleted BasicService instances associated with the specified Resource Group
|
||||
func (b BService) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListBasicServices, error) {
|
||||
url := "/cloudapi/bservice/listDeleted"
|
||||
|
||||
|
||||
@@ -168,9 +168,18 @@ type ItemSnapshot struct {
|
||||
Valid bool `json:"valid"`
|
||||
}
|
||||
|
||||
// List of Snapshots
|
||||
// List of Snapshot
|
||||
type ListSnapshots []ItemSnapshot
|
||||
|
||||
// List of Snapshots
|
||||
type ListInfoSnapshots struct {
|
||||
// Data
|
||||
Data ListSnapshots `json:"data"`
|
||||
|
||||
// EntryCount
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
// Main information about Group
|
||||
type RecordGroup struct {
|
||||
// Account ID
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for restores BasicService instance
|
||||
// RestoreRequest struct to restore BasicService instance
|
||||
type RestoreRequest struct {
|
||||
// ID of the BasicService to be restored
|
||||
// Required: true
|
||||
@@ -19,9 +19,7 @@ type RestoreRequest struct {
|
||||
func (b BService) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/restore"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create snapshot
|
||||
// SnapshotCreateRequest struct to create snapshot
|
||||
type SnapshotCreateRequest struct {
|
||||
// ID of the Basic Service
|
||||
// Required: true
|
||||
@@ -23,9 +23,7 @@ type SnapshotCreateRequest struct {
|
||||
func (b BService) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/snapshotCreate"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete snapshot
|
||||
// SnapshotDeleteRequest struct to delete snapshot
|
||||
type SnapshotDeleteRequest struct {
|
||||
// ID of the Basic Service
|
||||
// Required: true
|
||||
@@ -23,9 +23,7 @@ type SnapshotDeleteRequest struct {
|
||||
func (b BService) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/snapshotDelete"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get list existing snapshots
|
||||
// SnapshotListRequest struct to get list of existing snapshots
|
||||
type SnapshotListRequest struct {
|
||||
// ID of the Basic Service
|
||||
// Required: true
|
||||
@@ -16,12 +16,10 @@ type SnapshotListRequest struct {
|
||||
}
|
||||
|
||||
// SnapshotList gets list existing snapshots of the Basic Service
|
||||
func (b BService) SnapshotList(ctx context.Context, req SnapshotListRequest) (ListSnapshots, error) {
|
||||
func (b BService) SnapshotList(ctx context.Context, req SnapshotListRequest) (*ListInfoSnapshots, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/snapshotList"
|
||||
@@ -31,12 +29,12 @@ func (b BService) SnapshotList(ctx context.Context, req SnapshotListRequest) (Li
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := ListSnapshots{}
|
||||
list := ListInfoSnapshots{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
return &list, nil
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for rollback snapshot
|
||||
// SnapshotRollbackRequest struct to rollback snapshot
|
||||
type SnapshotRollbackRequest struct {
|
||||
// ID of the Basic Service
|
||||
// Required: true
|
||||
@@ -23,9 +23,7 @@ type SnapshotRollbackRequest struct {
|
||||
func (b BService) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/snapshotRollback"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for start service
|
||||
// StartRequest struct to start service
|
||||
type StartRequest struct {
|
||||
// ID of the service to start
|
||||
// Required: true
|
||||
@@ -21,9 +21,7 @@ type StartRequest struct {
|
||||
func (b BService) Start(ctx context.Context, req StartRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/start"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for stop service
|
||||
// StopRequest struct to stop service
|
||||
type StopRequest struct {
|
||||
// ID of the service to stop
|
||||
// Required: true
|
||||
@@ -21,9 +21,7 @@ type StopRequest struct {
|
||||
func (b BService) Stop(ctx context.Context, req StopRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/bservice/stop"
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for check all computes with current affinity label can start
|
||||
// AffinityGroupCheckStartRequest struct to check all computes with current affinity label can start
|
||||
type AffinityGroupCheckStartRequest struct {
|
||||
// ID of the resource group
|
||||
// Required: true
|
||||
@@ -22,9 +22,7 @@ type AffinityGroupCheckStartRequest struct {
|
||||
func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/affinityGroupCheckStart"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for clear affinity label for compute
|
||||
// AffinityLabelRemoveRequest struct to clear affinity label for compute
|
||||
type AffinityLabelRemoveRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
@@ -19,9 +19,7 @@ type AffinityLabelRemoveRequest struct {
|
||||
func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/affinityLabelRemove"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for set affinity label for compute
|
||||
// AffinityLabelSetRequest struct to set affinity label for compute
|
||||
type AffinityLabelSetRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
@@ -23,9 +23,7 @@ type AffinityLabelSetRequest struct {
|
||||
func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/affinityLabelSet"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get dict of computes
|
||||
// AffinityRelationsRequest struct to get dict of computes
|
||||
type AffinityRelationsRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
@@ -19,9 +19,7 @@ type AffinityRelationsRequest struct {
|
||||
func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest) (*RecordAffinityRelations, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/affinityRelations"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for add affinity rule
|
||||
// AffinityRuleAddRequest struct to add affinity rule
|
||||
type AffinityRuleAddRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
@@ -46,9 +46,7 @@ type AffinityRuleAddRequest struct {
|
||||
func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/affinityRuleAdd"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for remove affinity rule
|
||||
// AffinityRuleRemoveRequest struct to remove affinity rule
|
||||
type AffinityRuleRemoveRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
@@ -46,9 +46,7 @@ type AffinityRuleRemoveRequest struct {
|
||||
func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/affinityRuleRemove"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for clear affinity rules
|
||||
// AffinityRulesClearRequest struct to clear affinity rules
|
||||
type AffinityRulesClearRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
@@ -19,9 +19,7 @@ type AffinityRulesClearRequest struct {
|
||||
func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/affinityRulesClear"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for add anti affinity rule
|
||||
// AntiAffinityRuleAddRequest struct to add anti affinity rule
|
||||
type AntiAffinityRuleAddRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
@@ -46,9 +46,7 @@ type AntiAffinityRuleAddRequest struct {
|
||||
func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/antiAffinityRuleAdd"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for remove anti affinity rule
|
||||
// AntiAffinityRuleRemoveRequest struct to remove anti affinity rule
|
||||
type AntiAffinityRuleRemoveRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
@@ -46,9 +46,7 @@ type AntiAffinityRuleRemoveRequest struct {
|
||||
func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/antiAffinityRuleRemove"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for clear anti affinity rules
|
||||
// AntiAffinityRulesClearRequest struct to clear anti affinity rules
|
||||
type AntiAffinityRulesClearRequest struct {
|
||||
// ID of the compute instance
|
||||
// Required: true
|
||||
@@ -19,9 +19,7 @@ type AntiAffinityRulesClearRequest struct {
|
||||
func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/antiAffinityRulesClear"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for attach GPU for compute
|
||||
// AttachGPURequest struct to attach GPU for compute
|
||||
type AttachGPURequest struct {
|
||||
// Identifier compute
|
||||
// Required: true
|
||||
@@ -23,9 +23,7 @@ type AttachGPURequest struct {
|
||||
func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/attachGpu"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for atttach PCI device
|
||||
// AttachPCIDeviceRequest struct to attach PCI device
|
||||
type AttachPCIDeviceRequest struct {
|
||||
// Identifier compute
|
||||
// Required: true
|
||||
@@ -23,9 +23,7 @@ type AttachPCIDeviceRequest struct {
|
||||
func (c Compute) AttachPCIDevice(ctx context.Context, req AttachPCIDeviceRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/attachPciDevice"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for get audit records
|
||||
// AuditsRequest struct to get audit records
|
||||
type AuditsRequest struct {
|
||||
// ID of the compute
|
||||
// Required: true
|
||||
@@ -19,9 +19,7 @@ type AuditsRequest struct {
|
||||
func (c Compute) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/audits"
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for getting boot order
|
||||
// BootOrderGetRequest struct to get boot order
|
||||
type BootOrderGetRequest struct {
|
||||
// Compute ID
|
||||
// Required: true
|
||||
@@ -18,9 +18,7 @@ type BootOrderGetRequest struct {
|
||||
func (c Compute) BootOrderGet(ctx context.Context, req BootOrderGetRequest) ([]string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/bootOrderGet"
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for setting boot order
|
||||
// BootOrderSetRequest struct to set boot order
|
||||
type BootOrderSetRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
@@ -26,9 +26,7 @@ type BootOrderSetRequest struct {
|
||||
func (c Compute) BootOrderSet(ctx context.Context, req BootOrderSetRequest) ([]string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return nil, validators.ValidationError(validationError)
|
||||
}
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/bootOrderSet"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for eject CD image
|
||||
// CDEjectRequest struct to eject CD image
|
||||
type CDEjectRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
@@ -19,9 +19,7 @@ type CDEjectRequest struct {
|
||||
func (c Compute) CDEject(ctx context.Context, req CDEjectRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/cdEject"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for insert new CD image
|
||||
// CDInsertRequest struct to insert new CD image
|
||||
type CDInsertRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
@@ -23,9 +23,7 @@ type CDInsertRequest struct {
|
||||
func (c Compute) CDInsert(ctx context.Context, req CDInsertRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/cdInsert"
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// Request struct for changing link state
|
||||
// ChangeLinkStateRequest struct to change link state
|
||||
type ChangeLinkStateRequest struct {
|
||||
// Compute ID
|
||||
// Required: true
|
||||
@@ -27,9 +27,7 @@ type ChangeLinkStateRequest struct {
|
||||
func (c Compute) ChangeLinkState(ctx context.Context, req ChangeLinkStateRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/changeLinkState"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for clone compute instance
|
||||
// CloneRequest struct to clone compute instance
|
||||
type CloneRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
@@ -31,9 +31,7 @@ type CloneRequest struct {
|
||||
func (c Compute) Clone(ctx context.Context, req CloneRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/clone"
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create template
|
||||
// CreateTemplateRequest struct to create template
|
||||
type CreateTemplateRequest struct {
|
||||
// ID of the compute to create template from
|
||||
// Required: true
|
||||
@@ -30,9 +30,7 @@ type wrapperCreateTemplateRequest struct {
|
||||
func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateTemplateRequest{
|
||||
@@ -59,9 +57,7 @@ func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest)
|
||||
func (c Compute) CreateTemplateAsync(ctx context.Context, req CreateTemplateRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return "", validators.ValidationError(validationError)
|
||||
}
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
reqWrapped := wrapperCreateTemplateRequest{
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for delete compute
|
||||
// DeleteRequest struct to delete compute
|
||||
type DeleteRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
@@ -27,9 +27,7 @@ type DeleteRequest struct {
|
||||
func (c Compute) 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)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/delete"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for deleting compute's custome fields
|
||||
// DeleteCustomFieldsRequest struct to delete compute's custom fields
|
||||
type DeleteCustomFieldsRequest struct {
|
||||
// ID of the compute
|
||||
// Required: true
|
||||
@@ -19,9 +19,7 @@ type DeleteCustomFieldsRequest struct {
|
||||
func (c Compute) DeleteCustomFields(ctx context.Context, req DeleteCustomFieldsRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/deleteCustomFields"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for detach vgpu for compute
|
||||
// DetachGPURequest struct to detach vgpu for compute
|
||||
type DetachGPURequest struct {
|
||||
// Identifier compute
|
||||
// Required: true
|
||||
@@ -24,9 +24,7 @@ type DetachGPURequest struct {
|
||||
func (c Compute) DetachGPU(ctx context.Context, req DetachGPURequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/detachGpu"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for detach PCI device
|
||||
// DetachPCIDeviceRequest struct to detach PCI device
|
||||
type DetachPCIDeviceRequest struct {
|
||||
// Identifier compute
|
||||
// Required: true
|
||||
@@ -23,9 +23,7 @@ type DetachPCIDeviceRequest struct {
|
||||
func (c Compute) DetachPCIDevice(ctx context.Context, req DetachPCIDeviceRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/detachPciDevice"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for disable compute
|
||||
// DisableRequest struct to disable compute
|
||||
type DisableRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
@@ -19,9 +19,7 @@ type DisableRequest struct {
|
||||
func (c Compute) Disable(ctx context.Context, req DisableRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return false, validators.ValidationError(validationError)
|
||||
}
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/disable"
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// Request struct for create and attach disk to compute
|
||||
// DiskAddRequest struct to create and attach disk to compute
|
||||
type DiskAddRequest struct {
|
||||
// ID of compute instance
|
||||
// Required: true
|
||||
@@ -52,9 +52,7 @@ type DiskAddRequest struct {
|
||||
func (c Compute) DiskAdd(ctx context.Context, req DiskAddRequest) (uint64, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
for _, validationError := range validators.GetErrors(err) {
|
||||
return 0, validators.ValidationError(validationError)
|
||||
}
|
||||
return 0, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/compute/diskAdd"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user