Compare commits

..

4 Commits

Author SHA1 Message Date
1972956aeb v1.6.0-gamma 2023-09-15 12:41:04 +03:00
afcbc7e749 1.6.0-beta 2023-09-14 15:05:38 +03:00
0b3de4df7f 1.6.0-alfa 2023-09-11 13:11:33 +03:00
c0608d08b9 1.5.8-gostech 2023-09-07 18:11:25 +03:00
730 changed files with 3428 additions and 6202 deletions

View File

@@ -1,4 +1,4 @@
## Version 1.6.11
## Version 1.6.0-beta
## Bugfix
- Remove tag "required" from field Value in AffinityRuleAddRequest, AntiAffinityRuleAddRequest, AffinityRuleRemoveRequest AntiAffinityRuleRemoveRequest in cloudapi/compute and cloudbroker/compute
### Bugfix
- Refactored client, made it concurrent safe

152
README.md
View File

@@ -10,7 +10,6 @@ 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 версии платформы
## Оглавление
@@ -63,11 +62,12 @@ 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,7 +75,6 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
- `Locations` - получение информации о grid площадки;
- `RG` - управление ресурсными группами аккаунта;
- `Sizes` - получение информации о потребляемых ресурсах виртуальными машинами и дисками;
- `Stack` - получение информации о вычислительных узлах;
- `Tasks` - получение информации о ходе выполнения асинхронных задач (например, создание кластера);
- `VINS` - управление виртуальными изолированными сетями.
@@ -85,39 +84,30 @@ 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. Выполнение запроса.
1. Настройка конфигурации клиента.
2. Парсинг конфигурации из файла.
3. Создание клиента.
4. Создание структуры запроса.
5. Выполнение запроса.
### Настройка конфигурации клиента
@@ -130,7 +120,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата |
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
| Token | string | Нет | JWT токен |
#### Пример конфигурации клиента
@@ -241,6 +231,7 @@ 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`
@@ -252,33 +243,24 @@ func main() {
- `pkg/cloudapi/lb` - для `LB`
- `pkg/cloudapi/locations` - для `Locations`
- `pkg/cloudapi/rg` - для `RG`
- `pkg/cloudapi/sizes` - для `Sizes`
- `pkg/cloudapi/stack` - для `Stack`
- `pkg/cloudapi/sizes` - для `RG`
- `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`
Все поля структуры имеют описание, в которых содержится:
@@ -415,7 +397,7 @@ func main() {
Чтобы выполнить запрос, необходимо:
1. Вызвать у клиента метод, отвечаеющий за определение группы API для взаимодействия, это может быть `.CloudAPI()`, либо `.CloudBroker()`. Данные методы возвращаеют соответствующие структуры, с помощью которых можно совершать запросы.
1. Вызвать у клиента метод, отвечаеющий за определение группы API для взаимодействия, это может быть `.CloudAPI()`, либо `.CloudBroker()`. Данные методы возвращаеют соответствующие структуры, с помощью которых можно соверать запросы.
2. Вызвать у возвращенной структуры метод, определяющий группу ручек для взаимодействия.
Доступные методы для `.CloudAPI()`:
@@ -423,6 +405,7 @@ func main() {
- `.Account()` - для работы с `Account`
- `.BService()` - для работы с `BService`
- `.Compute()` - для работы с `Compute`
- `.ComputeCI()` - для работы с `ComputeCI`
- `.Disks()` - для работы с `Disks`
- `.ExtNet()` - для работы с `ExtNet`
- `.FLIPgroup()` - для работы с `FLIPGroup`
@@ -435,46 +418,37 @@ 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>.<группа>.<метод>
@@ -527,56 +501,6 @@ 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()`, например:
@@ -766,52 +690,6 @@ 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.
@@ -827,7 +705,7 @@ func main() {
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата |
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
| Token | string | Нет | JWT токен |
#### Пример конфигурации legacy клиента

319
client.go
View File

@@ -4,21 +4,19 @@ import (
"bytes"
"context"
"crypto/tls"
"errors"
"fmt"
"io"
"mime/multipart"
"net/http"
"strconv"
"strings"
"sync"
"time"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
"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
@@ -70,23 +68,12 @@ 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) {
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())
values, err := query.Values(params)
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 {
return nil, err
@@ -96,11 +83,22 @@ func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, p
return nil, err
}
// perform request
var respBytes []byte
respBytes, err = dc.do(req, ctype)
resp, err := dc.do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return respBytes, err
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 (dc *DecortClient) getToken(ctx context.Context) error {
@@ -137,262 +135,29 @@ func (dc *DecortClient) getToken(ctx context.Context) error {
return nil
}
func (dc *DecortClient) do(req *http.Request, ctype string) ([]byte, error) {
if ctype != "" {
req.Header.Add("Content-Type", ctype)
} else {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
}
func (dc *DecortClient) do(req *http.Request) (*http.Response, error) {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Authorization", "bearer "+dc.cfg.Token)
req.Header.Set("Accept", "application/json")
buf, err := io.ReadAll(req.Body)
if err != nil {
return nil, err
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()
}
}
req.Body = io.NopCloser(bytes.NewBuffer(buf))
resp, err := dc.client.Do(req)
if err != nil || resp == nil {
return nil, err
}
defer resp.Body.Close()
// handle successful request
respBytes, _ := io.ReadAll(resp.Body)
if resp.StatusCode == 200 {
return respBytes, nil
}
// handle errors with status code other than 200
err = fmt.Errorf("%s", respBytes)
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)
defer writer.Close()
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()
return reqBody, ct
}
func createK8sCloudBroker(req k8s_cb.CreateRequest) (*bytes.Buffer, string) {
reqBody := &bytes.Buffer{}
writer := multipart.NewWriter(reqBody)
defer writer.Close()
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()
return reqBody, ct
}

View File

@@ -42,7 +42,7 @@ type Config struct {
// Required: false
Retries uint64 `json:"retries" yaml:"retries"`
// Skip verify
// Skip verify, true by default
// Required: false
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
@@ -72,7 +72,9 @@ func ParseConfigJSON(path string) (Config, error) {
err = validators.ValidateConfig(config)
if err != nil {
return Config{}, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return Config{}, validators.ValidationError(validationError)
}
}
return config, nil
@@ -94,7 +96,9 @@ func ParseConfigYAML(path string) (Config, error) {
err = validators.ValidateConfig(config)
if err != nil {
return Config{}, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return Config{}, validators.ValidationError(validationError)
}
}
return config, nil

View File

@@ -36,7 +36,7 @@ type LegacyConfig struct {
// Required: false
Retries uint64 `json:"retries" yaml:"retries"`
// Skip verify
// Skip verify, true by default
// Required: false
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
@@ -66,7 +66,9 @@ func ParseLegacyConfigJSON(path string) (LegacyConfig, error) {
err = validators.ValidateConfig(config)
if err != nil {
return LegacyConfig{}, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return LegacyConfig{}, validators.ValidationError(validationError)
}
}
return config, nil
@@ -88,7 +90,9 @@ func ParseLegacyConfigYAML(path string) (LegacyConfig, error) {
err = validators.ValidateConfig(config)
if err != nil {
return LegacyConfig{}, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return LegacyConfig{}, validators.ValidationError(validationError)
}
}
return config, nil

View File

@@ -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)
}
}

