Compare commits
3 Commits
v1.5.0-alf
...
v1.4.4
| Author | SHA1 | Date | |
|---|---|---|---|
| c9e4ae6afe | |||
| 2a1593f45f | |||
| 190f24dac1 |
@@ -1,6 +1,4 @@
|
|||||||
## Version 1.4.2
|
## Version 1.4.4
|
||||||
|
|
||||||
### Bug Fixes
|
### Features
|
||||||
|
- Added "Timeout" param to Config/LegacyConfig that allows configuring HTTP client timeout
|
||||||
- Fixed cloudapi/cloudbroker/compute/pfwAdd publicPortEnd request field type
|
|
||||||
- Fixed typo in cloudapi/k8s/disable/enable request name
|
|
||||||
|
|||||||
17
README.md
17
README.md
@@ -118,6 +118,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
| SSOURL | string | Да | URL адрес сервиса аутентификации и авторизации |
|
| SSOURL | string | Да | URL адрес сервиса аутентификации и авторизации |
|
||||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||||
|
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
||||||
| Token | string | Нет | JWT токен |
|
| Token | string | Нет | JWT токен |
|
||||||
|
|
||||||
@@ -127,6 +128,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
|
|||||||
import (
|
import (
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main(){
|
func main(){
|
||||||
// Настройка конфигурации
|
// Настройка конфигурации
|
||||||
cfg := config.Config{
|
cfg := config.Config{
|
||||||
@@ -136,6 +138,8 @@ func main(){
|
|||||||
DecortURL: "https://mr4.digitalenergy.online",
|
DecortURL: "https://mr4.digitalenergy.online",
|
||||||
Retries: 5,
|
Retries: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.SetTimeout(5 * time.Minute)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -165,6 +169,7 @@ func main() {
|
|||||||
"ssoUrl": "https://sso.digitalenergy.online",
|
"ssoUrl": "https://sso.digitalenergy.online",
|
||||||
"decortUrl": "https://mr4.digitalenergy.online",
|
"decortUrl": "https://mr4.digitalenergy.online",
|
||||||
"retries": 5,
|
"retries": 5,
|
||||||
|
"timeout": "5m",
|
||||||
"sslSkipVerify": false
|
"sslSkipVerify": false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -177,6 +182,7 @@ appSecret: <APP_SECRET>
|
|||||||
ssoUrl: https://sso.digitalenergy.online
|
ssoUrl: https://sso.digitalenergy.online
|
||||||
decortUrl: https://mr4.digitalenergy.online
|
decortUrl: https://mr4.digitalenergy.online
|
||||||
retries: 5
|
retries: 5
|
||||||
|
timeout: 5m
|
||||||
sslSkipVerify: false
|
sslSkipVerify: false
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -204,6 +210,8 @@ func main() {
|
|||||||
Retries: 5,
|
Retries: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.SetTimeout(5 * time.Minute)
|
||||||
|
|
||||||
// Создание клиента
|
// Создание клиента
|
||||||
client := decort.New(cfg)
|
client := decort.New(cfg)
|
||||||
}
|
}
|
||||||
@@ -647,6 +655,8 @@ func main() {
|
|||||||
DecortURL: "<DECORT_URL>",
|
DecortURL: "<DECORT_URL>",
|
||||||
Retries: 5,
|
Retries: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfg.SetTimeout(5 * time.Minute)
|
||||||
|
|
||||||
// Создание клиента
|
// Создание клиента
|
||||||
client := decort.New(cfg)
|
client := decort.New(cfg)
|
||||||
@@ -693,6 +703,7 @@ func main() {
|
|||||||
| Password | string | Да | пароль legacy пользователя |
|
| Password | string | Да | пароль legacy пользователя |
|
||||||
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
|
||||||
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
|
||||||
|
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
|
||||||
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
|
||||||
| Token | string | Нет | JWT токен |
|
| Token | string | Нет | JWT токен |
|
||||||
|
|
||||||
@@ -711,6 +722,8 @@ func main(){
|
|||||||
DecortURL: "https://mr4.digitalenergy.online",
|
DecortURL: "https://mr4.digitalenergy.online",
|
||||||
Retries: 5,
|
Retries: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
legacyCfg.SetTimeout(5 * time.Minute)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -739,6 +752,7 @@ func main() {
|
|||||||
"password": "<PASSWORD>",
|
"password": "<PASSWORD>",
|
||||||
"decortUrl": "https://mr4.digitalenergy.online",
|
"decortUrl": "https://mr4.digitalenergy.online",
|
||||||
"retries": 5,
|
"retries": 5,
|
||||||
|
"timeout": "5m",
|
||||||
"sslSkipVerify": true
|
"sslSkipVerify": true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -749,6 +763,7 @@ username: <USERNAME>
|
|||||||
password: <PASSWORD>
|
password: <PASSWORD>
|
||||||
decortUrl: https://mr4.digitalenergy.online
|
decortUrl: https://mr4.digitalenergy.online
|
||||||
retries: 5
|
retries: 5
|
||||||
|
timeout: 5m
|
||||||
sslSkipVerify: true
|
sslSkipVerify: true
|
||||||
```
|
```
|
||||||
### Создание legacy клиента
|
### Создание legacy клиента
|
||||||
@@ -774,6 +789,8 @@ func main() {
|
|||||||
Retries: 5,
|
Retries: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
legacyCfg.SetTimeout(5 * time.Minute)
|
||||||
|
|
||||||
// Создание клиента
|
// Создание клиента
|
||||||
legacyClient := decort.NewLegacy(cfg)
|
legacyClient := decort.NewLegacy(cfg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
@@ -44,6 +45,15 @@ type Config struct {
|
|||||||
// Skip verify, true by default
|
// Skip verify, true by default
|
||||||
// Required: false
|
// Required: false
|
||||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||||
|
|
||||||
|
// HTTP client timeout, unlimited if left empty
|
||||||
|
// Required: false
|
||||||
|
Timeout Duration `json:"timeout" yaml:"timeout"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTimeout is used to set HTTP client timeout.
|
||||||
|
func (c *Config) SetTimeout(dur time.Duration) {
|
||||||
|
c.Timeout = Duration(dur)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseConfigJSON parses Config from specified JSON-formatted file.
|
// ParseConfigJSON parses Config from specified JSON-formatted file.
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||||
@@ -38,6 +39,15 @@ type LegacyConfig struct {
|
|||||||
// Skip verify, true by default
|
// Skip verify, true by default
|
||||||
// Required: false
|
// Required: false
|
||||||
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
SSLSkipVerify bool `json:"sslSkipVerify" yaml:"sslSkipVerify"`
|
||||||
|
|
||||||
|
// HTTP client timeout, unlimited if left empty
|
||||||
|
// Required: false
|
||||||
|
Timeout Duration `json:"timeout" yaml:"timeout"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTimeout is used to set HTTP client timeout.
|
||||||
|
func (c *LegacyConfig) SetTimeout(dur time.Duration) {
|
||||||
|
c.Timeout = Duration(dur)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseLegacyConfigJSON parses LegacyConfig from specified JSON-formatted file.
|
// ParseLegacyConfigJSON parses LegacyConfig from specified JSON-formatted file.
|
||||||
|
|||||||
50
config/timeouts.go
Normal file
50
config/timeouts.go
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Duration is a wrapper around time.Duration (used for better user experience)
|
||||||
|
type Duration time.Duration
|
||||||
|
|
||||||
|
func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
var v interface{}
|
||||||
|
if err := unmarshal(&v); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch value := v.(type) {
|
||||||
|
case string:
|
||||||
|
tmp, err := time.ParseDuration(value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*d = Duration(tmp)
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("Invalid duration %v", value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Duration) UnmarshalJSON(b []byte) error {
|
||||||
|
var v interface{}
|
||||||
|
if err := json.Unmarshal(b, &v); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
switch value := v.(type) {
|
||||||
|
case string:
|
||||||
|
tmp, err := time.ParseDuration(value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*d = Duration(tmp)
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("Invalid duration %v", value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Duration) Get() time.Duration {
|
||||||
|
return time.Duration(*d)
|
||||||
|
}
|
||||||
@@ -35,6 +35,6 @@ func NewHttpClient(cfg config.Config) *http.Client {
|
|||||||
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
},
|
},
|
||||||
|
|
||||||
Timeout: 5 * time.Minute,
|
Timeout: cfg.Timeout.Get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
|
||||||
|
|
||||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||||
)
|
)
|
||||||
@@ -28,6 +27,6 @@ func NewLegacyHttpClient(cfg config.LegacyConfig) *http.Client {
|
|||||||
decortURL: cfg.DecortURL,
|
decortURL: cfg.DecortURL,
|
||||||
},
|
},
|
||||||
|
|
||||||
Timeout: 5 * time.Minute,
|
Timeout: cfg.Timeout.Get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,29 +7,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
once sync.Once
|
once sync.Once
|
||||||
instance *DecortValidator
|
decortValidator = validator.New()
|
||||||
)
|
)
|
||||||
|
|
||||||
type DecortValidator struct {
|
|
||||||
decortValidator *validator.Validate
|
|
||||||
}
|
|
||||||
|
|
||||||
// getDecortValidator returns singleton instance of DecortValidator.
|
// getDecortValidator returns singleton instance of DecortValidator.
|
||||||
func getDecortValidator() *validator.Validate {
|
func getDecortValidator() *validator.Validate {
|
||||||
if instance == nil {
|
once.Do(func() {
|
||||||
once.Do(func() {
|
err := registerAllValidators(decortValidator)
|
||||||
instance = new(DecortValidator)
|
if err != nil {
|
||||||
instance.decortValidator = validator.New()
|
panic(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
err := registerAllValidators(instance.decortValidator)
|
return decortValidator
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance.decortValidator
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// registerAllValidators registers all custom validators in DecortValidator.
|
// registerAllValidators registers all custom validators in DecortValidator.
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ type InfoBackup struct {
|
|||||||
|
|
||||||
// Backup path
|
// Backup path
|
||||||
BackupPath string `json:"backupPath"`
|
BackupPath string `json:"backupPath"`
|
||||||
|
|
||||||
|
// Possible error
|
||||||
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateDisksBackup response
|
// CreateDisksBackup response
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"appId": "<APP_ID>",
|
"appId": "<APP_ID>",
|
||||||
"appSecret": "<APP_SECRET>",
|
"appSecret": "<APP_SECRET>",
|
||||||
"ssoUrl": "https://sso.digitalenergy.online",
|
"ssoUrl": "https://sso.digitalenergy.online",
|
||||||
"decortUrl": "https://mr4.digitalenergy.online",
|
"decortUrl": "https://mr4.digitalenergy.online",
|
||||||
"retries": 5,
|
"retries": 5,
|
||||||
"sslSkipVerify": false
|
"timeout": "5m",
|
||||||
|
"sslSkipVerify": false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,4 +3,5 @@ appSecret: <APP_SECRET>
|
|||||||
ssoUrl: https://sso.digitalenergy.online
|
ssoUrl: https://sso.digitalenergy.online
|
||||||
decortUrl: https://mr4.digitalenergy.online
|
decortUrl: https://mr4.digitalenergy.online
|
||||||
retries: 5
|
retries: 5
|
||||||
|
timeout: 5m
|
||||||
sslSkipVerify: false
|
sslSkipVerify: false
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"username": "<USERNAME>",
|
"username": "<USERNAME>",
|
||||||
"password": "<PASSWORD>",
|
"password": "<PASSWORD>",
|
||||||
"decortUrl": "https://mr4.digitalenergy.online",
|
"decortUrl": "https://mr4.digitalenergy.online",
|
||||||
"retries": 5,
|
"retries": 5,
|
||||||
"sslSkipVerify": true
|
"timeout": "5m",
|
||||||
|
"sslSkipVerify": true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,4 +2,5 @@ username: <USERNAME>
|
|||||||
password: <PASSWORD>
|
password: <PASSWORD>
|
||||||
decortUrl: https://mr4.digitalenergy.online
|
decortUrl: https://mr4.digitalenergy.online
|
||||||
retries: 5
|
retries: 5
|
||||||
|
timeout: 5m
|
||||||
sslSkipVerify: true
|
sslSkipVerify: true
|
||||||
|
|||||||
Reference in New Issue
Block a user