This is an automated email from the ASF dual-hosted git repository.
bstoyanov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack-cloudmonkey.git
The following commit(s) were added to refs/heads/main by this push:
new f43904f Do not encode asterisks on requests (#130)
f43904f is described below
commit f43904f319a2c57d9ef9bd50ec9024205f87301f
Author: Nicolas Vazquez <[email protected]>
AuthorDate: Fri Apr 21 08:53:11 2023 -0300
Do not encode asterisks on requests (#130)
---
cmd/network.go | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/cmd/network.go b/cmd/network.go
index 5bc280a..a3fb9e3 100644
--- a/cmd/network.go
+++ b/cmd/network.go
@@ -120,7 +120,12 @@ func encodeRequestParams(params url.Values) string {
}
buf.WriteString(key)
buf.WriteString("=")
- buf.WriteString(url.QueryEscape(value))
+ escaped := url.QueryEscape(value)
+ // we need to ensure + (representing a space) is encoded as %20
+ escaped = strings.Replace(escaped, "+", "%20", -1)
+ // we need to ensure * is not escaped
+ escaped = strings.Replace(escaped, "%2A", "*", -1)
+ buf.WriteString(escaped)
}
return buf.String()
}
@@ -204,7 +209,7 @@ func NewAPIRequest(r *Request, api string, args []string,
isAsync bool) (map[str
encodedParams = encodeRequestParams(params)
mac := hmac.New(sha1.New, []byte(secretKey))
-
mac.Write([]byte(strings.Replace(strings.ToLower(encodedParams), "+", "%20",
-1)))
+ 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 {