View File

@@ -1,41 +0,0 @@
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
}

View File

@@ -2,7 +2,6 @@ package validators
import (
"errors"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/multierror"
"github.com/go-playground/validator/v10"
)
@@ -21,14 +20,6 @@ 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)

View File

@@ -4,12 +4,11 @@ import (
"bytes"
"context"
"crypto/tls"
"errors"
"fmt"
"io"
"mime/multipart"
"net/http"
"net/url"
"strconv"
"strings"
"sync"
"time"
@@ -17,9 +16,7 @@ import (
"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"
)
// Legacy HTTP-client for platform
@@ -71,38 +68,38 @@ 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) {
if err := ldc.getToken(ctx); err != nil {
values, err := query.Values(params)
if 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))
if err = ldc.getToken(ctx); err != nil {
return nil, err
}
body := strings.NewReader(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
}
// perform request
var respBytes []byte
respBytes, err = ldc.do(req, ctype)
resp, err := ldc.do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return respBytes, err
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 (ldc *LegacyDecortClient) getToken(ctx context.Context) error {
@@ -136,268 +133,28 @@ func (ldc *LegacyDecortClient) getToken(ctx context.Context) error {
return nil
}
func (ldc *LegacyDecortClient) do(req *http.Request, ctype string) ([]byte, error) {
if ctype != "" {
req.Header.Add("Content-Type", ctype)
} else {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
}
func (ldc *LegacyDecortClient) do(req *http.Request) (*http.Response, error) {
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Accept", "application/json")
buf, err := io.ReadAll(req.Body)
if err != nil {
return nil, err
}
req.Body.Close()
req.Body = io.NopCloser(bytes.NewBuffer(buf))
var resp *http.Response
var err error
buf, _ := io.ReadAll(req.Body)
resp, err := ldc.client.Do(req)
if err != nil || resp == nil {
return nil, err
}
defer resp.Body.Close()
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)
// handle successful request
respBytes, err := io.ReadAll(resp.Body)
if err!= nil {
return nil, err
}
if resp.StatusCode == 200 {
return respBytes, nil
if err == nil {
if resp.StatusCode == 200 {
return resp, err
}
respBytes, _ := io.ReadAll(resp.Body)
err = fmt.Errorf("%s", respBytes)
resp.Body.Close()
}
}
// handle errors with status code other than 200
err = fmt.Errorf("%s", respBytes)
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)
defer writer.Close()
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()
return reqBody, ct
}
func createK8sCloudBrokerLegacy(req k8s_cb.CreateRequest, token string) (*bytes.Buffer, string) {
reqBody := &bytes.Buffer{}
writer := multipart.NewWriter(reqBody)
defer writer.Close()
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()
return reqBody, ct
}

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AddUserRequest struct to add permission to access account for a user
// Request struct for adding permission to access to account for a user
type AddUserRequest struct {
// ID of account to add to
// Required: true
@@ -30,7 +30,9 @@ type AddUserRequest struct {
func (a Account) AddUser(ctx context.Context, req AddUserRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/addUser"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AuditsRequest struct to give list of account audits
// Request struct for give list account audits
type AuditsRequest struct {
// ID of the account
// Required: true
@@ -19,7 +19,9 @@ type AuditsRequest struct {
func (a Account) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/audits"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// CreateRequest struct for creating account
// Request struct for creating account
type CreateRequest struct {
// Display name
// Required: true
@@ -56,7 +56,9 @@ type CreateRequest struct {
func (a Account) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/create"

View File

@@ -7,7 +7,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DeleteRequest struct to delete account
// Request struct for delete account
type DeleteRequest struct {
// ID of account to delete
// Required: true
@@ -22,7 +22,9 @@ type DeleteRequest struct {
func (a Account) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/delete"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DeleteUserRequest struct to revoke access to account
// Request struct for revoke access to account
type DeleteUserRequest struct {
// ID of the account
// Required: true
@@ -20,14 +20,16 @@ type DeleteUserRequest struct {
// Recursively revoke access rights from owned cloudspaces and vmachines
// Required: false
RecursiveDelete bool `url:"recursivedelete" json:"recursivedelete"`
RecursiveDelete bool `url:"recursivedelete,omitempty" json:"recursivedelete,omitempty"`
}
// 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 {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/deleteUser"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DisableEnableRequest struct to change status of account
// Request struct for change status of account
type DisableEnableRequest struct {
// ID of account
// Required: true
@@ -19,7 +19,9 @@ type DisableEnableRequest struct {
func (a Account) Disable(ctx context.Context, req DisableEnableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/disable"
@@ -41,7 +43,9 @@ 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 {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/enable"

View File

@@ -8,16 +8,25 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetRequest struct to get information about account
// Request struct for 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 as a RecordAccount struct
// Get gets account details
func (a Account) Get(ctx context.Context, req GetRequest) (*RecordAccount, error) {
res, err := a.GetRaw(ctx, req)
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)
if err != nil {
return nil, err
}
@@ -32,16 +41,3 @@ 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
}

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetConsumedAccountUnitsRequest struct to calculate the currently consumed units for all cloudspaces and resource groups in the account
// Request struct for calculate the currently consumed units for all cloudspaces and resource groups in the account
type GetConsumedAccountUnitsRequest struct {
// ID an account
// Required: true
@@ -25,7 +25,9 @@ type GetConsumedAccountUnitsRequest struct {
func (a Account) GetConsumedAccountUnits(ctx context.Context, req GetConsumedAccountUnitsRequest) (*ResourceLimits, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/getConsumedAccountUnits"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetConsumedCloudUnitsByTypeRequest struct to calculate the currently consumed cloud units of the specified type for all cloudspaces and resource groups in the account
// Request struct for 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,7 +35,9 @@ type GetConsumedCloudUnitsByTypeRequest struct {
func (a Account) GetConsumedCloudUnitsByType(ctx context.Context, req GetConsumedCloudUnitsByTypeRequest) (float64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/getConsumedCloudUnitsByType"

View File

@@ -7,7 +7,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetConsumptionRequest struct to download the resources tracking files for an account
// Request struct for download the resources tracking files for an account
type GetConsumptionRequest struct {
// ID an account
// Required: true
@@ -26,7 +26,9 @@ type GetConsumptionRequest struct {
func (a Account) GetConsumption(ctx context.Context, req GetConsumptionRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/getConsumption"
@@ -44,7 +46,9 @@ 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 {
return "", validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/getConsumption"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetReservedAccountUnitsRequest struct to calculate the reserved units for all cloudspaces and resource groups in the account
// Request struct for calculate the reserved units for all cloudspaces and resource groups in the account
type GetReservedAccountUnitsRequest struct {
// ID an account
// Required: true
@@ -26,7 +26,9 @@ type GetReservedAccountUnitsRequest struct {
func (a Account) GetReservedAccountUnits(ctx context.Context, req GetReservedAccountUnitsRequest) (*ResourceLimits, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/getReservedAccountUnits"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetResourceConsumptionRequest struct to get resource consumption
// Request struct for getting resource consumption
type GetResourceConsumptionRequest struct {
// ID an account
// Required: true
@@ -19,7 +19,9 @@ type GetResourceConsumptionRequest struct {
func (a Account) GetResourceConsumption(ctx context.Context, req GetResourceConsumptionRequest) (*RecordResourceConsumption, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/getResourceConsumption"

View File

@@ -1,73 +0,0 @@
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
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// ListRequest struct to get list of accounts
// Request struct for get list of accounts
type ListRequest struct {
// Find by ID
// Required: false
@@ -33,9 +33,11 @@ type ListRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets a list of all accounts the user has access to a ListAccounts struct
// List gets list all accounts the user has access to
func (a Account) List(ctx context.Context, req ListRequest) (*ListAccounts, error) {
res, err := a.ListRaw(ctx, req)
url := "/cloudapi/account/list"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
@@ -49,11 +51,3 @@ 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
}

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ListComputesRequest struct to get a list of compute instances
// Request struct for a get list compute instances
type ListComputesRequest struct {
// ID an account
// Required: true
@@ -59,7 +59,9 @@ type ListComputesRequest struct {
func (a Account) ListComputes(ctx context.Context, req ListComputesRequest) (*ListComputes, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/listComputes"

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// ListDeletedRequest struct to get a list of deleted accounts
// Request struct for get list 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 of all deleted accounts the user has access to
// ListDeleted gets list all deleted accounts the user has access to
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListAccounts, error) {
url := "/cloudapi/account/listDeleted"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ListDisksRequest struct to get a list of deleted disks
// Request struct for get list deleted disks
type ListDisksRequest struct {
// ID an account
// Required: true
@@ -43,7 +43,9 @@ type ListDisksRequest struct {
func (a Account) ListDisks(ctx context.Context, req ListDisksRequest) (*ListDisks, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/listDisks"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ListFLIPGroupsRequest struct to get a list of FLIPGroups
// Request struct for get list FLIPGroups
type ListFLIPGroupsRequest struct {
// ID of the account
// Required: true
@@ -51,7 +51,9 @@ type ListFLIPGroupsRequest struct {
func (a Account) ListFLIPGroups(ctx context.Context, req ListFLIPGroupsRequest) (*ListFLIPGroups, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/listFlipGroups"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ListRGRequest struct to get a list of resource groups
// Request struct for get list resource groups
type ListRGRequest struct {
// ID an account
// Required: true
@@ -43,11 +43,13 @@ type ListRGRequest struct {
Status string `url:"status,omitempty" json:"status,omitempty"`
}
// ListRG gets list of all resource groups under specified account, accessible by the user
// ListRG gets list 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 {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/listRG"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ListTemplatesRequest struct to get a list of templates
// Request struct for get list templates
type ListTemplatesRequest struct {
// ID an account
// Required: true
@@ -39,11 +39,13 @@ type ListTemplatesRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// ListTemplates gets list of templates which can be managed by this account
// ListTemplates gets list 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 {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/listTemplates"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// ListVINSRequest struct to get a list of VINS
// Request struct for get list VINS
type ListVINSRequest struct {
// ID an account
// Required: true
@@ -39,11 +39,13 @@ type ListVINSRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// ListVINS gets list of all ViNSes under specified account, accessible by the user
// ListVINS gets list 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 {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/listVins"

View File

@@ -88,7 +88,7 @@ type Resource struct {
DiskSize float64 `json:"disksize"`
// Max disk size
DiskSizeMax float64 `json:"disksizemax"`
DiskSizeMax uint64 `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
Consumed Resource `json:"consumed"`
Current Resource `json:"Current"`
// Reserved information about resources
Reserved Resource `json:"reserved"`
Reserved Resource `json:"Reserved"`
// Account ID
AccountID uint64 `json:"id"`

View File

@@ -6,7 +6,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// RestoreRequest struct to restore a deleted account
// Request struct for restore a deleted account
type RestoreRequest struct {
// ID an account
// Required: true
@@ -17,7 +17,9 @@ type RestoreRequest struct {
func (a Account) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/restore"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// UpdateRequest struct to update account
// Request struct for updaate account
type UpdateRequest struct {
// ID an account
// Required: true
@@ -51,7 +51,9 @@ type UpdateRequest struct {
func (a Account) Update(ctx context.Context, req UpdateRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/update"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// UpdateUserRequest struct to update user access rights
// Request struct for update user access rights
type UpdateUserRequest struct {
// ID of the account
// Required: true
@@ -30,7 +30,9 @@ type UpdateUserRequest struct {
func (a Account) UpdateUser(ctx context.Context, req UpdateUserRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/account/updateUser"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// CreateRequest struct for BasicService
// Request struct for BasicService
type CreateRequest struct {
// Name of the service
// Required: true
@@ -31,7 +31,9 @@ type CreateRequest struct {
func (b BService) Create(ctx context.Context, req CreateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/create"

View File

@@ -8,11 +8,11 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DeleteRequest struct to delete basic service
// Request struct for 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,7 +23,9 @@ type DeleteRequest struct {
func (b BService) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/delete"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DisableRequest struct for disable service
// Request struct for disable service
type DisableRequest struct {
// ID of the service to disable
// Required: true
@@ -21,7 +21,9 @@ type DisableRequest struct {
func (b BService) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/delete"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// EnableRequest struct to disable service
// Request struct for disable service
type EnableRequest struct {
// ID of the service to enable
// Required: true
@@ -22,7 +22,9 @@ type EnableRequest struct {
func (b BService) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/enable"

View File

@@ -8,39 +8,35 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetRequest struct to get detailed information about service
// Request struct for 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 as a RecordBasicService struct
// Get gets detailed specifications for the BasicService.
func (b BService) Get(ctx context.Context, req GetRequest) (*RecordBasicService, error) {
res, err := b.GetRaw(ctx, req)
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)
if err != nil {
return nil, err
}
info := RecordBasicService{}
err = json.Unmarshal(res, &info)
err = json.Unmarshal(bsRaw, &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
}

View File

@@ -8,42 +8,42 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GroupAddRequest struct to create new compute group within BasicService
// Request struct for 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,10 +68,6 @@ 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.
@@ -80,7 +76,9 @@ type GroupAddRequest struct {
func (b BService) GroupAdd(ctx context.Context, req GroupAddRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/groupAdd"

View File

@@ -8,11 +8,11 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GroupComputeRemoveRequest struct to remove group compute
// Request struct for 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,7 +27,9 @@ type GroupComputeRemoveRequest struct {
func (b BService) GroupComputeRemove(ctx context.Context, req GroupComputeRemoveRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/groupComputeRemove"

View File

@@ -8,11 +8,11 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GroupGetRequest struct to get detailed information about Compute Group
// Request struct for 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,7 +23,9 @@ type GroupGetRequest struct {
func (b BService) GroupGet(ctx context.Context, req GroupGetRequest) (*RecordGroup, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/groupGet"

View File

@@ -8,11 +8,12 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GroupParentAddRequest struct to add parent Compute Group relation to the specified Compute Group
// Request struct for add parent Compute Group relation emove 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
@@ -27,7 +28,9 @@ type GroupParentAddRequest struct {
func (b BService) GroupParentAdd(ctx context.Context, req GroupParentAddRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/groupParentAdd"

View File

@@ -8,28 +8,30 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GroupParentRemoveRequest struct to remove parent Compute Group
// relation from the specified Compute Group
// Request struct for remove parent Compute Group
// relation to 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 {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/groupParentRemove"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GroupRemoveRequest struct for destroy the specified Compute Group
// Request struct for destroy the specified Compute Group
type GroupRemoveRequest struct {
// ID of the Basic Service of Compute Group
// Required: true
@@ -23,7 +23,9 @@ type GroupRemoveRequest struct {
func (b BService) GroupRemove(ctx context.Context, req GroupRemoveRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/groupRemove"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GroupResizeRequest struct to resize the group
// Request struct for resize the group
type GroupResizeRequest struct {
// ID of the Basic Service of Compute Group
// Required: true
@@ -34,7 +34,9 @@ type GroupResizeRequest struct {
func (b BService) GroupResize(ctx context.Context, req GroupResizeRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/groupResize"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GroupStartRequest struct to start the specified Compute Group
// Request struct for start the specified Compute Group
type GroupStartRequest struct {
// ID of the Basic Service of Compute Group
// Required: true
@@ -23,7 +23,9 @@ type GroupStartRequest struct {
func (b BService) GroupStart(ctx context.Context, req GroupStartRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/groupStart"

View File

@@ -8,15 +8,15 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GroupStopRequest struct to stop the specified Compute Group
// Request struct for 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,7 +27,9 @@ type GroupStopRequest struct {
func (b BService) GroupStop(ctx context.Context, req GroupStopRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/groupStop"

View File

@@ -8,15 +8,15 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GroupUpdateRequest struct to update existing Compute group
// Request struct for 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,7 +47,9 @@ type GroupUpdateRequest struct {
func (b BService) GroupUpdate(ctx context.Context, req GroupUpdateRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/groupUpdate"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GroupUpdateExtNetRequest struct to update External Network settings
// Request struct for update External Network settings
type GroupUpdateExtNetRequest struct {
// ID of the Basic Service of Compute Group
// Required: true
@@ -27,7 +27,9 @@ type GroupUpdateExtNetRequest struct {
func (b BService) GroupUpdateExtNet(ctx context.Context, req GroupUpdateExtNetRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/groupUpdateExtnet"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GroupUpdateVINSRequest struct to update VINS settings
// Request struct for update VINS settings
type GroupUpdateVINSRequest struct {
// ID of the Basic Service of Compute Group
// Required: true
@@ -27,7 +27,9 @@ type GroupUpdateVINSRequest struct {
func (b BService) GroupUpdateVINS(ctx context.Context, req GroupUpdateVINSRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/groupUpdateVins"

View File

@@ -1,37 +0,0 @@
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
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// ListRequest struct to get list of BasicService instances
// Request struct for get list BasicService instances
type ListRequest struct {
// Find by ID
// Required: false
@@ -49,9 +49,11 @@ type ListRequest struct {
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets list of BasicService instances associated with the specified Resource Group as a ListBasicServices struct
// List gets list BasicService instances associated with the specified Resource Group
func (b BService) List(ctx context.Context, req ListRequest) (*ListBasicServices, error) {
res, err := b.ListRaw(ctx, req)
url := "/cloudapi/bservice/list"
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
@@ -65,11 +67,3 @@ 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
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// ListDeletedRequest struct to get list of deleted BasicService instances
// Request struct for 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 of deleted BasicService instances associated with the specified Resource Group
// ListDeleted gets list deleted BasicService instances associated with the specified Resource Group
func (b BService) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListBasicServices, error) {
url := "/cloudapi/bservice/listDeleted"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// RestoreRequest struct to restore BasicService instance
// Request struct for restores BasicService instance
type RestoreRequest struct {
// ID of the BasicService to be restored
// Required: true
@@ -19,7 +19,9 @@ type RestoreRequest struct {
func (b BService) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/restore"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// SnapshotCreateRequest struct to create snapshot
// Request struct for create snapshot
type SnapshotCreateRequest struct {
// ID of the Basic Service
// Required: true
@@ -23,7 +23,9 @@ type SnapshotCreateRequest struct {
func (b BService) SnapshotCreate(ctx context.Context, req SnapshotCreateRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/snapshotCreate"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// SnapshotDeleteRequest struct to delete snapshot
// Request struct for delete snapshot
type SnapshotDeleteRequest struct {
// ID of the Basic Service
// Required: true
@@ -23,7 +23,9 @@ type SnapshotDeleteRequest struct {
func (b BService) SnapshotDelete(ctx context.Context, req SnapshotDeleteRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/snapshotDelete"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// SnapshotListRequest struct to get list of existing snapshots
// Request struct for get list existing snapshots
type SnapshotListRequest struct {
// ID of the Basic Service
// Required: true
@@ -19,7 +19,9 @@ type SnapshotListRequest struct {
func (b BService) SnapshotList(ctx context.Context, req SnapshotListRequest) (ListSnapshots, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/snapshotList"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// SnapshotRollbackRequest struct to rollback snapshot
// Request struct for rollback snapshot
type SnapshotRollbackRequest struct {
// ID of the Basic Service
// Required: true
@@ -23,7 +23,9 @@ type SnapshotRollbackRequest struct {
func (b BService) SnapshotRollback(ctx context.Context, req SnapshotRollbackRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/snapshotRollback"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// StartRequest struct to start service
// Request struct for start service
type StartRequest struct {
// ID of the service to start
// Required: true
@@ -21,7 +21,9 @@ type StartRequest struct {
func (b BService) Start(ctx context.Context, req StartRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/start"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// StopRequest struct to stop service
// Request struct for stop service
type StopRequest struct {
// ID of the service to stop
// Required: true
@@ -21,7 +21,9 @@ type StopRequest struct {
func (b BService) Stop(ctx context.Context, req StopRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/bservice/stop"

View File

@@ -7,7 +7,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AffinityGroupCheckStartRequest struct to check all computes with current affinity label can start
// Request struct for check all computes with current affinity label can start
type AffinityGroupCheckStartRequest struct {
// ID of the resource group
// Required: true
@@ -22,7 +22,9 @@ type AffinityGroupCheckStartRequest struct {
func (c Compute) AffinityGroupCheckStart(ctx context.Context, req AffinityGroupCheckStartRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/affinityGroupCheckStart"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AffinityLabelRemoveRequest struct to clear affinity label for compute
// Request struct for clear affinity label for compute
type AffinityLabelRemoveRequest struct {
// ID of the compute instance
// Required: true
@@ -19,7 +19,9 @@ type AffinityLabelRemoveRequest struct {
func (c Compute) AffinityLabelRemove(ctx context.Context, req AffinityLabelRemoveRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/affinityLabelRemove"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AffinityLabelSetRequest struct to set affinity label for compute
// Request struct for set affinity label for compute
type AffinityLabelSetRequest struct {
// ID of the compute instance
// Required: true
@@ -23,7 +23,9 @@ type AffinityLabelSetRequest struct {
func (c Compute) AffinityLabelSet(ctx context.Context, req AffinityLabelSetRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/affinityLabelSet"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AffinityRelationsRequest struct to get dict of computes
// Request struct for get dict of computes
type AffinityRelationsRequest struct {
// ID of the compute instance
// Required: true
@@ -19,7 +19,9 @@ type AffinityRelationsRequest struct {
func (c Compute) AffinityRelations(ctx context.Context, req AffinityRelationsRequest) (*RecordAffinityRelations, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/affinityRelations"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AffinityRuleAddRequest struct to add affinity rule
// Request struct for add affinity rule
type AffinityRuleAddRequest struct {
// ID of the compute instance
// Required: true
@@ -38,15 +38,17 @@ type AffinityRuleAddRequest struct {
Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: false
Value string `url:"value" json:"value"`
// Required: true
Value string `url:"value" json:"value" validate:"required"`
}
// AffinityRuleAdd add affinity rule
func (c Compute) AffinityRuleAdd(ctx context.Context, req AffinityRuleAddRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/affinityRuleAdd"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AffinityRuleRemoveRequest struct to remove affinity rule
// Request struct for remove affinity rule
type AffinityRuleRemoveRequest struct {
// ID of the compute instance
// Required: true
@@ -38,15 +38,17 @@ type AffinityRuleRemoveRequest struct {
Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: false
Value string `url:"value" json:"value"`
// Required: true
Value string `url:"value" json:"value" validate:"required"`
}
// AffinityRuleRemove remove affinity rule
func (c Compute) AffinityRuleRemove(ctx context.Context, req AffinityRuleRemoveRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/affinityRuleRemove"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AffinityRulesClearRequest struct to clear affinity rules
// Request struct for clear affinity rules
type AffinityRulesClearRequest struct {
// ID of the compute instance
// Required: true
@@ -19,7 +19,9 @@ type AffinityRulesClearRequest struct {
func (c Compute) AffinityRulesClear(ctx context.Context, req AffinityRulesClearRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/affinityRulesClear"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AntiAffinityRuleAddRequest struct to add anti affinity rule
// Request struct for add anti affinity rule
type AntiAffinityRuleAddRequest struct {
// ID of the compute instance
// Required: true
@@ -38,15 +38,17 @@ type AntiAffinityRuleAddRequest struct {
Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: false
Value string `url:"value" json:"value"`
// Required: true
Value string `url:"value" json:"value" validate:"required"`
}
// AntiAffinityRuleAdd add anti affinity rule
func (c Compute) AntiAffinityRuleAdd(ctx context.Context, req AntiAffinityRuleAddRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/antiAffinityRuleAdd"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AntiAffinityRuleRemoveRequest struct to remove anti affinity rule
// Request struct for remove anti affinity rule
type AntiAffinityRuleRemoveRequest struct {
// ID of the compute instance
// Required: true
@@ -38,15 +38,17 @@ type AntiAffinityRuleRemoveRequest struct {
Key string `url:"key" json:"key" validate:"required"`
// Value that must match the key to be taken into account when analyzing this rule
// Required: false
Value string `url:"value" json:"value"`
// Required: true
Value string `url:"value" json:"value" validate:"required"`
}
// AntiAffinityRuleRemove remove anti affinity rule
func (c Compute) AntiAffinityRuleRemove(ctx context.Context, req AntiAffinityRuleRemoveRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/antiAffinityRuleRemove"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AntiAffinityRulesClearRequest struct to clear anti affinity rules
// Request struct for clear anti affinity rules
type AntiAffinityRulesClearRequest struct {
// ID of the compute instance
// Required: true
@@ -19,7 +19,9 @@ type AntiAffinityRulesClearRequest struct {
func (c Compute) AntiAffinityRulesClear(ctx context.Context, req AntiAffinityRulesClearRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/antiAffinityRulesClear"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AttachGPURequest struct to attach GPU for compute
// Request struct for attach GPU for compute
type AttachGPURequest struct {
// Identifier compute
// Required: true
@@ -23,7 +23,9 @@ type AttachGPURequest struct {
func (c Compute) AttachGPU(ctx context.Context, req AttachGPURequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/attachGpu"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AttachPCIDeviceRequest struct to attach PCI device
// Request struct for atttach PCI device
type AttachPCIDeviceRequest struct {
// Identifier compute
// Required: true
@@ -23,7 +23,9 @@ type AttachPCIDeviceRequest struct {
func (c Compute) AttachPCIDevice(ctx context.Context, req AttachPCIDeviceRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/attachPciDevice"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AuditsRequest struct to get audit records
// Request struct for get audit records
type AuditsRequest struct {
// ID of the compute
// Required: true
@@ -19,7 +19,9 @@ type AuditsRequest struct {
func (c Compute) Audits(ctx context.Context, req AuditsRequest) (ListAudits, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/audits"

View File

@@ -7,7 +7,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// BootOrderGetRequest struct to get boot order
// Request struct for getting boot order
type BootOrderGetRequest struct {
// Compute ID
// Required: true
@@ -18,7 +18,9 @@ type BootOrderGetRequest struct {
func (c Compute) BootOrderGet(ctx context.Context, req BootOrderGetRequest) ([]string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/bootOrderGet"

View File

@@ -7,7 +7,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// BootOrderSetRequest struct to set boot order
// Request struct for setting boot order
type BootOrderSetRequest struct {
// ID of compute instance
// Required: true
@@ -26,7 +26,9 @@ type BootOrderSetRequest struct {
func (c Compute) BootOrderSet(ctx context.Context, req BootOrderSetRequest) ([]string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/bootOrderSet"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// CDEjectRequest struct to eject CD image
// Request struct for eject CD image
type CDEjectRequest struct {
// ID of compute instance
// Required: true
@@ -19,7 +19,9 @@ type CDEjectRequest struct {
func (c Compute) CDEject(ctx context.Context, req CDEjectRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/cdEject"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// CDInsertRequest struct to insert new CD image
// Request struct for insert new CD image
type CDInsertRequest struct {
// ID of compute instance
// Required: true
@@ -23,7 +23,9 @@ type CDInsertRequest struct {
func (c Compute) CDInsert(ctx context.Context, req CDInsertRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/cdInsert"

View File

@@ -7,7 +7,7 @@ import (
"strconv"
)
// ChangeLinkStateRequest struct to change link state
// Request struct for changing link state
type ChangeLinkStateRequest struct {
// Compute ID
// Required: true
@@ -27,7 +27,9 @@ type ChangeLinkStateRequest struct {
func (c Compute) ChangeLinkState(ctx context.Context, req ChangeLinkStateRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/changeLinkState"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// CloneRequest struct to clone compute instance
// Request struct for clone compute instance
type CloneRequest struct {
// ID of compute instance
// Required: true
@@ -31,7 +31,9 @@ type CloneRequest struct {
func (c Compute) Clone(ctx context.Context, req CloneRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/clone"

View File

@@ -9,7 +9,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// CreateTemplateRequest struct to create template
// Request struct for create template
type CreateTemplateRequest struct {
// ID of the compute to create template from
// Required: true
@@ -30,7 +30,9 @@ type wrapperCreateTemplateRequest struct {
func (c Compute) CreateTemplate(ctx context.Context, req CreateTemplateRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
reqWrapped := wrapperCreateTemplateRequest{
@@ -57,7 +59,9 @@ 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 {
return "", validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
reqWrapped := wrapperCreateTemplateRequest{

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DeleteRequest struct to delete compute
// Request struct for delete compute
type DeleteRequest struct {
// ID of compute instance
// Required: true
@@ -27,7 +27,9 @@ type DeleteRequest struct {
func (c Compute) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/delete"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DeleteCustomFieldsRequest struct to delete compute's custom fields
// Request struct for deleting compute's custome fields
type DeleteCustomFieldsRequest struct {
// ID of the compute
// Required: true
@@ -19,7 +19,9 @@ type DeleteCustomFieldsRequest struct {
func (c Compute) DeleteCustomFields(ctx context.Context, req DeleteCustomFieldsRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/deleteCustomFields"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DetachGPURequest struct to detach vgpu for compute
// Request struct for detach vgpu for compute
type DetachGPURequest struct {
// Identifier compute
// Required: true
@@ -24,7 +24,9 @@ type DetachGPURequest struct {
func (c Compute) DetachGPU(ctx context.Context, req DetachGPURequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/detachGpu"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DetachPCIDeviceRequest struct to detach PCI device
// Request struct for detach PCI device
type DetachPCIDeviceRequest struct {
// Identifier compute
// Required: true
@@ -23,7 +23,9 @@ type DetachPCIDeviceRequest struct {
func (c Compute) DetachPCIDevice(ctx context.Context, req DetachPCIDeviceRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/detachPciDevice"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DisableRequest struct to disable compute
// Request struct for disable compute
type DisableRequest struct {
// ID of compute instance
// Required: true
@@ -19,7 +19,9 @@ type DisableRequest struct {
func (c Compute) Disable(ctx context.Context, req DisableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/disable"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DiskAddRequest struct to create and attach disk to compute
// Request struct for create and attach disk to compute
type DiskAddRequest struct {
// ID of compute instance
// Required: true
@@ -52,7 +52,9 @@ type DiskAddRequest struct {
func (c Compute) DiskAdd(ctx context.Context, req DiskAddRequest) (uint64, error) {
err := validators.ValidateRequest(req)
if err != nil {
return 0, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return 0, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/diskAdd"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DiskAttachRequest struct to attach disk to compute
// Request struct for attach disk to compute
type DiskAttachRequest struct {
// ID of compute instance
// Required: true
@@ -27,7 +27,9 @@ type DiskAttachRequest struct {
func (c Compute) DiskAttach(ctx context.Context, req DiskAttachRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/diskAttach"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DiskDelRequest struct to detach and delete disk from compute
// Request struct for detach and delete disk from compute
type DiskDelRequest struct {
// ID of compute instance
// Required: true
@@ -27,7 +27,9 @@ type DiskDelRequest struct {
func (c Compute) DiskDel(ctx context.Context, req DiskDelRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/diskDel"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DiskDetachRequest struct to detach disk from compute
// Request struct for detach disk from compute
type DiskDetachRequest struct {
// ID of compute instance
// Required: true
@@ -23,7 +23,9 @@ type DiskDetachRequest struct {
func (c Compute) DiskDetach(ctx context.Context, req DiskDetachRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/diskDetach"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DiskQOSRequest struct to change QoS of the disk
// Request struct for change QoS of the disk
type DiskQOSRequest struct {
// ID of compute instance
// Required: true
@@ -27,7 +27,9 @@ type DiskQOSRequest struct {
func (c Compute) DiskQOS(ctx context.Context, req DiskQOSRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/diskQos"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DiskResizeRequest struct to change disk size
// Request struct for change disk size
type DiskResizeRequest struct {
// ID of compute instance
// Required: true
@@ -27,7 +27,9 @@ type DiskResizeRequest struct {
func (c Compute) DiskResize(ctx context.Context, req DiskResizeRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/diskResize"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// EnableRequest struct to enable compute
// Request struct for enable compute
type EnableRequest struct {
// ID of compute instance
// Required: true
@@ -19,7 +19,9 @@ type EnableRequest struct {
func (c Compute) Enable(ctx context.Context, req EnableRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return false, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/enable"

View File

@@ -8,16 +8,25 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetRequest struct to get information about compute
// Request for get information about compute
type GetRequest struct {
// ID of compute instance
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// Get gets information about compute as a RecordCompute struct
// Get Gets information about compute
func (c Compute) Get(ctx context.Context, req GetRequest) (*RecordCompute, error) {
res, err := c.GetRaw(ctx, req)
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/get"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
@@ -31,16 +40,3 @@ func (c Compute) Get(ctx context.Context, req GetRequest) (*RecordCompute, error
return &info, nil
}
// GetRaw gets information about compute as an array of bytes
func (c Compute) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/compute/get"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetAuditsRequest struct to get compute audits
// Request struct for get compute audits
type GetAuditsRequest struct {
// ID of compute instance
// Required: true
@@ -19,7 +19,9 @@ type GetAuditsRequest struct {
func (c Compute) GetAudits(ctx context.Context, req GetAuditsRequest) (ListShortAudits, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/getAudits"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetConsoleURLRequest struct to get console URL
// Request struct for get console URL
type GetConsoleURLRequest struct {
// ID of compute instance to get console for
// Required: true
@@ -19,7 +19,9 @@ type GetConsoleURLRequest struct {
func (c Compute) GetConsoleURL(ctx context.Context, req GetConsoleURLRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/getConsoleUrl"

View File

@@ -8,7 +8,7 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetCustomFieldsRequest struct to get Compute's customFields
// Request struct for getting Compute's customFields
type GetCustomFieldsRequest struct {
// Compute ID
// Required: true
@@ -19,7 +19,9 @@ type GetCustomFieldsRequest struct {
func (c Compute) GetCustomFields(ctx context.Context, req GetCustomFieldsRequest) (interface{}, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/getCustomFields"

View File

@@ -7,22 +7,24 @@ import (
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetLogRequest struct to get compute logs
// Request struct for get compute logs
type GetLogRequest struct {
// ID of compute instance to get log for
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
// Path to log file
// Required: true
Path string `url:"path" json:"path" validate:"required"`
Path string `url:"path" json:"path" validate:"required"`
}
// GetLog gets compute's log file by path
func (c Compute) GetLog(ctx context.Context, req GetLogRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi/compute/getLog"
@@ -39,7 +41,9 @@ func (c Compute) GetLog(ctx context.Context, req GetLogRequest) (string, error)
func (c Compute) GetLogGet(ctx context.Context, req GetLogRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
for _, validationError := range validators.GetErrors(err) {
return "", validators.ValidationError(validationError)
}
}
url := "/cloudapi//compute/getLog"

View File

@@ -1,37 +0,0 @@
package compute
// 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.ID)
}
return res
}
// IDs gets array of DiskIDs from ListInfoDisks struct
func (li ListInfoDisks) IDs() []uint64 {
res := make([]uint64, 0, len(li))
for _, i := range li {
res = append(res, i.ID)
}
return res
}
// IDs gets array of PFWsIDs from ListPFWs struct
func (lp ListPFWs) IDs() []uint64 {
res := make([]uint64, 0, len(lp.Data))
for _, p := range lp.Data {
res = append(res, p.ID)
}
return res
}
// IDs gets array of DiskIDs from ListComputeDisks struct
func (lcd ListComputeDisks) IDs() []uint64 {
res := make([]uint64, 0, len(lcd))
for _, cd := range lcd {
res = append(res, cd.ID)
}
return res
}

View File

@@ -6,7 +6,7 @@ import (
"net/http"
)
// ListRequest struct to get list of available computes
// Request struct for get list available computes
type ListRequest struct {
// Find by ID
// Required: false
@@ -64,7 +64,9 @@ type ListRequest struct {
// List gets list of the available computes.
// Filtering based on status is possible
func (c Compute) List(ctx context.Context, req ListRequest) (*ListComputes, error) {
res, err := c.ListRaw(ctx, req)
url := "/cloudapi/compute/list"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
@@ -78,11 +80,3 @@ func (c Compute) List(ctx context.Context, req ListRequest) (*ListComputes, erro
return &list, nil
}
// ListRaw gets list of the available computes.
func (c Compute) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudapi/compute/list"
res, err := c.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

Some files were not shown because too many files have changed in this diff Show More