Skip to content

Commit 4133f08

Browse files
committed
Convert GET to POST requests
1 parent 2d641ae commit 4133f08

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

cmd/network.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ package cmd
1919

2020
import (
2121
"bytes"
22-
"crypto/hmac"
23-
"crypto/sha1"
24-
"encoding/base64"
2522
"encoding/json"
2623
"errors"
2724
"fmt"
@@ -196,38 +193,30 @@ func NewAPIRequest(r *Request, api string, args []string, isAsync bool) (map[str
196193
}
197194
params.Add("response", "json")
198195

199-
var encodedParams string
200196
var err error
201197

202198
if len(r.Config.ActiveProfile.APIKey) > 0 && len(r.Config.ActiveProfile.SecretKey) > 0 {
203199
apiKey := r.Config.ActiveProfile.APIKey
204-
secretKey := r.Config.ActiveProfile.SecretKey
205200

206201
if len(apiKey) > 0 {
207202
params.Add("apiKey", apiKey)
208203
}
209-
encodedParams = encodeRequestParams(params)
210-
211-
mac := hmac.New(sha1.New, []byte(secretKey))
212-
mac.Write([]byte(strings.ToLower(encodedParams)))
213-
signature := base64.StdEncoding.EncodeToString(mac.Sum(nil))
214-
encodedParams = encodedParams + fmt.Sprintf("&signature=%s", url.QueryEscape(signature))
215204
} else if len(r.Config.ActiveProfile.Username) > 0 && len(r.Config.ActiveProfile.Password) > 0 {
216205
sessionKey, err := Login(r)
217206
if err != nil {
218207
return nil, err
219208
}
220209
params.Add("sessionkey", sessionKey)
221-
encodedParams = encodeRequestParams(params)
222210
} else {
223211
fmt.Println("Please provide either apikey/secretkey or username/password to make an API call")
224212
return nil, errors.New("failed to authenticate to make API call")
225213
}
226214

227-
requestURL := fmt.Sprintf("%s?%s", r.Config.ActiveProfile.URL, encodedParams)
215+
requestURL := fmt.Sprintf("%s", r.Config.ActiveProfile.URL)
228216
config.Debug("NewAPIRequest API request URL:", requestURL)
229217

230-
response, err := r.Client().Get(requestURL)
218+
response, err := r.Client().PostForm(requestURL, params)
219+
231220
if err != nil {
232221
return nil, err
233222
}
@@ -243,7 +232,7 @@ func NewAPIRequest(r *Request, api string, args []string, isAsync bool) (map[str
243232
params.Add("sessionkey", sessionKey)
244233
requestURL = fmt.Sprintf("%s?%s", r.Config.ActiveProfile.URL, encodeRequestParams(params))
245234
config.Debug("NewAPIRequest API request URL:", requestURL)
246-
response, err = r.Client().Get(requestURL)
235+
response, err = r.Client().PostForm(requestURL, params)
247236
if err != nil {
248237
return nil, err
249238
}

0 commit comments

Comments
 (0)