test git
This commit is contained in:
41
CHANGELOG.md
41
CHANGELOG.md
@@ -1,41 +0,0 @@
|
|||||||
## Version 1.15.2
|
|
||||||
|
|
||||||
Методы `Audits` в cloudapi/compute, cloudbroker/compute, cloudapi/account, cloudbroker/account, cloudapi/vins, cloudbroker/vins, cloudapi/rg и cloudbroker/rg стали deprecated и в следующих версиях будут удалены, вместо них необходимо использовать метод `List` в cloudapi/audit и cloudbroker/audit с соответствующими фильтрами
|
|
||||||
Методы `AccessGrant`, `AccessGrantToPool`, `AccessRevoke`, `AccessRevokeToPool` в cloudbroker/sep стали deprecated и в следующих версиях будут удалены
|
|
||||||
Методы `ComputeCISet`, `ComputeCIUnset`, `GetAudits` в cloudbroker/compute и `GetAudits` в cloudapi/compute стали deprecated и будут удалены в следующих версиях
|
|
||||||
Методы `ComputeCISet`, `ComputeCIUnset` в cloudbroker/image стали deprecated и будут удалены в следующих версиях
|
|
||||||
|
|
||||||
Все методы группы `.SDN()` находятся в альфа-версии.
|
|
||||||
|
|
||||||
|
|
||||||
### Добавлено
|
|
||||||
|
|
||||||
#### image
|
|
||||||
| Идентификатор задачи | Описание |
|
|
||||||
| --- | --- |
|
|
||||||
| BGOS-916 | Вычисляемые поля `Compute` и `MemoryDumpImage` в структуру ответа `ItemSnapSet` в cloudapi/image |
|
|
||||||
|
|
||||||
#### node
|
|
||||||
| Идентификатор задачи | Описание |
|
|
||||||
| --- | --- |
|
|
||||||
| BGOS-919 | Вычисляемое поле `MaxSupportedGeneration` в структуру ответа `CpuInfo` в cloudbroker/node |
|
|
||||||
|
|
||||||
#### zone
|
|
||||||
| Идентификатор задачи | Описание |
|
|
||||||
| --- | --- |
|
|
||||||
| BGOS-914 | Вычисляемые поля `ID`, `Name` и `ConsumedBy` в структуру ответа `RecordConsumption` в cloudbroker/sep |
|
|
||||||
| BGOS-914 | Структура ответа `ListConsumption` в cloudbroker/sep |
|
|
||||||
|
|
||||||
|
|
||||||
### Изменено
|
|
||||||
|
|
||||||
#### account
|
|
||||||
| Идентификатор задачи | Описание |
|
|
||||||
| --- | --- |
|
|
||||||
| BGOS-918 | Тип обязательного поля `Ratio` с `float64` на `uint64` в структуре запроса `SetCPUAllocationRatioRequest` в cloudbroker/account |
|
|
||||||
|
|
||||||
#### SEP
|
|
||||||
| Идентификатор задачи | Описание |
|
|
||||||
| --- | --- |
|
|
||||||
| BGOS-914 | Тип поля `SEPID` с обязательного на опциональный в структуре запроса `ConsumptionRequest` в cloudbroker/sep |
|
|
||||||
| BGOS-914 | Тип ответа метода `Consumption` с `RecordConsumption` на `ListConsumption` в cloudbroker/sep |
|
|
||||||
201
LICENSE
201
LICENSE
@@ -1,201 +0,0 @@
|
|||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright 2022 Basis LTD
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
10
Makefile
10
Makefile
@@ -1,10 +0,0 @@
|
|||||||
all: lint test
|
|
||||||
.PHONY: all
|
|
||||||
|
|
||||||
lint:
|
|
||||||
golangci-lint run --timeout 600s
|
|
||||||
test:
|
|
||||||
go test -v -failfast -timeout 600s ./...
|
|
||||||
|
|
||||||
.DEFAULT_GOAL := lint
|
|
||||||
|
|
||||||
106
check.go
106
check.go
@@ -1,106 +0,0 @@
|
|||||||
package decortsdk
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
|
||||||
)
|
|
||||||
|
|
||||||
type CheckInfo struct {
|
|
||||||
Version string `json:"version"`
|
|
||||||
Build uint64 `json:"build"`
|
|
||||||
}
|
|
||||||
|
|
||||||
const versionURL = "/system/info/version"
|
|
||||||
|
|
||||||
func (de DecortClient) Check() (*CheckInfo, error) {
|
|
||||||
res, err := de.DecortApiCall(context.Background(), http.MethodGet, versionURL, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
info := CheckInfo{}
|
|
||||||
|
|
||||||
err = json.Unmarshal([]byte(strings.Replace(strings.Trim(string(res), `"`), "\\", "", -1)), &info)
|
|
||||||
if err != nil {
|
|
||||||
var v string
|
|
||||||
json.Unmarshal([]byte(res), &v)
|
|
||||||
if _, exists := constants.VersionMap[v]; exists {
|
|
||||||
info.Version = v
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("platform version isn't supported")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if v, ok := constants.VersionMap[info.Version]; ok {
|
|
||||||
if v == "-" {
|
|
||||||
return &info, nil
|
|
||||||
}
|
|
||||||
return nil, errors.New(fmt.Sprintf("SDK don't support platform version %s, please use %s SDK version", info.Version, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, errors.New(fmt.Sprintf("platform version %s isn't supported", info.Version))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bvs BVSDecortClient) Check() (*CheckInfo, error) {
|
|
||||||
res, err := bvs.DecortApiCall(context.Background(), http.MethodGet, versionURL, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
info := CheckInfo{}
|
|
||||||
|
|
||||||
err = json.Unmarshal([]byte(strings.Replace(strings.Trim(string(res), `"`), "\\", "", -1)), &info)
|
|
||||||
if err != nil {
|
|
||||||
var v string
|
|
||||||
json.Unmarshal([]byte(res), &v)
|
|
||||||
if _, exists := constants.VersionMap[v]; exists {
|
|
||||||
info.Version = v
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("platform version isn't supported")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if v, ok := constants.VersionMap[info.Version]; ok {
|
|
||||||
if v == "-" {
|
|
||||||
return &info, nil
|
|
||||||
}
|
|
||||||
return nil, errors.New(fmt.Sprintf("SDK don't support platform version %s, please use %s SDK version", info.Version, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, errors.New(fmt.Sprintf("platform version %s isn't supported", info.Version))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ldc LegacyDecortClient) Check() (*CheckInfo, error) {
|
|
||||||
res, err := ldc.DecortApiCall(context.Background(), http.MethodGet, versionURL, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
info := CheckInfo{}
|
|
||||||
|
|
||||||
err = json.Unmarshal([]byte(strings.Replace(strings.Trim(string(res), `"`), "\\", "", -1)), &info)
|
|
||||||
if err != nil {
|
|
||||||
var v string
|
|
||||||
json.Unmarshal([]byte(res), &v)
|
|
||||||
if _, exists := constants.VersionMap[v]; exists {
|
|
||||||
info.Version = v
|
|
||||||
} else {
|
|
||||||
return nil, fmt.Errorf("platform version isn't supported")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if v, ok := constants.VersionMap[info.Version]; ok {
|
|
||||||
if v == "-" {
|
|
||||||
return &info, nil
|
|
||||||
}
|
|
||||||
return nil, errors.New(fmt.Sprintf("SDK don't support platform version %s, please use %s SDK version", info.Version, v))
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, errors.New(fmt.Sprintf("platform version %s isn't supported", info.Version))
|
|
||||||
}
|
|
||||||
453
client.go
453
client.go
@@ -1,453 +0,0 @@
|
|||||||
package decortsdk
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"context"
|
|
||||||
"crypto/tls"
|
|
||||||
"encoding/base64"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"mime/multipart"
|
|
||||||
"net/http"
|
|
||||||
"reflect"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/google/go-querystring/query"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DecortClient is HTTP-client for platform
|
|
||||||
type DecortClient struct {
|
|
||||||
decortURL string
|
|
||||||
client *http.Client
|
|
||||||
cfg config.Config
|
|
||||||
expiryTime time.Time
|
|
||||||
mutex *sync.Mutex
|
|
||||||
}
|
|
||||||
|
|
||||||
// Сlient builder
|
|
||||||
func New(cfg config.Config) *DecortClient {
|
|
||||||
if err := validators.ValidateConfig(cfg); err != nil {
|
|
||||||
panic(validators.ValidationErrors(validators.GetErrors(err)))
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.Retries == 0 {
|
|
||||||
cfg.Retries = 5
|
|
||||||
}
|
|
||||||
|
|
||||||
return &DecortClient{
|
|
||||||
decortURL: cfg.DecortURL,
|
|
||||||
client: &http.Client{
|
|
||||||
Transport: &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{
|
|
||||||
//nolint:gosec
|
|
||||||
InsecureSkipVerify: cfg.SSLSkipVerify,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
cfg: trimConfig(&cfg),
|
|
||||||
mutex: &sync.Mutex{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CloudAPI builder
|
|
||||||
func (dc *DecortClient) CloudAPI() *cloudapi.CloudAPI {
|
|
||||||
return cloudapi.New(dc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CloudBroker builder
|
|
||||||
func (dc *DecortClient) CloudBroker() *cloudbroker.CloudBroker {
|
|
||||||
return cloudbroker.New(dc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SDN builder
|
|
||||||
func (dc *DecortClient) SDN() *sdn.SDN {
|
|
||||||
return sdn.New(dc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecortApiCall method for sending requests to the platform
|
|
||||||
func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
|
||||||
|
|
||||||
var body *bytes.Buffer
|
|
||||||
var ctype string
|
|
||||||
|
|
||||||
byteSlice, ok := params.([]byte)
|
|
||||||
if ok {
|
|
||||||
body = bytes.NewBuffer(byteSlice)
|
|
||||||
// ctype = "application/x-iso9660-image"
|
|
||||||
ctype = "application/octet-stream"
|
|
||||||
} else {
|
|
||||||
values, err := query.Values(params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
body = bytes.NewBufferString(values.Encode())
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+constants.RESTMACHINE+url, body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// get token
|
|
||||||
if err = dc.getToken(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// perform request
|
|
||||||
respBytes, err := dc.do(req, ctype)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return respBytes, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecortApiCallCtype method for sending requests to the platform with content type
|
|
||||||
func (dc *DecortClient) DecortApiCallCtype(ctx context.Context, method, url, ctype string, params interface{}) ([]byte, error) {
|
|
||||||
|
|
||||||
var body *bytes.Buffer
|
|
||||||
|
|
||||||
switch ctype {
|
|
||||||
case constants.MIMESTREAM:
|
|
||||||
body = bytes.NewBuffer(params.([]byte))
|
|
||||||
case constants.MIMEJSON:
|
|
||||||
jsonBody, err := json.Marshal(params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
body = bytes.NewBuffer(jsonBody)
|
|
||||||
default:
|
|
||||||
ctype = constants.MIMEPOSTForm
|
|
||||||
values, err := query.Values(params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
body = bytes.NewBufferString(values.Encode())
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+constants.RESTMACHINE+url, body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// get token
|
|
||||||
if err = dc.getToken(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// perform request
|
|
||||||
respBytes, err := dc.do(req, ctype)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return respBytes, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecortApiCallMP method for sending requests to the platform
|
|
||||||
func (dc *DecortClient) DecortApiCallMP(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
|
||||||
body, ctype, err := multiPartReq(params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+constants.RESTMACHINE+url, body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// get token
|
|
||||||
if err = dc.getToken(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// perform request
|
|
||||||
respBytes, err := dc.do(req, ctype)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return respBytes, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dc *DecortClient) getToken(ctx context.Context) error {
|
|
||||||
dc.mutex.Lock()
|
|
||||||
defer dc.mutex.Unlock()
|
|
||||||
|
|
||||||
// new token is not needed
|
|
||||||
if dc.cfg.Token != "" && !time.Now().After(dc.expiryTime) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// set up request headers and body
|
|
||||||
body := fmt.Sprintf("grant_type=client_credentials&client_id=%s&client_secret=%s&response_type=id_token", dc.cfg.AppID, dc.cfg.AppSecret)
|
|
||||||
bodyReader := strings.NewReader(body)
|
|
||||||
|
|
||||||
dc.cfg.SSOURL = strings.TrimSuffix(dc.cfg.SSOURL, "/")
|
|
||||||
|
|
||||||
req, _ := http.NewRequestWithContext(ctx, "POST", dc.cfg.SSOURL+"/v1/oauth/access_token", bodyReader)
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
|
|
||||||
// request token
|
|
||||||
resp, err := dc.client.Do(req)
|
|
||||||
if err != nil || resp == nil {
|
|
||||||
return fmt.Errorf("cannot get token: %w", err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
var tokenBytes []byte
|
|
||||||
tokenBytes, err = io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot get token: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
return fmt.Errorf("cannot get token: %s", tokenBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// save token in config
|
|
||||||
token := string(tokenBytes)
|
|
||||||
expiryTime, err := getTokenExp(token)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot get expiry time: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.cfg.Token = token
|
|
||||||
dc.expiryTime = expiryTime
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// do method performs request and returns response as an array of bytes and nil error in case of response status code 200.
|
|
||||||
// In any other cases do returns nil response and error.
|
|
||||||
// Retries are implemented in case of connection reset errors.
|
|
||||||
func (dc *DecortClient) do(req *http.Request, ctype string) ([]byte, error) {
|
|
||||||
// set up request headers and body
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
if ctype != "" {
|
|
||||||
req.Header.Set("Content-Type", ctype)
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
req.Body.Close()
|
|
||||||
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
|
||||||
|
|
||||||
resp, err := dc.client.Do(req)
|
|
||||||
if resp != nil {
|
|
||||||
defer resp.Body.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
// retries logic GOES HERE
|
|
||||||
// get http response
|
|
||||||
//var resp *http.Response
|
|
||||||
//for i := uint64(0); i < dc.cfg.Retries; i++ {
|
|
||||||
// req := req.Clone(req.Context())
|
|
||||||
// req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
|
||||||
//
|
|
||||||
// if i > 0 {
|
|
||||||
// time.Sleep(5 * time.Second) // no time sleep for the first request
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// resp, err = dc.client.Do(req)
|
|
||||||
//
|
|
||||||
// // stop retries on success and close response body
|
|
||||||
// if resp != nil {
|
|
||||||
// defer resp.Body.Close()
|
|
||||||
// }
|
|
||||||
// if err == nil {
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // retries in case of connection errors with time sleep
|
|
||||||
// if isConnectionError(err) {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // return error in case of non-connection error
|
|
||||||
// return nil, err
|
|
||||||
//}
|
|
||||||
|
|
||||||
// handle http request errors
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if resp == nil {
|
|
||||||
return nil, fmt.Errorf("got empty response without error")
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle successful request
|
|
||||||
respBytes, _ := io.ReadAll(resp.Body)
|
|
||||||
if resp.StatusCode == 200 || resp.StatusCode == 204 {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// isConnectionError checks if given error falls within specific and associated connection errors
|
|
||||||
//func isConnectionError(err error) bool {
|
|
||||||
// if strings.Contains(err.Error(), "connection reset by peer") {
|
|
||||||
// return true
|
|
||||||
// }
|
|
||||||
// if errors.Is(err, io.EOF) {
|
|
||||||
// return true
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return false
|
|
||||||
//}
|
|
||||||
|
|
||||||
// multiPartReq writes the request structure to the request body, and also returns string of the content-type
|
|
||||||
func multiPartReq(params interface{}) (*bytes.Buffer, string, error) {
|
|
||||||
reqBody := &bytes.Buffer{}
|
|
||||||
writer := multipart.NewWriter(reqBody)
|
|
||||||
values := reflect.ValueOf(params)
|
|
||||||
types := values.Type()
|
|
||||||
defer writer.Close()
|
|
||||||
for i := 0; i < values.NumField(); i++ {
|
|
||||||
if !values.Field(i).IsValid() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if values.Field(i).IsZero() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if file, ok := constants.FileName[types.Field(i).Name]; ok {
|
|
||||||
part, err := writer.CreateFormFile(trimString(types.Field(i)), file)
|
|
||||||
if err != nil {
|
|
||||||
return &bytes.Buffer{}, "", err
|
|
||||||
}
|
|
||||||
_, err = io.Copy(part, strings.NewReader(valueToString(values.Field(i).Interface())))
|
|
||||||
if err != nil {
|
|
||||||
return &bytes.Buffer{}, "", err
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if values.Field(i).Type().Kind() == reflect.Slice {
|
|
||||||
switch slice := values.Field(i).Interface().(type) {
|
|
||||||
case []string:
|
|
||||||
if validators.IsInSlice(trimString(types.Field(i)), constants.K8sValues) {
|
|
||||||
code, err := json.Marshal(slice)
|
|
||||||
if err != nil {
|
|
||||||
return &bytes.Buffer{}, "", err
|
|
||||||
}
|
|
||||||
err = writer.WriteField(trimString(types.Field(i)), string(code))
|
|
||||||
if err != nil {
|
|
||||||
return &bytes.Buffer{}, "", err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for _, val := range slice {
|
|
||||||
err := writer.WriteField(trimString(types.Field(i)), val)
|
|
||||||
if err != nil {
|
|
||||||
return &bytes.Buffer{}, "", err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case []uint:
|
|
||||||
for _, val := range slice {
|
|
||||||
err := writer.WriteField(trimString(types.Field(i)), strconv.FormatUint(uint64(val), 10))
|
|
||||||
if err != nil {
|
|
||||||
return &bytes.Buffer{}, "", err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case []uint64:
|
|
||||||
for _, val := range slice {
|
|
||||||
err := writer.WriteField(trimString(types.Field(i)), strconv.FormatUint(val, 10))
|
|
||||||
if err != nil {
|
|
||||||
return &bytes.Buffer{}, "", err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case []map[string]interface{}:
|
|
||||||
for _, val := range slice {
|
|
||||||
encodeStr, err := json.Marshal(val)
|
|
||||||
if err != nil {
|
|
||||||
return &bytes.Buffer{}, "", err
|
|
||||||
}
|
|
||||||
err = writer.WriteField(trimString(types.Field(i)), string(encodeStr))
|
|
||||||
if err != nil {
|
|
||||||
return &bytes.Buffer{}, "", err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return &bytes.Buffer{}, "", fmt.Errorf("unsupported slice type:%T", slice)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
err := writer.WriteField(trimString(types.Field(i)), valueToString(values.Field(i).Interface()))
|
|
||||||
if err != nil {
|
|
||||||
return &bytes.Buffer{}, "", err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ct := writer.FormDataContentType()
|
|
||||||
return reqBody, ct, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func valueToString(a any) string {
|
|
||||||
switch str := a.(type) {
|
|
||||||
case string:
|
|
||||||
return str
|
|
||||||
case uint:
|
|
||||||
return strconv.FormatUint(uint64(str), 10)
|
|
||||||
case uint64:
|
|
||||||
return strconv.FormatUint(str, 10)
|
|
||||||
case bool:
|
|
||||||
return strconv.FormatBool(str)
|
|
||||||
default:
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func trimString(el reflect.StructField) string {
|
|
||||||
return strings.TrimSuffix(el.Tag.Get("url"), ",omitempty")
|
|
||||||
}
|
|
||||||
|
|
||||||
func trimConfig(cfg *config.Config) config.Config {
|
|
||||||
cfg.SSOURL = strings.TrimSuffix(cfg.SSOURL, "/")
|
|
||||||
cfg.DecortURL = strings.TrimSuffix(cfg.DecortURL, "/")
|
|
||||||
return *cfg
|
|
||||||
}
|
|
||||||
|
|
||||||
func getTokenExp(token string) (time.Time, error) {
|
|
||||||
parts := strings.Split(token, ".")
|
|
||||||
if len(parts) != 3 {
|
|
||||||
return time.Time{}, fmt.Errorf("invalid token format")
|
|
||||||
}
|
|
||||||
|
|
||||||
payload, err := base64.RawURLEncoding.DecodeString(parts[1])
|
|
||||||
if err != nil {
|
|
||||||
return time.Time{}, fmt.Errorf("error decode payload from token: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var claims map[string]interface{}
|
|
||||||
if err := json.Unmarshal(payload, &claims); err != nil {
|
|
||||||
return time.Time{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
exp, ok := claims["exp"]
|
|
||||||
if !ok {
|
|
||||||
return time.Time{}, fmt.Errorf("exp time bot found")
|
|
||||||
}
|
|
||||||
|
|
||||||
expTime := time.Unix(int64(exp.(float64)), 0)
|
|
||||||
|
|
||||||
return expTime, nil
|
|
||||||
}
|
|
||||||
472
client_bvs.go
472
client_bvs.go
@@ -1,472 +0,0 @@
|
|||||||
package decortsdk
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"context"
|
|
||||||
"crypto/tls"
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/google/go-querystring/query"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn"
|
|
||||||
)
|
|
||||||
|
|
||||||
// BVSDecortClient is HTTP-client for platform
|
|
||||||
type BVSDecortClient struct {
|
|
||||||
client *http.Client
|
|
||||||
cfg config.BVSConfig
|
|
||||||
mutex *sync.Mutex
|
|
||||||
decortURL string
|
|
||||||
}
|
|
||||||
|
|
||||||
type tokenJSON struct {
|
|
||||||
AccessToken string `json:"access_token"`
|
|
||||||
TokenType string `json:"token_type"`
|
|
||||||
RefreshToken string `json:"refresh_token"`
|
|
||||||
ExpiresIn uint64 `json:"expires_in"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Сlient builder
|
|
||||||
func NewBVS(cfg config.BVSConfig) *BVSDecortClient {
|
|
||||||
if err := validators.ValidateConfig(cfg); err != nil {
|
|
||||||
panic(validators.ValidationErrors(validators.GetErrors(err)))
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.Retries == 0 {
|
|
||||||
cfg.Retries = 5
|
|
||||||
}
|
|
||||||
if cfg.TimeToRefresh == 0 {
|
|
||||||
cfg.TimeToRefresh = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
return &BVSDecortClient{
|
|
||||||
decortURL: cfg.DecortURL,
|
|
||||||
client: &http.Client{
|
|
||||||
Transport: &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{
|
|
||||||
//nolint:gosec
|
|
||||||
InsecureSkipVerify: cfg.SSLSkipVerify,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
cfg: trimBVSConfig(&cfg),
|
|
||||||
mutex: &sync.Mutex{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CloudAPI builder
|
|
||||||
func (bdc *BVSDecortClient) CloudAPI() *cloudapi.CloudAPI {
|
|
||||||
return cloudapi.New(bdc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CloudBroker builder
|
|
||||||
func (bdc *BVSDecortClient) CloudBroker() *cloudbroker.CloudBroker {
|
|
||||||
return cloudbroker.New(bdc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SDN builder
|
|
||||||
func (bdc *BVSDecortClient) SDN() *sdn.SDN {
|
|
||||||
return sdn.New(bdc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecortApiCall method for sending requests to the platform
|
|
||||||
func (bdc *BVSDecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
|
||||||
var body *bytes.Buffer
|
|
||||||
var ctype string
|
|
||||||
|
|
||||||
byteSlice, ok := params.([]byte)
|
|
||||||
if ok {
|
|
||||||
body = bytes.NewBuffer(byteSlice)
|
|
||||||
// ctype = "application/x-iso9660-image"
|
|
||||||
ctype = "application/octet-stream"
|
|
||||||
} else {
|
|
||||||
values, err := query.Values(params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
body = bytes.NewBufferString(values.Encode())
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, method, bdc.decortURL+constants.RESTMACHINE+url, body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// get token
|
|
||||||
if bdc.cfg.Token.AccessToken == "" {
|
|
||||||
if _, err = bdc.GetToken(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// refresh token
|
|
||||||
if bdc.cfg.Token.RefreshToken != "" && bdc.cfg.Token.Expiry.Add(-time.Duration(bdc.cfg.TimeToRefresh)*time.Minute).Before(time.Now()) {
|
|
||||||
if _, err := bdc.RefreshToken(ctx); err != nil {
|
|
||||||
if _, err = bdc.GetToken(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// perform request
|
|
||||||
reqCopy := req.Clone(ctx)
|
|
||||||
respBytes, err := bdc.do(req, ctype)
|
|
||||||
if err == nil {
|
|
||||||
return respBytes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// get token and retry in case of access denied
|
|
||||||
if err.Error() == "access is denied" {
|
|
||||||
_, err = bdc.GetToken(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
respBytes, err = bdc.do(reqCopy, "")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return respBytes, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecortApiCallCtype method for sending requests to the platform with content type
|
|
||||||
func (bdc *BVSDecortClient) DecortApiCallCtype(ctx context.Context, method, url, ctype string, params interface{}) ([]byte, error) {
|
|
||||||
var body *bytes.Buffer
|
|
||||||
|
|
||||||
switch ctype {
|
|
||||||
case constants.MIMESTREAM:
|
|
||||||
body = bytes.NewBuffer(params.([]byte))
|
|
||||||
case constants.MIMEJSON:
|
|
||||||
jsonBody, err := json.Marshal(params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
body = bytes.NewBuffer(jsonBody)
|
|
||||||
default:
|
|
||||||
ctype = constants.MIMEPOSTForm
|
|
||||||
values, err := query.Values(params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
body = bytes.NewBufferString(values.Encode())
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, method, bdc.decortURL+constants.RESTMACHINE+url, body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// get token
|
|
||||||
if bdc.cfg.Token.AccessToken == "" {
|
|
||||||
if _, err = bdc.GetToken(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// refresh token
|
|
||||||
if bdc.cfg.Token.RefreshToken != "" && bdc.cfg.Token.Expiry.Add(-time.Duration(bdc.cfg.TimeToRefresh)*time.Minute).Before(time.Now()) {
|
|
||||||
if _, err := bdc.RefreshToken(ctx); err != nil {
|
|
||||||
if _, err = bdc.GetToken(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// perform request
|
|
||||||
reqCopy := req.Clone(ctx)
|
|
||||||
respBytes, err := bdc.do(req, ctype)
|
|
||||||
if err == nil {
|
|
||||||
return respBytes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// get token and retry in case of access denied
|
|
||||||
if err.Error() == "access is denied" {
|
|
||||||
_, err = bdc.GetToken(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
respBytes, err = bdc.do(reqCopy, "")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return respBytes, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bdc *BVSDecortClient) DecortApiCallMP(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
|
||||||
body, ctype, err := multiPartReq(params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, method, bdc.decortURL+constants.RESTMACHINE+url, body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// get token
|
|
||||||
if bdc.cfg.Token.AccessToken == "" {
|
|
||||||
if _, err = bdc.GetToken(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// refresh token
|
|
||||||
if bdc.cfg.Token.RefreshToken != "" && bdc.cfg.Token.Expiry.Add(-time.Duration(bdc.cfg.TimeToRefresh)*time.Minute).Before(time.Now()) {
|
|
||||||
if _, err := bdc.RefreshToken(ctx); err != nil {
|
|
||||||
if _, err = bdc.GetToken(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// perform request
|
|
||||||
reqCopy := req.Clone(ctx)
|
|
||||||
respBytes, err := bdc.do(req, ctype)
|
|
||||||
if err == nil {
|
|
||||||
return respBytes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// get token and retry in case of access denied
|
|
||||||
if err.Error() == "access is denied" {
|
|
||||||
_, err = bdc.GetToken(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
respBytes, err = bdc.do(reqCopy, ctype)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return respBytes, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetToken allows you to get a token and returns the token structure. When specifying the PathCfg variable,
|
|
||||||
// the token and configuration will be written to a file.
|
|
||||||
// When specifying the PathToken variable, the token will be written to a file.
|
|
||||||
func (bdc *BVSDecortClient) GetToken(ctx context.Context) (config.Token, error) {
|
|
||||||
bdc.mutex.Lock()
|
|
||||||
defer bdc.mutex.Unlock()
|
|
||||||
|
|
||||||
// set up request headers and body
|
|
||||||
body := fmt.Sprintf("grant_type=password&client_id=%s&client_secret=%s&username=%s&password=%s&response_type=token&scope=openid", bdc.cfg.AppID, bdc.cfg.AppSecret, bdc.cfg.Username, bdc.cfg.Password)
|
|
||||||
bodyReader := strings.NewReader(body)
|
|
||||||
|
|
||||||
bdc.cfg.SSOURL = strings.TrimSuffix(bdc.cfg.SSOURL, "/")
|
|
||||||
|
|
||||||
req, _ := http.NewRequestWithContext(ctx, "POST", bdc.cfg.SSOURL+"/realms/"+bdc.cfg.Domain+"/protocol/openid-connect/token", bodyReader)
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
|
|
||||||
// request token
|
|
||||||
resp, err := bdc.client.Do(req)
|
|
||||||
if err != nil || resp == nil {
|
|
||||||
return config.Token{}, fmt.Errorf("cannot get token: %w", err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
var tokenBytes []byte
|
|
||||||
tokenBytes, err = io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return config.Token{}, fmt.Errorf("cannot get token: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
return config.Token{}, fmt.Errorf("cannot get token: %s", tokenBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// save token in config
|
|
||||||
var tj tokenJSON
|
|
||||||
if err = json.Unmarshal(tokenBytes, &tj); err != nil {
|
|
||||||
return config.Token{}, fmt.Errorf("cannot unmarshal token: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
bdc.cfg.Token = config.Token{
|
|
||||||
AccessToken: tj.AccessToken,
|
|
||||||
TokenType: tj.TokenType,
|
|
||||||
RefreshToken: tj.RefreshToken,
|
|
||||||
Expiry: tj.expiry(),
|
|
||||||
}
|
|
||||||
|
|
||||||
if bdc.cfg.PathCfg != "" {
|
|
||||||
ser, _ := bdc.cfg.Serialize("", " ")
|
|
||||||
_ = ser.WriteToFile(bdc.cfg.PathCfg)
|
|
||||||
}
|
|
||||||
|
|
||||||
if bdc.cfg.PathToken != "" {
|
|
||||||
ser, _ := bdc.cfg.Token.Serialize("", " ")
|
|
||||||
_ = ser.WriteToFile(bdc.cfg.PathToken)
|
|
||||||
}
|
|
||||||
|
|
||||||
return bdc.cfg.Token, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// RefreshToken allows you to refresh a token and returns the token structure. When specifying the PathCfg variable,
|
|
||||||
// the token and configuration will be written to a file.
|
|
||||||
// When specifying the PathToken variable, the token will be written to a file
|
|
||||||
func (bdc *BVSDecortClient) RefreshToken(ctx context.Context) (config.Token, error) {
|
|
||||||
bdc.mutex.Lock()
|
|
||||||
defer bdc.mutex.Unlock()
|
|
||||||
|
|
||||||
// set up request headers and body
|
|
||||||
body := fmt.Sprintf("grant_type=refresh_token&client_id=%s&client_secret=%s&refresh_token=%s&scope=openid", bdc.cfg.AppID, bdc.cfg.AppSecret, bdc.cfg.Token.RefreshToken)
|
|
||||||
bodyReader := strings.NewReader(body)
|
|
||||||
|
|
||||||
bdc.cfg.SSOURL = strings.TrimSuffix(bdc.cfg.SSOURL, "/")
|
|
||||||
|
|
||||||
req, _ := http.NewRequestWithContext(ctx, "POST", bdc.cfg.SSOURL+"/realms/"+bdc.cfg.Domain+"/protocol/openid-connect/token", bodyReader)
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
|
|
||||||
// refresh token
|
|
||||||
resp, err := bdc.client.Do(req)
|
|
||||||
if err != nil || resp == nil {
|
|
||||||
return config.Token{}, fmt.Errorf("cannot refresh token: %w", err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
var tokenBytes []byte
|
|
||||||
tokenBytes, err = io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return config.Token{}, fmt.Errorf("cannot refresh token: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
return config.Token{}, fmt.Errorf("cannot refresh token: %s", tokenBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// save token in config
|
|
||||||
var tj tokenJSON
|
|
||||||
if err = json.Unmarshal(tokenBytes, &tj); err != nil {
|
|
||||||
return config.Token{}, fmt.Errorf("cannot unmarshal after refresh token: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
bdc.cfg.Token = config.Token{
|
|
||||||
AccessToken: tj.AccessToken,
|
|
||||||
TokenType: tj.TokenType,
|
|
||||||
RefreshToken: tj.RefreshToken,
|
|
||||||
Expiry: tj.expiry(),
|
|
||||||
}
|
|
||||||
|
|
||||||
if bdc.cfg.PathCfg != "" {
|
|
||||||
ser, _ := bdc.cfg.Serialize("", " ")
|
|
||||||
_ = ser.WriteToFile(bdc.cfg.PathCfg)
|
|
||||||
}
|
|
||||||
|
|
||||||
if bdc.cfg.PathToken != "" {
|
|
||||||
ser, _ := bdc.cfg.Token.Serialize("", " ")
|
|
||||||
_ = ser.WriteToFile(bdc.cfg.PathToken)
|
|
||||||
}
|
|
||||||
|
|
||||||
return bdc.cfg.Token, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *tokenJSON) expiry() (t time.Time) {
|
|
||||||
if v := e.ExpiresIn; v != 0 {
|
|
||||||
return time.Now().Add(time.Duration(v) * time.Second)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// do method performs request and returns response as an array of bytes and nil error in case of response status code 200.
|
|
||||||
// In any other cases do returns nil response and error.
|
|
||||||
// Retries are implemented in case of connection reset errors.
|
|
||||||
func (bdc *BVSDecortClient) do(req *http.Request, ctype string) ([]byte, error) {
|
|
||||||
// set up request headers and body
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
if ctype != "" {
|
|
||||||
req.Header.Set("Content-Type", ctype)
|
|
||||||
}
|
|
||||||
|
|
||||||
req.Header.Add("Authorization", "bearer "+bdc.cfg.Token.AccessToken)
|
|
||||||
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))
|
|
||||||
|
|
||||||
resp, err := bdc.client.Do(req)
|
|
||||||
if resp != nil {
|
|
||||||
defer resp.Body.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
// retries logic GOES HERE
|
|
||||||
// get http response
|
|
||||||
//var resp *http.Response
|
|
||||||
//for i := uint64(0); i < bdc.cfg.Retries; i++ {
|
|
||||||
// req := req.Clone(req.Context())
|
|
||||||
// req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
|
||||||
//
|
|
||||||
// if i > 0 {
|
|
||||||
// time.Sleep(5 * time.Second) // no time sleep for the first request
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// resp, err = bdc.client.Do(req)
|
|
||||||
//
|
|
||||||
// // stop retries on success and close response body
|
|
||||||
// if resp != nil {
|
|
||||||
// defer resp.Body.Close()
|
|
||||||
// }
|
|
||||||
// if err == nil {
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // retries in case of connection errors with time sleep
|
|
||||||
// if isConnectionError(err) {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // return error in case of non-connection error
|
|
||||||
// return nil, err
|
|
||||||
//}
|
|
||||||
|
|
||||||
// handle http request errors
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if resp == nil {
|
|
||||||
return nil, fmt.Errorf("got empty response without error")
|
|
||||||
}
|
|
||||||
|
|
||||||
var respBytes []byte
|
|
||||||
respBytes, err = io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle access denied and successful request
|
|
||||||
if resp.StatusCode == 401 {
|
|
||||||
return respBytes, errors.New("access is denied")
|
|
||||||
}
|
|
||||||
if resp.StatusCode == 200 {
|
|
||||||
return respBytes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle errors with other status codes
|
|
||||||
err = fmt.Errorf("%s", respBytes)
|
|
||||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func trimBVSConfig(cfg *config.BVSConfig) config.BVSConfig {
|
|
||||||
cfg.SSOURL = strings.TrimSuffix(cfg.SSOURL, "/")
|
|
||||||
cfg.DecortURL = strings.TrimSuffix(cfg.DecortURL, "/")
|
|
||||||
return *cfg
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package decortsdk
|
|
||||||
|
|
||||||
import (
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn"
|
|
||||||
)
|
|
||||||
|
|
||||||
type MockDecortClient struct {
|
|
||||||
apiCaller *MockCaller
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewMockDecortClient(apiCaller *MockCaller) ClientInterface {
|
|
||||||
return &MockDecortClient{
|
|
||||||
apiCaller: apiCaller,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CloudAPI builder
|
|
||||||
func (mdc *MockDecortClient) CloudAPI() *cloudapi.CloudAPI {
|
|
||||||
return cloudapi.New(mdc.apiCaller)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CloudBroker builder
|
|
||||||
func (mdc *MockDecortClient) CloudBroker() *cloudbroker.CloudBroker {
|
|
||||||
return cloudbroker.New(mdc.apiCaller)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SDN builder
|
|
||||||
func (mdc *MockDecortClient) SDN() *sdn.SDN {
|
|
||||||
return sdn.New(mdc.apiCaller)
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
// Code generated by MockGen. DO NOT EDIT.
|
|
||||||
// Source: interfaces/caller.go
|
|
||||||
//
|
|
||||||
// Generated by this command:
|
|
||||||
//
|
|
||||||
// mockgen -package decortsdk -source interfaces/caller.go
|
|
||||||
//
|
|
||||||
|
|
||||||
// Package decortsdk is a generated GoMock package.
|
|
||||||
package decortsdk
|
|
||||||
|
|
||||||
import (
|
|
||||||
context "context"
|
|
||||||
reflect "reflect"
|
|
||||||
|
|
||||||
gomock "go.uber.org/mock/gomock"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MockCaller is a mock of Caller interface.
|
|
||||||
type MockCaller struct {
|
|
||||||
ctrl *gomock.Controller
|
|
||||||
recorder *MockCallerMockRecorder
|
|
||||||
isgomock struct{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MockCallerMockRecorder is the mock recorder for MockCaller.
|
|
||||||
type MockCallerMockRecorder struct {
|
|
||||||
mock *MockCaller
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMockCaller creates a new mock instance.
|
|
||||||
func NewMockCaller(ctrl *gomock.Controller) *MockCaller {
|
|
||||||
mock := &MockCaller{ctrl: ctrl}
|
|
||||||
mock.recorder = &MockCallerMockRecorder{mock}
|
|
||||||
return mock
|
|
||||||
}
|
|
||||||
|
|
||||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
|
||||||
func (m *MockCaller) EXPECT() *MockCallerMockRecorder {
|
|
||||||
return m.recorder
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecortApiCall mocks base method.
|
|
||||||
func (m *MockCaller) DecortApiCall(ctx context.Context, method, url string, params any) ([]byte, error) {
|
|
||||||
m.ctrl.T.Helper()
|
|
||||||
ret := m.ctrl.Call(m, "DecortApiCall", ctx, method, url, params)
|
|
||||||
ret0, _ := ret[0].([]byte)
|
|
||||||
ret1, _ := ret[1].(error)
|
|
||||||
return ret0, ret1
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecortApiCall indicates an expected call of DecortApiCall.
|
|
||||||
func (mr *MockCallerMockRecorder) DecortApiCall(ctx, method, url, params any) *gomock.Call {
|
|
||||||
mr.mock.ctrl.T.Helper()
|
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DecortApiCall", reflect.TypeOf((*MockCaller)(nil).DecortApiCall), ctx, method, url, params)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecortApiCallCtype mocks base method.
|
|
||||||
func (m *MockCaller) DecortApiCallCtype(ctx context.Context, method, url, ctype string, params any) ([]byte, error) {
|
|
||||||
m.ctrl.T.Helper()
|
|
||||||
ret := m.ctrl.Call(m, "DecortApiCallCtype", ctx, method, url, ctype, params)
|
|
||||||
ret0, _ := ret[0].([]byte)
|
|
||||||
ret1, _ := ret[1].(error)
|
|
||||||
return ret0, ret1
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecortApiCallCtype indicates an expected call of DecortApiCallCtype.
|
|
||||||
func (mr *MockCallerMockRecorder) DecortApiCallCtype(ctx, method, url, ctype, params any) *gomock.Call {
|
|
||||||
mr.mock.ctrl.T.Helper()
|
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DecortApiCallCtype", reflect.TypeOf((*MockCaller)(nil).DecortApiCallCtype), ctx, method, url, ctype, params)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecortApiCallMP mocks base method.
|
|
||||||
func (m *MockCaller) DecortApiCallMP(ctx context.Context, method, url string, params any) ([]byte, error) {
|
|
||||||
m.ctrl.T.Helper()
|
|
||||||
ret := m.ctrl.Call(m, "DecortApiCallMP", ctx, method, url, params)
|
|
||||||
ret0, _ := ret[0].([]byte)
|
|
||||||
ret1, _ := ret[1].(error)
|
|
||||||
return ret0, ret1
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecortApiCallMP indicates an expected call of DecortApiCallMP.
|
|
||||||
func (mr *MockCallerMockRecorder) DecortApiCallMP(ctx, method, url, params any) *gomock.Call {
|
|
||||||
mr.mock.ctrl.T.Helper()
|
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DecortApiCallMP", reflect.TypeOf((*MockCaller)(nil).DecortApiCallMP), ctx, method, url, params)
|
|
||||||
}
|
|
||||||
101
config/config.go
101
config/config.go
@@ -1,101 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Configuration for creating request to platform
|
|
||||||
type Config struct {
|
|
||||||
// JWT platform token
|
|
||||||
// Required: false
|
|
||||||
// Example: "qwqwdfwv68979we0q9bfv7e9sbvd89798qrwv97ff"
|
|
||||||
Token string `json:"token" yaml:"token"`
|
|
||||||
|
|
||||||
// Application (client) identifier for authorization
|
|
||||||
// in the cloud platform controller in oauth2 mode.
|
|
||||||
// Required: true
|
|
||||||
// Example: "ewqfrvea7s890avw804389qwguf234h0otfi3w4eiu"
|
|
||||||
AppID string `json:"appId" yaml:"appId" validate:"required"`
|
|
||||||
|
|
||||||
// Application (client) secret code for authorization
|
|
||||||
// in the cloud platform controller in oauth2 mode.
|
|
||||||
// Example: "frvet09rvesfis0c9erv9fsov0vsdfi09ovds0f"
|
|
||||||
AppSecret string `json:"appSecret" yaml:"appSecret" validate:"required"`
|
|
||||||
|
|
||||||
// Platform authentication service address
|
|
||||||
// Required: true
|
|
||||||
// Example: "https://sso.digitalenergy.online"
|
|
||||||
SSOURL string `json:"ssoUrl" yaml:"ssoUrl" validate:"url"`
|
|
||||||
|
|
||||||
// The address of the platform on which the actions are planned
|
|
||||||
// Required: true
|
|
||||||
// Example: "https://mr4.digitalenergy.online"
|
|
||||||
DecortURL string `json:"decortUrl" yaml:"decortUrl" validate:"url"`
|
|
||||||
|
|
||||||
// Amount platform request attempts
|
|
||||||
// Default value: 5
|
|
||||||
// Required: false
|
|
||||||
Retries uint64 `json:"retries" yaml:"retries"`
|
|
||||||
|
|
||||||
// Skip verify
|
|
||||||
// Required: false
|
|
||||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
|
||||||
|
|
||||||
// HTTP client timeout, unlimited if left empty
|
|
||||||
// Required: false
|
|
||||||
Timeout Duration `json:"timeout" yaml:"timeout"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetTimeout is used to set HTTP client timeout.
|
|
||||||
func (c *Config) SetTimeout(dur time.Duration) {
|
|
||||||
c.Timeout = Duration(dur)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseConfigJSON parses Config from specified JSON-formatted file.
|
|
||||||
func ParseConfigJSON(path string) (Config, error) {
|
|
||||||
file, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return Config{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var config Config
|
|
||||||
|
|
||||||
err = json.Unmarshal(file, &config)
|
|
||||||
if err != nil {
|
|
||||||
return Config{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validators.ValidateConfig(config)
|
|
||||||
if err != nil {
|
|
||||||
return Config{}, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseConfigYAML parses Config from specified YAML-formatted file.
|
|
||||||
func ParseConfigYAML(path string) (Config, error) {
|
|
||||||
file, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return Config{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var config Config
|
|
||||||
|
|
||||||
err = yaml.Unmarshal(file, &config)
|
|
||||||
if err != nil {
|
|
||||||
return Config{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validators.ValidateConfig(config)
|
|
||||||
if err != nil {
|
|
||||||
return Config{}, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
@@ -1,216 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/serialization"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
type BVSConfig struct {
|
|
||||||
// ServiceAccount username
|
|
||||||
// Required: true
|
|
||||||
// Example : "osh_mikoev"
|
|
||||||
Username string `json:"username" yaml:"username" validate:"required"`
|
|
||||||
|
|
||||||
// ServiceAccount password
|
|
||||||
// Required: true
|
|
||||||
// Example: "[1o>hYkjnJr)HI78q7t&#%8Lm"
|
|
||||||
Password string `json:"password" yaml:"password" validate:"required"`
|
|
||||||
|
|
||||||
// Domain name
|
|
||||||
// Required: true
|
|
||||||
// Example: "dynamix"
|
|
||||||
Domain string `json:"domain" yaml:"domain" validate:"required"`
|
|
||||||
|
|
||||||
// Application (client) identifier for authorization
|
|
||||||
// in the cloud platform controller in oauth2 mode.
|
|
||||||
// Required: true
|
|
||||||
// Example: "ewqfrvea7s890avw804389qwguf234h0otfi3w4eiu"
|
|
||||||
AppID string `json:"appId" yaml:"appId" validate:"required"`
|
|
||||||
|
|
||||||
// Application (client) secret code for authorization
|
|
||||||
// in the cloud platform controller in oauth2 mode.
|
|
||||||
// Example: "frvet09rvesfis0c9erv9fsov0vsdfi09ovds0f"
|
|
||||||
AppSecret string `json:"appSecret" yaml:"appSecret" validate:"required"`
|
|
||||||
|
|
||||||
// Platform authentication service address
|
|
||||||
// Required: true
|
|
||||||
// Example: "https://sso.digitalenergy.online"
|
|
||||||
SSOURL string `json:"ssoUrl" yaml:"ssoUrl" validate:"url"`
|
|
||||||
|
|
||||||
// The address of the platform on which the actions are planned
|
|
||||||
// Required: true
|
|
||||||
// Example: "https://mr4.digitalenergy.online"
|
|
||||||
DecortURL string `json:"decortUrl" yaml:"decortUrl" validate:"url"`
|
|
||||||
|
|
||||||
// JWT platform token
|
|
||||||
// Required: false
|
|
||||||
// Example: "qwqwdfwv68979we0q9bfv7e9sbvd89798qrwv97ff"
|
|
||||||
Token Token `json:"token" yaml:"token"`
|
|
||||||
|
|
||||||
// Amount platform request attempts
|
|
||||||
// Default value: 5
|
|
||||||
// Required: false
|
|
||||||
Retries uint64 `json:"retries" yaml:"retries"`
|
|
||||||
|
|
||||||
// Skip verify
|
|
||||||
// Required: false
|
|
||||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
|
||||||
|
|
||||||
// HTTP client timeout, unlimited if left empty
|
|
||||||
// Required: false
|
|
||||||
Timeout Duration `json:"timeout" yaml:"timeout"`
|
|
||||||
|
|
||||||
// The path of the configuration file entry
|
|
||||||
// Required: false
|
|
||||||
PathCfg string `json:"path_cfg" yaml:"path_cfg"`
|
|
||||||
|
|
||||||
// The path of the token file entry
|
|
||||||
// Required: false
|
|
||||||
PathToken string `json:"path_token" yaml:"path_token"`
|
|
||||||
|
|
||||||
// The number of minutes before the expiration of the token, a refresh will be made
|
|
||||||
// Required: false
|
|
||||||
TimeToRefresh int64 `json:"timeToRefresh" yaml:"timeToRefresh"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Token struct {
|
|
||||||
// AccessToken is the token that authorizes and authenticates
|
|
||||||
// the requests.
|
|
||||||
// Required: false
|
|
||||||
AccessToken string `json:"access_token" yaml:"access_token"`
|
|
||||||
|
|
||||||
// TokenType is the type of token.
|
|
||||||
// The Type method returns either this or "Bearer", the default.
|
|
||||||
// Required: false
|
|
||||||
TokenType string `json:"token_type" yaml:"token_type"`
|
|
||||||
|
|
||||||
// RefreshToken is a token that's used by the application
|
|
||||||
// (as opposed to the user) to refresh the access token
|
|
||||||
// if it expires.
|
|
||||||
// Required: false
|
|
||||||
RefreshToken string `json:"refresh_token" yaml:"refresh_token"`
|
|
||||||
|
|
||||||
// Expiry is the optional expiration time of the access token.
|
|
||||||
// Required: false
|
|
||||||
Expiry time.Time `json:"expiry" yaml:"expiry"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetTimeout is used to set HTTP client timeout.
|
|
||||||
func (c *BVSConfig) SetTimeout(dur time.Duration) {
|
|
||||||
c.Timeout = Duration(dur)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseConfigJSON parses Config from specified JSON-formatted file.
|
|
||||||
func ParseConfigBVSJSON(path string) (BVSConfig, error) {
|
|
||||||
file, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return BVSConfig{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var config BVSConfig
|
|
||||||
|
|
||||||
err = json.Unmarshal(file, &config)
|
|
||||||
if err != nil {
|
|
||||||
return BVSConfig{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validators.ValidateConfig(config)
|
|
||||||
if err != nil {
|
|
||||||
return BVSConfig{}, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseConfigJSON parses Token from specified JSON-formatted file.
|
|
||||||
func ParseTokenBVSJSON(path string) (Token, error) {
|
|
||||||
file, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return Token{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var token Token
|
|
||||||
|
|
||||||
err = json.Unmarshal(file, &token)
|
|
||||||
if err != nil {
|
|
||||||
return Token{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validators.ValidateConfig(token)
|
|
||||||
if err != nil {
|
|
||||||
return Token{}, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
return token, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseTokenBVSYAML parses Token from specified YAML-formatted file.
|
|
||||||
func ParseTokenBVSYAML(path string) (Token, error) {
|
|
||||||
file, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return Token{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var token Token
|
|
||||||
|
|
||||||
err = yaml.Unmarshal(file, &token)
|
|
||||||
if err != nil {
|
|
||||||
return Token{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validators.ValidateConfig(token)
|
|
||||||
if err != nil {
|
|
||||||
return Token{}, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
return token, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseConfigYAML parses Config from specified YAML-formatted file.
|
|
||||||
func ParseConfigBVSYAML(path string) (BVSConfig, error) {
|
|
||||||
file, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return BVSConfig{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var config BVSConfig
|
|
||||||
|
|
||||||
err = yaml.Unmarshal(file, &config)
|
|
||||||
if err != nil {
|
|
||||||
return BVSConfig{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validators.ValidateConfig(config)
|
|
||||||
if err != nil {
|
|
||||||
return BVSConfig{}, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t Token) Serialize(params ...string) (serialization.Serialized, error) {
|
|
||||||
if len(params) > 1 {
|
|
||||||
prefix := params[0]
|
|
||||||
indent := params[1]
|
|
||||||
|
|
||||||
return json.MarshalIndent(t, prefix, indent)
|
|
||||||
}
|
|
||||||
|
|
||||||
return json.Marshal(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c BVSConfig) Serialize(params ...string) (serialization.Serialized, error) {
|
|
||||||
if len(params) > 1 {
|
|
||||||
prefix := params[0]
|
|
||||||
indent := params[1]
|
|
||||||
|
|
||||||
return json.MarshalIndent(c, prefix, indent)
|
|
||||||
}
|
|
||||||
|
|
||||||
return json.Marshal(c)
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Legacy client configuration
|
|
||||||
type LegacyConfig struct {
|
|
||||||
// ServiceAccount username
|
|
||||||
// Required: true
|
|
||||||
// Example : "osh_mikoev"
|
|
||||||
Username string `json:"username" yaml:"username" validate:"required"`
|
|
||||||
|
|
||||||
// ServiceAccount password
|
|
||||||
// Required: true
|
|
||||||
// Example: "[1o>hYkjnJr)HI78q7t&#%8Lm"
|
|
||||||
Password string `json:"password" yaml:"password" validate:"required"`
|
|
||||||
|
|
||||||
// Platform token
|
|
||||||
// Required: false
|
|
||||||
// Example: "158e76424b0d4810b6086hgbhj928fc4a6bc06e"
|
|
||||||
Token string `json:"token" yaml:"token"`
|
|
||||||
|
|
||||||
// Address of the platform on which the actions are planned
|
|
||||||
// Required: true
|
|
||||||
// Example: "https://mr4.digitalenergy.online"
|
|
||||||
DecortURL string `json:"decortUrl" yaml:"decortUrl" validate:"url"`
|
|
||||||
|
|
||||||
// Amount platform request attempts
|
|
||||||
// Default value: 5
|
|
||||||
// Required: false
|
|
||||||
Retries uint64 `json:"retries" yaml:"retries"`
|
|
||||||
|
|
||||||
// Skip verify
|
|
||||||
// Required: false
|
|
||||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
|
||||||
|
|
||||||
// HTTP client timeout, unlimited if left empty
|
|
||||||
// Required: false
|
|
||||||
Timeout Duration `json:"timeout" yaml:"timeout"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetTimeout is used to set HTTP client timeout.
|
|
||||||
func (c *LegacyConfig) SetTimeout(dur time.Duration) {
|
|
||||||
c.Timeout = Duration(dur)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseLegacyConfigJSON parses LegacyConfig from specified JSON-formatted file.
|
|
||||||
func ParseLegacyConfigJSON(path string) (LegacyConfig, error) {
|
|
||||||
file, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return LegacyConfig{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var config LegacyConfig
|
|
||||||
|
|
||||||
err = json.Unmarshal(file, &config)
|
|
||||||
if err != nil {
|
|
||||||
return LegacyConfig{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validators.ValidateConfig(config)
|
|
||||||
if err != nil {
|
|
||||||
return LegacyConfig{}, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseLegacyConfigYAML parses LegacyConfig from specified YAML-formatted file.
|
|
||||||
func ParseLegacyConfigYAML(path string) (LegacyConfig, error) {
|
|
||||||
file, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return LegacyConfig{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var config LegacyConfig
|
|
||||||
|
|
||||||
err = yaml.Unmarshal(file, &config)
|
|
||||||
if err != nil {
|
|
||||||
return LegacyConfig{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validators.ValidateConfig(config)
|
|
||||||
if err != nil {
|
|
||||||
return LegacyConfig{}, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Duration is a wrapper around time.Duration (used for better user experience)
|
|
||||||
type Duration time.Duration
|
|
||||||
|
|
||||||
func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
||||||
var v interface{}
|
|
||||||
if err := unmarshal(&v); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
switch value := v.(type) {
|
|
||||||
case string:
|
|
||||||
tmp, err := time.ParseDuration(value)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*d = Duration(tmp)
|
|
||||||
return nil
|
|
||||||
case float64:
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("invalid duration %v", value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Duration) UnmarshalJSON(b []byte) error {
|
|
||||||
var v interface{}
|
|
||||||
if err := json.Unmarshal(b, &v); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
switch value := v.(type) {
|
|
||||||
case string:
|
|
||||||
tmp, err := time.ParseDuration(value)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*d = Duration(tmp)
|
|
||||||
return nil
|
|
||||||
case float64:
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("invalid duration %v", value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Duration) Get() time.Duration {
|
|
||||||
return time.Duration(*d)
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
// UniversalConfig combines configurations for different types of clients
|
|
||||||
type UniversalConfig struct {
|
|
||||||
Decs3oConfig *Config `json:"decs3oConfig,omitempty" yaml:"decs3oConfig,omitempty"`
|
|
||||||
BVSConfig *BVSConfig `json:"bvsConfig,omitempty" yaml:"bvsConfig,omitempty"`
|
|
||||||
LegacyConfig *LegacyConfig `json:"legacyConfig,omitempty" yaml:"legacyConfig,omitempty"`
|
|
||||||
}
|
|
||||||
25
go.mod
25
go.mod
@@ -1,25 +0,0 @@
|
|||||||
module repository.basistech.ru/BASIS/decort-golang-sdk
|
|
||||||
|
|
||||||
go 1.24.0
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/go-playground/validator/v10 v10.28.0
|
|
||||||
github.com/google/go-querystring v1.1.0
|
|
||||||
github.com/joho/godotenv v1.5.1
|
|
||||||
github.com/stretchr/testify v1.9.0
|
|
||||||
go.uber.org/mock v0.6.0
|
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
|
||||||
github.com/gabriel-vasile/mimetype v1.4.10 // indirect
|
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
|
||||||
github.com/google/go-cmp v0.5.9 // indirect
|
|
||||||
github.com/leodido/go-urn v1.4.0 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
|
||||||
golang.org/x/crypto v0.42.0 // indirect
|
|
||||||
golang.org/x/sys v0.36.0 // indirect
|
|
||||||
golang.org/x/text v0.29.0 // indirect
|
|
||||||
)
|
|
||||||
38
go.sum
38
go.sum
@@ -1,38 +0,0 @@
|
|||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/gabriel-vasile/mimetype v1.4.10 h1:zyueNbySn/z8mJZHLt6IPw0KoZsiQNszIpU+bX4+ZK0=
|
|
||||||
github.com/gabriel-vasile/mimetype v1.4.10/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
|
||||||
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
|
||||||
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
|
||||||
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
|
||||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
|
||||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
|
||||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
|
||||||
github.com/go-playground/validator/v10 v10.28.0 h1:Q7ibns33JjyW48gHkuFT91qX48KG0ktULL6FgHdG688=
|
|
||||||
github.com/go-playground/validator/v10 v10.28.0/go.mod h1:GoI6I1SjPBh9p7ykNE/yj3fFYbyDOpwMn5KXd+m2hUU=
|
|
||||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
|
||||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
|
||||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
|
||||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
|
||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
|
||||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
|
||||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
|
||||||
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
|
|
||||||
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
|
|
||||||
golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
|
|
||||||
golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
|
|
||||||
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
|
|
||||||
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
|
||||||
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
|
|
||||||
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package interfaces
|
|
||||||
|
|
||||||
import "context"
|
|
||||||
|
|
||||||
// Interface for sending requests to platform
|
|
||||||
type Caller interface {
|
|
||||||
// DecortApiCall method for sending requests to the platform
|
|
||||||
DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error)
|
|
||||||
|
|
||||||
// DecortApiCallCtype method for sending requests to the platform
|
|
||||||
DecortApiCallCtype(ctx context.Context, method, url, ctype string, params interface{}) ([]byte, error)
|
|
||||||
|
|
||||||
// DecortApiCallMP method for sending requests to the platform
|
|
||||||
DecortApiCallMP(ctx context.Context, method, url string, params interface{}) ([]byte, error)
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package interfaces
|
|
||||||
|
|
||||||
// Interface to valiate RAM values
|
|
||||||
type RequestWithRAM interface {
|
|
||||||
// GetRAM returns RAM values
|
|
||||||
GetRAM() map[string]uint64
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package constants
|
|
||||||
|
|
||||||
const (
|
|
||||||
RESTMACHINE = "/restmachine"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
MIMEJSON = "application/json"
|
|
||||||
MIMEHTML = "text/html"
|
|
||||||
MIMEXML = "application/xml"
|
|
||||||
MIMEXML2 = "text/xml"
|
|
||||||
MIMEPlain = "text/plain"
|
|
||||||
MIMEPOSTForm = "application/x-www-form-urlencoded"
|
|
||||||
MIMEMultipartPOSTForm = "multipart/form-data"
|
|
||||||
MIMEPROTOBUF = "application/x-protobuf"
|
|
||||||
MIMEMSGPACK = "application/x-msgpack"
|
|
||||||
MIMEMSGPACK2 = "application/msgpack"
|
|
||||||
MIMEYAML = "application/x-yaml"
|
|
||||||
MIMEYAML2 = "application/yaml"
|
|
||||||
MIMETOML = "application/toml"
|
|
||||||
MIMESTREAM = "application/octet-stream"
|
|
||||||
)
|
|
||||||
|
|
||||||
var FileName = map[string]string{
|
|
||||||
"OidcCertificate": "ca.crt",
|
|
||||||
}
|
|
||||||
|
|
||||||
var K8sValues = []string{"labels", "taints", "annotations, additionalSANs"}
|
|
||||||
|
|
||||||
var VersionMap = map[string]string{
|
|
||||||
"4.7.0": "-",
|
|
||||||
"4.6.0": "-",
|
|
||||||
"4.5.0": "-",
|
|
||||||
"4.4.0": "-",
|
|
||||||
"4.3.0": "-",
|
|
||||||
"4.2.0": "-",
|
|
||||||
"4.1.1": "-",
|
|
||||||
"4.1.0": "-",
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package serialization
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Writable interface {
|
|
||||||
WriteToFile(string) error
|
|
||||||
}
|
|
||||||
|
|
||||||
type Serialized []byte
|
|
||||||
|
|
||||||
// WriteToFile writes serialized data to specified file.
|
|
||||||
//
|
|
||||||
// Make sure to use .json extension for best compatibility.
|
|
||||||
func (s Serialized) WriteToFile(path string) error {
|
|
||||||
return os.WriteFile(path, s, 0600)
|
|
||||||
}
|
|
||||||
@@ -1,486 +0,0 @@
|
|||||||
package validators
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"net/url"
|
|
||||||
"reflect"
|
|
||||||
"regexp"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/go-playground/validator/v10"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/multierror"
|
|
||||||
)
|
|
||||||
|
|
||||||
// protoValidator is used to validate Proto fields.
|
|
||||||
func protoValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, protoValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// apiGroupValidator is used to validate APIGroup fields
|
|
||||||
func apiGroupValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, apiGroupValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// accessTypeValidator is used to validate AccessType fields.
|
|
||||||
func accessTypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, accessTypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// resTypesValidator is used to validate ResTypes fields.
|
|
||||||
func resTypesValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldSlice, ok := fe.Field().Interface().([]string)
|
|
||||||
if !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, value := range fieldSlice {
|
|
||||||
if !IsInSlice(value, resTypesValues) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// accountCUTypeValidator is used to validate CUType field.
|
|
||||||
func accountCUTypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, accountCUTypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// bserviceModeValidator is used to validate Mode field.
|
|
||||||
func bserviceModeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, bserviceModeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// computeTopologyValidator is used to validate Topology field.
|
|
||||||
func computeTopologyValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, computeTopologyValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// computePolicyValidator is used to validate Policy field.
|
|
||||||
func computePolicyValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, computePolicyValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// computeModeValidator is used to validate Mode field.
|
|
||||||
func computeModeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, computeModeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// computeNetTypeValidator is used to validate NetType field.
|
|
||||||
func computeNetTypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, computeNetTypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// computex86NetTypeValidator is used to validate NetType field.
|
|
||||||
func computex86NetTypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, computex86NetTypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// securityGroupDirectionValidator is used to validate Direction field
|
|
||||||
func securityGroupDirectionValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, securityGroupDirectionValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// securityGroupEthertypeValidator is used to validate Ethertype field
|
|
||||||
func securityGroupEthertypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, securityGroupEthertypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// securityGroupProtocolValidator is used to validate Protocol field
|
|
||||||
func securityGroupProtocolValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, securityGroupProtocolValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// computeOrderValidator is used to validate Order field.
|
|
||||||
func computeOrderValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldSlice, ok := fe.Field().Interface().([]string)
|
|
||||||
if !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, value := range fieldSlice {
|
|
||||||
if !IsInSlice(value, computeOrderValues) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// computeDataDisksValidator is used to validate DataDisks field.
|
|
||||||
func computeDataDisksValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, computeDataDisksValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// flipgroupClientTypeValidator is used to validate ClientType field.
|
|
||||||
func flipgroupClientTypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, flipgroupClientTypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// massCreateTypeValidator is used to validate net type field when mass creating kvm
|
|
||||||
func massCreateTypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, massCreateNetTypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// lbAlgorithmValidator is used to validate Algorithm field.
|
|
||||||
func lbAlgorithmValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, lbAlgorithmValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// rgDefNetValidator is used to validate DefNet field.
|
|
||||||
func rgDefNetValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, rgDefNetValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// rgNetTypeValidator is used to validate NetType field.
|
|
||||||
func rgNetTypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, rgNetTypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// vinsTypeValidator is used to validate Type field.
|
|
||||||
func vinsTypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, vinsTypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// imageBootTypeValidator is used to validate BootType field.
|
|
||||||
func imageBootTypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, imageBootTypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// imageTypeValidator is used to validate ImageType field.
|
|
||||||
func imageTypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, imageTypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// imageArchitectureValidator is used to validate Architecture field.
|
|
||||||
func imageArchitectureValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, imageArchitectureValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// sepFieldTypeValidator is used to validate FieldType field.
|
|
||||||
func sepFieldTypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, sepFieldTypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// hwPathValidator is used to validate HWPath field.
|
|
||||||
func hwPathValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
ok, _ := regexp.MatchString(`^\b[0-9a-f]{4}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}.\d{1}$`, fieldValue)
|
|
||||||
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
// networkPluginValidator is used to validate NetworkPlugin field
|
|
||||||
func networkPluginValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
fieldValue = strings.ToLower(fieldValue)
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, networkPluginValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// networkPluginsValidator is used to validate NetworkPlugins field
|
|
||||||
func networkPluginsValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldSlice, ok := fe.Field().Interface().([]string)
|
|
||||||
if !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, item := range fieldSlice {
|
|
||||||
item = strings.ToLower(item)
|
|
||||||
|
|
||||||
if !IsInSlice(item, networkPluginValues) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func interfaceStateValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
fieldValue = strings.ToLower(fieldValue)
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, interfaceStateValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
func interfaceTXModelValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
fieldValue = strings.ToLower(fieldValue)
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, txModelValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
func interfaceIOEventFDValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
fieldValue = strings.ToLower(fieldValue)
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, ioEventFDValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
func interfaceEventIDxValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
fieldValue = strings.ToLower(fieldValue)
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, eventIDxValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
func strictLooseValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
fieldValue = strings.ToLower(fieldValue)
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, strictLooseValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// name workerGroup must be more 3 symbol
|
|
||||||
func workerGroupNameValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
fieldValue = strings.Trim(fieldValue, " ")
|
|
||||||
|
|
||||||
return len(fieldValue) >= 3
|
|
||||||
}
|
|
||||||
|
|
||||||
func sortByValidator(fe validator.FieldLevel) bool {
|
|
||||||
|
|
||||||
sortByRegexp := regexp.MustCompile(`^[+-][a-zA-Z_]+`)
|
|
||||||
|
|
||||||
return sortByRegexp.MatchString(fe.Field().String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func actionValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, actionValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
func vmActionValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, vmActionValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
func mtuValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().Uint()
|
|
||||||
|
|
||||||
return fieldValue >= uint64(mtuMin) && fieldValue <= uint64(mtuMax)
|
|
||||||
}
|
|
||||||
|
|
||||||
func computeFeaturesValidator(fe validator.FieldLevel) bool {
|
|
||||||
field := fe.Field()
|
|
||||||
slice, ok := field.Interface().([]string)
|
|
||||||
if !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return IsSubSlice(slice, computeFeaturesValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
func networkInterfaceNamingValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, networkInterfaceNamingValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
func numaAffinityValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, numaAffinityValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// kvmx86NetTypeValidator is used to validate NetType field for x86 compute.
|
|
||||||
func kvmx86NetTypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, kvmx86NetTypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
func isBoolTypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
return fe.Field().CanConvert(reflect.TypeOf(true))
|
|
||||||
}
|
|
||||||
|
|
||||||
func urlValidartor(fl validator.FieldLevel) bool {
|
|
||||||
fieldValues := fl.Field().String()
|
|
||||||
|
|
||||||
_, err := url.ParseRequestURI(fieldValues)
|
|
||||||
return err == nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func chipsetValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, chipsetValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
func preferredCPUValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldSlice, ok := fe.Field().Interface().([]int64)
|
|
||||||
if !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, value := range fieldSlice {
|
|
||||||
if value < -1 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// loaderTypeValidator is used to validate loaderType fields
|
|
||||||
func loaderTypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, loaderTypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// languageValidator is used to validate language fields
|
|
||||||
func languageValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, languageValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
func userProviderValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, userProviders)
|
|
||||||
}
|
|
||||||
|
|
||||||
// sepTypeValidator is used to validate sepType fields
|
|
||||||
func sepTypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, sepTypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// deviceValidator is used to validate extnet device fields
|
|
||||||
func deviceValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, deviceValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ipTypesValidator is used to validate ip types version fields
|
|
||||||
func ipTypesValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, ipTypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ValidateRAM checks if request contains RAM value that is positive integer divisible by divisibility passed.
|
|
||||||
// It is recommended to pass constants.RAM_DIVISIBILITY as divisility arguement
|
|
||||||
func ValidateRAM(r interfaces.RequestWithRAM, divisibility uint64) error {
|
|
||||||
|
|
||||||
if divisibility == 0 {
|
|
||||||
|
|
||||||
return errors.New("second argument of ValidateRAM should be greater than 0")
|
|
||||||
}
|
|
||||||
mapRAM := r.GetRAM()
|
|
||||||
|
|
||||||
errs := make([]error, 0, len(mapRAM))
|
|
||||||
|
|
||||||
for k, v := range mapRAM {
|
|
||||||
|
|
||||||
if v%divisibility != 0 {
|
|
||||||
|
|
||||||
errs = append(errs, fmt.Errorf("expected value of %s: \"%d\" should be divisible by %d", k, v, divisibility))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return multierror.Join(errs...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// trunkTagsValidator checks if trunk_tags is in range from 1 to 4095
|
|
||||||
func trunkTagsValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
numFieldValue, err := strconv.ParseInt(fieldValue, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return uint64(numFieldValue) >= uint64(trunkTagsMin) && uint64(numFieldValue) <= uint64(trunkTagsMax)
|
|
||||||
}
|
|
||||||
|
|
||||||
// addressPoolNetTypeValidator is used to validate NetAddressType fields
|
|
||||||
func addressPoolNetTypeValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, addressPoolNetTypeValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// sepTechStatusValidator is used to validate SepTechStatus fields
|
|
||||||
func sepTechStatusValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
return IsInSlice(fieldValue, sepTechStatusValues)
|
|
||||||
}
|
|
||||||
|
|
||||||
// pciDeviceHWPathValidator is used to validate PCI device hardware path fields (e.g. 0000:81:00.0)
|
|
||||||
func pciDeviceHWPathValidator(fe validator.FieldLevel) bool {
|
|
||||||
fieldValue := fe.Field().String()
|
|
||||||
|
|
||||||
ok, _ := regexp.MatchString(`^[0-9a-fA-F]{4}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-7]$`, fieldValue)
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
// sepNameValidator is used to validate SEP name fields
|
|
||||||
func sepNameValidator(fe validator.FieldLevel) bool {
|
|
||||||
ok, _ := regexp.MatchString(`^[a-zA-Zа-яА-ЯёЁ0-9][a-zA-Zа-яА-ЯёЁ0-9_.\[\]()\-]*$`, fe.Field().String())
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
// sepDescriptionValidator is used to validate SEP description fields
|
|
||||||
func sepDescriptionValidator(fe validator.FieldLevel) bool {
|
|
||||||
ok, _ := regexp.MatchString(`^[a-zA-Zа-яА-ЯёЁ0-9_.\[\]()\-]*$`, fe.Field().String())
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
package validators
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/multierror"
|
|
||||||
|
|
||||||
"github.com/go-playground/validator/v10"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ValidateRequest(req interface{}) error {
|
|
||||||
validate := getDecortValidator()
|
|
||||||
return validate.Struct(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ValidateConfig(cfg interface{}) error {
|
|
||||||
validate := getDecortValidator()
|
|
||||||
return validate.Struct(cfg)
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsInSlice(str string, target []string) bool {
|
|
||||||
for _, v := range target {
|
|
||||||
if v == str {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func IsSubSlice(source []string, target []string) bool {
|
|
||||||
for _, s := range source {
|
|
||||||
if !IsInSlice(s, target) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
@@ -1,369 +0,0 @@
|
|||||||
package validators
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/go-playground/validator/v10"
|
|
||||||
)
|
|
||||||
|
|
||||||
func errorMessage(fe validator.FieldError) string {
|
|
||||||
prefix := "validation-error:"
|
|
||||||
|
|
||||||
switch fe.Tag() {
|
|
||||||
|
|
||||||
// Common Validators
|
|
||||||
case "required":
|
|
||||||
return fmt.Sprintf("%s %s is required", prefix, fe.Field())
|
|
||||||
case "gt":
|
|
||||||
return fmt.Sprintf("%s %s can't be less or equal to zero", prefix, fe.Field())
|
|
||||||
case "min":
|
|
||||||
return fmt.Sprintf("%s %s: not enough elements", prefix, fe.Field())
|
|
||||||
case "max":
|
|
||||||
return fmt.Sprintf("%s %s: too many elements", prefix, fe.Field())
|
|
||||||
case "url":
|
|
||||||
return fmt.Sprintf("%s %s: unexpected URL format", prefix, fe.Field())
|
|
||||||
case "email":
|
|
||||||
return fmt.Sprintf("%s %s: unexpected E-Mail format", prefix, fe.Field())
|
|
||||||
case "isBool":
|
|
||||||
return fmt.Sprintf("%s %s: must be bool type", prefix, fe.Field())
|
|
||||||
|
|
||||||
case "accessType":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(accessTypeValues))
|
|
||||||
|
|
||||||
case "resTypes":
|
|
||||||
return fmt.Sprintf("%s %s can contain only the following values: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(resTypesValues))
|
|
||||||
|
|
||||||
case "proto":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(protoValues))
|
|
||||||
|
|
||||||
// apiGroup Validators
|
|
||||||
case "apiGroup":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(apiGroupValues))
|
|
||||||
|
|
||||||
// Account Validators
|
|
||||||
case "accountCUType":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(accountCUTypeValues))
|
|
||||||
|
|
||||||
// BService Validators
|
|
||||||
case "bserviceMode":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(bserviceModeValues))
|
|
||||||
|
|
||||||
// Compute Validators
|
|
||||||
case "computeTopology":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(computeTopologyValues))
|
|
||||||
|
|
||||||
case "computePolicy":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(computePolicyValues))
|
|
||||||
|
|
||||||
case "computeMode":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(computeModeValues))
|
|
||||||
|
|
||||||
case "mtu":
|
|
||||||
return fmt.Sprint(prefix, fe.Field(), "must be ", mtuMin, "-", mtuMax)
|
|
||||||
|
|
||||||
case "preferredCPU":
|
|
||||||
return fmt.Sprint(prefix, fe.Field(), "must be equal to or greater than", -1)
|
|
||||||
|
|
||||||
case "computex86NetType":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(computex86NetTypeValues))
|
|
||||||
|
|
||||||
case "computeNetType":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(computeNetTypeValues))
|
|
||||||
|
|
||||||
case "computeOrder":
|
|
||||||
return fmt.Sprintf("%s %s can contain only the following values: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(computeOrderValues))
|
|
||||||
|
|
||||||
case "computeDataDisks":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(computeDataDisksValues))
|
|
||||||
|
|
||||||
// Flipgroup Validators
|
|
||||||
case "flipgroupClientType":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(flipgroupClientTypeValues))
|
|
||||||
|
|
||||||
// k8s Validators
|
|
||||||
case "workerGroupName":
|
|
||||||
return fmt.Sprintf("%s %s must be more 3 symbol",
|
|
||||||
prefix,
|
|
||||||
fe.Field())
|
|
||||||
|
|
||||||
// KVM_X86 Mass create validators
|
|
||||||
case "massCreateNetType":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(massCreateNetTypeValues))
|
|
||||||
|
|
||||||
// LB Validators
|
|
||||||
case "lbAlgorithm":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(lbAlgorithmValues))
|
|
||||||
|
|
||||||
// RG Validators
|
|
||||||
case "rgDefNet":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(rgDefNetValues))
|
|
||||||
|
|
||||||
case "rgNetType":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(rgNetTypeValues))
|
|
||||||
|
|
||||||
// ViNS Validators
|
|
||||||
case "vinsType":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(vinsTypeValues))
|
|
||||||
|
|
||||||
// Image Validators
|
|
||||||
case "imageBootType":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(imageBootTypeValues))
|
|
||||||
|
|
||||||
case "imageType":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(imageTypeValues))
|
|
||||||
|
|
||||||
case "imageArchitecture":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(imageArchitectureValues))
|
|
||||||
|
|
||||||
// SEP Validators
|
|
||||||
case "sepFieldType":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(sepFieldTypeValues))
|
|
||||||
|
|
||||||
// HWPath Validators
|
|
||||||
case "hwPath":
|
|
||||||
return fmt.Sprintf("%s %s must be in format 0000:1f:2b.0",
|
|
||||||
prefix,
|
|
||||||
fe.Field())
|
|
||||||
|
|
||||||
// Network plugin Validators
|
|
||||||
case "networkPlugin":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(networkPluginValues))
|
|
||||||
|
|
||||||
case "networkPlugins":
|
|
||||||
return fmt.Sprintf("%s %s must contain only the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(networkPluginValues))
|
|
||||||
|
|
||||||
case "strict_loose":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(strictLooseValues))
|
|
||||||
|
|
||||||
case "interfaceState":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(interfaceStateValues))
|
|
||||||
|
|
||||||
case "interfaceTXModel":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(txModelValues))
|
|
||||||
|
|
||||||
case "interfaceIOEventFD":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(ioEventFDValues))
|
|
||||||
|
|
||||||
case "interfaceEventIDx":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(eventIDxValues))
|
|
||||||
|
|
||||||
case "sortBy":
|
|
||||||
return fmt.Sprintf("%s %s must be in format +|-(field)",
|
|
||||||
prefix,
|
|
||||||
fe.Field())
|
|
||||||
|
|
||||||
case "action":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(actionValues))
|
|
||||||
|
|
||||||
case "vmaction":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(vmActionValues))
|
|
||||||
|
|
||||||
case "computeFeatures":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(computeFeaturesValues))
|
|
||||||
|
|
||||||
case "networkInterfaceNaming":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(networkInterfaceNamingValues))
|
|
||||||
|
|
||||||
case "numaAffinity":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(numaAffinityValues))
|
|
||||||
|
|
||||||
case "kvmx86NetType":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(kvmx86NetTypeValues))
|
|
||||||
|
|
||||||
case "chipset":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(chipsetValues))
|
|
||||||
|
|
||||||
case "loaderType":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(loaderTypeValues))
|
|
||||||
|
|
||||||
case "language":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(languageValues))
|
|
||||||
|
|
||||||
case "sepType":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(sepTypeValues))
|
|
||||||
|
|
||||||
// user validators
|
|
||||||
case "userProvider":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(userProviders))
|
|
||||||
|
|
||||||
// security group validators
|
|
||||||
case "securityGroupDirection":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(securityGroupDirectionValues))
|
|
||||||
|
|
||||||
case "securityGroupEthertype":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(securityGroupEthertypeValues))
|
|
||||||
|
|
||||||
case "securityGroupProtocol":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(securityGroupProtocolValues))
|
|
||||||
|
|
||||||
// trunk tags validator
|
|
||||||
case "trunkTags":
|
|
||||||
return fmt.Sprintf("%s %s must be in range from 1 to 4095",
|
|
||||||
prefix,
|
|
||||||
fe.Field())
|
|
||||||
|
|
||||||
// addressPoolNetTypeValidator validator
|
|
||||||
case "addressPoolNetTypeValidator":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(addressPoolNetTypeValues))
|
|
||||||
|
|
||||||
case "device":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(deviceValues))
|
|
||||||
|
|
||||||
case "ipTypes":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(ipTypeValues))
|
|
||||||
|
|
||||||
case "sepTechStatus":
|
|
||||||
return fmt.Sprintf("%s %s must be one of the following: %s",
|
|
||||||
prefix,
|
|
||||||
fe.Field(),
|
|
||||||
joinValues(sepTechStatusValues))
|
|
||||||
}
|
|
||||||
|
|
||||||
return fe.Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
func joinValues(values []string) string {
|
|
||||||
return strings.Join(values, ", ")
|
|
||||||
}
|
|
||||||
@@ -1,325 +0,0 @@
|
|||||||
package validators
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/go-playground/validator/v10"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
once sync.Once
|
|
||||||
decortValidator = validator.New()
|
|
||||||
)
|
|
||||||
|
|
||||||
// getDecortValidator returns singleton instance of DecortValidator.
|
|
||||||
func getDecortValidator() *validator.Validate {
|
|
||||||
once.Do(func() {
|
|
||||||
err := registerAllValidators(decortValidator)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return decortValidator
|
|
||||||
}
|
|
||||||
|
|
||||||
// registerAllValidators registers all custom validators in DecortValidator.
|
|
||||||
func registerAllValidators(validate *validator.Validate) error {
|
|
||||||
|
|
||||||
err := validate.RegisterValidation("proto", protoValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("apiGroup", apiGroupValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("accessType", accessTypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("resTypes", resTypesValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("imageBootType", imageBootTypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("imageType", imageTypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("imageArchitecture", imageArchitectureValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("accountCUType", accountCUTypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("bserviceMode", bserviceModeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("computeTopology", computeTopologyValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("computePolicy", computePolicyValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("computeMode", computeModeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("computeNetType", computeNetTypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("computex86NetType", computex86NetTypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("computeOrder", computeOrderValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("computeDataDisks", computeDataDisksValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("flipgroupClientType", flipgroupClientTypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("massCreateNetType", massCreateTypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("lbAlgorithm", lbAlgorithmValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("rgDefNet", rgDefNetValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("rgNetType", rgNetTypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("vinsType", vinsTypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("sepFieldType", sepFieldTypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("hwPath", hwPathValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("networkPlugin", networkPluginValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("networkPlugins", networkPluginsValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("strict_loose", strictLooseValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("interfaceState", interfaceStateValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("interfaceTXModel", interfaceTXModelValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("interfaceIOEventFD", interfaceIOEventFDValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("interfaceEventIDx", interfaceEventIDxValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("workerGroupName", workerGroupNameValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("sortBy", sortByValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("action", actionValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("vmaction", vmActionValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("mtu", mtuValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("computeFeatures", computeFeaturesValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("networkInterfaceNaming", networkInterfaceNamingValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("numaAffinity", numaAffinityValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("kvmx86NetType", kvmx86NetTypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("isBool", isBoolTypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("url", urlValidartor)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("chipset", chipsetValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("preferredCPU", preferredCPUValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("loaderType", loaderTypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("language", languageValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("userProvider", userProviderValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("sepType", sepTypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("device", deviceValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("trunkTags", trunkTagsValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("securityGroupDirection", securityGroupDirectionValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("securityGroupEthertype", securityGroupEthertypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("securityGroupProtocol", securityGroupProtocolValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("addressPoolNetTypeValidator", addressPoolNetTypeValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("ipTypes", ipTypesValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("sepTechStatus", sepTechStatusValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("pciDeviceHWPath", pciDeviceHWPathValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("sepName", sepNameValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = validate.RegisterValidation("sepDescription", sepDescriptionValidator)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
package validators
|
|
||||||
|
|
||||||
var (
|
|
||||||
apiGroupValues = []string{"cloudapi", "cloudbroker", "system"}
|
|
||||||
|
|
||||||
accessTypeValues = []string{"R", "RCX", "ARCXDU"}
|
|
||||||
resTypesValues = []string{"compute", "vins", "k8s", "openshift", "lb", "flipgroup"}
|
|
||||||
protoValues = []string{"tcp", "udp"}
|
|
||||||
|
|
||||||
accountCUTypeValues = []string{"CU_M", "CU_C", "CU_D", "CU_DM", "CU_I", "gpu_units"}
|
|
||||||
|
|
||||||
bserviceModeValues = []string{"ABSOLUTE", "RELATIVE"}
|
|
||||||
|
|
||||||
computeTopologyValues = []string{"compute", "node"}
|
|
||||||
computePolicyValues = []string{"RECOMMENDED", "REQUIRED"}
|
|
||||||
computeModeValues = []string{"EQ", "EN", "ANY"}
|
|
||||||
computeNetTypeValues = []string{"EXTNET", "VINS"}
|
|
||||||
computex86NetTypeValues = []string{"EXTNET", "VINS", "VFNIC", "DPDK", "SDN", "EMPTY", "TRUNK"}
|
|
||||||
computeOrderValues = []string{"cdrom", "network", "hd"}
|
|
||||||
computeDataDisksValues = []string{"KEEP", "DETACH", "DESTROY"}
|
|
||||||
|
|
||||||
flipgroupClientTypeValues = []string{"compute", "vins"}
|
|
||||||
|
|
||||||
massCreateNetTypeValues = []string{"EXTNET", "VINS", "TRUNK"}
|
|
||||||
kvmx86NetTypeValues = []string{"EXTNET", "VINS", "EMPTY", "VFNIC", "DPDK", "SDN", "TRUNK"}
|
|
||||||
|
|
||||||
lbAlgorithmValues = []string{"roundrobin", "static-rr", "leastconn"}
|
|
||||||
|
|
||||||
rgDefNetValues = []string{"PRIVATE", "PUBLIC", "NONE"}
|
|
||||||
rgNetTypeValues = []string{"PUBLIC", "PRIVATE"}
|
|
||||||
|
|
||||||
vinsTypeValues = []string{"DHCP", "VIP", "EXCLUDED"}
|
|
||||||
|
|
||||||
imageBootTypeValues = []string{"uefi", "bios"}
|
|
||||||
imageTypeValues = []string{"windows", "linux", "unknown"}
|
|
||||||
imageArchitectureValues = []string{"X86_64"}
|
|
||||||
|
|
||||||
sepFieldTypeValues = []string{"int", "str", "bool", "list", "dict"}
|
|
||||||
|
|
||||||
networkPluginValues = []string{"flannel", "weavenet", "calico"}
|
|
||||||
|
|
||||||
strictLooseValues = []string{"strict", "loose"}
|
|
||||||
|
|
||||||
interfaceStateValues = []string{"on", "off"}
|
|
||||||
|
|
||||||
actionValues = []string{"is_powered", "power_on", "shutdown", "force_shutdown", "reboot"}
|
|
||||||
|
|
||||||
vmActionValues = []string{"stop", "move"}
|
|
||||||
|
|
||||||
computeFeaturesValues = []string{"hugepages", "numa", "cpupin", "vfnic", "dpdk", "changemac", "trunk"}
|
|
||||||
|
|
||||||
networkInterfaceNamingValues = []string{"eth", "ens"}
|
|
||||||
|
|
||||||
numaAffinityValues = []string{"none", "strict", "loose"}
|
|
||||||
|
|
||||||
txModelValues = []string{"iothread", "timer", "selected by hypervisor"}
|
|
||||||
|
|
||||||
ioEventFDValues = []string{"on", "off", "selected by hypervisor"}
|
|
||||||
|
|
||||||
eventIDxValues = []string{"on", "off", "selected by hypervisor"}
|
|
||||||
|
|
||||||
chipsetValues = []string{"i440fx", "Q35"}
|
|
||||||
|
|
||||||
loaderTypeValues = []string{"linux", "windows", "unknown"}
|
|
||||||
|
|
||||||
sepTypeValues = []string{"hitachi", "dorado", "tatlin", "shared", "local", "des", "ustor"}
|
|
||||||
|
|
||||||
languageValues = []string{"ru", "en"}
|
|
||||||
|
|
||||||
userProviders = []string{"bvs", "decs3o"}
|
|
||||||
|
|
||||||
deviceValues = []string{"primary", "secondary"}
|
|
||||||
|
|
||||||
securityGroupDirectionValues = []string{"inbound", "outbound"}
|
|
||||||
securityGroupEthertypeValues = []string{"IPv4", "IPv6"}
|
|
||||||
securityGroupProtocolValues = []string{"icmp", "tcp", "udp"}
|
|
||||||
|
|
||||||
addressPoolNetTypeValues = []string{"IPv4", "IPv6", "MAC"}
|
|
||||||
|
|
||||||
ipTypeValues = []string{"v4, v6"}
|
|
||||||
|
|
||||||
sepTechStatusValues = []string{"ENABLED", "DISABLED"}
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
mtuMin = 1500
|
|
||||||
mtuMax = 9216
|
|
||||||
|
|
||||||
trunkTagsMin = 1
|
|
||||||
trunkTagsMax = 4095
|
|
||||||
)
|
|
||||||
301
legacy-client.go
301
legacy-client.go
@@ -1,301 +0,0 @@
|
|||||||
package decortsdk
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"context"
|
|
||||||
"crypto/tls"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/google/go-querystring/query"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn"
|
|
||||||
)
|
|
||||||
|
|
||||||
// LegacyDecortClient is Legacy HTTP-client for platform
|
|
||||||
type LegacyDecortClient struct {
|
|
||||||
decortURL string
|
|
||||||
client *http.Client
|
|
||||||
cfg config.LegacyConfig
|
|
||||||
expiryTime time.Time
|
|
||||||
mutex *sync.Mutex
|
|
||||||
}
|
|
||||||
|
|
||||||
// Legacy client builder
|
|
||||||
func NewLegacy(cfg config.LegacyConfig) *LegacyDecortClient {
|
|
||||||
if err := validators.ValidateConfig(cfg); err != nil {
|
|
||||||
panic(validators.ValidationErrors(validators.GetErrors(err)))
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.Retries == 0 {
|
|
||||||
cfg.Retries = 5
|
|
||||||
}
|
|
||||||
|
|
||||||
var expiryTime time.Time
|
|
||||||
|
|
||||||
if cfg.Token != "" {
|
|
||||||
expiryTime = time.Now().AddDate(0, 0, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &LegacyDecortClient{
|
|
||||||
decortURL: cfg.DecortURL,
|
|
||||||
client: &http.Client{
|
|
||||||
Transport: &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{
|
|
||||||
//nolint:gosec
|
|
||||||
InsecureSkipVerify: cfg.SSLSkipVerify,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
cfg: trimLegacyConfig(&cfg),
|
|
||||||
expiryTime: expiryTime,
|
|
||||||
mutex: &sync.Mutex{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CloudAPI builder
|
|
||||||
func (ldc *LegacyDecortClient) CloudAPI() *cloudapi.CloudAPI {
|
|
||||||
return cloudapi.New(ldc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CloudBroker builder
|
|
||||||
func (ldc *LegacyDecortClient) CloudBroker() *cloudbroker.CloudBroker {
|
|
||||||
return cloudbroker.New(ldc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SDN builder
|
|
||||||
func (ldc *LegacyDecortClient) SDN() *sdn.SDN {
|
|
||||||
return sdn.New(ldc)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecortApiCall method for sending requests to the platform
|
|
||||||
func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
|
||||||
// get token
|
|
||||||
if err := ldc.getToken(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var body *bytes.Buffer
|
|
||||||
var ctype string
|
|
||||||
|
|
||||||
byteSlice, ok := params.([]byte)
|
|
||||||
if ok {
|
|
||||||
body = bytes.NewBuffer(byteSlice)
|
|
||||||
ctype = "application/octet-stream"
|
|
||||||
} else {
|
|
||||||
values, err := query.Values(params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
body = bytes.NewBufferString(values.Encode() + fmt.Sprintf("&authkey=%s", ldc.cfg.Token))
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+constants.RESTMACHINE+url, body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// perform request
|
|
||||||
respBytes, err := ldc.do(req, ctype)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return respBytes, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecortApiCallCtype method for sending requests to the platform with content type
|
|
||||||
func (ldc *LegacyDecortClient) DecortApiCallCtype(ctx context.Context, method, url, ctype string, params interface{}) ([]byte, error) {
|
|
||||||
// get token
|
|
||||||
if err := ldc.getToken(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var body *bytes.Buffer
|
|
||||||
|
|
||||||
switch ctype {
|
|
||||||
case constants.MIMESTREAM:
|
|
||||||
body = bytes.NewBuffer(params.([]byte))
|
|
||||||
case constants.MIMEJSON:
|
|
||||||
jsonBody, err := json.Marshal(params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
body = bytes.NewBuffer(jsonBody)
|
|
||||||
default:
|
|
||||||
ctype = constants.MIMEPOSTForm
|
|
||||||
values, err := query.Values(params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
body = bytes.NewBufferString(values.Encode() + fmt.Sprintf("&authkey=%s", ldc.cfg.Token))
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+constants.RESTMACHINE+url, body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// perform request
|
|
||||||
respBytes, err := ldc.do(req, ctype)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return respBytes, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ldc *LegacyDecortClient) DecortApiCallMP(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
|
||||||
body, ctype, err := multiPartReq(params)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+constants.RESTMACHINE+url, body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// get token
|
|
||||||
if err = ldc.getToken(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// perform request
|
|
||||||
respBytes, err := ldc.do(req, ctype)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return respBytes, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ldc *LegacyDecortClient) getToken(ctx context.Context) error {
|
|
||||||
ldc.mutex.Lock()
|
|
||||||
defer ldc.mutex.Unlock()
|
|
||||||
|
|
||||||
// new token is not needed
|
|
||||||
if ldc.cfg.Token != "" && !time.Now().After(ldc.expiryTime) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// set up request headers and body
|
|
||||||
body := fmt.Sprintf("username=%s&password=%s", url.QueryEscape(ldc.cfg.Username), url.QueryEscape(ldc.cfg.Password))
|
|
||||||
bodyReader := strings.NewReader(body)
|
|
||||||
|
|
||||||
req, _ := http.NewRequestWithContext(ctx, "POST", ldc.cfg.DecortURL+constants.RESTMACHINE+"/cloudapi/user/authenticate", bodyReader)
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
|
|
||||||
// request token
|
|
||||||
resp, err := ldc.client.Do(req)
|
|
||||||
if err != nil || resp == nil {
|
|
||||||
return fmt.Errorf("cannot get token: %w", err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
var tokenBytes []byte
|
|
||||||
tokenBytes, err = io.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot get token: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
return fmt.Errorf("cannot get token: %s", tokenBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// save token in config
|
|
||||||
token := string(tokenBytes)
|
|
||||||
ldc.cfg.Token = token
|
|
||||||
ldc.expiryTime = time.Now().AddDate(0, 0, 1)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// do method performs request and returns response as an array of bytes and nil error in case of response status code 200.
|
|
||||||
// In any other cases do returns nil response and error.
|
|
||||||
// Retries are implemented in case of connection reset errors.
|
|
||||||
func (ldc *LegacyDecortClient) do(req *http.Request, ctype string) ([]byte, error) {
|
|
||||||
// set up request headers and body
|
|
||||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
|
||||||
if ctype != "" {
|
|
||||||
req.Header.Set("Content-Type", ctype)
|
|
||||||
}
|
|
||||||
|
|
||||||
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))
|
|
||||||
|
|
||||||
resp, err := ldc.client.Do(req)
|
|
||||||
if resp != nil {
|
|
||||||
defer resp.Body.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
// retries logic GOES HERE
|
|
||||||
// get http response
|
|
||||||
//var resp *http.Response
|
|
||||||
//for i := uint64(0); i < ldc.cfg.Retries; i++ {
|
|
||||||
// req := req.Clone(req.Context())
|
|
||||||
// req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
|
||||||
//
|
|
||||||
// if i > 0 {
|
|
||||||
// time.Sleep(5 * time.Second) // no time sleep for the first request
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// resp, err = ldc.client.Do(req)
|
|
||||||
//
|
|
||||||
// // stop retries on success and close response body
|
|
||||||
// if resp != nil {
|
|
||||||
// defer resp.Body.Close()
|
|
||||||
// }
|
|
||||||
// if err == nil {
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // retries in case of connection errors with time sleep
|
|
||||||
// if isConnectionError(err) {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// // return error in case of non-connection error
|
|
||||||
// return nil, err
|
|
||||||
//}
|
|
||||||
|
|
||||||
// handle http request errors
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if resp == nil {
|
|
||||||
return nil, fmt.Errorf("got empty response without error")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 trimLegacyConfig(cfg *config.LegacyConfig) config.LegacyConfig {
|
|
||||||
cfg.DecortURL = strings.TrimSuffix(cfg.DecortURL, "/")
|
|
||||||
return *cfg
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package cloudapi
|
|
||||||
|
|
||||||
import (
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/account"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Accessing the Account method group
|
|
||||||
func (ca *CloudAPI) Account() *account.Account {
|
|
||||||
return account.New(ca.client)
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
// API Actor API for managing account
|
|
||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Structure for creating request to account
|
|
||||||
type Account struct {
|
|
||||||
client interfaces.Caller
|
|
||||||
}
|
|
||||||
|
|
||||||
// Builder for account endpoints
|
|
||||||
func New(client interfaces.Caller) *Account {
|
|
||||||
return &Account{
|
|
||||||
client,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// AddUserRequest struct to add permission to access account for a user
|
|
||||||
type AddUserRequest struct {
|
|
||||||
// ID of account to add to
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
|
|
||||||
// Name of the user to be given rights
|
|
||||||
// Required: true
|
|
||||||
UserID string `url:"userId" json:"userId" validate:"required"`
|
|
||||||
|
|
||||||
// Account permission types:
|
|
||||||
// - 'R' for read only access
|
|
||||||
// - 'RCX' for Write
|
|
||||||
// - 'ARCXDU' for Admin
|
|
||||||
// Required: true
|
|
||||||
AccessType string `url:"accesstype" json:"accesstype" validate:"required,accessType"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddUser gives a user access rights.
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/addUser"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// AuditsRequest struct to give list of account audits
|
|
||||||
type AuditsRequest struct {
|
|
||||||
// ID of the account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Audits gets audit records for the specified account object
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/audits"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
list := ListAudits{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return list, nil
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DeleteRequest struct to delete account
|
|
||||||
type DeleteRequest struct {
|
|
||||||
// ID of account to delete
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
|
|
||||||
// Whether to completely delete the account
|
|
||||||
// Required: false
|
|
||||||
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete completes delete an account from the system Returns true if account is deleted or was already deleted or never existed
|
|
||||||
func (a Account) Delete(ctx context.Context, req DeleteRequest) (string, error) {
|
|
||||||
err := validators.ValidateRequest(req)
|
|
||||||
if err != nil {
|
|
||||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/delete"
|
|
||||||
|
|
||||||
result, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(result), nil
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DeleteUserRequest struct to revoke access to account
|
|
||||||
type DeleteUserRequest struct {
|
|
||||||
// ID of the account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
|
|
||||||
// ID or emailaddress of the user to remove
|
|
||||||
// Required: true
|
|
||||||
UserID string `url:"userId" json:"userId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/deleteUser"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DisableEnableRequest struct to change status of account
|
|
||||||
type DisableEnableRequest struct {
|
|
||||||
// ID of account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable disables an account
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/disable"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable enables an account
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/enable"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
// FilterByID returns ListAccounts with specified ID.
|
|
||||||
func (la ListAccounts) FilterByID(id uint64) ListAccounts {
|
|
||||||
predicate := func(ia ItemAccount) bool {
|
|
||||||
return ia.ID == id
|
|
||||||
}
|
|
||||||
|
|
||||||
return la.FilterFunc(predicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterByName returns ListAccounts with specified Name.
|
|
||||||
func (la ListAccounts) FilterByName(name string) ListAccounts {
|
|
||||||
predicate := func(ia ItemAccount) bool {
|
|
||||||
return ia.Name == name
|
|
||||||
}
|
|
||||||
|
|
||||||
return la.FilterFunc(predicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterByStatus returns ListAccounts with specified Status.
|
|
||||||
func (la ListAccounts) FilterByStatus(status string) ListAccounts {
|
|
||||||
predicate := func(ia ItemAccount) bool {
|
|
||||||
return ia.Status == status
|
|
||||||
}
|
|
||||||
|
|
||||||
return la.FilterFunc(predicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterByUserGroupID returns ListAccounts with specified UserGroupID.
|
|
||||||
func (la ListAccounts) FilterByUserGroupID(userGroupID string) ListAccounts {
|
|
||||||
predicate := func(ia ItemAccount) bool {
|
|
||||||
acl := ia.ACL
|
|
||||||
|
|
||||||
for _, item := range acl {
|
|
||||||
if item.UgroupID == userGroupID {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return la.FilterFunc(predicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterFunc allows filtering ListAccounts based on a user-specified predicate.
|
|
||||||
func (la ListAccounts) FilterFunc(predicate func(ItemAccount) bool) ListAccounts {
|
|
||||||
var result ListAccounts
|
|
||||||
|
|
||||||
for _, acc := range la.Data {
|
|
||||||
if predicate(acc) {
|
|
||||||
result.Data = append(result.Data, acc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result.EntryCount = uint64(len(result.Data))
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// FindOne returns first found ItemAccount.
|
|
||||||
// If none was found, returns an empty struct.
|
|
||||||
func (la ListAccounts) FindOne() ItemAccount {
|
|
||||||
if len(la.Data) == 0 {
|
|
||||||
return ItemAccount{}
|
|
||||||
}
|
|
||||||
|
|
||||||
return la.Data[0]
|
|
||||||
}
|
|
||||||
@@ -1,149 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
var accounts = ListAccounts{
|
|
||||||
Data: []ItemAccount{
|
|
||||||
{
|
|
||||||
ACL: []ListRecordACL{
|
|
||||||
{
|
|
||||||
IsExplicit: true,
|
|
||||||
GUID: "",
|
|
||||||
Rights: "CXDRAU",
|
|
||||||
Status: "CONFIRMED",
|
|
||||||
Type: "U",
|
|
||||||
UgroupID: "timofey_tkachev_1@decs3o",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
CreatedTime: 1676645275,
|
|
||||||
DeletedTime: 0,
|
|
||||||
ID: 132846,
|
|
||||||
Name: "std",
|
|
||||||
Status: "CONFIRMED",
|
|
||||||
UpdatedTime: 1676645275,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ACL: []ListRecordACL{
|
|
||||||
{
|
|
||||||
IsExplicit: true,
|
|
||||||
GUID: "",
|
|
||||||
Rights: "CXDRAU",
|
|
||||||
Status: "CONFIRMED",
|
|
||||||
Type: "U",
|
|
||||||
UgroupID: "not_really_timofey_tkachev_1@decs3o",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
CreatedTime: 1676878820,
|
|
||||||
DeletedTime: 0,
|
|
||||||
ID: 132847,
|
|
||||||
Name: "std_2",
|
|
||||||
Status: "CONFIRMED",
|
|
||||||
UpdatedTime: 1676645275,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ACL: []ListRecordACL{
|
|
||||||
{
|
|
||||||
IsExplicit: true,
|
|
||||||
GUID: "",
|
|
||||||
Rights: "CXDRAU",
|
|
||||||
Status: "CONFIRMED",
|
|
||||||
Type: "U",
|
|
||||||
UgroupID: "timofey_tkachev_1@decs3o",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
IsExplicit: true,
|
|
||||||
GUID: "",
|
|
||||||
Rights: "CXDRAU",
|
|
||||||
Status: "CONFIRMED",
|
|
||||||
Type: "U",
|
|
||||||
UgroupID: "second_account@decs3o",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
CreatedTime: 1676883850,
|
|
||||||
DeletedTime: 1676883899,
|
|
||||||
ID: 132848,
|
|
||||||
Name: "std_broker",
|
|
||||||
Status: "DELETED",
|
|
||||||
UpdatedTime: 1676878820,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
EntryCount: 3,
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterByID(t *testing.T) {
|
|
||||||
actual := accounts.FilterByID(132846).FindOne()
|
|
||||||
|
|
||||||
if actual.ID != 132846 {
|
|
||||||
t.Fatal("actual: ", actual.ID, " > expected: 132846")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterByUserGroupId(t *testing.T) {
|
|
||||||
actual := accounts.FilterByUserGroupID("second_account@decs3o").FindOne()
|
|
||||||
|
|
||||||
for _, item := range actual.ACL {
|
|
||||||
if item.UgroupID == "second_account@decs3o" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Fatal("second_account@decs3o has not been found. expected 1 found")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterByName(t *testing.T) {
|
|
||||||
actual := accounts.FilterByName("std_broker").FindOne()
|
|
||||||
|
|
||||||
if actual.Name != "std_broker" {
|
|
||||||
t.Fatal("actual: ", actual.Name, " >> expected: std_broker")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterByStatus(t *testing.T) {
|
|
||||||
actual := accounts.FilterByStatus("CONFIRMED")
|
|
||||||
|
|
||||||
if len(actual.Data) != 2 {
|
|
||||||
t.Fatal("Expected 2 elements in slice, found: ", len(actual.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, item := range actual.Data {
|
|
||||||
if item.Status != "CONFIRMED" {
|
|
||||||
t.Fatal("expected CONFIRMED, found: ", item.Status)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterFunc(t *testing.T) {
|
|
||||||
actual := accounts.FilterFunc(func(ia ItemAccount) bool {
|
|
||||||
return ia.DeletedTime == 0
|
|
||||||
})
|
|
||||||
|
|
||||||
for _, item := range actual.Data {
|
|
||||||
if item.DeletedTime != 0 {
|
|
||||||
t.Fatal("Expected DeletedTime = 0, found: ", item.DeletedTime)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSortingByCreatedTime(t *testing.T) {
|
|
||||||
actual := accounts.SortByCreatedTime(false)
|
|
||||||
|
|
||||||
if actual.Data[0].Name != "std" {
|
|
||||||
t.Fatal("Expected account std as earliest, found: ", actual.Data[0].Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
actual = accounts.SortByCreatedTime(true)
|
|
||||||
|
|
||||||
if actual.Data[0].Name != "std_broker" {
|
|
||||||
t.Fatal("Expected account std_broker as latest, found: ", actual.Data[0].Name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterEmpty(t *testing.T) {
|
|
||||||
actual := accounts.FilterByID(0)
|
|
||||||
|
|
||||||
if len(actual.Data) != 0 {
|
|
||||||
t.Fatal("Expected 0 found, actual: ", len(actual.Data))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetRequest struct to get information about account
|
|
||||||
type GetRequest struct {
|
|
||||||
// ID an account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gets account details as a RecordAccount struct
|
|
||||||
func (a Account) Get(ctx context.Context, req GetRequest) (*RecordAccount, error) {
|
|
||||||
res, err := a.GetRaw(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
info := RecordAccount{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &info)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"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
|
|
||||||
type GetConsumedAccountUnitsRequest struct {
|
|
||||||
// ID an account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetConsumedAccountUnits calculates the currently consumed units for all cloudspaces and resource groups in the account.
|
|
||||||
// Calculated cloud units are returned in a dict which includes:
|
|
||||||
// - CU_M: consumed memory in MB
|
|
||||||
// - CU_C: number of cpu cores
|
|
||||||
// - CU_D: consumed vdisk storage in GB
|
|
||||||
// - CU_DM: consumed max vdisk storage in GB
|
|
||||||
// - CU_I: number of public IPs
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/getConsumedAccountUnits"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
info := ResourceLimits{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &info)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &info, nil
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"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
|
|
||||||
type GetConsumedCloudUnitsByTypeRequest struct {
|
|
||||||
// ID an account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
|
|
||||||
// Cloud unit resource type
|
|
||||||
// Required: true
|
|
||||||
CUType string `url:"cutype" json:"cutype" validate:"required,accountCUType"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetConsumedCloudUnitsByType calculates the currently consumed cloud units of the specified type for all cloudspaces
|
|
||||||
// and resource groups in the account.
|
|
||||||
// Possible types of cloud units are include:
|
|
||||||
//
|
|
||||||
// - CU_M: returns consumed memory in MB
|
|
||||||
// - CU_C: returns number of virtual cpu cores
|
|
||||||
// - CU_D: returns consumed virtual disk storage in GB
|
|
||||||
// - CU_DM: returns consumed max virtual disk storage in GB
|
|
||||||
// - CU_I: returns number of public IPs
|
|
||||||
// - gpu_units: return number of GPU units
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/getConsumedCloudUnitsByType"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseFloat(string(res), 64)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"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
|
|
||||||
type GetReservedAccountUnitsRequest struct {
|
|
||||||
// ID an account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetReservedAccountUnits calculates the reserved units for all cloudspaces and resource groups in the account.
|
|
||||||
// Calculated cloud units are returned in a dict which includes:
|
|
||||||
//
|
|
||||||
// - CU_M: reserved memory in MB
|
|
||||||
// - CU_C: number of cpu cores
|
|
||||||
// - CU_D: reserved vdisk storage in GB
|
|
||||||
// - CU_DM: reserved max vdisk storage in GB
|
|
||||||
// - CU_I: number of public IPs
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/getReservedAccountUnits"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
info := ResourceLimits{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &info)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &info, nil
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetResourceConsumptionRequest struct to get resource consumption
|
|
||||||
type GetResourceConsumptionRequest struct {
|
|
||||||
// ID an account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetResourceConsumption show amount of consumed and reserved resources (cpu, ram, disk) by specific account
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/getResourceConsumption"
|
|
||||||
|
|
||||||
info := RecordResourceConsumption{}
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &info)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &info, nil
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ListRequest struct to get list of accounts
|
|
||||||
type ListRequest struct {
|
|
||||||
// Find by ID
|
|
||||||
// Required: false
|
|
||||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
|
||||||
|
|
||||||
// Find by name
|
|
||||||
// Required: false
|
|
||||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
|
||||||
|
|
||||||
// Find by access control list
|
|
||||||
// Required: false
|
|
||||||
ACL string `url:"acl,omitempty" json:"acl,omitempty"`
|
|
||||||
|
|
||||||
// Find by status
|
|
||||||
// Required: false
|
|
||||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
|
||||||
|
|
||||||
// Sort by one of supported fields, format +|-(field)
|
|
||||||
// Required: false
|
|
||||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
|
||||||
|
|
||||||
// Sort by zone id
|
|
||||||
// Default value: 0
|
|
||||||
// Required: false
|
|
||||||
ZoneID uint64 `url:"zone_id,omitempty" json:"zone_id,omitempty"`
|
|
||||||
|
|
||||||
// Page number
|
|
||||||
// Required: false
|
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
|
||||||
|
|
||||||
// Page size
|
|
||||||
// Required: false
|
|
||||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List gets a list of all accounts the user has access to a ListAccounts struct
|
|
||||||
func (a Account) List(ctx context.Context, req ListRequest) (*ListAccounts, error) {
|
|
||||||
|
|
||||||
res, err := a.ListRaw(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
list := ListAccounts{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
|
|
||||||
if err := validators.ValidateRequest(req); err != nil {
|
|
||||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/list"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ListComputesRequest struct to get a list of compute instances
|
|
||||||
type ListComputesRequest struct {
|
|
||||||
// ID an account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
|
|
||||||
// Find by compute id
|
|
||||||
// Required: false
|
|
||||||
ComputeID uint64 `url:"computeId,omitempty" json:"computeId,omitempty"`
|
|
||||||
|
|
||||||
// Find by name
|
|
||||||
// Required: false
|
|
||||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
|
||||||
|
|
||||||
// Find by resource group name
|
|
||||||
// Required: false
|
|
||||||
RGName string `url:"rgName,omitempty" json:"rgName,omitempty"`
|
|
||||||
|
|
||||||
// Find by resource group id
|
|
||||||
// Required: false
|
|
||||||
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
|
||||||
|
|
||||||
// Find by tech status
|
|
||||||
// Required: false
|
|
||||||
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
|
|
||||||
|
|
||||||
// Find by ip address
|
|
||||||
// Required: false
|
|
||||||
IPAddress string `url:"ipAddress,omitempty" json:"ipAddress,omitempty"`
|
|
||||||
|
|
||||||
// Find by external network name
|
|
||||||
// Required: false
|
|
||||||
ExtNetName string `url:"extNetName,omitempty" json:"extNetName,omitempty"`
|
|
||||||
|
|
||||||
// Find by external network id
|
|
||||||
// Required: false
|
|
||||||
ExtNetID uint64 `url:"extNetId,omitempty" json:"extNetId,omitempty"`
|
|
||||||
|
|
||||||
// Sort by one of supported fields, format +|-(field)
|
|
||||||
// Required: false
|
|
||||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
|
||||||
|
|
||||||
// Page number
|
|
||||||
// Required: false
|
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
|
||||||
|
|
||||||
// Page size
|
|
||||||
// Required: false
|
|
||||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListComputes gets list all compute instances under specified account, accessible by the user
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/listComputes"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
list := ListComputes{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &list, nil
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ListDeletedRequest struct to get a list of deleted accounts
|
|
||||||
type ListDeletedRequest struct {
|
|
||||||
// Page number
|
|
||||||
// Required: false
|
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
|
||||||
|
|
||||||
// Page size
|
|
||||||
// Required: false
|
|
||||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
|
||||||
|
|
||||||
// Find by ID
|
|
||||||
// Required: false
|
|
||||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
|
||||||
|
|
||||||
// Find by name
|
|
||||||
// Required: false
|
|
||||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
|
||||||
|
|
||||||
// Find by access control list
|
|
||||||
// Required: false
|
|
||||||
ACL string `url:"acl,omitempty" json:"acl,omitempty"`
|
|
||||||
|
|
||||||
// Sort by one of supported fields, format +|-(field)
|
|
||||||
// Required: false
|
|
||||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListDeleted gets list of all deleted accounts the user has access to
|
|
||||||
func (a Account) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListAccounts, error) {
|
|
||||||
|
|
||||||
err := validators.ValidateRequest(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/listDeleted"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
list := ListAccounts{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &list, nil
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ListDisksRequest struct to get a list of deleted disks
|
|
||||||
type ListDisksRequest struct {
|
|
||||||
// ID an account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
|
|
||||||
// Find by disk id
|
|
||||||
// Required: false
|
|
||||||
DiskID uint64 `url:"diskId,omitempty" json:"diskId,omitempty"`
|
|
||||||
|
|
||||||
// Find by name
|
|
||||||
// Required: false
|
|
||||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
|
||||||
|
|
||||||
// Find by max size disk
|
|
||||||
// Required: false
|
|
||||||
DiskMaxSize uint64 `url:"diskMaxSize,omitempty" json:"diskMaxSize,omitempty"`
|
|
||||||
|
|
||||||
// Type of the disks
|
|
||||||
// Required: false
|
|
||||||
Type string `url:"type,omitempty" json:"type,omitempty"`
|
|
||||||
|
|
||||||
// Sort by one of supported fields, format +|-(field)
|
|
||||||
// Required: false
|
|
||||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
|
||||||
|
|
||||||
// Page number
|
|
||||||
// Required: false
|
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
|
||||||
|
|
||||||
// Page size
|
|
||||||
// Required: false
|
|
||||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListDisks gets list all currently unattached disks under specified account
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/listDisks"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
list := ListDisks{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &list, nil
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ListFLIPGroupsRequest struct to get a list of FLIPGroups
|
|
||||||
type ListFLIPGroupsRequest struct {
|
|
||||||
// ID of the account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
|
|
||||||
// Find by name
|
|
||||||
// Required: false
|
|
||||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
|
||||||
|
|
||||||
// Find by vinsId
|
|
||||||
// Required: false
|
|
||||||
VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
|
|
||||||
|
|
||||||
// Find by VINS name
|
|
||||||
// Required: false
|
|
||||||
VINSName string `url:"vinsName,omitempty" json:"vinsName,omitempty"`
|
|
||||||
|
|
||||||
// Find by external network id
|
|
||||||
// Required: false
|
|
||||||
ExtNetID uint64 `url:"extnetId,omitempty" json:"extnetId,omitempty"`
|
|
||||||
|
|
||||||
// Find by IP
|
|
||||||
// Required: false
|
|
||||||
ByIP string `url:"byIp,omitempty" json:"byIp,omitempty"`
|
|
||||||
|
|
||||||
// Find by flipGroup Id
|
|
||||||
// Required: false
|
|
||||||
FLIPGroupID uint64 `url:"flipGroupId,omitempty" json:"flipGroupId,omitempty"`
|
|
||||||
|
|
||||||
// Sort by one of supported fields, format +|-(field)
|
|
||||||
// Required: false
|
|
||||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
|
||||||
|
|
||||||
// Page number
|
|
||||||
// Required: false
|
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
|
||||||
|
|
||||||
// Page size
|
|
||||||
// Required: false
|
|
||||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListFLIPGroups gets list all FLIPGroups under specified account, accessible by the user
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/listFlipGroups"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
list := ListFLIPGroups{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &list, nil
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ListResourceConsumption show data list amount of consumed and reserved resources (cpu, ram, disk) by specific accounts
|
|
||||||
func (a Account) ListResourceConsumption(ctx context.Context) (*ListResourceConsumption, error) {
|
|
||||||
url := "/cloudapi/account/listResourceConsumption"
|
|
||||||
|
|
||||||
info := ListResourceConsumption{}
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &info)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &info, nil
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ListRGRequest struct to get a list of resource groups
|
|
||||||
type ListRGRequest struct {
|
|
||||||
// ID an account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
|
|
||||||
// Page number
|
|
||||||
// Required: false
|
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
|
||||||
|
|
||||||
// Page size
|
|
||||||
// Required: false
|
|
||||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
|
||||||
|
|
||||||
// Find by resource group id
|
|
||||||
// Required: false
|
|
||||||
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
|
||||||
|
|
||||||
// Find by name
|
|
||||||
// Required: false
|
|
||||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
|
||||||
|
|
||||||
// Find by vinsId
|
|
||||||
// Required: false
|
|
||||||
VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
|
|
||||||
|
|
||||||
// Find by VM ID
|
|
||||||
// Required: false
|
|
||||||
VMID uint64 `url:"vmId,omitempty" json:"vmId,omitempty"`
|
|
||||||
|
|
||||||
// Find by status
|
|
||||||
// Required: false
|
|
||||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
|
||||||
|
|
||||||
// Sort by one of supported fields, format +|-(field)
|
|
||||||
// Required: false
|
|
||||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListRG gets list of all resource groups under specified account, accessible by the user
|
|
||||||
func (a Account) ListRG(ctx context.Context, req ListRGRequest) (*ListRG, error) {
|
|
||||||
|
|
||||||
err := validators.ValidateRequest(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/listRG"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
list := ListRG{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &list, nil
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ListTemplatesRequest struct to get a list of templates
|
|
||||||
type ListTemplatesRequest struct {
|
|
||||||
// ID an account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
|
|
||||||
// Include deleted images
|
|
||||||
// Required: false
|
|
||||||
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`
|
|
||||||
|
|
||||||
// Find by image id
|
|
||||||
// Required: false
|
|
||||||
ImageID uint64 `url:"imageId,omitempty" json:"imageId,omitempty"`
|
|
||||||
|
|
||||||
// Find by name
|
|
||||||
// Required: false
|
|
||||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
|
||||||
|
|
||||||
// Find by type
|
|
||||||
// Required: false
|
|
||||||
Type string `url:"type,omitempty" json:"type,omitempty"`
|
|
||||||
|
|
||||||
// Sort by one of supported fields, format +|-(field)
|
|
||||||
// Required: false
|
|
||||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
|
||||||
|
|
||||||
// Page number
|
|
||||||
// Required: false
|
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
|
||||||
|
|
||||||
// Page size
|
|
||||||
// Required: false
|
|
||||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListTemplates gets list of templates which can be managed by this account
|
|
||||||
func (a Account) ListTemplates(ctx context.Context, req ListTemplatesRequest) (*ListTemplates, error) {
|
|
||||||
|
|
||||||
err := validators.ValidateRequest(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/listTemplates"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
list := ListTemplates{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &list, nil
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ListVINSRequest struct to get a list of VINS
|
|
||||||
type ListVINSRequest struct {
|
|
||||||
// ID an account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
|
|
||||||
// Find by VINS ID
|
|
||||||
// Required: false
|
|
||||||
VINSID uint64 `url:"vins,omitempty" json:"vinsId,omitempty"`
|
|
||||||
|
|
||||||
// Find by name
|
|
||||||
// Required: false
|
|
||||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
|
||||||
|
|
||||||
// Find by resource group id
|
|
||||||
// Required: false
|
|
||||||
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
|
||||||
|
|
||||||
// Find by external network ip
|
|
||||||
// Required: false
|
|
||||||
ExtIP string `url:"extIp,omitempty" json:"extIp,omitempty"`
|
|
||||||
|
|
||||||
// Sort by one of supported fields, format +|-(field)
|
|
||||||
// Required: false
|
|
||||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
|
||||||
|
|
||||||
// Page number
|
|
||||||
// Required: false
|
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
|
||||||
|
|
||||||
// Page size
|
|
||||||
// Required: false
|
|
||||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListVINS gets list of all ViNSes under specified account, accessible by the user
|
|
||||||
func (a Account) ListVINS(ctx context.Context, req ListVINSRequest) (*ListVINS, error) {
|
|
||||||
|
|
||||||
err := validators.ValidateRequest(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/listVins"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
list := ListVINS{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &list, nil
|
|
||||||
}
|
|
||||||
@@ -1,742 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
// Access Control List
|
|
||||||
type ListRecordACL struct {
|
|
||||||
// Whether access is explicitly specified
|
|
||||||
IsExplicit bool `json:"explicit"`
|
|
||||||
|
|
||||||
// GUID
|
|
||||||
GUID string `json:"guid"`
|
|
||||||
|
|
||||||
// Access rights
|
|
||||||
Rights string `json:"right"`
|
|
||||||
|
|
||||||
// Status
|
|
||||||
Status string `json:"status"`
|
|
||||||
|
|
||||||
// Account Type
|
|
||||||
Type string `json:"type"`
|
|
||||||
|
|
||||||
// Account owner ID
|
|
||||||
UgroupID string `json:"userGroupId"`
|
|
||||||
|
|
||||||
// Is it possible to remove
|
|
||||||
CanBeDeleted bool `json:"canBeDeleted"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Access Control List
|
|
||||||
type RecordACL struct {
|
|
||||||
// Emails
|
|
||||||
Emails []string `json:"emails"`
|
|
||||||
|
|
||||||
// Whether access is explicitly specified
|
|
||||||
IsExplicit bool `json:"explicit"`
|
|
||||||
|
|
||||||
// GUID
|
|
||||||
GUID string `json:"guid"`
|
|
||||||
|
|
||||||
// Access rights
|
|
||||||
Rights string `json:"right"`
|
|
||||||
|
|
||||||
// Status
|
|
||||||
Status string `json:"status"`
|
|
||||||
|
|
||||||
// Account Type
|
|
||||||
Type string `json:"type"`
|
|
||||||
|
|
||||||
// Account owner ID
|
|
||||||
UgroupID string `json:"userGroupId"`
|
|
||||||
|
|
||||||
// Is it possible to remove
|
|
||||||
CanBeDeleted bool `json:"canBeDeleted"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resource limits
|
|
||||||
type ResourceLimits struct {
|
|
||||||
// Number of cores
|
|
||||||
CUC float64 `json:"CU_C"`
|
|
||||||
|
|
||||||
// Disk size, GB
|
|
||||||
CUD float64 `json:"CU_D"`
|
|
||||||
|
|
||||||
// Max disk size, GB
|
|
||||||
CUDM float64 `json:"CU_DM"`
|
|
||||||
|
|
||||||
// Number of public IP addresses
|
|
||||||
CUI float64 `json:"CU_I"`
|
|
||||||
|
|
||||||
// RAM size, MB
|
|
||||||
CUM float64 `json:"CU_M"`
|
|
||||||
|
|
||||||
// Number of graphics cores
|
|
||||||
GPUUnits float64 `json:"gpu_units"`
|
|
||||||
|
|
||||||
// Storage policy
|
|
||||||
StoragePolicy []StoragePolicyItem `json:"storage_policy"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type StoragePolicyItem struct {
|
|
||||||
ID uint64 `json:"id"`
|
|
||||||
|
|
||||||
Limit int `json:"limit"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main information in one of if the list of accounts
|
|
||||||
type ItemAccount struct {
|
|
||||||
// Access Control List
|
|
||||||
ACL []ListRecordACL `json:"acl"`
|
|
||||||
|
|
||||||
// Compute Features
|
|
||||||
ComputeFeatures []string `json:"computeFeatures"`
|
|
||||||
|
|
||||||
// Created time
|
|
||||||
CreatedTime uint64 `json:"createdTime"`
|
|
||||||
|
|
||||||
// Deleted time
|
|
||||||
DeletedTime uint64 `json:"deletedTime"`
|
|
||||||
|
|
||||||
// Deleted by
|
|
||||||
DeletedBy string `json:"deletedBy"`
|
|
||||||
|
|
||||||
// Description
|
|
||||||
Description string `json:"desc"`
|
|
||||||
|
|
||||||
// ID
|
|
||||||
ID uint64 `json:"id"`
|
|
||||||
|
|
||||||
// Name
|
|
||||||
Name string `json:"name"`
|
|
||||||
|
|
||||||
// Status
|
|
||||||
Status string `json:"status"`
|
|
||||||
|
|
||||||
// Updated by
|
|
||||||
UpdatedBy string `json:"updatedBy"`
|
|
||||||
|
|
||||||
// Updated time
|
|
||||||
UpdatedTime uint64 `json:"updatedTime"`
|
|
||||||
|
|
||||||
// Zones
|
|
||||||
ZoneIDs []uint64 `json:"zoneIds"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of accounts
|
|
||||||
type ListAccounts struct {
|
|
||||||
Data []ItemAccount `json:"data"`
|
|
||||||
|
|
||||||
EntryCount uint64 `json:"entryCount"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Policy
|
|
||||||
type Policy struct {
|
|
||||||
// Size of the disk
|
|
||||||
DiskSize float64 `json:"disksize"`
|
|
||||||
|
|
||||||
// Max size of the disk
|
|
||||||
DiskSizeMax float64 `json:"disksizemax"`
|
|
||||||
|
|
||||||
// SEPs used
|
|
||||||
SEPs map[string]map[string]DiskUsage `json:"seps"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resources used
|
|
||||||
type Resource struct {
|
|
||||||
// Number of cores
|
|
||||||
CPU int64 `json:"cpu"`
|
|
||||||
|
|
||||||
// Disk size
|
|
||||||
DiskSize float64 `json:"disksize"`
|
|
||||||
|
|
||||||
// Max disk size
|
|
||||||
DiskSizeMax float64 `json:"disksizemax"`
|
|
||||||
|
|
||||||
// Number of External IPs
|
|
||||||
ExtIPs int64 `json:"extips"`
|
|
||||||
|
|
||||||
// Number of grafic cores
|
|
||||||
GPU int64 `json:"gpu"`
|
|
||||||
|
|
||||||
// Policies
|
|
||||||
Policies map[string]Policy `json:"policies"`
|
|
||||||
|
|
||||||
// Number of RAM
|
|
||||||
RAM int64 `json:"ram"`
|
|
||||||
|
|
||||||
// SEPs
|
|
||||||
SEPs map[string]map[string]DiskUsage `json:"seps"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disk usage
|
|
||||||
type DiskUsage struct {
|
|
||||||
// Disk size
|
|
||||||
DiskSize float64 `json:"disksize"`
|
|
||||||
|
|
||||||
// Disk size max
|
|
||||||
DiskSizeMax float64 `json:"disksizemax"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Information about resource consumption
|
|
||||||
type RecordResourceConsumption struct {
|
|
||||||
ItemResourceConsumption
|
|
||||||
|
|
||||||
// Resource limits
|
|
||||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Information about resources
|
|
||||||
type ItemResourceConsumption struct {
|
|
||||||
// Current information about resources
|
|
||||||
Consumed Resource `json:"consumed"`
|
|
||||||
|
|
||||||
// Reserved information about resources
|
|
||||||
Reserved Resource `json:"reserved"`
|
|
||||||
|
|
||||||
// Account ID
|
|
||||||
AccountID uint64 `json:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListResourceConsumption struct {
|
|
||||||
Data []ItemResourceConsumption `json:"data"`
|
|
||||||
|
|
||||||
EntryCount uint64 `json:"entryCount"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Information about computes
|
|
||||||
type Computes struct {
|
|
||||||
// Number of started computes
|
|
||||||
Started uint64 `json:"started"`
|
|
||||||
|
|
||||||
// Number of stopped computes
|
|
||||||
Stopped uint64 `json:"stopped"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Information about machines
|
|
||||||
type Machines struct {
|
|
||||||
// Number of running machines
|
|
||||||
Running uint64 `json:"running"`
|
|
||||||
|
|
||||||
// Number of halted machines
|
|
||||||
Halted uint64 `json:"halted"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detailed information about the account zone
|
|
||||||
type ZoneID struct {
|
|
||||||
// ID of zone
|
|
||||||
ID int64 `json:"id"`
|
|
||||||
|
|
||||||
// Name of zone
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main information about account
|
|
||||||
type RecordAccount struct {
|
|
||||||
// DCLocation
|
|
||||||
DCLocation string `json:"DCLocation"`
|
|
||||||
|
|
||||||
// Access control list
|
|
||||||
ACL []RecordACL `json:"acl"`
|
|
||||||
|
|
||||||
// Company
|
|
||||||
Company string `json:"company"`
|
|
||||||
|
|
||||||
// Company URL
|
|
||||||
CompanyURL string `json:"companyurl"`
|
|
||||||
|
|
||||||
// Compute Features
|
|
||||||
ComputeFeatures []string `json:"computeFeatures"`
|
|
||||||
|
|
||||||
// Computes
|
|
||||||
Computes Computes `json:"computes"`
|
|
||||||
|
|
||||||
// CPU allocation parameter
|
|
||||||
CPUAllocationParameter string `json:"cpu_allocation_parameter"`
|
|
||||||
|
|
||||||
// CPU allocation ratio
|
|
||||||
CPUAllocationRatio uint64 `json:"cpu_allocation_ratio"`
|
|
||||||
|
|
||||||
// Created by
|
|
||||||
CreatedBy string `json:"createdBy"`
|
|
||||||
|
|
||||||
// Created time
|
|
||||||
CreatedTime uint64 `json:"createdTime"`
|
|
||||||
|
|
||||||
// Description
|
|
||||||
Description string `json:"desc"`
|
|
||||||
|
|
||||||
// Deactivation time
|
|
||||||
DeactivationTime float64 `json:"deactivationTime"`
|
|
||||||
|
|
||||||
// Deleted by
|
|
||||||
DeletedBy string `json:"deletedBy"`
|
|
||||||
|
|
||||||
// Deleted time
|
|
||||||
DeletedTime uint64 `json:"deletedTime"`
|
|
||||||
|
|
||||||
// Display name
|
|
||||||
DisplayName string `json:"displayname"`
|
|
||||||
|
|
||||||
// GUID
|
|
||||||
GUID uint64 `json:"guid"`
|
|
||||||
|
|
||||||
// ID
|
|
||||||
ID uint64 `json:"id"`
|
|
||||||
|
|
||||||
// Machines
|
|
||||||
Machines Machines `json:"machines"`
|
|
||||||
|
|
||||||
// Name
|
|
||||||
Name string `json:"name"`
|
|
||||||
|
|
||||||
// Resource limits
|
|
||||||
ResourceLimits ResourceLimits `json:"resourceLimits"`
|
|
||||||
|
|
||||||
// Resource types
|
|
||||||
ResTypes []string `json:"resourceTypes"`
|
|
||||||
|
|
||||||
// Send access emails
|
|
||||||
SendAccessEmails bool `json:"sendAccessEmails"`
|
|
||||||
|
|
||||||
// Status
|
|
||||||
Status string `json:"status"`
|
|
||||||
|
|
||||||
// Storage policy ids
|
|
||||||
StoragePolicyIDs []uint64 `json:"storage_policy_ids"`
|
|
||||||
|
|
||||||
// UniqPools
|
|
||||||
UniqPools []interface{} `json:"uniqPools"`
|
|
||||||
|
|
||||||
// Updated By
|
|
||||||
UpdatedBy string `json:"updatedBy"`
|
|
||||||
|
|
||||||
// Updated time
|
|
||||||
UpdatedTime uint64 `json:"updatedTime"`
|
|
||||||
|
|
||||||
// Version
|
|
||||||
Version uint64 `json:"version"`
|
|
||||||
|
|
||||||
// VINS
|
|
||||||
VINS []uint64 `json:"vins"`
|
|
||||||
|
|
||||||
// VINSes
|
|
||||||
VINSes uint64 `json:"vinses"`
|
|
||||||
|
|
||||||
// Zone
|
|
||||||
ZoneIDs []ZoneID `json:"zoneIds"`
|
|
||||||
|
|
||||||
// Zones
|
|
||||||
DefaultZoneID uint64 `json:"defaultZoneId"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main information about compute
|
|
||||||
type ItemCompute struct {
|
|
||||||
// ID an account
|
|
||||||
AccountID uint64 `json:"accountId"`
|
|
||||||
|
|
||||||
// Account name
|
|
||||||
AccountName string `json:"accountName"`
|
|
||||||
|
|
||||||
// Number of CPU
|
|
||||||
CPUs uint64 `json:"cpus"`
|
|
||||||
|
|
||||||
// Created by
|
|
||||||
CreatedBy string `json:"createdBy"`
|
|
||||||
|
|
||||||
// Created time
|
|
||||||
CreatedTime uint64 `json:"createdTime"`
|
|
||||||
|
|
||||||
// Deleted by
|
|
||||||
DeletedBy string `json:"deletedBy"`
|
|
||||||
|
|
||||||
// Deleted time
|
|
||||||
DeletedTime uint64 `json:"deletedTime"`
|
|
||||||
|
|
||||||
// ID compute
|
|
||||||
ComputeID uint64 `json:"id"`
|
|
||||||
|
|
||||||
// Compute name
|
|
||||||
ComputeName string `json:"name"`
|
|
||||||
|
|
||||||
// Number of RAM
|
|
||||||
RAM uint64 `json:"ram"`
|
|
||||||
|
|
||||||
// Registered or not
|
|
||||||
Registered bool `json:"registered"`
|
|
||||||
|
|
||||||
// Resource group ID
|
|
||||||
RGID uint64 `json:"rgId"`
|
|
||||||
|
|
||||||
// Resource group Name
|
|
||||||
RGName string `json:"rgName"`
|
|
||||||
|
|
||||||
// Status
|
|
||||||
Status string `json:"status"`
|
|
||||||
|
|
||||||
// Tech status
|
|
||||||
TechStatus string `json:"techStatus"`
|
|
||||||
|
|
||||||
// Total disks size
|
|
||||||
TotalDisksSize uint64 `json:"totalDisksSize"`
|
|
||||||
|
|
||||||
// Updated by
|
|
||||||
UpdatedBy string `json:"updatedBy"`
|
|
||||||
|
|
||||||
// Updated time
|
|
||||||
UpdatedTime uint64 `json:"updatedTime"`
|
|
||||||
|
|
||||||
// User controlled or not
|
|
||||||
UserManaged bool `json:"userManaged"`
|
|
||||||
|
|
||||||
// Number of connected VINS
|
|
||||||
VINSConnected uint64 `json:"vinsConnected"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of computes
|
|
||||||
type ListComputes struct {
|
|
||||||
// Data
|
|
||||||
Data []ItemCompute `json:"data"`
|
|
||||||
|
|
||||||
// Entry count
|
|
||||||
EntryCount uint64 `json:"entryCount"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main information about disk
|
|
||||||
type ItemDisk struct {
|
|
||||||
// ID
|
|
||||||
ID uint64 `json:"id"`
|
|
||||||
|
|
||||||
// Name
|
|
||||||
Name string `json:"name"`
|
|
||||||
|
|
||||||
// Pool
|
|
||||||
Pool string `json:"pool"`
|
|
||||||
|
|
||||||
// ID SEP
|
|
||||||
SEPID uint64 `json:"sepId"`
|
|
||||||
|
|
||||||
// Shareable
|
|
||||||
Shareable bool `json:"shareable"`
|
|
||||||
|
|
||||||
// Max size
|
|
||||||
SizeMax uint64 `json:"sizeMax"`
|
|
||||||
|
|
||||||
// Disk type
|
|
||||||
Type string `json:"type"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of disks
|
|
||||||
type ListDisks struct {
|
|
||||||
// Data
|
|
||||||
Data []ItemDisk `json:"data"`
|
|
||||||
|
|
||||||
// Entry count
|
|
||||||
EntryCount uint64 `json:"entryCount"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main information about VINS
|
|
||||||
type ItemVINS struct {
|
|
||||||
// Account ID
|
|
||||||
AccountID uint64 `json:"accountId"`
|
|
||||||
|
|
||||||
// Name of account
|
|
||||||
AccountName string `json:"accountName"`
|
|
||||||
|
|
||||||
// Number of computes
|
|
||||||
Computes uint64 `json:"computes"`
|
|
||||||
|
|
||||||
// Created by
|
|
||||||
CreatedBy string `json:"createdBy"`
|
|
||||||
|
|
||||||
// Created time
|
|
||||||
CreatedTime uint64 `json:"createdTime"`
|
|
||||||
|
|
||||||
// Deleted by
|
|
||||||
DeletedBy string `json:"deletedBy"`
|
|
||||||
|
|
||||||
// Deleted time
|
|
||||||
DeletedTime uint64 `json:"deletedTime"`
|
|
||||||
|
|
||||||
// External IP
|
|
||||||
ExternalIP string `json:"externalIP"`
|
|
||||||
|
|
||||||
// Extnet ID
|
|
||||||
ExtnetId uint64 `json:"extnetId"`
|
|
||||||
|
|
||||||
// Free IPs
|
|
||||||
FreeIPs int64 `json:"freeIPs"`
|
|
||||||
|
|
||||||
// ID
|
|
||||||
ID uint64 `json:"id"`
|
|
||||||
|
|
||||||
// Name
|
|
||||||
Name string `json:"name"`
|
|
||||||
|
|
||||||
// Network
|
|
||||||
Network string `json:"network"`
|
|
||||||
|
|
||||||
// NNFDev ID
|
|
||||||
PriVNFDevID uint64 `json:"priVnfDevId"`
|
|
||||||
|
|
||||||
// Resource group ID
|
|
||||||
RGID uint64 `json:"rgId"`
|
|
||||||
|
|
||||||
// Resource group name
|
|
||||||
RGName string `json:"rgName"`
|
|
||||||
|
|
||||||
// Status
|
|
||||||
Status string `json:"status"`
|
|
||||||
|
|
||||||
// Updated by
|
|
||||||
UpdatedBy string `json:"updatedBy"`
|
|
||||||
|
|
||||||
// Updated time
|
|
||||||
UpdatedTime uint64 `json:"updatedTime"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of VINS
|
|
||||||
type ListVINS struct {
|
|
||||||
// Data
|
|
||||||
Data []ItemVINS `json:"data"`
|
|
||||||
|
|
||||||
// Entry count
|
|
||||||
EntryCount uint64 `json:"entryCount"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main info about audit
|
|
||||||
type ItemAudit struct {
|
|
||||||
// Call
|
|
||||||
Call string `json:"call"`
|
|
||||||
|
|
||||||
// Response time
|
|
||||||
ResponseTime float64 `json:"responsetime"`
|
|
||||||
|
|
||||||
// Status code
|
|
||||||
StatusCode uint64 `json:"statuscode"`
|
|
||||||
|
|
||||||
// Timestamp
|
|
||||||
Timestamp float64 `json:"timestamp"`
|
|
||||||
|
|
||||||
// User
|
|
||||||
User string `json:"user"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of audits
|
|
||||||
type ListAudits []ItemAudit
|
|
||||||
|
|
||||||
// Information compute in resource group
|
|
||||||
type RGComputes struct {
|
|
||||||
// Number of started computes
|
|
||||||
Started uint64 `json:"Started"`
|
|
||||||
|
|
||||||
// Number of stopped computes
|
|
||||||
Stopped uint64 `json:"Stopped"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resources of Resource group
|
|
||||||
type RGResources struct {
|
|
||||||
// Consumed
|
|
||||||
Consumed Resource `json:"Consumed"`
|
|
||||||
|
|
||||||
// Limits
|
|
||||||
Limits LimitsRG `json:"Limits"`
|
|
||||||
|
|
||||||
// Reserved
|
|
||||||
Reserved Resource `json:"Reserved"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resources used
|
|
||||||
type LimitsRG struct {
|
|
||||||
// Number of cores
|
|
||||||
CPU int64 `json:"cpu"`
|
|
||||||
|
|
||||||
// Disk size
|
|
||||||
DiskSize int64 `json:"disksize"`
|
|
||||||
|
|
||||||
// Max disk size
|
|
||||||
DiskSizeMax int64 `json:"disksizemax"`
|
|
||||||
|
|
||||||
// Number of External IPs
|
|
||||||
ExtIPs int64 `json:"extips"`
|
|
||||||
|
|
||||||
// Number of grafic cores
|
|
||||||
GPU int64 `json:"gpu"`
|
|
||||||
|
|
||||||
// Number of RAM
|
|
||||||
RAM int64 `json:"ram"`
|
|
||||||
|
|
||||||
// SEPs
|
|
||||||
SEPs uint64 `json:"seps"`
|
|
||||||
|
|
||||||
// Policies
|
|
||||||
Policies map[string]Policy `json:"policies"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main information about resource group
|
|
||||||
type ItemRG struct {
|
|
||||||
// Computes
|
|
||||||
Computes RGComputes `json:"Computes"`
|
|
||||||
|
|
||||||
// Resources
|
|
||||||
Resources RGResources `json:"Resources"`
|
|
||||||
|
|
||||||
// Created by
|
|
||||||
CreatedBy string `json:"createdBy"`
|
|
||||||
|
|
||||||
// Created time
|
|
||||||
CreatedTime uint64 `json:"createdTime"`
|
|
||||||
|
|
||||||
// Deleted by
|
|
||||||
DeletedBy string `json:"deletedBy"`
|
|
||||||
|
|
||||||
// Deleted time
|
|
||||||
DeletedTime uint64 `json:"deletedTime"`
|
|
||||||
|
|
||||||
// Description
|
|
||||||
Description string `json:"desc"`
|
|
||||||
|
|
||||||
// Resource group ID
|
|
||||||
RGID uint64 `json:"id"`
|
|
||||||
|
|
||||||
// Milestones
|
|
||||||
Milestones uint64 `json:"milestones"`
|
|
||||||
|
|
||||||
// Resource group name
|
|
||||||
RGName string `json:"name"`
|
|
||||||
|
|
||||||
// Status
|
|
||||||
Status string `json:"status"`
|
|
||||||
|
|
||||||
// Updated by
|
|
||||||
UpdatedBy string `json:"updatedBy"`
|
|
||||||
|
|
||||||
// Updated time
|
|
||||||
UpdatedTime uint64 `json:"updatedTime"`
|
|
||||||
|
|
||||||
// Number of VINS
|
|
||||||
VINSes uint64 `json:"vinses"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of Resource groups
|
|
||||||
type ListRG struct {
|
|
||||||
// Data
|
|
||||||
Data []ItemRG `json:"data"`
|
|
||||||
|
|
||||||
// Enrtry count
|
|
||||||
EntryCount uint64 `json:"entryCount"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main information about template
|
|
||||||
type ItemTemplate struct {
|
|
||||||
// UNCPath
|
|
||||||
UNCPath string `json:"UNCPath"`
|
|
||||||
|
|
||||||
// Account ID
|
|
||||||
AccountID uint64 `json:"accountId"`
|
|
||||||
|
|
||||||
// Description
|
|
||||||
Description string `json:"desc"`
|
|
||||||
|
|
||||||
// ID
|
|
||||||
ID uint64 `json:"id"`
|
|
||||||
|
|
||||||
// Name
|
|
||||||
Name string `json:"name"`
|
|
||||||
|
|
||||||
// Public or not
|
|
||||||
Public bool `json:"public"`
|
|
||||||
|
|
||||||
// Size
|
|
||||||
Size uint64 `json:"size"`
|
|
||||||
|
|
||||||
// Status
|
|
||||||
Status string `json:"status"`
|
|
||||||
|
|
||||||
// Type
|
|
||||||
Type string `json:"type"`
|
|
||||||
|
|
||||||
// Username
|
|
||||||
Username string `json:"username"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of templates
|
|
||||||
type ListTemplates struct {
|
|
||||||
// Data
|
|
||||||
Data []ItemTemplate `json:"data"`
|
|
||||||
|
|
||||||
// Entry count
|
|
||||||
EntryCount uint64 `json:"entryCount"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main information about FLIPGroup
|
|
||||||
type ItemFLIPGroup struct {
|
|
||||||
// Account ID
|
|
||||||
AccountID uint64 `json:"accountId"`
|
|
||||||
|
|
||||||
// Client type
|
|
||||||
ClientType string `json:"clientType"`
|
|
||||||
|
|
||||||
// Connection type
|
|
||||||
ConnType string `json:"connType"`
|
|
||||||
|
|
||||||
// Created by
|
|
||||||
CreatedBy string `json:"createdBy"`
|
|
||||||
|
|
||||||
// Created time
|
|
||||||
CreatedTime uint64 `json:"createdTime"`
|
|
||||||
|
|
||||||
// Default GW
|
|
||||||
DefaultGW string `json:"defaultGW"`
|
|
||||||
|
|
||||||
// Deleted by
|
|
||||||
DeletedBy string `json:"deletedBy"`
|
|
||||||
|
|
||||||
// Deleted time
|
|
||||||
DeletedTime uint64 `json:"deletedTime"`
|
|
||||||
|
|
||||||
// Description
|
|
||||||
Description string `json:"desc"`
|
|
||||||
|
|
||||||
// Grid ID
|
|
||||||
GID uint64 `json:"gid"`
|
|
||||||
|
|
||||||
// GUID
|
|
||||||
GUID uint64 `json:"guid"`
|
|
||||||
|
|
||||||
// ID
|
|
||||||
ID uint64 `json:"id"`
|
|
||||||
|
|
||||||
// IP
|
|
||||||
IP string `json:"ip"`
|
|
||||||
|
|
||||||
// Milestones
|
|
||||||
Milestones uint64 `json:"milestones"`
|
|
||||||
|
|
||||||
// Name
|
|
||||||
Name string `json:"name"`
|
|
||||||
|
|
||||||
// Network ID
|
|
||||||
NetID uint64 `json:"netId"`
|
|
||||||
|
|
||||||
// Network type
|
|
||||||
NetType string `json:"netType"`
|
|
||||||
|
|
||||||
// Network mask
|
|
||||||
NetMask uint64 `json:"netmask"`
|
|
||||||
|
|
||||||
// Status
|
|
||||||
Status string `json:"status"`
|
|
||||||
|
|
||||||
// Updated by
|
|
||||||
UpdatedBy string `json:"updatedBy"`
|
|
||||||
|
|
||||||
// Updated time
|
|
||||||
UpdatedTime uint64 `json:"updatedTime"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of FLIPGroups
|
|
||||||
type ListFLIPGroups struct {
|
|
||||||
// Data
|
|
||||||
Data []ItemFLIPGroup `json:"data"`
|
|
||||||
|
|
||||||
// Entry count
|
|
||||||
EntryCount uint64 `json:"entryCount"`
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RestoreRequest struct to restore a deleted account
|
|
||||||
type RestoreRequest struct {
|
|
||||||
// ID an account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore restores a deleted account
|
|
||||||
func (a Account) Restore(ctx context.Context, req RestoreRequest) (string, error) {
|
|
||||||
err := validators.ValidateRequest(req)
|
|
||||||
if err != nil {
|
|
||||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/restore"
|
|
||||||
|
|
||||||
result, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(result), nil
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/serialization"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
|
||||||
//
|
|
||||||
// In order to serialize with indent make sure to follow these guidelines:
|
|
||||||
// - First argument -> prefix
|
|
||||||
// - Second argument -> indent
|
|
||||||
func (la ListAccounts) Serialize(params ...string) (serialization.Serialized, error) {
|
|
||||||
if len(la.Data) == 0 {
|
|
||||||
return []byte{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(params) > 1 {
|
|
||||||
prefix := params[0]
|
|
||||||
indent := params[1]
|
|
||||||
|
|
||||||
return json.MarshalIndent(la, prefix, indent)
|
|
||||||
}
|
|
||||||
|
|
||||||
return json.Marshal(la)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
|
||||||
//
|
|
||||||
// In order to serialize with indent make sure to follow these guidelines:
|
|
||||||
// - First argument -> prefix
|
|
||||||
// - Second argument -> indent
|
|
||||||
func (ia ItemAccount) Serialize(params ...string) (serialization.Serialized, error) {
|
|
||||||
if len(params) > 1 {
|
|
||||||
prefix := params[0]
|
|
||||||
indent := params[1]
|
|
||||||
|
|
||||||
return json.MarshalIndent(ia, prefix, indent)
|
|
||||||
}
|
|
||||||
|
|
||||||
return json.Marshal(ia)
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import "sort"
|
|
||||||
|
|
||||||
// SortByCreatedTime sorts ListAccounts by the CreatedTime field in ascending order.
|
|
||||||
//
|
|
||||||
// If inverse param is set to true, the order is reversed.
|
|
||||||
func (la ListAccounts) SortByCreatedTime(inverse bool) ListAccounts {
|
|
||||||
if len(la.Data) < 2 {
|
|
||||||
return la
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Slice(la.Data, func(i, j int) bool {
|
|
||||||
if inverse {
|
|
||||||
return la.Data[i].CreatedTime > la.Data[j].CreatedTime
|
|
||||||
}
|
|
||||||
|
|
||||||
return la.Data[i].CreatedTime < la.Data[j].CreatedTime
|
|
||||||
})
|
|
||||||
|
|
||||||
return la
|
|
||||||
}
|
|
||||||
|
|
||||||
// SortByUpdatedTime sorts ListAccounts by the UpdatedTime field in ascending order.
|
|
||||||
//
|
|
||||||
// If inverse param is set to true, the order is reversed.
|
|
||||||
func (la ListAccounts) SortByUpdatedTime(inverse bool) ListAccounts {
|
|
||||||
if len(la.Data) < 2 {
|
|
||||||
return la
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Slice(la.Data, func(i, j int) bool {
|
|
||||||
if inverse {
|
|
||||||
return la.Data[i].UpdatedTime > la.Data[j].UpdatedTime
|
|
||||||
}
|
|
||||||
|
|
||||||
return la.Data[i].UpdatedTime < la.Data[j].UpdatedTime
|
|
||||||
})
|
|
||||||
|
|
||||||
return la
|
|
||||||
}
|
|
||||||
|
|
||||||
// SortByDeletedTime sorts ListAccounts by the DeletedTime field in ascending order.
|
|
||||||
//
|
|
||||||
// If inverse param is set to true, the order is reversed.
|
|
||||||
func (la ListAccounts) SortByDeletedTime(inverse bool) ListAccounts {
|
|
||||||
if len(la.Data) < 2 {
|
|
||||||
return la
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Slice(la.Data, func(i, j int) bool {
|
|
||||||
if inverse {
|
|
||||||
return la.Data[i].DeletedTime > la.Data[j].DeletedTime
|
|
||||||
}
|
|
||||||
|
|
||||||
return la.Data[i].DeletedTime < la.Data[j].DeletedTime
|
|
||||||
})
|
|
||||||
|
|
||||||
return la
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// UpdateRequest struct to update account
|
|
||||||
type UpdateRequest struct {
|
|
||||||
// ID an account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
|
|
||||||
// Description
|
|
||||||
// Required: false
|
|
||||||
Description string `url:"desc,omitempty" json:"desc,omitempty"`
|
|
||||||
|
|
||||||
// Name of the account
|
|
||||||
// Required: false
|
|
||||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
|
||||||
|
|
||||||
// Max size of memory in MB
|
|
||||||
// Required: false
|
|
||||||
MaxMemoryCapacity int64 `url:"maxMemoryCapacity,omitempty" json:"maxMemoryCapacity,omitempty"`
|
|
||||||
|
|
||||||
// Max size of aggregated vdisks in GB
|
|
||||||
// Required: false
|
|
||||||
MaxVDiskCapacity int64 `url:"maxVDiskCapacity,omitempty" json:"maxVDiskCapacity,omitempty"`
|
|
||||||
|
|
||||||
// Max number of CPU cores
|
|
||||||
// Required: false
|
|
||||||
MaxCPUCapacity int64 `url:"maxCPUCapacity,omitempty" json:"maxCPUCapacity,omitempty"`
|
|
||||||
|
|
||||||
// Max number of assigned public IPs
|
|
||||||
// Required: false
|
|
||||||
MaxNumPublicIP int64 `url:"maxNumPublicIP,omitempty" json:"maxNumPublicIP,omitempty"`
|
|
||||||
|
|
||||||
// If true send emails when a user is granted access to resources
|
|
||||||
// Required: false
|
|
||||||
SendAccessEmails bool `url:"sendAccessEmails" json:"sendAccessEmails"`
|
|
||||||
|
|
||||||
// Limit (positive) or disable (0) GPU resources
|
|
||||||
// Required: false
|
|
||||||
GPUUnits int64 `url:"gpu_units,omitempty" json:"gpu_units,omitempty"`
|
|
||||||
|
|
||||||
// List of strings with pools
|
|
||||||
// i.e.: ["sep1_poolName1", "sep2_poolName2", etc]
|
|
||||||
// Required: false
|
|
||||||
UniqPools []string `url:"uniqPools,omitempty" json:"uniqPools,omitempty"`
|
|
||||||
|
|
||||||
// Default zone ID
|
|
||||||
// Required: false
|
|
||||||
DefaultZoneID uint64 `url:"defaultZoneId,omitempty" json:"defaultZoneId,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update updates an account name and resource types and limits
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/update"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package account
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// UpdateUserRequest struct to update user access rights
|
|
||||||
type UpdateUserRequest struct {
|
|
||||||
// ID of the account
|
|
||||||
// Required: true
|
|
||||||
AccountID uint64 `url:"accountId" json:"accountId" validate:"required"`
|
|
||||||
|
|
||||||
// Userid/Email for registered users or emailaddress for unregistered users
|
|
||||||
// Required: true
|
|
||||||
UserID string `url:"userId" json:"userId" validate:"required"`
|
|
||||||
|
|
||||||
// Account permission types:
|
|
||||||
// - 'R' for read only access
|
|
||||||
// - 'RCX' for Write
|
|
||||||
// - 'ARCXDU' for Admin
|
|
||||||
// Required: true
|
|
||||||
AccessType string `url:"accesstype" json:"accesstype" validate:"required,accessType"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateUser updates user access rights
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/account/updateUser"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package cloudapi
|
|
||||||
|
|
||||||
import (
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/audit"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Accessing the Stack method group
|
|
||||||
func (ca *CloudAPI) Audit() *audit.Audit {
|
|
||||||
return audit.New(ca.client)
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package audit
|
|
||||||
|
|
||||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
|
||||||
|
|
||||||
// Structure for creating request to audit
|
|
||||||
type Audit struct {
|
|
||||||
client interfaces.Caller
|
|
||||||
}
|
|
||||||
|
|
||||||
// Builder for audit endpoint
|
|
||||||
func New(client interfaces.Caller) *Audit{
|
|
||||||
return &Audit{
|
|
||||||
client: client,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
package audit
|
|
||||||
|
|
||||||
// FilterByID returns ListAudits with specified ID.
|
|
||||||
func (la ListAudits) FilterByID(guid string) ListAudits {
|
|
||||||
predicate := func(ia ItemAudit) bool {
|
|
||||||
return ia.GUID == guid
|
|
||||||
}
|
|
||||||
|
|
||||||
return la.FilterFunc(predicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterByCall returns ListAudits with specified call.
|
|
||||||
func (la ListAudits) FilterByCall(call string) ListAudits {
|
|
||||||
predicate := func(ic ItemAudit) bool {
|
|
||||||
return ic.Call == call
|
|
||||||
}
|
|
||||||
|
|
||||||
return la.FilterFunc(predicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterByCorrelationID returns ListAudits with specified correlation id.
|
|
||||||
func (la ListAudits) FilterByCorrelationID(correlationID string) ListAudits {
|
|
||||||
predicate := func(ic ItemAudit) bool {
|
|
||||||
return ic.CorrelationID == correlationID
|
|
||||||
}
|
|
||||||
|
|
||||||
return la.FilterFunc(predicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterByRemoteAddr returns ListAudits with specified remote address.
|
|
||||||
func (la ListAudits) FilterByRemoteAddr(remoteAddr string) ListAudits {
|
|
||||||
predicate := func(ic ItemAudit) bool {
|
|
||||||
return ic.RemoteAddr == remoteAddr
|
|
||||||
}
|
|
||||||
|
|
||||||
return la.FilterFunc(predicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterByUser returns ListAudits with specified user name.
|
|
||||||
func (la ListAudits) FilterByUser(user string) ListAudits {
|
|
||||||
predicate := func(ic ItemAudit) bool {
|
|
||||||
return ic.User == user
|
|
||||||
}
|
|
||||||
|
|
||||||
return la.FilterFunc(predicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterByStatusCode return ListAudits with specified status code.
|
|
||||||
func (la ListAudits) FilterByStatusCode(statusCode uint64) ListAudits {
|
|
||||||
predicate := func(ic ItemAudit) bool {
|
|
||||||
return ic.StatusCode == statusCode
|
|
||||||
}
|
|
||||||
|
|
||||||
return la.FilterFunc(predicate)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterFunc allows filtering ListAudits based on a user-specified predicate.
|
|
||||||
func (la ListAudits) FilterFunc(predicate func(ItemAudit) bool) ListAudits {
|
|
||||||
var result ListAudits
|
|
||||||
|
|
||||||
for _, item := range la.Data {
|
|
||||||
if predicate(item) {
|
|
||||||
result.Data = append(result.Data, item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result.EntryCount = uint64(len(result.Data))
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// FindOne returns first found ItemAudit
|
|
||||||
// If none was found, returns an empty struct.
|
|
||||||
func (la ListAudits) FindOne() ItemAudit {
|
|
||||||
if len(la.Data) == 0 {
|
|
||||||
return ItemAudit{}
|
|
||||||
}
|
|
||||||
|
|
||||||
return la.Data[0]
|
|
||||||
}
|
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
package audit
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
var audits = ListAudits{
|
|
||||||
Data: []ItemAudit{
|
|
||||||
{
|
|
||||||
Args: "[]",
|
|
||||||
Call: "/restmachine/cloudapi/audit/linkedJobs",
|
|
||||||
GUID: "550e8400-e29b-41d4-a716-446655440001",
|
|
||||||
CorrelationID: "550e8400-e29b-41d4-a716-446655440001",
|
|
||||||
Kwargs: `{\"audit_guid\":\"dd8623a1-a887-48c1-a500-c10210d404cf\"}`,
|
|
||||||
RemoteAddr: "192.168.1.100",
|
|
||||||
ResponseTime: 1,
|
|
||||||
Result: `[]`,
|
|
||||||
StatusCode: 200,
|
|
||||||
Timestamp: 1640995200,
|
|
||||||
TimestampEnd: 1640995201,
|
|
||||||
User: "test@example.com",
|
|
||||||
TTL: "2025-07-31T14:22:57.028000",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Args: "[]",
|
|
||||||
Call: "/restmachine/cloudapi/audit/test",
|
|
||||||
GUID: "550e8400-e29b-41d4-a716-446655440002",
|
|
||||||
CorrelationID: "550e8400-e29b-41d4-a716-446655440002",
|
|
||||||
Kwargs: `{\"audit_guid\":\"dd8623a1-a887-48c1-a500-c10210d404cf\"}`,
|
|
||||||
RemoteAddr: "192.168.1.105",
|
|
||||||
ResponseTime: 5,
|
|
||||||
Result: `[]`,
|
|
||||||
StatusCode: 400,
|
|
||||||
Timestamp: 1640995200,
|
|
||||||
TimestampEnd: 1640995201,
|
|
||||||
User: "test2@example.com",
|
|
||||||
TTL: "2025-07-31T14:22:57.028000",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
EntryCount: 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterByID(t *testing.T) {
|
|
||||||
actual := audits.FilterByID("550e8400-e29b-41d4-a716-446655440002").FindOne()
|
|
||||||
|
|
||||||
if actual.GUID != "550e8400-e29b-41d4-a716-446655440002" {
|
|
||||||
t.Fatal("expected GUID 550e8400-e29b-41d4-a716-446655440002, found: ", actual.GUID)
|
|
||||||
}
|
|
||||||
|
|
||||||
actualEmpty := audits.FilterByID("")
|
|
||||||
|
|
||||||
if len(actualEmpty.Data) != 0 {
|
|
||||||
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterByCorrelationID(t *testing.T) {
|
|
||||||
actual := audits.FilterByCorrelationID("550e8400-e29b-41d4-a716-446655440002").FindOne()
|
|
||||||
|
|
||||||
if actual.CorrelationID != "550e8400-e29b-41d4-a716-446655440002" {
|
|
||||||
t.Fatal("expected GUID 550e8400-e29b-41d4-a716-446655440002, found: ", actual.CorrelationID)
|
|
||||||
}
|
|
||||||
|
|
||||||
actualEmpty := audits.FilterByCorrelationID("")
|
|
||||||
|
|
||||||
if len(actualEmpty.Data) != 0 {
|
|
||||||
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterByRemoteAddr(t *testing.T) {
|
|
||||||
actual := audits.FilterByRemoteAddr("192.168.1.100").FindOne()
|
|
||||||
|
|
||||||
if actual.RemoteAddr != "192.168.1.100" {
|
|
||||||
t.Fatal("expected remote address 192.168.1.100, found: ", actual.RemoteAddr)
|
|
||||||
}
|
|
||||||
|
|
||||||
actualEmpty := audits.FilterByRemoteAddr("")
|
|
||||||
|
|
||||||
if len(actualEmpty.Data) != 0 {
|
|
||||||
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterByUser(t *testing.T) {
|
|
||||||
actual := audits.FilterByUser("test@example.com").FindOne()
|
|
||||||
|
|
||||||
if actual.User != "test@example.com" {
|
|
||||||
t.Fatal("expected user test@example.com, found: ", actual.RemoteAddr)
|
|
||||||
}
|
|
||||||
|
|
||||||
actualEmpty := audits.FilterByUser("")
|
|
||||||
|
|
||||||
if len(actualEmpty.Data) != 0 {
|
|
||||||
t.Fatal("expected empty, actual: ", len(actualEmpty.Data))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterByCall(t *testing.T) {
|
|
||||||
actual := audits.FilterByCall("/restmachine/cloudapi/audit/test").FindOne()
|
|
||||||
|
|
||||||
if actual.Call != "/restmachine/cloudapi/audit/test" {
|
|
||||||
t.Fatal("expected call /restmachine/cloudapi/audit/test, found: ", actual.Call)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterByStatusCode(t *testing.T) {
|
|
||||||
actual := audits.FilterByStatusCode(200)
|
|
||||||
|
|
||||||
for _, item := range actual.Data {
|
|
||||||
if item.StatusCode != 200 {
|
|
||||||
t.Fatal("expected 200 status code, found: ", item.StatusCode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package audit
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetRequest struct to get information about account
|
|
||||||
type GetRequest struct {
|
|
||||||
// Audit GUID
|
|
||||||
// Required: true
|
|
||||||
AuditGuid string `url:"audit_guid" json:"audit_guid" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gets information about audit as a RecordAudit struct
|
|
||||||
func (a Audit) Get(ctx context.Context, req GetRequest) (*RecordAudit, error) {
|
|
||||||
res, err := a.GetRaw(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
info := RecordAudit{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &info)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &info, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRaw gets information about audit as an array of bytes
|
|
||||||
func (a Audit) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
|
||||||
err := validators.ValidateRequest(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/audit/get"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
package audit
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ListRequest struct to give list of account audits
|
|
||||||
type ListRequest struct {
|
|
||||||
|
|
||||||
// Find all audits after point in time (unixtime)
|
|
||||||
// Required: false
|
|
||||||
TimestampAt uint64 `url:"timestamp_at,omitempty" json:"timestamp_at,omitempty"`
|
|
||||||
|
|
||||||
// Find all audits before point in time (unixtime)
|
|
||||||
// Required: false
|
|
||||||
TimestampTo uint64 `url:"timestamp_to,omitempty" json:"timestamp_to,omitempty"`
|
|
||||||
|
|
||||||
// Find by user (Mongo RegExp supported)
|
|
||||||
// Required: false
|
|
||||||
User string `url:"user,omitempty" json:"user,omitempty"`
|
|
||||||
|
|
||||||
// Find by api endpoint (Mongo RegExp supported)
|
|
||||||
// Required: false
|
|
||||||
Call string `url:"call,omitempty" json:"call,omitempty"`
|
|
||||||
|
|
||||||
// Find by request id
|
|
||||||
// Required: false
|
|
||||||
RequestID string `url:"request_id,omitempty" json:"request_id,omitempty"`
|
|
||||||
|
|
||||||
// Find by HTTP min status code
|
|
||||||
// Required: false
|
|
||||||
MinStatusCode uint64 `url:"min_status_code,omitempty" json:"min_status_code,omitempty"`
|
|
||||||
|
|
||||||
// Find by HTTP max status code
|
|
||||||
// Required: false
|
|
||||||
MaxStatusCode uint64 `url:"max_status_code,omitempty" json:"max_status_code,omitempty"`
|
|
||||||
|
|
||||||
// Sort by one of supported fields, format +|-(field)
|
|
||||||
// Required: false
|
|
||||||
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty" validate:"omitempty,sortBy"`
|
|
||||||
|
|
||||||
// Page number
|
|
||||||
// Required: false
|
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
|
||||||
|
|
||||||
// Page size
|
|
||||||
// Required: false
|
|
||||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
|
||||||
|
|
||||||
// Find by resource group id
|
|
||||||
// Required: false
|
|
||||||
RGID uint64 `url:"resgroup_id,omitempty" json:"resgroup_id,omitempty"`
|
|
||||||
|
|
||||||
// Find by compute id
|
|
||||||
// Required: false
|
|
||||||
ComputeID uint64 `url:"compute_id,omitempty" json:"compute_id,omitempty"`
|
|
||||||
|
|
||||||
// Find by account id
|
|
||||||
// Required: false
|
|
||||||
AccountID uint64 `url:"account_id,omitempty" json:"account_id,omitempty"`
|
|
||||||
|
|
||||||
// Find by vins id
|
|
||||||
// Required: false
|
|
||||||
VINSID uint64 `url:"vins_id,omitempty" json:"vins_id,omitempty"`
|
|
||||||
|
|
||||||
// Find by service id
|
|
||||||
// Required: false
|
|
||||||
ServiceID uint64 `url:"service_id,omitempty" json:"service_id,omitempty"`
|
|
||||||
|
|
||||||
// Find by k8s id
|
|
||||||
// Required: false
|
|
||||||
K8SID uint64 `url:"k8s_id,omitempty" json:"k8s_id,omitempty"`
|
|
||||||
|
|
||||||
// Find by flipgroup id
|
|
||||||
// Required: false
|
|
||||||
FLIPGroupID uint64 `url:"flipgroup_id,omitempty" json:"flipgroup_id,omitempty"`
|
|
||||||
|
|
||||||
// Find by load balancer id
|
|
||||||
// Required: false
|
|
||||||
LBID uint64 `url:"lb_id,omitempty" json:"lb_id,omitempty"`
|
|
||||||
|
|
||||||
// Find by sep id
|
|
||||||
// Required: false
|
|
||||||
SEPID uint64 `url:"sep_id,omitempty" json:"sep_id,omitempty"`
|
|
||||||
|
|
||||||
// Exclude audit lines from response
|
|
||||||
// Required: false
|
|
||||||
ExcludeAuditLines bool `url:"exclude_audit_lines,omitempty" json:"exclude_audit_lines,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List gets audit records for the specified account object
|
|
||||||
func (a Audit) List(ctx context.Context, req ListRequest) (*ListAudits, error) {
|
|
||||||
|
|
||||||
res, err := a.ListRaw(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
list := ListAudits{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &list, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListRaw gets list of audit records an array of bytes
|
|
||||||
func (a Audit) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
|
|
||||||
|
|
||||||
if err := validators.ValidateRequest(req); err != nil {
|
|
||||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/audit/list"
|
|
||||||
|
|
||||||
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
package audit
|
|
||||||
|
|
||||||
// Main info about audit
|
|
||||||
type RecordAudit struct {
|
|
||||||
|
|
||||||
// Arguments
|
|
||||||
Arguments string `json:"args"`
|
|
||||||
|
|
||||||
// Call
|
|
||||||
Call string `json:"call"`
|
|
||||||
|
|
||||||
// GUID
|
|
||||||
GUID string `json:"guid"`
|
|
||||||
|
|
||||||
// Correlation ID
|
|
||||||
CorrelationID string `json:"correlation_id"`
|
|
||||||
|
|
||||||
// Kwargs
|
|
||||||
Kwargs string `json:"kwargs"`
|
|
||||||
|
|
||||||
// RemoteAddr
|
|
||||||
RemoteAddr string `json:"remote_addr"`
|
|
||||||
|
|
||||||
// Response time
|
|
||||||
ResponseTime float64 `json:"responsetime"`
|
|
||||||
|
|
||||||
// Result
|
|
||||||
Result string `json:"result"`
|
|
||||||
|
|
||||||
// Status code
|
|
||||||
StatusCode uint64 `json:"statuscode"`
|
|
||||||
|
|
||||||
// Tags
|
|
||||||
Tags string `json:"tags"`
|
|
||||||
|
|
||||||
// Timestamp
|
|
||||||
Timestamp float64 `json:"timestamp"`
|
|
||||||
|
|
||||||
// TimestampEnd
|
|
||||||
TimestampEnd float64 `json:"timestampEnd"`
|
|
||||||
|
|
||||||
// User
|
|
||||||
User string `json:"user"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main info about audit
|
|
||||||
type ItemAudit struct {
|
|
||||||
// Args
|
|
||||||
Args string `json:"args"`
|
|
||||||
|
|
||||||
// Call
|
|
||||||
Call string `json:"call"`
|
|
||||||
|
|
||||||
// GUID
|
|
||||||
GUID string `json:"guid"`
|
|
||||||
|
|
||||||
// Correlation ID
|
|
||||||
CorrelationID string `json:"correlation_id"`
|
|
||||||
|
|
||||||
// Kwargs
|
|
||||||
Kwargs string `json:"kwargs"`
|
|
||||||
|
|
||||||
// RemoteAddr
|
|
||||||
RemoteAddr string `json:"remote_addr"`
|
|
||||||
|
|
||||||
// Response time
|
|
||||||
ResponseTime float64 `json:"responsetime"`
|
|
||||||
|
|
||||||
// Result
|
|
||||||
Result string `json:"result"`
|
|
||||||
|
|
||||||
// Status code
|
|
||||||
StatusCode uint64 `json:"statuscode"`
|
|
||||||
|
|
||||||
// Timestamp
|
|
||||||
Timestamp float64 `json:"timestamp"`
|
|
||||||
|
|
||||||
// Timestamp End
|
|
||||||
TimestampEnd float64 `json:"timestampEnd"`
|
|
||||||
|
|
||||||
// User
|
|
||||||
User string `json:"user"`
|
|
||||||
|
|
||||||
// TTL
|
|
||||||
TTL string `json:"_ttl"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of audits
|
|
||||||
type ListAudits struct {
|
|
||||||
// Data
|
|
||||||
Data []ItemAudit `json:"data"`
|
|
||||||
|
|
||||||
// EntryCount
|
|
||||||
EntryCount uint64 `json:"entryCount"`
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package cloudapi
|
|
||||||
|
|
||||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/bservice"
|
|
||||||
|
|
||||||
// Accessing the BService method group
|
|
||||||
func (ca *CloudAPI) BService() *bservice.BService {
|
|
||||||
return bservice.New(ca.client)
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
// API Actor for managing Compute Group. This actor is a final API for endusers to manage Compute Group
|
|
||||||
package bservice
|
|
||||||
|
|
||||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
|
||||||
|
|
||||||
// Structure for creating request to bservice
|
|
||||||
type BService struct {
|
|
||||||
client interfaces.Caller
|
|
||||||
}
|
|
||||||
|
|
||||||
// Builder for bservice endpoints
|
|
||||||
func New(client interfaces.Caller) *BService {
|
|
||||||
return &BService{
|
|
||||||
client,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// CreateRequest struct for BasicService
|
|
||||||
type CreateRequest struct {
|
|
||||||
// Name of the service
|
|
||||||
// Required: true
|
|
||||||
Name string `url:"name" json:"name" validate:"required"`
|
|
||||||
|
|
||||||
// ID of the Resource Group where this service will be placed
|
|
||||||
// Required: true
|
|
||||||
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
|
|
||||||
|
|
||||||
// Name of the user to deploy SSH key for. Pass empty string if no SSH key deployment is required
|
|
||||||
// Required: false
|
|
||||||
SSHUser string `url:"sshUser,omitempty" json:"sshUser,omitempty"`
|
|
||||||
|
|
||||||
// SSH key to deploy for the specified user. Same key will be deployed to all computes of the service
|
|
||||||
// Required: false
|
|
||||||
SSHKey string `url:"sshKey,omitempty" json:"sshKey,omitempty"`
|
|
||||||
|
|
||||||
// Zone ID
|
|
||||||
// Required: false
|
|
||||||
ZoneID uint64 `url:"zoneId,omitempty" json:"zoneId,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create creates blank BasicService instance
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/create"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DeleteRequest struct to delete basic service
|
|
||||||
type DeleteRequest struct {
|
|
||||||
// ID of the BasicService to be delete
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// If set to False, Basic service will be deleted to recycle bin. Otherwise destroyed immediately
|
|
||||||
// Required: false
|
|
||||||
// Default: false
|
|
||||||
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete deletes BasicService instance
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/delete"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DisableRequest struct for disable service
|
|
||||||
type DisableRequest struct {
|
|
||||||
// ID of the service to disable
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable disables service.
|
|
||||||
// Disabling a service technically means setting model status
|
|
||||||
// of all computes and service itself to DISABLED and stopping all computes.
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/disable"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// EnableRequest struct to disable service
|
|
||||||
type EnableRequest struct {
|
|
||||||
// ID of the service to enable
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable enables service.
|
|
||||||
// Enabling a service technically means setting model status of
|
|
||||||
// all computes and service itself to ENABLED.
|
|
||||||
// It does not start computes.
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/enable"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
// FilterByID returns ListBasicServices with specified ID.
|
|
||||||
func (lbs ListBasicServices) FilterByID(id uint64) ListBasicServices {
|
|
||||||
predicate := func(ibs ItemBasicService) bool {
|
|
||||||
return ibs.ID == id
|
|
||||||
}
|
|
||||||
|
|
||||||
return lbs.FilterFunc(predicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterByName returns ListBasicServices with specified Name.
|
|
||||||
func (lbs ListBasicServices) FilterByName(name string) ListBasicServices {
|
|
||||||
predicate := func(ibs ItemBasicService) bool {
|
|
||||||
return ibs.Name == name
|
|
||||||
}
|
|
||||||
|
|
||||||
return lbs.FilterFunc(predicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterByRGID returns ListBasicServices with specified RGID.
|
|
||||||
func (lbs ListBasicServices) FilterByRGID(rgID uint64) ListBasicServices {
|
|
||||||
predicate := func(ibs ItemBasicService) bool {
|
|
||||||
return ibs.RGID == rgID
|
|
||||||
}
|
|
||||||
|
|
||||||
return lbs.FilterFunc(predicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterByStatus returns ListBasicServices with specified Status.
|
|
||||||
func (lbs ListBasicServices) FilterByStatus(status string) ListBasicServices {
|
|
||||||
predicate := func(ibs ItemBasicService) bool {
|
|
||||||
return ibs.Status == status
|
|
||||||
}
|
|
||||||
|
|
||||||
return lbs.FilterFunc(predicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterByTechStatus returns ListBasicServices with specified TechStatus.
|
|
||||||
func (lbs ListBasicServices) FilterByTechStatus(techStatus string) ListBasicServices {
|
|
||||||
predicate := func(ibs ItemBasicService) bool {
|
|
||||||
return ibs.TechStatus == techStatus
|
|
||||||
}
|
|
||||||
|
|
||||||
return lbs.FilterFunc(predicate)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FilterFunc allows filtering ListResourceGroups based on a user-specified predicate.
|
|
||||||
func (lbs ListBasicServices) FilterFunc(predicate func(ItemBasicService) bool) ListBasicServices {
|
|
||||||
var result ListBasicServices
|
|
||||||
|
|
||||||
for _, item := range lbs.Data {
|
|
||||||
if predicate(item) {
|
|
||||||
result.Data = append(result.Data, item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result.EntryCount = uint64(len(lbs.Data))
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// FindOne returns first found ItemBasicService
|
|
||||||
// If none was found, returns an empty struct.
|
|
||||||
func (lbs ListBasicServices) FindOne() ItemBasicService {
|
|
||||||
if lbs.EntryCount == 0 {
|
|
||||||
return ItemBasicService{}
|
|
||||||
}
|
|
||||||
|
|
||||||
return lbs.Data[0]
|
|
||||||
}
|
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
var bservices = ListBasicServices{
|
|
||||||
Data: []ItemBasicService{
|
|
||||||
{
|
|
||||||
AccountID: 1,
|
|
||||||
AccountName: "std_1",
|
|
||||||
BaseDomain: "",
|
|
||||||
CreatedBy: "sample_user_1@decs3o",
|
|
||||||
CreatedTime: 1677743675,
|
|
||||||
DeletedBy: "",
|
|
||||||
DeletedTime: 0,
|
|
||||||
GID: 212,
|
|
||||||
Groups: []uint64{},
|
|
||||||
GUID: 1,
|
|
||||||
ID: 1,
|
|
||||||
Name: "bservice_1",
|
|
||||||
ParentSrvID: 0,
|
|
||||||
ParentSrvType: "",
|
|
||||||
RGID: 7971,
|
|
||||||
RGName: "rg_1",
|
|
||||||
SSHUser: "",
|
|
||||||
Status: "CREATED",
|
|
||||||
TechStatus: "STOPPED",
|
|
||||||
UpdatedBy: "",
|
|
||||||
UpdatedTime: 0,
|
|
||||||
UserManaged: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
AccountID: 2,
|
|
||||||
AccountName: "std_2",
|
|
||||||
BaseDomain: "",
|
|
||||||
CreatedBy: "sample_user_1@decs3o",
|
|
||||||
CreatedTime: 1677743736,
|
|
||||||
DeletedBy: "",
|
|
||||||
DeletedTime: 0,
|
|
||||||
GID: 212,
|
|
||||||
Groups: []uint64{},
|
|
||||||
GUID: 2,
|
|
||||||
ID: 2,
|
|
||||||
Name: "bservice_2",
|
|
||||||
ParentSrvID: 0,
|
|
||||||
ParentSrvType: "",
|
|
||||||
RGID: 7972,
|
|
||||||
RGName: "rg_2",
|
|
||||||
SSHUser: "",
|
|
||||||
Status: "CREATED",
|
|
||||||
TechStatus: "STOPPED",
|
|
||||||
UpdatedBy: "",
|
|
||||||
UpdatedTime: 0,
|
|
||||||
UserManaged: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
AccountID: 3,
|
|
||||||
AccountName: "std_3",
|
|
||||||
BaseDomain: "",
|
|
||||||
CreatedBy: "sample_user_2@decs3o",
|
|
||||||
CreatedTime: 1677743830,
|
|
||||||
DeletedBy: "",
|
|
||||||
DeletedTime: 0,
|
|
||||||
GID: 212,
|
|
||||||
Groups: []uint64{},
|
|
||||||
GUID: 3,
|
|
||||||
ID: 3,
|
|
||||||
Name: "bservice_3",
|
|
||||||
ParentSrvID: 0,
|
|
||||||
ParentSrvType: "",
|
|
||||||
RGID: 7973,
|
|
||||||
RGName: "rg_3",
|
|
||||||
SSHUser: "",
|
|
||||||
Status: "ENABLED",
|
|
||||||
TechStatus: "STARTED",
|
|
||||||
UpdatedBy: "",
|
|
||||||
UpdatedTime: 0,
|
|
||||||
UserManaged: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
EntryCount: 3,
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterByID(t *testing.T) {
|
|
||||||
actual := bservices.FilterByID(1).FindOne()
|
|
||||||
|
|
||||||
if actual.ID != 1 {
|
|
||||||
t.Fatal("expected ID 1, found: ", actual.ID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterByName(t *testing.T) {
|
|
||||||
actual := bservices.FilterByName("bservice_3").FindOne()
|
|
||||||
|
|
||||||
if actual.Name != "bservice_3" {
|
|
||||||
t.Fatal("expected Name 'bservice_3', found: ", actual.Name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterByRGID(t *testing.T) {
|
|
||||||
actual := bservices.FilterByRGID(7971).FindOne()
|
|
||||||
|
|
||||||
if actual.RGID != 7971 {
|
|
||||||
t.Fatal("expected RGID 7971, found: ", actual.RGID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterByStatus(t *testing.T) {
|
|
||||||
actual := bservices.FilterByStatus("CREATED")
|
|
||||||
|
|
||||||
if len(actual.Data) != 2 {
|
|
||||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, item := range actual.Data {
|
|
||||||
if item.Status != "CREATED" {
|
|
||||||
t.Fatal("expected Status 'CREATED', found: ", item.Status)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterByTechStatus(t *testing.T) {
|
|
||||||
actual := bservices.FilterByTechStatus("STOPPED")
|
|
||||||
|
|
||||||
if len(actual.Data) != 2 {
|
|
||||||
t.Fatal("expected 2 found, actual: ", len(actual.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, item := range actual.Data {
|
|
||||||
if item.TechStatus != "STOPPED" {
|
|
||||||
t.Fatal("expected TechStatus 'STOPPED', found: ", item.TechStatus)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFilterFunc(t *testing.T) {
|
|
||||||
actual := bservices.FilterFunc(func(ibs ItemBasicService) bool {
|
|
||||||
return ibs.CreatedBy == "sample_user_2@decs3o"
|
|
||||||
})
|
|
||||||
|
|
||||||
if len(actual.Data) > 1 {
|
|
||||||
t.Fatal("expected 1 found, actual: ", len(actual.Data))
|
|
||||||
}
|
|
||||||
|
|
||||||
if actual.FindOne().CreatedBy != "sample_user_2@decs3o" {
|
|
||||||
t.Fatal("expected 'sample_user_2@decs3o', found: ", actual.FindOne().CreatedBy)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSortByCreatedTime(t *testing.T) {
|
|
||||||
actual := bservices.SortByCreatedTime(true)
|
|
||||||
|
|
||||||
if actual.Data[0].CreatedTime != 1677743830 || actual.Data[2].CreatedTime != 1677743675 {
|
|
||||||
t.Fatal("expected descending order, found ascending")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetRequest struct to get detailed information about service
|
|
||||||
type GetRequest struct {
|
|
||||||
// ID of the service to query information
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gets detailed specifications for the BasicService as a RecordBasicService struct
|
|
||||||
func (b BService) Get(ctx context.Context, req GetRequest) (*RecordBasicService, error) {
|
|
||||||
res, err := b.GetRaw(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
info := RecordBasicService{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &info)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &info, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRaw gets detailed specifications for the BasicService as an array of bytes
|
|
||||||
func (b BService) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
|
||||||
err := validators.ValidateRequest(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/get"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GroupAddRequest struct to create new compute group within BasicService
|
|
||||||
type GroupAddRequest struct {
|
|
||||||
// ID of the Basic Service to add a group to
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// Name of the Compute Group to add
|
|
||||||
// Required: true
|
|
||||||
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"`
|
|
||||||
|
|
||||||
// Compute CPU number. All computes in the group have the same CPU count
|
|
||||||
// Required: true
|
|
||||||
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"`
|
|
||||||
|
|
||||||
// Compute boot disk size in GB
|
|
||||||
// Required: true
|
|
||||||
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"`
|
|
||||||
|
|
||||||
// Storage endpoint provider ID
|
|
||||||
// Required: false
|
|
||||||
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
|
|
||||||
|
|
||||||
// Pool to use if sepId is set, can be also empty if needed to be chosen by system
|
|
||||||
// Required: false
|
|
||||||
SEPPool string `url:"sepPool,omitempty" json:"sepPool,omitempty"`
|
|
||||||
|
|
||||||
// Group role tag. Can be empty string, does not have to be unique
|
|
||||||
// Required: false
|
|
||||||
Role string `url:"role,omitempty" json:"role,omitempty"`
|
|
||||||
|
|
||||||
// List of ViNSes to connect computes to
|
|
||||||
// Required: false
|
|
||||||
VINSes []uint64 `url:"vinses,omitempty" json:"vinses,omitempty"`
|
|
||||||
|
|
||||||
// List of external networks to connect computes to
|
|
||||||
// Required: false
|
|
||||||
ExtNets []uint64 `url:"extnets,omitempty" json:"extnets,omitempty"`
|
|
||||||
|
|
||||||
// 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"`
|
|
||||||
|
|
||||||
// Chipset "i440fx" or "Q35
|
|
||||||
// Default value : Q35
|
|
||||||
// Required: false
|
|
||||||
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty" validate:"chipset,omitempty"`
|
|
||||||
|
|
||||||
// ID of the chosen storage policy
|
|
||||||
// Required: false
|
|
||||||
StoragePolicyID uint64 `url:"storage_policy_id,omitempty" json:"storage_policy_id,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRAM returns RAM field values
|
|
||||||
func (r GroupAddRequest) GetRAM() map[string]uint64 {
|
|
||||||
|
|
||||||
res := make(map[string]uint64, 1)
|
|
||||||
|
|
||||||
res["RAM"] = r.RAM
|
|
||||||
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// GroupAdd creates new Compute Group within BasicService.
|
|
||||||
// Compute Group is NOT started automatically,
|
|
||||||
// so you need to explicitly start it
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/groupAdd"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GroupComputeRemoveRequest struct to remove group compute
|
|
||||||
type GroupComputeRemoveRequest struct {
|
|
||||||
// ID of the Basic Service
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// ID of the Compute GROUP
|
|
||||||
// Required: true
|
|
||||||
CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
|
|
||||||
|
|
||||||
// ID of the Compute
|
|
||||||
// Required: true
|
|
||||||
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GroupComputeRemove makes group compute remove of the Basic Service
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/groupComputeRemove"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GroupGetRequest struct to get detailed information about Compute Group
|
|
||||||
type GroupGetRequest struct {
|
|
||||||
// ID of the Basic Service of Compute Group
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// ID of the Compute Group
|
|
||||||
// Required: true
|
|
||||||
CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GroupGet gets detailed specifications for the Compute Group
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/groupGet"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
info := RecordGroup{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &info)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &info, nil
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GroupParentAddRequest struct to add parent Compute Group relation to the specified Compute Group
|
|
||||||
type GroupParentAddRequest struct {
|
|
||||||
// ID of the Basic Service of Compute Group
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// ID of the Compute Group
|
|
||||||
// Required: true
|
|
||||||
CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
|
|
||||||
|
|
||||||
// ID of the parent Compute Group to register with the current Compute Group
|
|
||||||
// Required: true
|
|
||||||
ParentID uint64 `url:"parentId" json:"parentId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GroupParentAdd add parent Compute Group relation to the specified Compute Group
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/groupParentAdd"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GroupParentRemoveRequest struct to remove parent Compute Group
|
|
||||||
// relation from the specified Compute Group
|
|
||||||
type GroupParentRemoveRequest struct {
|
|
||||||
// ID of the Basic Service of Compute Group
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// ID of the Compute Group
|
|
||||||
// Required: true
|
|
||||||
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"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/groupParentRemove"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GroupRemoveRequest struct for destroy the specified Compute Group
|
|
||||||
type GroupRemoveRequest struct {
|
|
||||||
// ID of the Basic Service of Compute Group
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// ID of the Compute Group
|
|
||||||
// Required: true
|
|
||||||
CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GroupRemove destroy the specified Compute Group
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/groupRemove"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GroupResizeRequest struct to resize the group
|
|
||||||
type GroupResizeRequest struct {
|
|
||||||
// ID of the Basic Service of Compute Group
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// ID of the Compute Group to resize
|
|
||||||
// Required: true
|
|
||||||
CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
|
|
||||||
|
|
||||||
// Either delta or absolute value of computes
|
|
||||||
// Required: true
|
|
||||||
Count int64 `url:"count" json:"count" validate:"required"`
|
|
||||||
|
|
||||||
// Chipset for new computes, either i440fx or Q35 (i440fx by default)
|
|
||||||
// Available values : i440fx, Q35
|
|
||||||
// Default value : Q35
|
|
||||||
// Required: false
|
|
||||||
Chipset string `url:"chipset,omitempty" json:"chipset,omitempty" validate:"omitempty,chipset"`
|
|
||||||
|
|
||||||
// Either delta or absolute value of computes
|
|
||||||
// Should be one of:
|
|
||||||
// - ABSOLUTE
|
|
||||||
// - RELATIVE
|
|
||||||
// Required: false
|
|
||||||
Mode string `url:"mode,omitempty" json:"mode,omitempty" validate:"omitempty,bserviceMode"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GroupResize resize the group by changing the number of computes
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/groupResize"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseUint(string(res), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GroupStartRequest struct to start the specified Compute Group
|
|
||||||
type GroupStartRequest struct {
|
|
||||||
// ID of the Basic Service of Compute Group
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// ID of the Compute Group to start
|
|
||||||
// Required: true
|
|
||||||
CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GroupStart starts the specified Compute Group within BasicService
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/groupStart"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GroupStopRequest struct to stop the specified Compute Group
|
|
||||||
type GroupStopRequest struct {
|
|
||||||
// ID of the Basic Service of Compute Group
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// ID of the Compute Group to stop
|
|
||||||
// Required: true
|
|
||||||
CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
|
|
||||||
|
|
||||||
// Force stop Compute Group
|
|
||||||
// Required: false
|
|
||||||
Force bool `url:"force,omitempty" json:"force,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GroupStop stops the specified Compute Group within BasicService
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/groupStop"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GroupUpdateRequest struct to update existing Compute group
|
|
||||||
type GroupUpdateRequest struct {
|
|
||||||
// ID of the Basic Service of Compute Group
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// ID of the Compute Group
|
|
||||||
// Required: true
|
|
||||||
CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
|
|
||||||
|
|
||||||
// Specify non-empty string to update Compute Group name
|
|
||||||
// Required: false
|
|
||||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
|
||||||
|
|
||||||
// Specify non-empty string to update group role
|
|
||||||
// Required: false
|
|
||||||
Role string `url:"role,omitempty" json:"role,omitempty"`
|
|
||||||
|
|
||||||
// Specify positive value to set new compute CPU count
|
|
||||||
// Required: false
|
|
||||||
CPU uint64 `url:"cpu,omitempty" json:"cpu,omitempty"`
|
|
||||||
|
|
||||||
// Specify positive value to set new compute RAM volume in MB
|
|
||||||
// Required: false
|
|
||||||
RAM uint64 `url:"ram,omitempty" json:"ram,omitempty"`
|
|
||||||
|
|
||||||
// Specify new compute boot disk size in GB
|
|
||||||
// Required: false
|
|
||||||
Disk uint64 `url:"disk,omitempty" json:"disk,omitempty"`
|
|
||||||
|
|
||||||
// Force resize Compute Group
|
|
||||||
// Required: false
|
|
||||||
Force bool `url:"force,omitempty" json:"force,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRAM returns RAM field values
|
|
||||||
func (r GroupUpdateRequest) GetRAM() map[string]uint64 {
|
|
||||||
|
|
||||||
res := make(map[string]uint64, 1)
|
|
||||||
|
|
||||||
res["RAM"] = r.RAM
|
|
||||||
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
// GroupUpdate updates existing Compute group within Basic Service and apply new settings to its computes as necessary
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/groupUpdate"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GroupUpdateExtNetRequest struct to update External Network settings
|
|
||||||
type GroupUpdateExtNetRequest struct {
|
|
||||||
// ID of the Basic Service of Compute Group
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// ID of the Compute Group
|
|
||||||
// Required: true
|
|
||||||
CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
|
|
||||||
|
|
||||||
// List of Extnets to connect computes
|
|
||||||
// Required: false
|
|
||||||
ExtNets []uint64 `url:"extnets,omitempty" json:"extnets,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GroupUpdateExtNet updates External Network settings for the group according to the new list
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/groupUpdateExtnet"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GroupUpdateVINSRequest struct to update VINS settings
|
|
||||||
type GroupUpdateVINSRequest struct {
|
|
||||||
// ID of the Basic Service of Compute Group
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// ID of the Compute Group
|
|
||||||
// Required: true
|
|
||||||
CompGroupID uint64 `url:"compgroupId" json:"compgroupId" validate:"required"`
|
|
||||||
|
|
||||||
// List of ViNSes to connect computes
|
|
||||||
// Required: false
|
|
||||||
VINSes []uint64 `url:"vinses,omitempty" json:"vinses,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GroupUpdateVINS update ViNS settings for the group according to the new list
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/groupUpdateVins"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ListRequest struct to get list of BasicService instances
|
|
||||||
type ListRequest struct {
|
|
||||||
// Find by ID
|
|
||||||
// Required: false
|
|
||||||
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
|
|
||||||
|
|
||||||
// Find by name
|
|
||||||
// Required: false
|
|
||||||
Name string `url:"name,omitempty" json:"name,omitempty"`
|
|
||||||
|
|
||||||
// ID of the account to query for BasicService instances
|
|
||||||
// Required: false
|
|
||||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
|
||||||
|
|
||||||
// Find by resource group name
|
|
||||||
// Required: false
|
|
||||||
RGName string `url:"rgName,omitempty" json:"rgName,omitempty"`
|
|
||||||
|
|
||||||
// ID of the resource group to query for BasicService instances
|
|
||||||
// Required: false
|
|
||||||
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
|
||||||
|
|
||||||
// Find by tech status
|
|
||||||
// Required: false
|
|
||||||
TechStatus string `url:"techStatus,omitempty" json:"techStatus,omitempty"`
|
|
||||||
|
|
||||||
// Find by status
|
|
||||||
// Required: false
|
|
||||||
Status string `url:"status,omitempty" json:"status,omitempty"`
|
|
||||||
|
|
||||||
// Find by account name
|
|
||||||
// Required: false
|
|
||||||
AccountName string `url:"accountName,omitempty" json:"accountName,omitempty"`
|
|
||||||
|
|
||||||
// Sort by one of supported fields, format +|-(field)
|
|
||||||
// Required: false
|
|
||||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
|
||||||
|
|
||||||
// Sort by zone id
|
|
||||||
// Default value: 0
|
|
||||||
// Required: false
|
|
||||||
ZoneID uint64 `url:"zone_id,omitempty" json:"zone_id,omitempty"`
|
|
||||||
|
|
||||||
// Page number
|
|
||||||
// Required: false
|
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
|
||||||
|
|
||||||
// Page size
|
|
||||||
// Required: false
|
|
||||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List gets list of BasicService instances associated with the specified Resource Group as a ListBasicServices struct
|
|
||||||
func (b BService) List(ctx context.Context, req ListRequest) (*ListBasicServices, error) {
|
|
||||||
|
|
||||||
res, err := b.ListRaw(ctx, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
list := ListBasicServices{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
|
|
||||||
if err := validators.ValidateRequest(req); err != nil {
|
|
||||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/list"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ListDeletedRequest struct to get list of deleted BasicService instances
|
|
||||||
type ListDeletedRequest struct {
|
|
||||||
// ID of the account to query for BasicService instances
|
|
||||||
// Required: false
|
|
||||||
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
|
|
||||||
|
|
||||||
// ID of the resource group to query for BasicService instances
|
|
||||||
// Required: false
|
|
||||||
RGID uint64 `url:"rgId,omitempty" json:"rgId,omitempty"`
|
|
||||||
|
|
||||||
// Sort by one of supported fields, format +|-(field)
|
|
||||||
// Required: false
|
|
||||||
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty" validate:"omitempty,sortBy"`
|
|
||||||
|
|
||||||
// Page number
|
|
||||||
// Required: false
|
|
||||||
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
|
|
||||||
|
|
||||||
// Page size
|
|
||||||
// Required: false
|
|
||||||
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListDeleted gets list of deleted BasicService instances associated with the specified Resource Group
|
|
||||||
func (b BService) ListDeleted(ctx context.Context, req ListDeletedRequest) (*ListBasicServices, error) {
|
|
||||||
|
|
||||||
if err := validators.ValidateRequest(req); err != nil {
|
|
||||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/listDeleted"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
list := ListBasicServices{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &list, nil
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MigrateToZone struct to move basic service to another zone
|
|
||||||
type MigrateToZoneRequest struct {
|
|
||||||
// ID of the BasicService to move
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// ID of the zone to move
|
|
||||||
// Required: true
|
|
||||||
ZoneID uint64 `url:"zoneId" json:"zoneId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// MigrateToZone moves basic service instance to new zone
|
|
||||||
func (b BService) MigrateToZone(ctx context.Context, req MigrateToZoneRequest) (bool, error) {
|
|
||||||
err := validators.ValidateRequest(req)
|
|
||||||
if err != nil {
|
|
||||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/migrateToZone"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,398 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
// Detailed info about BasicService
|
|
||||||
type RecordBasicService struct {
|
|
||||||
// Account ID
|
|
||||||
AccountID uint64 `json:"accountId"`
|
|
||||||
|
|
||||||
// Account name
|
|
||||||
AccountName string `json:"accountName"`
|
|
||||||
|
|
||||||
// Base domain
|
|
||||||
BaseDomain string `json:"baseDomain"`
|
|
||||||
|
|
||||||
// List Computes
|
|
||||||
Computes ListComputes `json:"computes"`
|
|
||||||
|
|
||||||
// Number of cores
|
|
||||||
CPUTotal uint64 `json:"cpuTotal"`
|
|
||||||
|
|
||||||
// Created by
|
|
||||||
CreatedBy string `json:"createdBy"`
|
|
||||||
|
|
||||||
// Created time
|
|
||||||
CreatedTime uint64 `json:"createdTime"`
|
|
||||||
|
|
||||||
// Deleted by
|
|
||||||
DeletedBy string `json:"deletedBy"`
|
|
||||||
|
|
||||||
// Deleted time
|
|
||||||
DeletedTime uint64 `json:"deletedTime"`
|
|
||||||
|
|
||||||
// Amount of disk space used, GB
|
|
||||||
DiskTotal uint64 `json:"diskTotal"`
|
|
||||||
|
|
||||||
// Grid ID
|
|
||||||
GID uint64 `json:"gid"`
|
|
||||||
|
|
||||||
// List of Service Compute Groups
|
|
||||||
Groups ListGroups `json:"groups"`
|
|
||||||
|
|
||||||
// GUID
|
|
||||||
GUID uint64 `json:"guid"`
|
|
||||||
|
|
||||||
// ID
|
|
||||||
ID uint64 `json:"id"`
|
|
||||||
|
|
||||||
// Milestones
|
|
||||||
Milestones uint64 `json:"milestones"`
|
|
||||||
|
|
||||||
// Name
|
|
||||||
Name string `json:"name"`
|
|
||||||
|
|
||||||
// Parent service ID
|
|
||||||
ParentSrvID uint64 `json:"parentSrvId"`
|
|
||||||
|
|
||||||
// Parent service type
|
|
||||||
ParentSrvType string `json:"parentSrvType"`
|
|
||||||
|
|
||||||
// Total amount of RAM, MB
|
|
||||||
RAMTotal uint64 `json:"ramTotal"`
|
|
||||||
|
|
||||||
// Resource group ID
|
|
||||||
RGID uint64 `json:"rgId"`
|
|
||||||
|
|
||||||
// Resource group name
|
|
||||||
RGName string `json:"rgName"`
|
|
||||||
|
|
||||||
// List of snapshots
|
|
||||||
Snapshots ListSnapshots `json:"snapshots"`
|
|
||||||
|
|
||||||
// SSH key for connection
|
|
||||||
SSHKey string `json:"sshKey"`
|
|
||||||
|
|
||||||
// Username for SSH connection
|
|
||||||
SSHUser string `json:"sshUser"`
|
|
||||||
|
|
||||||
// status
|
|
||||||
Status string `json:"status"`
|
|
||||||
|
|
||||||
// TechStatus
|
|
||||||
TechStatus string `json:"techStatus"`
|
|
||||||
|
|
||||||
// Updated by
|
|
||||||
UpdatedBy string `json:"updatedBy"`
|
|
||||||
|
|
||||||
// Updated time
|
|
||||||
UpdatedTime uint64 `json:"updatedTime"`
|
|
||||||
|
|
||||||
// Whether user controlled
|
|
||||||
UserManaged bool `json:"userManaged"`
|
|
||||||
|
|
||||||
// Zone ID
|
|
||||||
ZoneID uint64 `json:"zoneId"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main information about Compute
|
|
||||||
type ItemCompute struct {
|
|
||||||
// Account ID
|
|
||||||
AccountID uint64 `json:"accountId"`
|
|
||||||
|
|
||||||
// Architecture
|
|
||||||
Architecture string `json:"arch"`
|
|
||||||
|
|
||||||
// Compute group ID
|
|
||||||
CompGroupID uint64 `json:"compgroupId"`
|
|
||||||
|
|
||||||
// Compute group name
|
|
||||||
CompGroupName string `json:"compgroupName"`
|
|
||||||
|
|
||||||
// compute group role
|
|
||||||
CompGroupRole string `json:"compgroupRole"`
|
|
||||||
|
|
||||||
// ID
|
|
||||||
ID uint64 `json:"id"`
|
|
||||||
|
|
||||||
// Name
|
|
||||||
Name string `json:"name"`
|
|
||||||
|
|
||||||
// Resource group ID
|
|
||||||
RGID uint64 `json:"rgId"`
|
|
||||||
|
|
||||||
// NodeID
|
|
||||||
NodeID uint64 `json:"node_id"`
|
|
||||||
|
|
||||||
// Status
|
|
||||||
Status string `json:"status"`
|
|
||||||
|
|
||||||
// Tech status
|
|
||||||
TechStatus string `json:"techStatus"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of Computes
|
|
||||||
type ListComputes []ItemCompute
|
|
||||||
|
|
||||||
// Main information about Group
|
|
||||||
type ItemGroup struct {
|
|
||||||
// Amount of computes
|
|
||||||
Computes uint64 `json:"computes"`
|
|
||||||
|
|
||||||
// Consistency
|
|
||||||
Consistency bool `json:"consistency"`
|
|
||||||
|
|
||||||
// Group ID
|
|
||||||
ID uint64 `json:"id"`
|
|
||||||
|
|
||||||
// Group name
|
|
||||||
Name string `json:"name"`
|
|
||||||
|
|
||||||
// Status
|
|
||||||
Status string `json:"status"`
|
|
||||||
|
|
||||||
// TechStatus
|
|
||||||
TechStatus string `json:"techStatus"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of Groups
|
|
||||||
type ListGroups []ItemGroup
|
|
||||||
|
|
||||||
// Main information about Snapshot
|
|
||||||
type ItemSnapshot struct {
|
|
||||||
// GUID
|
|
||||||
GUID string `json:"guid"`
|
|
||||||
|
|
||||||
// Label
|
|
||||||
Label string `json:"label"`
|
|
||||||
|
|
||||||
// Timestamp
|
|
||||||
Timestamp uint64 `json:"timestamp"`
|
|
||||||
|
|
||||||
// Valid or not
|
|
||||||
Valid bool `json:"valid"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of Snapshot
|
|
||||||
type ListSnapshots []ItemSnapshot
|
|
||||||
|
|
||||||
// List of Snapshots
|
|
||||||
type ListInfoSnapshots struct {
|
|
||||||
// Data
|
|
||||||
Data ListSnapshots `json:"data"`
|
|
||||||
|
|
||||||
// EntryCount
|
|
||||||
EntryCount uint64 `json:"entryCount"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main information about Group
|
|
||||||
type RecordGroup struct {
|
|
||||||
// Account ID
|
|
||||||
AccountID uint64 `json:"accountId"`
|
|
||||||
|
|
||||||
// Account Name
|
|
||||||
AccountName string `json:"accountName"`
|
|
||||||
|
|
||||||
// List of Computes
|
|
||||||
Computes ListGroupComputes `json:"computes"`
|
|
||||||
|
|
||||||
// Consistency or not
|
|
||||||
Consistency bool `json:"consistency"`
|
|
||||||
|
|
||||||
// Number of CPU
|
|
||||||
CPU uint64 `json:"cpu"`
|
|
||||||
|
|
||||||
// Created by
|
|
||||||
CreatedBy string `json:"createdBy"`
|
|
||||||
|
|
||||||
// Created time
|
|
||||||
CreatedTime uint64 `json:"createdTime"`
|
|
||||||
|
|
||||||
// Deleted by
|
|
||||||
DeletedBy string `json:"deletedBy"`
|
|
||||||
|
|
||||||
// Deleted time
|
|
||||||
DeletedTime uint64 `json:"deletedTime"`
|
|
||||||
|
|
||||||
// Amount of disk
|
|
||||||
Disk uint64 `json:"disk"`
|
|
||||||
|
|
||||||
// Driver
|
|
||||||
Driver string `json:"driver"`
|
|
||||||
|
|
||||||
// list of External Network IDs
|
|
||||||
ExtNets []uint64 `json:"extnets"`
|
|
||||||
|
|
||||||
// Grid ID
|
|
||||||
GID uint64 `json:"gid"`
|
|
||||||
|
|
||||||
// GUID
|
|
||||||
GUID uint64 `json:"guid"`
|
|
||||||
|
|
||||||
// ID
|
|
||||||
ID uint64 `json:"id"`
|
|
||||||
|
|
||||||
// Image ID
|
|
||||||
ImageID uint64 `json:"imageId"`
|
|
||||||
|
|
||||||
// Milestones
|
|
||||||
Milestones uint64 `json:"milestones"`
|
|
||||||
|
|
||||||
// Name
|
|
||||||
Name string `json:"name"`
|
|
||||||
|
|
||||||
// List of Parent IDs
|
|
||||||
Parents []uint64 `json:"parents"`
|
|
||||||
|
|
||||||
// Pool name
|
|
||||||
PoolName string `json:"poolName"`
|
|
||||||
|
|
||||||
// Number of RAM, MB
|
|
||||||
RAM uint64 `json:"ram"`
|
|
||||||
|
|
||||||
// Resource group ID
|
|
||||||
RGID uint64 `json:"rgId"`
|
|
||||||
|
|
||||||
// Resource group name
|
|
||||||
RGName string `json:"rgName"`
|
|
||||||
|
|
||||||
// Role
|
|
||||||
Role string `json:"role"`
|
|
||||||
|
|
||||||
// SEPID
|
|
||||||
SEPID uint64 `json:"sepId"`
|
|
||||||
|
|
||||||
// Sequence number
|
|
||||||
SeqNo uint64 `json:"seqNo"`
|
|
||||||
|
|
||||||
// Service ID
|
|
||||||
ServiceID uint64 `json:"serviceId"`
|
|
||||||
|
|
||||||
// Status
|
|
||||||
Status string `json:"status"`
|
|
||||||
|
|
||||||
// TechStatus
|
|
||||||
TechStatus string `json:"techStatus"`
|
|
||||||
|
|
||||||
// Timeout Start
|
|
||||||
TimeoutStart uint64 `json:"timeoutStart"`
|
|
||||||
|
|
||||||
// Updated by
|
|
||||||
UpdatedBy string `json:"updatedBy"`
|
|
||||||
|
|
||||||
// Updated time
|
|
||||||
UpdatedTime uint64 `json:"updatedTime"`
|
|
||||||
|
|
||||||
// List of VINS IDs
|
|
||||||
VINSes []uint64 `json:"vinses"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main information about Group Compute
|
|
||||||
type ItemGroupCompute struct {
|
|
||||||
// ID
|
|
||||||
ID uint64 `json:"id"`
|
|
||||||
|
|
||||||
// IP Addresses
|
|
||||||
IPAddresses []string `json:"ipAddresses"`
|
|
||||||
|
|
||||||
// Name
|
|
||||||
Name string `json:"name"`
|
|
||||||
|
|
||||||
// List of information about OS Users
|
|
||||||
OSUsers ListOSUsers `json:"osUsers"`
|
|
||||||
|
|
||||||
//Chipset
|
|
||||||
Chipset string `json:"chipset"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of Group Computes
|
|
||||||
type ListGroupComputes []ItemGroupCompute
|
|
||||||
|
|
||||||
// Main information about OS User
|
|
||||||
type ItemOSUser struct {
|
|
||||||
// Login
|
|
||||||
Login string `json:"login"`
|
|
||||||
|
|
||||||
// Password
|
|
||||||
Password string `json:"password"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of information about OS Users
|
|
||||||
type ListOSUsers []ItemOSUser
|
|
||||||
|
|
||||||
// Main information about BasicService
|
|
||||||
type ItemBasicService struct {
|
|
||||||
// Account ID
|
|
||||||
AccountID uint64 `json:"accountId"`
|
|
||||||
|
|
||||||
// Account name
|
|
||||||
AccountName string `json:"accountName"`
|
|
||||||
|
|
||||||
// Base domain
|
|
||||||
BaseDomain string `json:"baseDomain"`
|
|
||||||
|
|
||||||
// Created by
|
|
||||||
CreatedBy string `json:"createdBy"`
|
|
||||||
|
|
||||||
// Created time
|
|
||||||
CreatedTime uint64 `json:"createdTime"`
|
|
||||||
|
|
||||||
// Deleted by
|
|
||||||
DeletedBy string `json:"deletedBy"`
|
|
||||||
|
|
||||||
// Deleted time
|
|
||||||
DeletedTime uint64 `json:"deletedTime"`
|
|
||||||
|
|
||||||
// Grid ID
|
|
||||||
GID uint64 `json:"gid"`
|
|
||||||
|
|
||||||
// List of group IDs
|
|
||||||
Groups []uint64 `json:"groups"`
|
|
||||||
|
|
||||||
// GUID
|
|
||||||
GUID uint64 `json:"guid"`
|
|
||||||
|
|
||||||
// ID
|
|
||||||
ID uint64 `json:"id"`
|
|
||||||
|
|
||||||
// Name
|
|
||||||
Name string `json:"name"`
|
|
||||||
|
|
||||||
// Parent service ID
|
|
||||||
ParentSrvID uint64 `json:"parentSrvId"`
|
|
||||||
|
|
||||||
// Parent service type
|
|
||||||
ParentSrvType string `json:"parentSrvType"`
|
|
||||||
|
|
||||||
// Resource group ID
|
|
||||||
RGID uint64 `json:"rgId"`
|
|
||||||
|
|
||||||
// Resource group name
|
|
||||||
RGName string `json:"rgName"`
|
|
||||||
|
|
||||||
// SSH user
|
|
||||||
SSHUser string `json:"sshUser"`
|
|
||||||
|
|
||||||
// Status
|
|
||||||
Status string `json:"status"`
|
|
||||||
|
|
||||||
// TechStatus
|
|
||||||
TechStatus string `json:"techStatus"`
|
|
||||||
|
|
||||||
// Updated by
|
|
||||||
UpdatedBy string `json:"updatedBy"`
|
|
||||||
|
|
||||||
// Updated time
|
|
||||||
UpdatedTime uint64 `json:"updatedTime"`
|
|
||||||
|
|
||||||
// User Managed or not
|
|
||||||
UserManaged bool `json:"userManaged"`
|
|
||||||
|
|
||||||
// Zone ID
|
|
||||||
ZoneID uint64 `json:"zoneId"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// List of BasicServices
|
|
||||||
type ListBasicServices struct {
|
|
||||||
Data []ItemBasicService `json:"data"`
|
|
||||||
|
|
||||||
EntryCount uint64 `json:"entryCount"`
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RestoreRequest struct to restore BasicService instance
|
|
||||||
type RestoreRequest struct {
|
|
||||||
// ID of the BasicService to be restored
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore restores BasicService instance
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/restore"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/serialization"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
|
||||||
//
|
|
||||||
// In order to serialize with indent make sure to follow these guidelines:
|
|
||||||
// - First argument -> prefix
|
|
||||||
// - Second argument -> indent
|
|
||||||
func (lbs ListBasicServices) Serialize(params ...string) (serialization.Serialized, error) {
|
|
||||||
if lbs.EntryCount == 0 {
|
|
||||||
return []byte{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(params) > 1 {
|
|
||||||
prefix := params[0]
|
|
||||||
indent := params[1]
|
|
||||||
|
|
||||||
return json.MarshalIndent(lbs, prefix, indent)
|
|
||||||
}
|
|
||||||
|
|
||||||
return json.Marshal(lbs)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
|
|
||||||
//
|
|
||||||
// In order to serialize with indent make sure to follow these guidelines:
|
|
||||||
// - First argument -> prefix
|
|
||||||
// - Second argument -> indent
|
|
||||||
func (ibs ItemBasicService) Serialize(params ...string) (serialization.Serialized, error) {
|
|
||||||
if len(params) > 1 {
|
|
||||||
prefix := params[0]
|
|
||||||
indent := params[1]
|
|
||||||
|
|
||||||
return json.MarshalIndent(ibs, prefix, indent)
|
|
||||||
}
|
|
||||||
|
|
||||||
return json.Marshal(ibs)
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SnapshotCreateRequest struct to create snapshot
|
|
||||||
type SnapshotCreateRequest struct {
|
|
||||||
// ID of the Basic Service
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// Label of the snapshot
|
|
||||||
// Required: true
|
|
||||||
Label string `url:"label" json:"label" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// SnapshotCreate create snapshot of the Basic Service
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/snapshotCreate"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SnapshotDeleteRequest struct to delete snapshot
|
|
||||||
type SnapshotDeleteRequest struct {
|
|
||||||
// ID of the Basic Service
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// Label of the snapshot
|
|
||||||
// Required: true
|
|
||||||
Label string `url:"label" json:"label" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// SnapshotDelete delete snapshot of the Basic Service
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/snapshotDelete"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SnapshotListRequest struct to get list of existing snapshots
|
|
||||||
type SnapshotListRequest struct {
|
|
||||||
// ID of the Basic Service
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// SnapshotList gets list existing snapshots of the Basic Service
|
|
||||||
func (b BService) SnapshotList(ctx context.Context, req SnapshotListRequest) (*ListInfoSnapshots, error) {
|
|
||||||
err := validators.ValidateRequest(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/snapshotList"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
list := ListInfoSnapshots{}
|
|
||||||
|
|
||||||
err = json.Unmarshal(res, &list)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &list, nil
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SnapshotRollbackRequest struct to rollback snapshot
|
|
||||||
type SnapshotRollbackRequest struct {
|
|
||||||
// ID of the Basic Service
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
|
|
||||||
// Label of the snapshot
|
|
||||||
// Required: true
|
|
||||||
Label string `url:"label" json:"label" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// SnapshotRollback rollback snapshot of the Basic Service
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/snapshotRollback"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import "sort"
|
|
||||||
|
|
||||||
// SortByCreatedTime sorts ListBasicServices by the CreatedTime field in ascending order.
|
|
||||||
//
|
|
||||||
// If inverse param is set to true, the order is reversed.
|
|
||||||
func (lbs ListBasicServices) SortByCreatedTime(inverse bool) ListBasicServices {
|
|
||||||
if lbs.EntryCount < 2 {
|
|
||||||
return lbs
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Slice(lbs.Data, func(i, j int) bool {
|
|
||||||
if inverse {
|
|
||||||
return lbs.Data[i].CreatedTime > lbs.Data[j].CreatedTime
|
|
||||||
}
|
|
||||||
|
|
||||||
return lbs.Data[i].CreatedTime < lbs.Data[j].CreatedTime
|
|
||||||
})
|
|
||||||
|
|
||||||
return lbs
|
|
||||||
}
|
|
||||||
|
|
||||||
// SortByUpdatedTime sorts ListBasicServices by the UpdatedTime field in ascending order.
|
|
||||||
//
|
|
||||||
// If inverse param is set to true, the order is reversed.
|
|
||||||
func (lbs ListBasicServices) SortByUpdatedTime(inverse bool) ListBasicServices {
|
|
||||||
if lbs.EntryCount < 2 {
|
|
||||||
return lbs
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Slice(lbs.Data, func(i, j int) bool {
|
|
||||||
if inverse {
|
|
||||||
return lbs.Data[i].UpdatedTime > lbs.Data[j].UpdatedTime
|
|
||||||
}
|
|
||||||
|
|
||||||
return lbs.Data[i].UpdatedTime < lbs.Data[j].UpdatedTime
|
|
||||||
})
|
|
||||||
|
|
||||||
return lbs
|
|
||||||
}
|
|
||||||
|
|
||||||
// SortByDeletedTime sorts ListBasicServices by the DeletedTime field in ascending order.
|
|
||||||
//
|
|
||||||
// If inverse param is set to true, the order is reversed.
|
|
||||||
func (lbs ListBasicServices) SortByDeletedTime(inverse bool) ListBasicServices {
|
|
||||||
if lbs.EntryCount < 2 {
|
|
||||||
return lbs
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Slice(lbs.Data, func(i, j int) bool {
|
|
||||||
if inverse {
|
|
||||||
return lbs.Data[i].DeletedTime > lbs.Data[j].DeletedTime
|
|
||||||
}
|
|
||||||
|
|
||||||
return lbs.Data[i].DeletedTime < lbs.Data[j].DeletedTime
|
|
||||||
})
|
|
||||||
|
|
||||||
return lbs
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// StartRequest struct to start service
|
|
||||||
type StartRequest struct {
|
|
||||||
// ID of the service to start
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start starts service.
|
|
||||||
// Starting a service technically means starting computes from all
|
|
||||||
// service groups according to group relations
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/start"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package bservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
|
||||||
)
|
|
||||||
|
|
||||||
// StopRequest struct to stop service
|
|
||||||
type StopRequest struct {
|
|
||||||
// ID of the service to stop
|
|
||||||
// Required: true
|
|
||||||
ServiceID uint64 `url:"serviceId" json:"serviceId" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop stops service.
|
|
||||||
// Stopping a service technically means stopping computes from
|
|
||||||
// all service groups
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
url := "/cloudapi/bservice/stop"
|
|
||||||
|
|
||||||
res, err := b.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result, err := strconv.ParseBool(string(res))
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user