Skip to content

Commit e1d24d9

Browse files
committed
get proxy address from an environment variable
This is more inline with what we already do to chage the API location
1 parent e1c7923 commit e1d24d9

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

internal/cmd/db_shell.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,10 @@ import (
2020
"github.com/tursodatabase/turso-cli/internal/turso"
2121
)
2222

23-
var proxy string
24-
2523
func init() {
2624
dbCmd.AddCommand(shellCmd)
2725
addInstanceFlag(shellCmd, "Connect to the database at the specified instance.")
2826
addLocationFlag(shellCmd, "Connect to the database at the specified location.")
29-
shellCmd.Flags().StringVar(&proxy, "proxy", "", "Proxy to use for the connection.")
30-
shellCmd.RegisterFlagCompletionFunc("proxy", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
31-
return []string{}, cobra.ShellCompDirectiveNoFileComp
32-
})
3327
flags.AddAttachClaims(shellCmd)
3428
}
3529

@@ -222,7 +216,7 @@ var shellCmd = &cobra.Command{
222216

223217
shellConfig := shell.ShellConfig{
224218
DbUri: dbUrl,
225-
Proxy: proxy,
219+
Proxy: getTursoProxyUrl(),
226220
AuthToken: authToken,
227221
InF: cmd.InOrStdin(),
228222
OutF: cmd.OutOrStdout(),

internal/cmd/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ func getTursoUrl() string {
265265
return url
266266
}
267267

268+
func getTursoProxyUrl() string {
269+
config, _ := settings.ReadSettings() // ok to ignore, we'll fallback to default
270+
return config.GetProxyURL()
271+
}
272+
268273
func promptConfirmation(prompt string) (bool, error) {
269274
reader := bufio.NewReader(os.Stdin)
270275

internal/settings/settings.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func ReadSettings() (*Settings, error) {
3434
configPath := configdir.LocalConfig("turso")
3535
viper.BindEnv("config-path", "TURSO_CONFIG_FOLDER")
3636
viper.BindEnv("baseURL", "TURSO_API_BASEURL")
37+
viper.BindEnv("proxyURL", "TURSO_PROXY_URL")
3738

3839
configPathFlag := viper.GetString("config-path")
3940
if len(configPathFlag) > 0 {
@@ -143,6 +144,10 @@ func (s *Settings) GetBaseURL() string {
143144
return viper.GetString("baseURL")
144145
}
145146

147+
func (s *Settings) GetProxyURL() string {
148+
return viper.GetString("proxyURL")
149+
}
150+
146151
func (s *Settings) SetAutoupdate(autoupdate string) {
147152
config := viper.GetStringMap("config")
148153
if config == nil {

0 commit comments

Comments
 (0)