Refactoring
This commit is contained in:
@@ -8,12 +8,12 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
decort "github.com/rudecs/decort-sdk"
|
||||
"github.com/rudecs/decort-sdk/kvmx86"
|
||||
"github.com/rudecs/decort-sdk/config"
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/kvmx86"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg := decort.Config{
|
||||
cfg := config.Config{
|
||||
AppID: "<APPID>",
|
||||
AppSecret: "<APPSECRET>",
|
||||
SSOURL: "https://sso.digitalenergy.online",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package client
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/account"
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/account"
|
||||
)
|
||||
|
||||
func (dc *decortClient) Account() *account.Account {
|
||||
|
||||
14
client.go
14
client.go
@@ -1,13 +1,15 @@
|
||||
package client
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
"github.com/rudecs/decort-sdk/config"
|
||||
"github.com/rudecs/decort-sdk/internal/client"
|
||||
)
|
||||
|
||||
type decortClient struct {
|
||||
@@ -15,10 +17,10 @@ type decortClient struct {
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
func New(config Config) *decortClient {
|
||||
func New(cfg config.Config) *decortClient {
|
||||
return &decortClient{
|
||||
decortUrl: config.DecortUrl,
|
||||
client: newHttpClient(config),
|
||||
decortUrl: cfg.DecortURL,
|
||||
client: client.NewHttpClient(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +39,7 @@ func (dc *decortClient) DecortApiCall(ctx context.Context, method, url string, p
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
respBytes, err := ioutil.ReadAll(resp.Body)
|
||||
respBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package client
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/compute"
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/compute"
|
||||
)
|
||||
|
||||
func (dc *decortClient) Compute() *compute.Compute {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package client
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/computeci"
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/computeci"
|
||||
)
|
||||
|
||||
func (dc *decortClient) ComputeCI() *computeci.ComputeCI {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package client
|
||||
package config
|
||||
|
||||
type Config struct {
|
||||
AppID string
|
||||
4
disks.go
4
disks.go
@@ -1,7 +1,7 @@
|
||||
package client
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/disks"
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/disks"
|
||||
)
|
||||
|
||||
func (dc *decortClient) Disks() *disks.Disks {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package client
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/extnet"
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/extnet"
|
||||
)
|
||||
|
||||
func (dc *decortClient) Extnet() *extnet.Extnet {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package client
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/flipgroup"
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/flipgroup"
|
||||
)
|
||||
|
||||
func (dc *decortClient) FlipGroup() *flipgroup.FlipGroup {
|
||||
|
||||
4
image.go
4
image.go
@@ -1,7 +1,7 @@
|
||||
package client
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/image"
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/image"
|
||||
)
|
||||
|
||||
func (dc *decortClient) Image() *image.Image {
|
||||
|
||||
@@ -4,19 +4,21 @@ import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/rudecs/decort-sdk/config"
|
||||
)
|
||||
|
||||
func newHttpClient(config Config) *http.Client {
|
||||
func NewHttpClient(cfg config.Config) *http.Client {
|
||||
|
||||
transCfg := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: config.SSLSkipVerify}}
|
||||
transCfg := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: cfg.SSLSkipVerify}}
|
||||
|
||||
return &http.Client{
|
||||
Transport: &transport{
|
||||
base: transCfg,
|
||||
retries: config.Retries,
|
||||
clientId: config.AppId,
|
||||
clientSecret: config.AppSecret,
|
||||
ssoUrl: config.SSOUrl,
|
||||
retries: cfg.Retries,
|
||||
clientId: cfg.AppID,
|
||||
clientSecret: cfg.AppSecret,
|
||||
ssoUrl: cfg.SSOURL,
|
||||
//TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -32,12 +31,13 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
return nil, fmt.Errorf("cannot get token: %v", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("cannot get token: %v", err)
|
||||
}
|
||||
|
||||
tokenBytes, _ := ioutil.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
return nil, fmt.Errorf("cannot get token: %s", tokenBytes)
|
||||
}
|
||||
|
||||
token := string(tokenBytes)
|
||||
|
||||
t.token = token
|
||||
@@ -48,8 +48,10 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
req.Header.Add("Authorization", "bearer "+t.token)
|
||||
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)
|
||||
resp, err = t.base.RoundTrip(req)
|
||||
if err == nil {
|
||||
if resp.StatusCode == 200 {
|
||||
return resp, nil
|
||||
@@ -58,8 +60,8 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
err = fmt.Errorf("%s", respBytes)
|
||||
resp.Body.Close()
|
||||
}
|
||||
fmt.Println(err)
|
||||
//logrus.Errorf("Could not execute request: %v. Retrying %d/%d", err, i+1, t.retries)
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
return nil, errors.New("number of retries exceeded")
|
||||
return nil, fmt.Errorf("could not execute request: %v", err)
|
||||
}
|
||||
4
k8ci.go
4
k8ci.go
@@ -1,7 +1,7 @@
|
||||
package client
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/k8ci"
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/k8ci"
|
||||
)
|
||||
|
||||
func (dc *decortClient) K8CI() *k8ci.K8CI {
|
||||
|
||||
4
k8s.go
4
k8s.go
@@ -1,7 +1,7 @@
|
||||
package client
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/k8s"
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/k8s"
|
||||
)
|
||||
|
||||
func (dc *decortClient) K8S() *k8s.K8S {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package client
|
||||
package decortsdk
|
||||
|
||||
import "github.com/rudecs/decort-sdk/kvmppc"
|
||||
import "github.com/rudecs/decort-sdk/pkg/cloudapi/kvmppc"
|
||||
|
||||
func (dc *decortClient) KVMPPC() *kvmppc.KVMPPC {
|
||||
return kvmppc.New(dc)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package client
|
||||
package decortsdk
|
||||
|
||||
import (
|
||||
"github.com/rudecs/decort-sdk/kvmx86"
|
||||
"github.com/rudecs/decort-sdk/pkg/cloudapi/kvmx86"
|
||||
)
|
||||
|
||||
func (dc *decortClient) KVMX86() *kvmx86.KVMX86 {
|
||||
|
||||
4
lb.go
4
lb.go
@@ -1,6 +1,6 @@
|
||||
package client
|
||||
package decortsdk
|
||||
|
||||
import "github.com/rudecs/decort-sdk/lb"
|
||||
import "github.com/rudecs/decort-sdk/pkg/cloudapi/lb"
|
||||
|
||||
func (dc *decortClient) LB() *lb.LB {
|
||||
return lb.New(dc)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package client
|
||||
package decortsdk
|
||||
|
||||
import "github.com/rudecs/decort-sdk/locations"
|
||||
import "github.com/rudecs/decort-sdk/pkg/cloudapi/locations"
|
||||
|
||||
func (dc *decortClient) Locations() *locations.Locations {
|
||||
return locations.New(dc)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user