Skip to content

Commit

Permalink
Bind turso base URL to config (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
athoscouto authored Oct 27, 2023
1 parent 15dd25b commit 0855bc5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 9 additions & 4 deletions internal/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import (
"golang.org/x/sync/errgroup"
)

const (
tursoDefaultBaseURL = "https://api.turso.tech"
)

func createTursoClientFromAccessToken(warnMultipleAccessTokenSources bool) (*turso.Client, error) {
token, err := getAccessToken(warnMultipleAccessTokenSources)
if err != nil {
Expand Down Expand Up @@ -248,11 +252,12 @@ func deleteDatabaseInstance(client *turso.Client, database, instance string) err
}

func getTursoUrl() string {
host := os.Getenv("TURSO_API_BASEURL")
if host == "" {
host = "https://api.turso.tech"
config, _ := settings.ReadSettings() // ok to ignore, we'll fallback to default
url := config.GetBaseURL()
if url == "" {
url = tursoDefaultBaseURL
}
return host
return url
}

func promptConfirmation(prompt string) (bool, error) {
Expand Down
5 changes: 5 additions & 0 deletions internal/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func ReadSettings() (*Settings, error) {

configPath := configdir.LocalConfig("turso")
viper.BindEnv("config-path", "TURSO_CONFIG_FOLDER")
viper.BindEnv("baseURL", "TURSO_API_BASEURL")

configPathFlag := viper.GetString("config-path")
if len(configPathFlag) > 0 {
Expand Down Expand Up @@ -121,6 +122,10 @@ func (s *Settings) GetUsername() string {
return viper.GetString("username")
}

func (s *Settings) GetBaseURL() string {
return viper.GetString("baseURL")
}

func (s *Settings) SetAutoupdate(autoupdate string) {
config := viper.GetStringMap("config")
if config == nil {
Expand Down

0 comments on commit 0855bc5

Please sign in to comment.