parent
de12bc2acc
commit
42800ac4fe
@ -1,54 +1,11 @@
|
||||
## Version 1.1.2
|
||||
|
||||
### Feature
|
||||
|
||||
#### Cloudbroker
|
||||
|
||||
- Disks
|
||||
- Add share method
|
||||
- Add unshare method
|
||||
## Version 1.2.0
|
||||
|
||||
### Bug fixes
|
||||
|
||||
#### CloudAPI
|
||||
#### Client
|
||||
|
||||
- Account/Create
|
||||
- Change the MaxMemoryCapacity field type to int64
|
||||
- Change the MaxVDiskCapacity field type to int64
|
||||
- Change the MaxCPUCapacity field type to int64
|
||||
- Change the MaxNetworkPeerTransfer field type to int64
|
||||
- Change the MaxNumPublicIP field type to int64
|
||||
- Change the GPUUnits field type to int64
|
||||
- Change url to cloudapi
|
||||
- Account/Models
|
||||
- Change the DiskSize field type to float64
|
||||
- Change the DiskSizeMax field type to uint64
|
||||
- RG/Create
|
||||
- Change the MaxMemoryCapacity field type to int64
|
||||
- Change the MaxVDiskCapacity field type to int64
|
||||
- Change the MaxCPUCapacity field type to int64
|
||||
- Change the MaxNumPublicIP field type to int64
|
||||
- RG/Models
|
||||
- Change the DiskSize field type to float64
|
||||
- Change the DiskSizeMax field type to uint64
|
||||
- Added legacy client authorization support
|
||||
|
||||
#### Cloudbroker
|
||||
#### All
|
||||
|
||||
- Account/Create
|
||||
- Change the MaxMemoryCapacity field type to int64
|
||||
- Change the MaxVDiskCapacity field type to int64
|
||||
- Change the MaxCPUCapacity field type to int64
|
||||
- Change the MaxNetworkPeerTransfer field type to int64
|
||||
- Change the MaxNumPublicIP field type to int64
|
||||
- Change the GPUUnits field type to int64
|
||||
- Account/Models
|
||||
- Change the DiskSize field type to float64
|
||||
- Change the DiskSizeMax field type to uint64
|
||||
- RG/Create
|
||||
- Change the MaxMemoryCapacity field type to int64
|
||||
- Change the MaxVDiskCapacity field type to int64
|
||||
- Change the MaxCPUCapacity field type to int64
|
||||
- Change the MaxNumPublicIP field type to int64
|
||||
- RG/Models
|
||||
- Change the DiskSize field type to float64
|
||||
- Change the DiskSizeMax field type to uint64
|
||||
- Add json tags for requests
|
||||
|
@ -0,0 +1,33 @@
|
||||
package config
|
||||
|
||||
// Legacy client configuration
|
||||
type LegacyConfig struct {
|
||||
// ServiceAccount username
|
||||
// Required: true
|
||||
// Example : "osh_mikoev"
|
||||
Username string
|
||||
|
||||
// ServiceAccount password
|
||||
// Required: true
|
||||
// Example: "[1o>hYkjnJr)HI78q7t&#%8Lm"
|
||||
Password string
|
||||
|
||||
// Platform token
|
||||
// Required: false
|
||||
// Example: "158e76424b0d4810b6086hgbhj928fc4a6bc06e"
|
||||
Token string
|
||||
|
||||
// Address of the platform on which the actions are planned
|
||||
// Required: true
|
||||
// Example: "https://mr4.digitalenergy.online"
|
||||
DecortURL string
|
||||
|
||||
// Amount platform request attempts
|
||||
// Default value: 5
|
||||
// Required: false
|
||||
Retries uint64
|
||||
|
||||
// Skip verify, true by default
|
||||
// Required: false
|
||||
SSLSkipVerify bool
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/rudecs/decort-sdk/config"
|
||||
)
|
||||
|
||||
// NewLegacyHttpClient creates legacy HTTP Client
|
||||
func NewLegacyHttpClient(cfg config.LegacyConfig) *http.Client {
|
||||
transCfg := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
//nolint:gosec
|
||||
InsecureSkipVerify: cfg.SSLSkipVerify,
|
||||
},
|
||||
}
|
||||
|
||||
return &http.Client{
|
||||
Transport: &transportLegacy{
|
||||
base: transCfg,
|
||||
username: cfg.Username,
|
||||
password: cfg.Password,
|
||||
retries: cfg.Retries,
|
||||
token: cfg.Token,
|
||||
decortURL: cfg.DecortURL,
|
||||
},
|
||||
|
||||
Timeout: 5 * time.Minute,
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type transportLegacy struct {
|
||||
base http.RoundTripper
|
||||
username string
|
||||
password string
|
||||
retries uint64
|
||||
token string
|
||||
decortURL string
|
||||
}
|
||||
|
||||
func (t *transportLegacy) RoundTrip(request *http.Request) (*http.Response, error) {
|
||||
if t.token == "" {
|
||||
body := fmt.Sprintf("username=%s&password=%s", t.username, t.password)
|
||||
bodyReader := strings.NewReader(body)
|
||||
|
||||
req, _ := http.NewRequestWithContext(request.Context(), "POST", t.decortURL+"/restmachine/cloudapi/user/authenticate", bodyReader)
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
resp, err := t.base.RoundTrip(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get token: %w", err)
|
||||
}
|
||||
|
||||
tokenBytes, _ := io.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("unable to get token: %s", tokenBytes)
|
||||
}
|
||||
|
||||
token := string(tokenBytes)
|
||||
t.token = token
|
||||
}
|
||||
|
||||
tokenValue := fmt.Sprintf("authkey=%s", t.token)
|
||||
tokenReader := strings.NewReader(tokenValue)
|
||||
|
||||
req, _ := http.NewRequestWithContext(request.Context(), request.Method, request.URL.String(), tokenReader)
|
||||
|
||||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
|
||||
req.Header.Set("Accept", "application/json")
|
||||
|
||||
var resp *http.Response
|
||||
var err error
|
||||
for i := uint64(0); i < t.retries; i++ {
|
||||
resp, err = t.base.RoundTrip(req)
|
||||
if err == nil {
|
||||
if resp.StatusCode == 200 {
|
||||
return resp, nil
|
||||
}
|
||||
respBytes, _ := io.ReadAll(resp.Body)
|
||||
err = fmt.Errorf("%s", respBytes)
|
||||
resp.Body.Close()
|
||||
}
|
||||
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
"github.com/rudecs/decort-sdk/config"
|
||||
"github.com/rudecs/decort-sdk/internal/client"
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi"
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudbroker"
|
||||
)
|
||||
|
||||
// Legacy HTTP-client for platform
|
||||
type LegacyDecortClient struct {
|
||||
decortURL string
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
// Legacy client builder
|
||||
func NewLegacy(cfg config.LegacyConfig) *LegacyDecortClient {
|
||||
if cfg.Retries == 0 {
|
||||
cfg.Retries = 5
|
||||
}
|
||||
|
||||
return &LegacyDecortClient{
|
||||
decortURL: cfg.DecortURL,
|
||||
client: client.NewLegacyHttpClient(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
// CloudAPI builder
|
||||
func (ldc *LegacyDecortClient) CloudAPI() *cloudapi.CloudAPI {
|
||||
return cloudapi.New(ldc)
|
||||
}
|
||||
|
||||
// CloudBroker builder
|
||||
func (ldc *LegacyDecortClient) CloudBroker() *cloudbroker.CloudBroker {
|
||||
return cloudbroker.New(ldc)
|
||||
}
|
||||
|
||||
// DecortApiCall method for sending requests to the platform
|
||||
func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url string, params interface{}) ([]byte, error) {
|
||||
values, err := query.Values(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
body := strings.NewReader(values.Encode())
|
||||
req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+"/restmachine"+url, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := ldc.client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
respBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, errors.New(string(respBytes))
|
||||
}
|
||||
|
||||
return respBytes, nil
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue