Compare commits

..

2 Commits

Author SHA1 Message Date
1c59ca338a v1.5.3 2023-08-15 11:42:30 +03:00
f1529c9aac v1.5.2 2023-08-09 19:33:50 +03:00
19 changed files with 95 additions and 31 deletions

View File

@@ -1,6 +1,10 @@
## Version 1.5.1 ## Version 1.5.3
### Bugfix ### Bugfix
- Changed StatelessSepID field type in cloudapi/compute/get and cloudapi/compute/list responde models - Add a fields SEPID and Pool in ListUnattachedRequest struct in cloudbroker/disks/listUnattached and cloudapi/disks/listUnattached
- Added oppurtunity to create compute without interface in cloudapi/cloubroker/kvm*/create* - Delete a field Shared in ListUnattachedRequest struct in cloudbroker/disks/listUnattached
- Delete tag Required at field Permanently in DiskDelRequest struct in cloudbroker/compute/disk_del and cloudapi/compute/disk_del
- Delete tag omitempty at field Permanently in DeleteRequest struct in cloudbroker/image/delete

View File

@@ -4,6 +4,7 @@ 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"
) )
@@ -17,14 +18,21 @@ func NewLegacyHttpClient(cfg config.LegacyConfig) *http.Client {
}, },
} }
var expiredTime time.Time
if cfg.Token != "" {
expiredTime = time.Now().AddDate(0, 0, 1)
}
return &http.Client{ return &http.Client{
Transport: &transportLegacy{ Transport: &transportLegacy{
base: transCfg, base: transCfg,
username: url.QueryEscape(cfg.Username), username: url.QueryEscape(cfg.Username),
password: url.QueryEscape(cfg.Password), password: url.QueryEscape(cfg.Password),
retries: cfg.Retries, retries: cfg.Retries,
token: cfg.Token, token: cfg.Token,
decortURL: cfg.DecortURL, decortURL: cfg.DecortURL,
expiryTime: expiredTime,
}, },
Timeout: cfg.Timeout.Get(), Timeout: cfg.Timeout.Get(),

View File

@@ -9,16 +9,17 @@ import (
) )
type transportLegacy struct { type transportLegacy struct {
base http.RoundTripper base http.RoundTripper
username string username string
password string password string
retries uint64 retries uint64
token string token string
decortURL string decortURL string
expiryTime time.Time
} }
func (t *transportLegacy) RoundTrip(request *http.Request) (*http.Response, error) { func (t *transportLegacy) RoundTrip(request *http.Request) (*http.Response, error) {
if t.token == "" { if t.token == "" || time.Now().After(t.expiryTime) {
body := fmt.Sprintf("username=%s&password=%s", t.username, t.password) body := fmt.Sprintf("username=%s&password=%s", t.username, t.password)
bodyReader := strings.NewReader(body) bodyReader := strings.NewReader(body)
@@ -39,6 +40,7 @@ func (t *transportLegacy) RoundTrip(request *http.Request) (*http.Response, erro
token := string(tokenBytes) token := string(tokenBytes)
t.token = token t.token = token
t.expiryTime = time.Now().AddDate(0, 0, 1)
} }
tokenValue := fmt.Sprintf("&authkey=%s", t.token) tokenValue := fmt.Sprintf("&authkey=%s", t.token)
@@ -63,7 +65,9 @@ func (t *transportLegacy) RoundTrip(request *http.Request) (*http.Response, erro
err = fmt.Errorf("%s", respBytes) err = fmt.Errorf("%s", respBytes)
resp.Body.Close() resp.Body.Close()
} }
if err != nil {
return nil, fmt.Errorf("could not execute request: %w", err)
}
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
} }
return nil, fmt.Errorf("could not execute request: %w", err) return nil, fmt.Errorf("could not execute request: %w", err)

View File

@@ -1,9 +1,10 @@
package validators package validators
import ( import (
"github.com/go-playground/validator/v10"
"regexp" "regexp"
"strings" "strings"
"github.com/go-playground/validator/v10"
) )
// computeDriverValidator is used to validate Driver field in kvmx86/kvmppc create. // computeDriverValidator is used to validate Driver field in kvmx86/kvmppc create.
@@ -263,3 +264,11 @@ func strictLooseValidator(fe validator.FieldLevel) bool {
return StringInSlice(fieldValue, strictLooseValues) return StringInSlice(fieldValue, strictLooseValues)
} }
// name workerGroup must be more 3 symbol
func workerGroupNameValidator(fe validator.FieldLevel) bool {
fieldValue := fe.Field().String()
fieldValue = strings.Trim(fieldValue, " ")
return len(fieldValue) >= 3
}

View File

@@ -127,6 +127,12 @@ func errorMessage(fe validator.FieldError) string {
fe.Field(), fe.Field(),
joinValues(flipgroupClientTypeValues)) joinValues(flipgroupClientTypeValues))
// k8s Validators
case "workerGroupName":
return fmt.Sprintf("%s %s must be more 3 symbol",
prefix,
fe.Field())
// KVM_X86/KVM_PPC Validators // KVM_X86/KVM_PPC Validators
case "kvmNetType": case "kvmNetType":
return fmt.Sprintf("%s %s must be one of the following: %s", return fmt.Sprintf("%s %s must be one of the following: %s",

View File

@@ -180,5 +180,10 @@ func registerAllValidators(validate *validator.Validate) error {
return err return err
} }
err = validate.RegisterValidation("workerGroupName", workerGroupNameValidator)
if err != nil {
return err
}
return nil return nil
} }

