• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / cli / 18835102741

27 Oct 2025 08:50AM UTC coverage: 54.703% (-0.03%) from 54.728%
18835102741

Pull #4345

github

web-flow
Merge 76edda1d2 into 64465dd82
Pull Request #4345: chore: sync API types from infrastructure

0 of 2 new or added lines in 2 files covered. (0.0%)

11 existing lines in 3 files now uncovered.

6386 of 11674 relevant lines covered (54.7%)

6.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/internal/branches/get/get.go
1
package get
2

3
import (
4
        "context"
5
        "fmt"
6
        "os"
7

8
        "github.com/go-errors/errors"
9
        "github.com/google/uuid"
10
        "github.com/jackc/pgconn"
11
        "github.com/spf13/afero"
12
        "github.com/supabase/cli/internal/projects/apiKeys"
13
        "github.com/supabase/cli/internal/utils"
14
        "github.com/supabase/cli/internal/utils/flags"
15
        "github.com/supabase/cli/pkg/api"
16
        "github.com/supabase/cli/pkg/cast"
17
)
18

19
func Run(ctx context.Context, branchId string, fsys afero.Fs) error {
×
20
        detail, err := getBranchDetail(ctx, branchId)
×
21
        if err != nil {
×
22
                return err
×
23
        }
×
24

25
        if utils.OutputFormat.Value != utils.OutputPretty {
×
26
                keys, err := apiKeys.RunGetApiKeys(ctx, detail.Ref)
×
27
                if err != nil {
×
28
                        return err
×
29
                }
×
30
                pooler, err := getPoolerConfig(ctx, detail.Ref)
×
31
                if err != nil {
×
32
                        return err
×
33
                }
×
34
                envs := toStandardEnvs(detail, pooler, keys)
×
35
                return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, envs)
×
36
        }
37

38
        table := `|HOST|PORT|USER|PASSWORD|JWT SECRET|POSTGRES VERSION|STATUS|
×
39
|-|-|-|-|-|-|-|
×
40
` + fmt.Sprintf(
×
41
                "|`%s`|`%d`|`%s`|`%s`|`%s`|`%s`|`%s`|\n",
×
42
                detail.DbHost,
×
43
                detail.DbPort,
×
44
                *detail.DbUser,
×
45
                *detail.DbPass,
×
46
                *detail.JwtSecret,
×
47
                detail.PostgresVersion,
×
48
                detail.Status,
×
49
        )
×
50

×
51
        return utils.RenderTable(table)
×
52
}
53

54
func getBranchDetail(ctx context.Context, branchId string) (api.BranchDetailResponse, error) {
×
55
        var result api.BranchDetailResponse
×
56
        if err := uuid.Validate(branchId); err != nil && !utils.ProjectRefPattern.Match([]byte(branchId)) {
×
57
                resp, err := utils.GetSupabase().V1GetABranchWithResponse(ctx, flags.ProjectRef, branchId)
×
58
                if err != nil {
×
59
                        return result, errors.Errorf("failed to find branch: %w", err)
×
60
                } else if resp.JSON200 == nil {
×
61
                        return result, errors.Errorf("unexpected find branch status %d: %s", resp.StatusCode(), string(resp.Body))
×
62
                }
×
63
                branchId = resp.JSON200.ProjectRef
×
64
        }
65
        resp, err := utils.GetSupabase().V1GetABranchConfigWithResponse(ctx, branchId)
×
66
        if err != nil {
×
67
                return result, errors.Errorf("failed to get branch: %w", err)
×
68
        } else if resp.JSON200 == nil {
×
69
                return result, errors.Errorf("unexpected get branch status %d: %s", resp.StatusCode(), string(resp.Body))
×
70
        }
×
71
        masked := "******"
×
72
        if resp.JSON200.DbUser == nil {
×
73
                resp.JSON200.DbUser = &masked
×
74
        }
×
75
        if resp.JSON200.DbPass == nil {
×
76
                resp.JSON200.DbPass = &masked
×
77
        }
×
78
        if resp.JSON200.JwtSecret == nil {
×
79
                resp.JSON200.JwtSecret = &masked
×
80
        }
×
81
        return *resp.JSON200, nil
×
82
}
83

84
func getPoolerConfig(ctx context.Context, ref string) (api.SupavisorConfigResponse, error) {
×
85
        var result api.SupavisorConfigResponse
×
86
        resp, err := utils.GetSupabase().V1GetPoolerConfigWithResponse(ctx, ref)
×
87
        if err != nil {
×
88
                return result, errors.Errorf("failed to get pooler: %w", err)
×
89
        } else if resp.JSON200 == nil {
×
90
                return result, errors.Errorf("unexpected get pooler status %d: %s", resp.StatusCode(), string(resp.Body))
×
91
        }
×
92
        for _, config := range *resp.JSON200 {
×
NEW
93
                if config.DatabaseType == api.SupavisorConfigResponseDatabaseTypePRIMARY {
×
94
                        return config, nil
×
95
                }
×
96
        }
97
        return result, errors.Errorf("primary database not found: %s", ref)
×
98
}
99

100
func toStandardEnvs(detail api.BranchDetailResponse, pooler api.SupavisorConfigResponse, keys []api.ApiKeyResponse) map[string]string {
×
101
        direct := pgconn.Config{
×
102
                Host:     detail.DbHost,
×
103
                Port:     cast.UIntToUInt16(cast.IntToUint(detail.DbPort)),
×
104
                User:     *detail.DbUser,
×
105
                Password: *detail.DbPass,
×
106
                Database: "postgres",
×
107
        }
×
108
        config, err := utils.ParsePoolerURL(pooler.ConnectionString)
×
109
        if err != nil {
×
110
                fmt.Fprintln(os.Stderr, utils.Yellow("WARNING:"), err)
×
111
                config = &direct
×
112
        } else {
×
113
                config.Password = direct.Password
×
114
        }
×
115
        envs := apiKeys.ToEnv(keys)
×
116
        envs["POSTGRES_URL"] = utils.ToPostgresURL(*config)
×
117
        envs["POSTGRES_URL_NON_POOLING"] = utils.ToPostgresURL(direct)
×
118
        envs["SUPABASE_URL"] = "https://" + utils.GetSupabaseHost(detail.Ref)
×
119
        envs["SUPABASE_JWT_SECRET"] = *detail.JwtSecret
×
120
        return envs
×
121
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc