|  |  |  | @ -4,7 +4,6 @@ import ( | 
			
		
	
		
			
				
					|  |  |  |  | 	"bytes" | 
			
		
	
		
			
				
					|  |  |  |  | 	"context" | 
			
		
	
		
			
				
					|  |  |  |  | 	"crypto/tls" | 
			
		
	
		
			
				
					|  |  |  |  | 	"errors" | 
			
		
	
		
			
				
					|  |  |  |  | 	"fmt" | 
			
		
	
		
			
				
					|  |  |  |  | 	"io" | 
			
		
	
		
			
				
					|  |  |  |  | 	"mime/multipart" | 
			
		
	
	
		
			
				
					|  |  |  | @ -78,7 +77,7 @@ func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url st | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	k8sCaCreateReq, okCa := params.(k8s_ca.CreateRequest) | 
			
		
	
		
			
				
					|  |  |  |  | 	k8sCbCreateReq, okCb := params.(k8s_cb.CreateRequest) | 
			
		
	
		
			
				
					|  |  |  |  | 	 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	var body *bytes.Buffer | 
			
		
	
		
			
				
					|  |  |  |  | 	var ctype string | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  |  | @ -93,28 +92,17 @@ func (ldc *LegacyDecortClient) DecortApiCall(ctx context.Context, method, url st | 
			
		
	
		
			
				
					|  |  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  |  | 		body = bytes.NewBufferString(values.Encode() + fmt.Sprintf("&authkey=%s", ldc.cfg.Token)) | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 	 | 
			
		
	
		
			
				
					|  |  |  |  | 	req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+"/restmachine"+url, body) | 
			
		
	
		
			
				
					|  |  |  |  | 	if err != nil { | 
			
		
	
		
			
				
					|  |  |  |  | 		return nil, err | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	resp, err := ldc.do(req, ctype) | 
			
		
	
		
			
				
					|  |  |  |  | 	if err != nil { | 
			
		
	
		
			
				
					|  |  |  |  | 		return nil, err | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 	defer resp.Body.Close() | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	respBytes, err := io.ReadAll(resp.Body) | 
			
		
	
		
			
				
					|  |  |  |  | 	req, err := http.NewRequestWithContext(ctx, method, ldc.decortURL+"/restmachine"+url, body) | 
			
		
	
		
			
				
					|  |  |  |  | 	if err != nil { | 
			
		
	
		
			
				
					|  |  |  |  | 		return nil, err | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	if resp.StatusCode != 200 { | 
			
		
	
		
			
				
					|  |  |  |  | 		return nil, errors.New(string(respBytes)) | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 	// perform request
 | 
			
		
	
		
			
				
					|  |  |  |  | 	var respBytes []byte | 
			
		
	
		
			
				
					|  |  |  |  | 	respBytes, err = ldc.do(req, ctype) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	return respBytes, nil | 
			
		
	
		
			
				
					|  |  |  |  | 	return respBytes, err | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | func (ldc *LegacyDecortClient) getToken(ctx context.Context) error { | 
			
		
	
	
		
			
				
					|  |  |  | @ -148,7 +136,7 @@ func (ldc *LegacyDecortClient) getToken(ctx context.Context) error { | 
			
		
	
		
			
				
					|  |  |  |  | 	return nil | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | func (ldc *LegacyDecortClient) do(req *http.Request, ctype string) (*http.Response, error) { | 
			
		
	
		
			
				
					|  |  |  |  | func (ldc *LegacyDecortClient) do(req *http.Request, ctype string) ([]byte, error) { | 
			
		
	
		
			
				
					|  |  |  |  | 	if ctype != "" { | 
			
		
	
		
			
				
					|  |  |  |  | 		req.Header.Add("Content-Type", ctype) | 
			
		
	
		
			
				
					|  |  |  |  | 	} else { | 
			
		
	
	
		
			
				
					|  |  |  | @ -156,32 +144,38 @@ func (ldc *LegacyDecortClient) do(req *http.Request, ctype string) (*http.Respon | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 	req.Header.Set("Accept", "application/json") | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	// var resp *http.Response
 | 
			
		
	
		
			
				
					|  |  |  |  | 	// var err error
 | 
			
		
	
		
			
				
					|  |  |  |  | 	buf, _ := io.ReadAll(req.Body) | 
			
		
	
		
			
				
					|  |  |  |  | 	// req = req.Clone(req.Context())
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	// for i := uint64(0); i < ldc.cfg.Retries; i++ {
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	buf, err := io.ReadAll(req.Body) | 
			
		
	
		
			
				
					|  |  |  |  | 	if err != nil { | 
			
		
	
		
			
				
					|  |  |  |  | 		return nil, err | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 	req.Body.Close() | 
			
		
	
		
			
				
					|  |  |  |  | 	req.Body = io.NopCloser(bytes.NewBuffer(buf)) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	resp, err := ldc.client.Do(req) | 
			
		
	
		
			
				
					|  |  |  |  | 	if err != nil || resp == nil { | 
			
		
	
		
			
				
					|  |  |  |  | 		return nil, err | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 	defer resp.Body.Close() | 
			
		
	
		
			
				
					|  |  |  |  | 	 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	// if err == nil {
 | 
			
		
	
		
			
				
					|  |  |  |  | 	// handle successful request
 | 
			
		
	
		
			
				
					|  |  |  |  | 	respBytes, err := io.ReadAll(resp.Body) | 
			
		
	
		
			
				
					|  |  |  |  | 	if err!= nil { | 
			
		
	
		
			
				
					|  |  |  |  | 		return nil, err | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 	if resp.StatusCode == 200 { | 
			
		
	
		
			
				
					|  |  |  |  | 		return resp, err | 
			
		
	
		
			
				
					|  |  |  |  | 		return respBytes, nil | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 	respBytes, _ := io.ReadAll(resp.Body) | 
			
		
	
		
			
				
					|  |  |  |  | 	err = fmt.Errorf("%s", respBytes) | 
			
		
	
		
			
				
					|  |  |  |  | 	resp.Body.Close() | 
			
		
	
		
			
				
					|  |  |  |  | 	// 	}
 | 
			
		
	
		
			
				
					|  |  |  |  | 	// }
 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	// handle errors with status code other than 200
 | 
			
		
	
		
			
				
					|  |  |  |  | 	err = fmt.Errorf("%s", respBytes) | 
			
		
	
		
			
				
					|  |  |  |  | 	return nil, fmt.Errorf("could not execute request: %w", err) | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | func createK8sCloudApiLegacy(req k8s_ca.CreateRequest, token string) (*bytes.Buffer, string) { | 
			
		
	
		
			
				
					|  |  |  |  | 	reqBody := &bytes.Buffer{} | 
			
		
	
		
			
				
					|  |  |  |  | 	writer := multipart.NewWriter(reqBody) | 
			
		
	
		
			
				
					|  |  |  |  | 	defer writer.Close() | 
			
		
	
		
			
				
					|  |  |  |  | 	if req.OidcCertificate != "" { | 
			
		
	
		
			
				
					|  |  |  |  | 		part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt") | 
			
		
	
		
			
				
					|  |  |  |  | 		_, _ = io.Copy(part, strings.NewReader(req.OidcCertificate)) | 
			
		
	
	
		
			
				
					|  |  |  | @ -290,14 +284,13 @@ func createK8sCloudApiLegacy(req k8s_ca.CreateRequest, token string) (*bytes.Buf | 
			
		
	
		
			
				
					|  |  |  |  | 	_ = writer.WriteField("authkey", token) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	ct := writer.FormDataContentType() | 
			
		
	
		
			
				
					|  |  |  |  | 	writer.Close() | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	return reqBody, ct | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | func createK8sCloudBrokerLegacy(req k8s_cb.CreateRequest, token string) (*bytes.Buffer, string) { | 
			
		
	
		
			
				
					|  |  |  |  | 	reqBody := &bytes.Buffer{} | 
			
		
	
		
			
				
					|  |  |  |  | 	writer := multipart.NewWriter(reqBody) | 
			
		
	
		
			
				
					|  |  |  |  | 	defer writer.Close() | 
			
		
	
		
			
				
					|  |  |  |  | 	if req.OidcCertificate != "" { | 
			
		
	
		
			
				
					|  |  |  |  | 		part, _ := writer.CreateFormFile("oidcCertificate", "ca.crt") | 
			
		
	
		
			
				
					|  |  |  |  | 		_, _ = io.Copy(part, strings.NewReader(req.OidcCertificate)) | 
			
		
	
	
		
			
				
					|  |  |  | @ -402,11 +395,9 @@ func createK8sCloudBrokerLegacy(req k8s_cb.CreateRequest, token string) (*bytes. | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	_ = writer.WriteField("extnetOnly", strconv.FormatBool(req.ExtNetOnly)) | 
			
		
	
		
			
				
					|  |  |  |  | 	 | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	_ = writer.WriteField("authkey", token) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	ct := writer.FormDataContentType() | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	writer.Close() | 
			
		
	
		
			
				
					|  |  |  |  | 	return reqBody, ct | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
	
		
			
				
					|  |  |  | 
 |