|  |  |  | @ -4,7 +4,6 @@ import ( | 
			
		
	
		
			
				
					|  |  |  |  | 	"bytes" | 
			
		
	
		
			
				
					|  |  |  |  | 	"context" | 
			
		
	
		
			
				
					|  |  |  |  | 	"crypto/tls" | 
			
		
	
		
			
				
					|  |  |  |  | 	"errors" | 
			
		
	
		
			
				
					|  |  |  |  | 	"fmt" | 
			
		
	
		
			
				
					|  |  |  |  | 	"io" | 
			
		
	
		
			
				
					|  |  |  |  | 	"mime/multipart" | 
			
		
	
	
		
			
				
					|  |  |  | @ -97,22 +96,11 @@ func (dc *DecortClient) DecortApiCall(ctx context.Context, method, url string, p | 
			
		
	
		
			
				
					|  |  |  |  | 		return nil, err | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	resp, err := dc.do(req, ctype) | 
			
		
	
		
			
				
					|  |  |  |  | 	if err != nil { | 
			
		
	
		
			
				
					|  |  |  |  | 		return nil, err | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 	defer resp.Body.Close() | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	respBytes, err := io.ReadAll(resp.Body) | 
			
		
	
		
			
				
					|  |  |  |  | 	if err != nil { | 
			
		
	
		
			
				
					|  |  |  |  | 		return nil, err | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 	// perform request
 | 
			
		
	
		
			
				
					|  |  |  |  | 	var respBytes []byte | 
			
		
	
		
			
				
					|  |  |  |  | 	respBytes, err = dc.do(req, ctype) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	if resp.StatusCode != 200 { | 
			
		
	
		
			
				
					|  |  |  |  | 		return nil, errors.New(string(respBytes)) | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	return respBytes, nil | 
			
		
	
		
			
				
					|  |  |  |  | 	return respBytes, err | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | func (dc *DecortClient) getToken(ctx context.Context) error { | 
			
		
	
	
		
			
				
					|  |  |  | @ -149,7 +137,7 @@ func (dc *DecortClient) getToken(ctx context.Context) error { | 
			
		
	
		
			
				
					|  |  |  |  | 	return nil | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | func (dc *DecortClient) do(req *http.Request, ctype string) (*http.Response, error) { | 
			
		
	
		
			
				
					|  |  |  |  | func (dc *DecortClient) do(req *http.Request, ctype string) ([]byte, error) { | 
			
		
	
		
			
				
					|  |  |  |  | 	if ctype != "" { | 
			
		
	
		
			
				
					|  |  |  |  | 		req.Header.Add("Content-Type", ctype) | 
			
		
	
		
			
				
					|  |  |  |  | 	} else { | 
			
		
	
	
		
			
				
					|  |  |  | @ -159,31 +147,34 @@ func (dc *DecortClient) do(req *http.Request, ctype string) (*http.Response, err | 
			
		
	
		
			
				
					|  |  |  |  | 	req.Header.Add("Authorization", "bearer "+dc.cfg.Token) | 
			
		
	
		
			
				
					|  |  |  |  | 	req.Header.Set("Accept", "application/json") | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	// var resp *http.Response
 | 
			
		
	
		
			
				
					|  |  |  |  | 	// var err error
 | 
			
		
	
		
			
				
					|  |  |  |  | 	buf, _ := io.ReadAll(req.Body) | 
			
		
	
		
			
				
					|  |  |  |  | 	// req = req.Clone(req.Context())
 | 
			
		
	
		
			
				
					|  |  |  |  | 	buf, err := io.ReadAll(req.Body) | 
			
		
	
		
			
				
					|  |  |  |  | 	if err != nil { | 
			
		
	
		
			
				
					|  |  |  |  | 		return nil, err | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	// for i := uint64(0); i < dc.cfg.Retries; i++ {
 | 
			
		
	
		
			
				
					|  |  |  |  | 	req.Body = io.NopCloser(bytes.NewBuffer(buf)) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	resp, err := dc.client.Do(req) | 
			
		
	
		
			
				
					|  |  |  |  | 	if err != nil || resp == nil { | 
			
		
	
		
			
				
					|  |  |  |  | 		return nil, err | 
			
		
	
		
			
				
					|  |  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  |  | 	defer resp.Body.Close() | 
			
		
	
		
			
				
					|  |  |  |  | 	 | 
			
		
	
		
			
				
					|  |  |  |  | 	// if err == nil {
 | 
			
		
	
		
			
				
					|  |  |  |  | 	// handle successful request
 | 
			
		
	
		
			
				
					|  |  |  |  | 	respBytes, _ := io.ReadAll(resp.Body) | 
			
		
	
		
			
				
					|  |  |  |  | 	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 createK8sCloudApi(req k8s_ca.CreateRequest) (*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 +281,13 @@ func createK8sCloudApi(req k8s_ca.CreateRequest) (*bytes.Buffer, string) { | 
			
		
	
		
			
				
					|  |  |  |  | 	_ = writer.WriteField("extnetOnly", strconv.FormatBool(req.ExtNetOnly)) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	ct := writer.FormDataContentType() | 
			
		
	
		
			
				
					|  |  |  |  | 	writer.Close() | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	return reqBody, ct | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | func createK8sCloudBroker(req k8s_cb.CreateRequest) (*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)) | 
			
		
	
	
		
			
				
					|  |  |  | @ -404,7 +394,5 @@ func createK8sCloudBroker(req k8s_cb.CreateRequest) (*bytes.Buffer, string) { | 
			
		
	
		
			
				
					|  |  |  |  | 	_ = writer.WriteField("extnetOnly", strconv.FormatBool(req.ExtNetOnly)) | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	ct := writer.FormDataContentType() | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  | 	writer.Close() | 
			
		
	
		
			
				
					|  |  |  |  | 	return reqBody, ct | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
	
		
			
				
					|  |  |  | 
 |