This is an automated email from the ASF dual-hosted git repository.

pearl11594 pushed a commit to branch bug/139-support-post-method
in repository https://gitbox.apache.org/repos/asf/cloudstack-cloudmonkey.git

commit 4133f08d132bed587d933f6b986d2d208359034e
Author: Pearl Dsilva <[email protected]>
AuthorDate: Wed Aug 9 21:42:40 2023 -0400

    Convert GET to POST requests
---
 cmd/network.go | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/cmd/network.go b/cmd/network.go
index a3fb9e3..28a32be 100644
--- a/cmd/network.go
+++ b/cmd/network.go
@@ -19,9 +19,6 @@ package cmd
 
 import (
        "bytes"
-       "crypto/hmac"
-       "crypto/sha1"
-       "encoding/base64"
        "encoding/json"
        "errors"
        "fmt"
@@ -196,38 +193,30 @@ func NewAPIRequest(r *Request, api string, args []string, 
isAsync bool) (map[str
        }
        params.Add("response", "json")
 
-       var encodedParams string
        var err error
 
        if len(r.Config.ActiveProfile.APIKey) > 0 && 
len(r.Config.ActiveProfile.SecretKey) > 0 {
                apiKey := r.Config.ActiveProfile.APIKey
-               secretKey := r.Config.ActiveProfile.SecretKey
 
                if len(apiKey) > 0 {
                        params.Add("apiKey", apiKey)
                }
-               encodedParams = encodeRequestParams(params)
-
-               mac := hmac.New(sha1.New, []byte(secretKey))
-               mac.Write([]byte(strings.ToLower(encodedParams)))
-               signature := base64.StdEncoding.EncodeToString(mac.Sum(nil))
-               encodedParams = encodedParams + fmt.Sprintf("&signature=%s", 
url.QueryEscape(signature))
        } else if len(r.Config.ActiveProfile.Username) > 0 && 
len(r.Config.ActiveProfile.Password) > 0 {
                sessionKey, err := Login(r)
                if err != nil {
                        return nil, err
                }
                params.Add("sessionkey", sessionKey)
-               encodedParams = encodeRequestParams(params)
        } else {
                fmt.Println("Please provide either apikey/secretkey or 
username/password to make an API call")
                return nil, errors.New("failed to authenticate to make API 
call")
        }
 
-       requestURL := fmt.Sprintf("%s?%s", r.Config.ActiveProfile.URL, 
encodedParams)
+       requestURL := fmt.Sprintf("%s", r.Config.ActiveProfile.URL)
        config.Debug("NewAPIRequest API request URL:", requestURL)
 
-       response, err := r.Client().Get(requestURL)
+       response, err := r.Client().PostForm(requestURL, params)
+
        if err != nil {
                return nil, err
        }
@@ -243,7 +232,7 @@ func NewAPIRequest(r *Request, api string, args []string, 
isAsync bool) (map[str
                params.Add("sessionkey", sessionKey)
                requestURL = fmt.Sprintf("%s?%s", r.Config.ActiveProfile.URL, 
encodeRequestParams(params))
                config.Debug("NewAPIRequest API request URL:", requestURL)
-               response, err = r.Client().Get(requestURL)
+               response, err = r.Client().PostForm(requestURL, params)
                if err != nil {
                        return nil, err
                }

Reply via email to