View File

@@ -20,7 +20,7 @@ type DiskDelRequest struct {
// False if disk is to be deleted to recycle bin // False if disk is to be deleted to recycle bin
// Required: true // Required: true
Permanently bool `url:"permanently" json:"permanently" validate:"required"` Permanently bool `url:"permanently" json:"permanently"`
} }
// DiskDel delete disk and detach from compute // DiskDel delete disk and detach from compute

View File

@@ -40,6 +40,14 @@ type ListRequest struct {
// Required: false // Required: false
Type string `url:"type,omitempty" json:"type,omitempty"` Type string `url:"type,omitempty" json:"type,omitempty"`
// Find by sep ID
// Required: false
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Find by pool name
// Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`

View File

@@ -32,6 +32,14 @@ type ListUnattachedRequest struct {
// Required: false // Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Find by sep ID
// Required: false
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Find by pool name
// Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`

View File

@@ -24,7 +24,7 @@ type CreateRequest struct {
// Name for first worker group created with cluster // Name for first worker group created with cluster
// Required: true // Required: true
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required"` WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required,workerGroupName"`
// Network plugin // Network plugin
// Must be one of these values: flannel, weawenet, calico // Must be one of these values: flannel, weawenet, calico

View File

@@ -20,7 +20,7 @@ type DeleteUserRequest struct {
// Recursively revoke access rights from owned cloudspaces and vmachines // Recursively revoke access rights from owned cloudspaces and vmachines
// Required: false // Required: false
RecursiveDelete bool `url:"recursivedelete,omitempty" json:"recursivedelete,omitempty"` RecursiveDelete bool `url:"recursivedelete" json:"recursivedelete" validate:"required"`
} }
// DeleteUser revokes user access from the account // DeleteUser revokes user access from the account

View File

@@ -16,7 +16,7 @@ type DisableRequest struct {
// Reason to disable // Reason to disable
// Required: true // Required: true
Reason string `url:"reason" json:"reason" validate:"required"` Reason string `url:"reason,omitempty" json:"reason,omitempty"`
} }
// Disable disables an account // Disable disables an account

View File

@@ -16,7 +16,7 @@ type EnableRequest struct {
// Reason to enable // Reason to enable
// Required: true // Required: true
Reason string `url:"reason" json:"reason" validate:"required"` Reason string `url:"reason,omitempty" json:"reason,omitempty"`
} }
// Enable enables an account // Enable enables an account

View File

@@ -16,7 +16,7 @@ type ListVINSRequest struct {
// Find by VINS ID // Find by VINS ID
// Required: false // Required: false
VINSID uint64 `url:"vins,omitempty" json:"vinsId,omitempty"` VINSID uint64 `url:"vinsId,omitempty" json:"vinsId,omitempty"`
// Find by name // Find by name
// Required: false // Required: false

View File

@@ -20,7 +20,7 @@ type DiskDelRequest struct {
// False if disk is to be deleted to recycle bin // False if disk is to be deleted to recycle bin
// Required: true // Required: true
Permanently bool `url:"permanently" json:"permanently" validate:"required"` Permanently bool `url:"permanently" json:"permanently"`
// Reason for action // Reason for action
// Required: false // Required: false

View File

@@ -40,6 +40,14 @@ type ListRequest struct {
// Required: false // Required: false
Type string `url:"type,omitempty" json:"type,omitempty"` Type string `url:"type,omitempty" json:"type,omitempty"`
// Find by sep ID
// Required: false
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Find by pool name
// Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`

View File

@@ -24,10 +24,6 @@ type ListUnattachedRequest struct {
// Required: false // Required: false
Status string `url:"status,omitempty" json:"status,omitempty"` Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by shared, true or false
// Required: false
Shared bool `url:"shared,omitempty" json:"shared,omitempty"`
// Type of the disks // Type of the disks
// Required: false // Required: false
Type string `url:"type,omitempty" json:"type,omitempty"` Type string `url:"type,omitempty" json:"type,omitempty"`
@@ -36,6 +32,14 @@ type ListUnattachedRequest struct {
// Required: false // Required: false
AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"` AccountID uint64 `url:"accountId,omitempty" json:"accountId,omitempty"`
// Find by sep ID
// Required: false
SEPID uint64 `url:"sepId,omitempty" json:"sepId,omitempty"`
// Find by pool name
// Required: false
Pool string `url:"pool,omitempty" json:"pool,omitempty"`
// Page number // Page number
// Required: false // Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"` Page uint64 `url:"page,omitempty" json:"page,omitempty"`

View File

@@ -20,7 +20,7 @@ type DeleteRequest struct {
// Whether to completely delete the image // Whether to completely delete the image
// Required: false // Required: false
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"` Permanently bool `url:"permanently" json:"permanently"`
} }
// Delete deletes image by ID // Delete deletes image by ID

View File

@@ -24,7 +24,7 @@ type CreateRequest struct {
// Name for first worker group created with cluster // Name for first worker group created with cluster
// Required: true // Required: true
WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required"` WorkerGroupName string `url:"workerGroupName" json:"workerGroupName" validate:"required, workerGroupName"`
// Network plugin // Network plugin
// Must be one of these values: flunnel, weawenet, calico // Must be one of these values: flunnel, weawenet, calico