Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions cmd/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@
}
}
params.Add("response", "json")
params.Add("signatureversion", "3")
params.Add(expiresKey, time.Now().UTC().Add(15 * time.Minute).Format(time.RFC3339))

Check failure on line 208 in cmd/network.go

View workflow job for this annotation

GitHub Actions / build

undefined: expiresKey

var encodedParams string
var err error
Expand All @@ -220,8 +222,13 @@
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 {
Expand Down Expand Up @@ -287,7 +294,7 @@
// 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 {
Expand Down
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -151,6 +152,7 @@ func defaultCoreConfig() Core {
VerifyCert: true,
ProfileName: "localcloud",
AutoComplete: true,
PostRequest: true,
}
}

Expand Down Expand Up @@ -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
}

Expand Down
Loading