This is an automated email from the ASF dual-hosted git repository.
rohit 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 a6552ee Allow users to send requests from CMK using POST requests.
(#161)
a6552ee is described below
commit a6552eea9faf717b07ae40518bda2dc00aaf24cb
Author: Kevin Li <[email protected]>
AuthorDate: Sun Jul 13 20:52:40 2025 -0700
Allow users to send requests from CMK using POST requests. (#161)
* Adding changes to reflect changes to Cloudstack that enforce POST and
timestamps
* Making some changes
* Fixing some errors based off PR
* Changing postRequest from true to false
* Adding config
* Fixing confusion
---------
Co-authored-by: Kevin Li <[email protected]>
---
cmd/network.go | 15 ++++++++++++---
config/config.go | 5 +++++
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/cmd/network.go b/cmd/network.go
index b5f4bef..0dae39f 100644
--- a/cmd/network.go
+++ b/cmd/network.go
@@ -203,7 +203,11 @@ func NewAPIRequest(r *Request, api string, args []string,
isAsync bool) (map[str
params.Add(key, value)
}
}
+ signatureversion := "3"
+ expiresKey := "expires"
params.Add("response", "json")
+ params.Add("signatureversion", signatureversion)
+ params.Add(expiresKey, time.Now().UTC().Add(15 *
time.Minute).Format(time.RFC3339))
var encodedParams string
var err error
@@ -220,8 +224,13 @@ func NewAPIRequest(r *Request, api string, args []string,
isAsync bool) (map[str
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))
- params = nil
+ if r.Config.Core.PostRequest {
+ params.Add("signature", signature)
+ } else {
+ encodedParams = encodedParams +
fmt.Sprintf("&signature=%s", url.QueryEscape(signature))
+ params = nil
+ }
+
} else if len(r.Config.ActiveProfile.Username) > 0 &&
len(r.Config.ActiveProfile.Password) > 0 {
sessionKey, err := Login(r)
if err != nil {
@@ -287,7 +296,7 @@ func NewAPIRequest(r *Request, api string, args []string,
isAsync bool) (map[str
// we can implement further conditions to do POST or GET (or other http
commands) here
func executeRequest(r *Request, requestURL string, params url.Values)
(*http.Response, error) {
config.SetupContext(r.Config)
- if params.Has("password") || params.Has("userdata") {
+ if params.Has("password") || params.Has("userdata") ||
r.Config.Core.PostRequest {
requestURL = fmt.Sprintf("%s", r.Config.ActiveProfile.URL)
return r.Client().PostForm(requestURL, params)
} else {
diff --git a/config/config.go b/config/config.go
index e390c22..52ee9f0 100644
--- a/config/config.go
+++ b/config/config.go
@@ -67,6 +67,7 @@ type Core struct {
VerifyCert bool `ini:"verifycert"`
ProfileName string `ini:"profile"`
AutoComplete bool `ini:"autocomplete"`
+ PostRequest bool `ini:postrequest`
}
// Config describes CLI config file and default options
@@ -151,6 +152,7 @@ func defaultCoreConfig() Core {
VerifyCert: true,
ProfileName: "localcloud",
AutoComplete: true,
+ PostRequest: true,
}
}
@@ -282,6 +284,9 @@ func saveConfig(cfg *Config) *Config {
core.AutoComplete = true
core.Output = JSON
}
+ if !conf.Section(ini.DEFAULT_SECTION).HasKey("postrequest") {
+ core.PostRequest = true
+ }
cfg.Core = core
}