Skip to content

Commit 831491b

Browse files
authored
Fix version string and auth header (#201)
* fix: Strip newlines from version value * fix: Set API key in headers not param
1 parent 2763f89 commit 831491b

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

api/query.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"os"
1010
"runtime"
11+
"strings"
1112
"time"
1213

1314
"github.com/spf13/viper"
@@ -40,15 +41,17 @@ func Query(input Input) (res *http.Response, err error) {
4041
return nil, errors.New("API key not found")
4142
}
4243

43-
req, err := http.NewRequest("POST", apiUrl+"?api_key="+apiKey, bytes.NewBuffer(jsonValue))
44+
req, err := http.NewRequest("POST", apiUrl, bytes.NewBuffer(jsonValue))
4445
if err != nil {
4546
return
4647
}
4748

48-
userAgent := "RunPod-CLI/" + Version + " (" + runtime.GOOS + "; " + runtime.GOARCH + ")"
49+
sanitizedVersion := strings.TrimRight(Version, "\r\n")
50+
userAgent := "RunPod-CLI/" + sanitizedVersion + " (" + runtime.GOOS + "; " + runtime.GOARCH + ")"
4951

5052
req.Header.Add("Content-Type", "application/json")
5153
req.Header.Set("User-Agent", userAgent)
54+
req.Header.Set("Authorization", "Bearer "+apiKey)
5255

5356
client := &http.Client{Timeout: time.Second * 10}
5457
return client.Do(req)

cmd/root.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"strings"
67

78
"github.com/runpod/runpodctl/api"
89
"github.com/runpod/runpodctl/cmd/config"
@@ -61,16 +62,21 @@ func registerCommands() {
6162
// Execute adds all child commands to the root command and sets flags appropriately.
6263
// This is called by main.main(). It only needs to happen once to the rootCmd.
6364
func Execute(ver string) {
64-
version = ver
65-
api.Version = ver
66-
rootCmd.Version = ver
65+
sanitizedVersion := sanitizeVersion(ver)
66+
version = sanitizedVersion
67+
api.Version = sanitizedVersion
68+
rootCmd.Version = sanitizedVersion
6769

6870
if err := rootCmd.Execute(); err != nil {
6971
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
7072
os.Exit(1)
7173
}
7274
}
7375

76+
func sanitizeVersion(ver string) string {
77+
return strings.TrimRight(ver, "\r\n")
78+
}
79+
7480
// initConfig reads in config file and ENV variables if set.
7581
func initConfig() {
7682
home, err := os.UserHomeDir()

0 commit comments

Comments
 (0)