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

supabase / cli / 13566973930

27 Feb 2025 12:59PM UTC coverage: 57.945% (-0.3%) from 58.218%
13566973930

push

github

sweatybridge
chore: dudupe output flag for gen keys

7811 of 13480 relevant lines covered (57.95%)

199.88 hits per line

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

66.67
/internal/projects/apiKeys/api_keys.go
1
package apiKeys
2

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

9
        "github.com/go-errors/errors"
10
        "github.com/spf13/afero"
11
        "github.com/supabase/cli/internal/migration/list"
12
        "github.com/supabase/cli/internal/utils"
13
        "github.com/supabase/cli/pkg/api"
14
)
15

16
func Run(ctx context.Context, projectRef string, fsys afero.Fs) error {
3✔
17
        keys, err := RunGetApiKeys(ctx, projectRef)
3✔
18
        if err != nil {
5✔
19
                return err
2✔
20
        }
2✔
21

22
        switch utils.OutputFormat.Value {
1✔
23
        case utils.OutputPretty:
1✔
24
                table := `|NAME|KEY VALUE|
1✔
25
|-|-|
1✔
26
`
1✔
27
                for _, entry := range keys {
2✔
28
                        table += fmt.Sprintf("|`%s`|`%s`|\n", strings.ReplaceAll(entry.Name, "|", "\\|"), entry.ApiKey)
1✔
29
                }
1✔
30

31
                return list.RenderTable(table)
1✔
32
        case utils.OutputToml, utils.OutputEnv:
×
33
                return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, ToEnv(keys))
×
34
        }
35

36
        return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, keys)
×
37
}
38

39
func RunGetApiKeys(ctx context.Context, projectRef string) ([]api.ApiKeyResponse, error) {
3✔
40
        resp, err := utils.GetSupabase().V1GetProjectApiKeysWithResponse(ctx, projectRef, &api.V1GetProjectApiKeysParams{})
3✔
41
        if err != nil {
4✔
42
                return nil, errors.Errorf("failed to get api keys: %w", err)
1✔
43
        } else if resp.JSON200 == nil {
4✔
44
                return nil, errors.Errorf("unexpected get api keys status %d: %s", resp.StatusCode(), string(resp.Body))
1✔
45
        }
1✔
46
        return *resp.JSON200, nil
1✔
47
}
48

49
func ToEnv(keys []api.ApiKeyResponse) map[string]string {
×
50
        envs := make(map[string]string, len(keys))
×
51
        for _, entry := range keys {
×
52
                name := strings.ToUpper(entry.Name)
×
53
                key := fmt.Sprintf("SUPABASE_%s_KEY", name)
×
54
                envs[key] = entry.ApiKey
×
55
        }
×
56
        return envs
×
57
}
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

© 2026 Coveralls, Inc