Compare commits

...

3 Commits

Author SHA1 Message Date
c9e4ae6afe v1.4.4 2023-06-01 16:50:10 +03:00
2a1593f45f v1.5.0-beta 2023-05-18 13:55:28 +03:00
190f24dac1 v1.4.3 2023-05-18 13:37:48 +03:00
13 changed files with 119 additions and 37 deletions

View File

@@ -1,6 +1,4 @@
## Version 1.4.2
## Version 1.4.4
### Bug Fixes
- Fixed cloudapi/cloudbroker/compute/pfwAdd publicPortEnd request field type
- Fixed typo in cloudapi/k8s/disable/enable request name
### Features
- Added "Timeout" param to Config/LegacyConfig that allows configuring HTTP client timeout

View File

@@ -118,6 +118,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
| SSOURL | string | Да | URL адрес сервиса аутентификации и авторизации |
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
| Token | string | Нет | JWT токен |
@@ -127,6 +128,7 @@ go get -u repository.basistech.ru/BASIS/decort-golang-sdk
import (
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
)
func main(){
// Настройка конфигурации
cfg := config.Config{
@@ -136,6 +138,8 @@ func main(){
DecortURL: "https://mr4.digitalenergy.online",
Retries: 5,
}
cfg.SetTimeout(5 * time.Minute)
}
```
@@ -165,6 +169,7 @@ func main() {
"ssoUrl": "https://sso.digitalenergy.online",
"decortUrl": "https://mr4.digitalenergy.online",
"retries": 5,
"timeout": "5m",
"sslSkipVerify": false
}
```
@@ -177,6 +182,7 @@ appSecret: <APP_SECRET>
ssoUrl: https://sso.digitalenergy.online
decortUrl: https://mr4.digitalenergy.online
retries: 5
timeout: 5m
sslSkipVerify: false
```
@@ -204,6 +210,8 @@ func main() {
Retries: 5,
}
cfg.SetTimeout(5 * time.Minute)
// Создание клиента
client := decort.New(cfg)
}
@@ -647,6 +655,8 @@ func main() {
DecortURL: "<DECORT_URL>",
Retries: 5,
}
cfg.SetTimeout(5 * time.Minute)
// Создание клиента
client := decort.New(cfg)
@@ -693,6 +703,7 @@ func main() {
| Password | string | Да | пароль legacy пользователя |
| DecortURL | string | Да | URL адрес платформы, с которой будет осуществляться взаимодействие |
| Retries | uint | Нет | Кол-во неудачных попыток выполнения запроса, по умолчанию - 5 |
| Timeout | config.Duration | Нет | Таймаут HTTP клиента, по умолчанию - без ограничений |
| SSLSkipVerify | bool | Нет | Пропуск проверки подлинности сертификата, по умолчанию - true |
| Token | string | Нет | JWT токен |
@@ -711,6 +722,8 @@ func main(){
DecortURL: "https://mr4.digitalenergy.online",
Retries: 5,
}
legacyCfg.SetTimeout(5 * time.Minute)
}
```
@@ -739,6 +752,7 @@ func main() {
"password": "<PASSWORD>",
"decortUrl": "https://mr4.digitalenergy.online",
"retries": 5,
"timeout": "5m",
"sslSkipVerify": true
}
```
@@ -749,6 +763,7 @@ username: <USERNAME>
password: <PASSWORD>
decortUrl: https://mr4.digitalenergy.online
retries: 5
timeout: 5m
sslSkipVerify: true
```
### Создание legacy клиента
@@ -774,6 +789,8 @@ func main() {
Retries: 5,
}
legacyCfg.SetTimeout(5 * time.Minute)
// Создание клиента
legacyClient := decort.NewLegacy(cfg)
}

View File

@@ -3,6 +3,7 @@ package config
import (
"encoding/json"
"os"
"time"
"gopkg.in/yaml.v3"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
@@ -44,6 +45,15 @@ type Config struct {
// Skip verify, true by default
// 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.

View File

@@ -3,6 +3,7 @@ package config
import (
"encoding/json"
"os"
"time"
"gopkg.in/yaml.v3"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
@@ -38,6 +39,15 @@ type LegacyConfig struct {
// Skip verify, true by default
// 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.

50
config/timeouts.go Normal file
View 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)
}

View File

@@ -35,6 +35,6 @@ func NewHttpClient(cfg config.Config) *http.Client {
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
Timeout: 5 * time.Minute,
Timeout: cfg.Timeout.Get(),
}
}

View File

@@ -4,7 +4,6 @@ import (
"crypto/tls"
"net/http"
"net/url"
"time"
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
)
@@ -28,6 +27,6 @@ func NewLegacyHttpClient(cfg config.LegacyConfig) *http.Client {
decortURL: cfg.DecortURL,
},
Timeout: 5 * time.Minute,
Timeout: cfg.Timeout.Get(),
}
}

View File

@@ -7,29 +7,20 @@ import (
)
var (
once sync.Once
instance *DecortValidator
once sync.Once
decortValidator = validator.New()
)
type DecortValidator struct {
decortValidator *validator.Validate
}
// getDecortValidator returns singleton instance of DecortValidator.
func getDecortValidator() *validator.Validate {
if instance == nil {
once.Do(func() {
instance = new(DecortValidator)
instance.decortValidator = validator.New()
once.Do(func() {
err := registerAllValidators(decortValidator)
if err != nil {
panic(err)
}
})
err := registerAllValidators(instance.decortValidator)
if err != nil {
panic(err)
}
})
}
return instance.decortValidator
return decortValidator
}
// registerAllValidators registers all custom validators in DecortValidator.

View File

@@ -10,6 +10,9 @@ type InfoBackup struct {
// Backup path
BackupPath string `json:"backupPath"`
// Possible error
Error string `json:"error"`
}
// CreateDisksBackup response

View File

@@ -1,8 +1,9 @@
{
"appId": "<APP_ID>",
"appSecret": "<APP_SECRET>",
"ssoUrl": "https://sso.digitalenergy.online",
"decortUrl": "https://mr4.digitalenergy.online",
"retries": 5,
"sslSkipVerify": false
"appId": "<APP_ID>",
"appSecret": "<APP_SECRET>",
"ssoUrl": "https://sso.digitalenergy.online",
"decortUrl": "https://mr4.digitalenergy.online",
"retries": 5,
"timeout": "5m",
"sslSkipVerify": false
}

View File

@@ -3,4 +3,5 @@ appSecret: <APP_SECRET>
ssoUrl: https://sso.digitalenergy.online
decortUrl: https://mr4.digitalenergy.online
retries: 5
timeout: 5m
sslSkipVerify: false

View File

@@ -1,7 +1,8 @@
{
"username": "<USERNAME>",
"password": "<PASSWORD>",
"decortUrl": "https://mr4.digitalenergy.online",
"retries": 5,
"sslSkipVerify": true
"username": "<USERNAME>",
"password": "<PASSWORD>",
"decortUrl": "https://mr4.digitalenergy.online",
"retries": 5,
"timeout": "5m",
"sslSkipVerify": true
}

View File

@@ -2,4 +2,5 @@ username: <USERNAME>
password: <PASSWORD>
decortUrl: https://mr4.digitalenergy.online
retries: 5
timeout: 5m
sslSkipVerify: true