Skip to content

Commit

Permalink
Merge branch 'develop' into avallete/fix-logout-credentials-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
avallete authored Sep 13, 2024
2 parents 8d1b7d2 + 54fa898 commit a27ce15
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 54 deletions.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ func init() {
flags.String("workdir", "", "path to a Supabase project directory")
flags.Bool("experimental", false, "enable experimental features")
flags.String("network-id", "", "use the specified docker network instead of a generated one")
flags.Var(&utils.OutputFormat, "output", "output format of status variables")
flags.Var(&utils.DNSResolver, "dns-resolver", "lookup domain names using the specified resolver")
flags.BoolVar(&createTicket, "create-ticket", false, "create a support ticket for any CLI error")
cobra.CheckErr(viper.BindPFlags(flags))
Expand Down
17 changes: 6 additions & 11 deletions cmd/sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ var (
ssoDomains []string
ssoAddDomains []string
ssoRemoveDomains []string
ssoOutput = utils.EnumFlag{
Allowed: utils.OutputDefaultAllowed,
Value: utils.OutputPretty,
}

ssoAddCmd = &cobra.Command{
Use: "add",
Expand All @@ -47,7 +43,7 @@ var (
return create.Run(cmd.Context(), create.RunParams{
ProjectRef: flags.ProjectRef,
Type: ssoProviderType.String(),
Format: ssoOutput.Value,
Format: utils.OutputFormat.Value,
MetadataFile: ssoMetadataFile,
MetadataURL: ssoMetadataURL,
SkipURLValidation: ssoSkipURLValidation,
Expand All @@ -68,7 +64,7 @@ var (
return errors.Errorf("identity provider ID %q is not a UUID", args[0])
}

return remove.Run(cmd.Context(), flags.ProjectRef, args[0], ssoOutput.Value)
return remove.Run(cmd.Context(), flags.ProjectRef, args[0], utils.OutputFormat.Value)
},
}

Expand All @@ -86,7 +82,7 @@ var (
return update.Run(cmd.Context(), update.RunParams{
ProjectRef: flags.ProjectRef,
ProviderID: args[0],
Format: ssoOutput.Value,
Format: utils.OutputFormat.Value,

MetadataFile: ssoMetadataFile,
MetadataURL: ssoMetadataURL,
Expand All @@ -110,7 +106,7 @@ var (
return errors.Errorf("identity provider ID %q is not a UUID", args[0])
}

format := ssoOutput.Value
format := utils.OutputFormat.Value
if ssoMetadata {
format = utils.OutputMetadata
}
Expand All @@ -125,7 +121,7 @@ var (
Long: "List all connections to a SSO identity provider to your Supabase project.",
Example: ` supabase sso list --project-ref mwjylndxudmiehsxhmmz`,
RunE: func(cmd *cobra.Command, args []string) error {
return list.Run(cmd.Context(), flags.ProjectRef, ssoOutput.Value)
return list.Run(cmd.Context(), flags.ProjectRef, utils.OutputFormat.Value)
},
}

Expand All @@ -135,15 +131,14 @@ var (
Long: "Returns all of the important SSO information necessary for your project to be registered with a SAML 2.0 compatible identity provider.",
Example: ` supabase sso info --project-ref mwjylndxudmiehsxhmmz`,
RunE: func(cmd *cobra.Command, args []string) error {
return info.Run(cmd.Context(), flags.ProjectRef, ssoOutput.Value)
return info.Run(cmd.Context(), flags.ProjectRef, utils.OutputFormat.Value)
},
}
)

func init() {
persistentFlags := ssoCmd.PersistentFlags()
persistentFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
persistentFlags.VarP(&ssoOutput, "output", "o", "Output format")
ssoAddFlags := ssoAddCmd.Flags()
ssoAddFlags.VarP(&ssoProviderType, "type", "t", "Type of identity provider (according to supported protocol).")
ssoAddFlags.StringSliceVar(&ssoDomains, "domains", nil, "Comma separated list of email domains to associate with the added identity provider.")
Expand Down
1 change: 1 addition & 0 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
Allowed: append([]string{utils.OutputEnv}, utils.OutputDefaultAllowed...),
Value: utils.OutputPretty,
}

statusCmd = &cobra.Command{
GroupID: groupLocalDev,
Use: "status",
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/muesli/reflow v0.3.0
github.com/oapi-codegen/runtime v1.1.1
github.com/slack-go/slack v0.13.1
github.com/slack-go/slack v0.14.0
github.com/spf13/afero v1.11.0
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
Expand All @@ -49,11 +49,11 @@ require (
github.com/stripe/pg-schema-diff v0.7.0
github.com/withfig/autocomplete-tools/packages/cobra v1.2.0
github.com/zalando/go-keyring v0.2.5
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel v1.30.0
golang.org/x/mod v0.20.0
golang.org/x/oauth2 v0.23.0
golang.org/x/term v0.24.0
google.golang.org/grpc v1.65.0
google.golang.org/grpc v1.66.2
gopkg.in/yaml.v3 v3.0.1
gotest.tools/gotestsum v1.12.0
)
Expand Down Expand Up @@ -322,10 +322,10 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/sdk v1.28.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,8 @@ github.com/sivchari/tenv v1.7.1 h1:PSpuD4bu6fSmtWMxSGWcvqUUgIn7k3yOJhOIzVWn8Ak=
github.com/sivchari/tenv v1.7.1/go.mod h1:64yStXKSOxDfX47NlhVwND4dHwfZDdbp2Lyl018Icvg=
github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A=
github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
github.com/slack-go/slack v0.13.1 h1:6UkM3U1OnbhPsYeb1IMkQ6HSNOSikWluwOncJt4Tz/o=
github.com/slack-go/slack v0.13.1/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw=
github.com/slack-go/slack v0.14.0 h1:6c0UTfbRnvRssZUsZ2qe0Iu07VAMPjRqOa6oX8ewF4k=
github.com/slack-go/slack v0.14.0/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw=
github.com/sonatard/noctx v0.0.2 h1:L7Dz4De2zDQhW8S0t+KUjY0MAQJd6SgVwhzNIc4ok00=
github.com/sonatard/noctx v0.0.2/go.mod h1:kzFz+CzWSjQ2OzIm46uJZoXuBpa2+0y3T36U18dWqIo=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
Expand Down Expand Up @@ -1028,8 +1028,8 @@ go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw=
go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
go.opentelemetry.io/otel v1.30.0 h1:F2t8sK4qf1fAmY9ua4ohFS/K+FUuOPemHUIXHtktrts=
go.opentelemetry.io/otel v1.30.0/go.mod h1:tFw4Br9b7fOS+uEao81PJjVMjW/5fvNCbpsDIXqP0pc=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0 h1:U2guen0GhqH8o/G2un8f/aG/y++OuW6MyCo6hT9prXk=
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0/go.mod h1:yeGZANgEcpdx/WK0IvvRFC+2oLiMS2u4L/0Rj2M2Qr0=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 h1:3Q/xZUyC1BBkualc9ROb4G8qkH90LXEIICcs5zv1OYY=
Expand All @@ -1038,14 +1038,14 @@ go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 h1:R3X6Z
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0/go.mod h1:QWFXnDavXWwMx2EEcZsf3yxgEKAqsxQ+Syjp+seyInw=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0 h1:j9+03ymgYhPKmeXGk5Zu+cIZOlVzd9Zv7QIiyItjFBU=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0/go.mod h1:Y5+XiUG4Emn1hTfciPzGPJaSI+RpDts6BnCIir0SLqk=
go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q=
go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s=
go.opentelemetry.io/otel/metric v1.30.0 h1:4xNulvn9gjzo4hjg+wzIKG7iNFEaBMX00Qd4QIZs7+w=
go.opentelemetry.io/otel/metric v1.30.0/go.mod h1:aXTfST94tswhWEb+5QjlSqG+cZlmyXy/u8jFpor3WqQ=
go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBqWyE=
go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg=
go.opentelemetry.io/otel/sdk/metric v1.28.0 h1:OkuaKgKrgAbYrrY0t92c+cC+2F6hsFNnCQArXCKlg08=
go.opentelemetry.io/otel/sdk/metric v1.28.0/go.mod h1:cWPjykihLAPvXKi4iZc1dpER3Jdq2Z0YLse3moQUCpg=
go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g=
go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI=
go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc=
go.opentelemetry.io/otel/trace v1.30.0/go.mod h1:5EyKqTzzmyqB9bwtCCq6pDLktPK6fmGf/Dph+8VI02o=
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
Expand Down Expand Up @@ -1479,8 +1479,8 @@ google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKa
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/grpc v1.66.2 h1:3QdXkuq3Bkh7w+ywLdLvM56cmGvQHUMZpiCzt6Rqaoo=
google.golang.org/grpc v1.66.2/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
13 changes: 9 additions & 4 deletions internal/projects/apiKeys/api_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package apiKeys
import (
"context"
"fmt"
"os"
"strings"

"github.com/go-errors/errors"
Expand All @@ -18,14 +19,18 @@ func Run(ctx context.Context, projectRef string, fsys afero.Fs) error {
return err
}

table := `|NAME|KEY VALUE|
if utils.OutputFormat.Value == utils.OutputPretty {
table := `|NAME|KEY VALUE|
|-|-|
`
for _, entry := range keys {
table += fmt.Sprintf("|`%s`|`%s`|\n", strings.ReplaceAll(entry.Name, "|", "\\|"), entry.ApiKey)
for _, entry := range keys {
table += fmt.Sprintf("|`%s`|`%s`|\n", strings.ReplaceAll(entry.Name, "|", "\\|"), entry.ApiKey)
}

return list.RenderTable(table)
}

return list.RenderTable(table)
return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, keys)
}

func RunGetApiKeys(ctx context.Context, projectRef string) ([]api.ApiKeyResponse, error) {
Expand Down
8 changes: 6 additions & 2 deletions internal/projects/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ func Run(ctx context.Context, params api.V1CreateProjectBody, fsys afero.Fs) err
}

projectUrl := fmt.Sprintf("%s/project/%s", utils.GetSupabaseDashboardURL(), resp.JSON201.Id)
fmt.Printf("Created a new project %s at %s\n", utils.Aqua(resp.JSON201.Name), utils.Bold(projectUrl))
return nil
fmt.Fprintf(os.Stderr, "Created a new project %s at %s\n", utils.Aqua(resp.JSON201.Name), utils.Bold(projectUrl))
if utils.OutputFormat.Value == utils.OutputPretty {
return nil
}

return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, resp.JSON201)
}

func printKeyValue(key, value string) string {
Expand Down
70 changes: 48 additions & 22 deletions internal/projects/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ import (
"fmt"
"os"
"strings"
"time"

"github.com/go-errors/errors"
"github.com/spf13/afero"
"github.com/supabase/cli/internal/migration/list"
"github.com/supabase/cli/internal/utils"
"github.com/supabase/cli/internal/utils/flags"
"github.com/supabase/cli/pkg/api"
)

type linkedProject struct {
api.V1ProjectResponse `yaml:",inline"`
Linked bool `json:"linked"`
}

func Run(ctx context.Context, fsys afero.Fs) error {
resp, err := utils.GetSupabase().V1ListAllProjectsWithResponse(ctx)
if err != nil {
Expand All @@ -29,30 +34,51 @@ func Run(ctx context.Context, fsys afero.Fs) error {
fmt.Fprintln(os.Stderr, err)
}

table := `LINKED|ORG ID|REFERENCE ID|NAME|REGION|CREATED AT (UTC)
var projects []linkedProject
for _, project := range *resp.JSON200 {
projects = append(projects, linkedProject{
V1ProjectResponse: project,
Linked: project.Id == projectRef,
})
}

if utils.OutputFormat.Value == utils.OutputPretty {
table := `LINKED|ORG ID|REFERENCE ID|NAME|REGION|CREATED AT (UTC)
|-|-|-|-|-|-|
`
for _, project := range *resp.JSON200 {
if t, err := time.Parse(time.RFC3339, project.CreatedAt); err == nil {
project.CreatedAt = t.UTC().Format("2006-01-02 15:04:05")
}
if region, ok := utils.RegionMap[project.Region]; ok {
project.Region = region
for _, project := range projects {
table += fmt.Sprintf(
"|`%s`|`%s`|`%s`|`%s`|`%s`|`%s`|\n",
formatBullet(project.Linked),
project.OrganizationId,
project.Id,
strings.ReplaceAll(project.Name, "|", "\\|"),
formatRegion(project.Region),
utils.FormatTimestamp(project.CreatedAt),
)
}
linked := " "
if project.Id == projectRef {
linked = " ●"
}
table += fmt.Sprintf(
"|`%s`|`%s`|`%s`|`%s`|`%s`|`%s`|\n",
linked,
project.OrganizationId,
project.Id,
strings.ReplaceAll(project.Name, "|", "\\|"),
project.Region,
utils.FormatTimestamp(project.CreatedAt),
)
return list.RenderTable(table)
} else if utils.OutputFormat.Value == utils.OutputToml {
return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, struct {
Projects []linkedProject `toml:"projects"`
}{
Projects: projects,
})
}

return list.RenderTable(table)
return utils.EncodeOutput(utils.OutputFormat.Value, os.Stdout, projects)
}

func formatBullet(value bool) string {
if value {
return " ●"
}
return " "
}

func formatRegion(region string) string {
if readable, ok := utils.RegionMap[region]; ok {
return readable
}
return region
}
5 changes: 5 additions & 0 deletions internal/utils/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ var (
OutputToml,
OutputYaml,
}

OutputFormat = EnumFlag{
Allowed: OutputDefaultAllowed,
Value: OutputPretty,
}
)

func EncodeOutput(format string, w io.Writer, value any) error {
Expand Down

0 comments on commit a27ce15

Please sign in to comment.