v1.7.2
This commit is contained in:
26
client.go
26
client.go
@@ -16,14 +16,13 @@ import (
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/config"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi"
|
||||
k8s_ca "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/k8s"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker"
|
||||
k8s_cb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/k8s"
|
||||
)
|
||||
|
||||
const restmachine = "/restmachine"
|
||||
|
||||
// HTTP-client for platform
|
||||
type DecortClient struct {
|
||||
decortURL string
|
||||
@@ -90,7 +89,7 @@ func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, p
|
||||
body = bytes.NewBufferString(values.Encode())
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+restmachine+url, body)
|
||||
req, err := http.NewRequestWithContext(ctx, method, dc.decortURL+constants.Restmachine+url, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -169,17 +168,20 @@ func (dc *DecortClient) do(req *http.Request, ctype string) (*http.Response, err
|
||||
// req = req.Clone(req.Context())
|
||||
req.Body = io.NopCloser(bytes.NewBuffer(buf))
|
||||
resp, err := dc.client.Do(req)
|
||||
if err == nil {
|
||||
if resp.StatusCode == 200 {
|
||||
return resp, err
|
||||
}
|
||||
if err != nil || resp == nil {
|
||||
return resp, err
|
||||
}
|
||||
// }
|
||||
respBytes, _ := io.ReadAll(resp.Body)
|
||||
err = fmt.Errorf("%s", respBytes)
|
||||
resp.Body.Close()
|
||||
|
||||
return nil, fmt.Errorf("could not execute request: %w", err)
|
||||
if resp.StatusCode == 200 {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
respBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.Body.Close()
|
||||
return resp, errors.New(string(respBytes))
|
||||
}
|
||||
|
||||
func createK8sCloudApi(req k8s_ca.CreateRequest) (*bytes.Buffer, string) {
|
||||
|
||||
Reference in New Issue
Block a user