github.com/supabase/cli@v1.168.1/internal/postgresConfig/get/get.go (about) 1 package get 2 3 import ( 4 "context" 5 "encoding/json" 6 "fmt" 7 "io" 8 "strings" 9 10 "github.com/go-errors/errors" 11 "github.com/spf13/afero" 12 "github.com/supabase/cli/internal/migration/list" 13 "github.com/supabase/cli/internal/utils" 14 ) 15 16 func Run(ctx context.Context, projectRef string, fsys afero.Fs) error { 17 // 1. get current config 18 { 19 config, err := GetCurrentPostgresConfig(ctx, projectRef) 20 if err != nil { 21 return err 22 } 23 err = PrintOutPostgresConfigOverrides(config) 24 if err != nil { 25 return err 26 } 27 return nil 28 } 29 } 30 31 func PrintOutPostgresConfigOverrides(config map[string]interface{}) error { 32 fmt.Println("- Custom Postgres Config -") 33 markdownTable := []string{ 34 "|Parameter|Value|\n|-|-|\n", 35 } 36 37 for k, v := range config { 38 markdownTable = append(markdownTable, fmt.Sprintf( 39 "|`%s`|`%+v`|\n", 40 k, v, 41 )) 42 } 43 44 if err := list.RenderTable(strings.Join(markdownTable, "")); err != nil { 45 return err 46 } 47 fmt.Println("- End of Custom Postgres Config -") 48 return nil 49 } 50 51 func GetCurrentPostgresConfig(ctx context.Context, projectRef string) (map[string]interface{}, error) { 52 resp, err := utils.GetSupabase().GetConfig(ctx, projectRef) 53 if err != nil { 54 return nil, errors.Errorf("failed to retrieve Postgres config overrides: %w", err) 55 } 56 if resp.StatusCode != 200 { 57 return nil, errors.Errorf("error in retrieving Postgres config overrides: %s", resp.Status) 58 } 59 contents, err := io.ReadAll(resp.Body) 60 if err != nil { 61 return nil, errors.Errorf("failed to read response body: %w", err) 62 } 63 64 var config map[string]interface{} 65 err = json.Unmarshal(contents, &config) 66 if err != nil { 67 return nil, errors.Errorf("failed to unmarshal response body: %w. Contents were %s", err, contents) 68 } 69 return config, nil 70 }