Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (
PostRunE: func(cmd *cobra.Command, args []string) error {
if prof := viper.GetString("PROFILE"); viper.IsSet("PROFILE") {
// Failure to save should block subsequent commands on CI
return utils.WriteFile(utils.ProfilePath, []byte(prof), afero.NewOsFs())
return utils.SaveProfileName(prof, afero.NewOsFs())
}
return nil
},
Expand Down
1 change: 0 additions & 1 deletion internal/utils/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ var (
PoolerVersionPath = filepath.Join(TempDir, "pooler-version")
RealtimeVersionPath = filepath.Join(TempDir, "realtime-version")
CliVersionPath = filepath.Join(TempDir, "cli-latest")
ProfilePath = filepath.Join(TempDir, "profile")
CurrBranchPath = filepath.Join(SupabaseDirPath, ".branches", "_current_branch")
SchemasDir = filepath.Join(SupabaseDirPath, "schemas")
MigrationsDir = filepath.Join(SupabaseDirPath, "migrations")
Expand Down
25 changes: 23 additions & 2 deletions internal/utils/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package utils
import (
"context"
"fmt"
"os"
"path/filepath"
"sort"
"strings"

Expand Down Expand Up @@ -121,15 +123,34 @@ func getProfileName(fsys afero.Fs) string {
if prof := viper.GetString("PROFILE"); viper.IsSet("PROFILE") {
fmt.Fprintln(debuglogger, "Loading profile from flag:", prof)
return prof
} else if content, err := afero.ReadFile(fsys, ProfilePath); err == nil {
fmt.Fprintln(debuglogger, "Loading profile from file:", ProfilePath)
} else if profilePath, err := getProfilePath(); err != nil {
fmt.Fprintln(debuglogger, err)
return prof
} else if content, err := afero.ReadFile(fsys, profilePath); err == nil {
fmt.Fprintln(debuglogger, "Loading profile from file:", profilePath)
return string(content)
} else {
fmt.Fprintln(debuglogger, err)
return prof
}
}

func getProfilePath() (string, error) {
home, err := os.UserHomeDir()
if err != nil {
return "", errors.Errorf("failed to get $HOME directory: %w", err)
}
return filepath.Join(home, ".supabase", "profile"), nil
}

func SaveProfileName(prof string, fsys afero.Fs) error {
profilePath, err := getProfilePath()
if err != nil {
return err
}
return WriteFile(profilePath, []byte(prof), fsys)
}

func AwsRegions() []string {
result := make([]string, len(allProfiles[0].ProjectRegions))
for i, region := range allProfiles[0].ProjectRegions {
Expand Down
Loading