Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 61b4181

Browse files
authored
fix(sg): provide suggestions we fail to get local gcp account email address (#64325)
Part of sourcegraph/devx-support#1142 If we fail to get the gcp address, provide steps the user can try to fix it ![Screenshot 2024-08-07 at 10 14 00](https://github.com/user-attachments/assets/39e6fdcb-ee60-43b8-bdca-d28a9d210b2e) ## Test plan Tested locally ## Changelog sg - provide steps a user can follow if we fail to get the local gcp email address
1 parent e1e7898 commit 61b4181

File tree

9 files changed

+19
-6
lines changed

9 files changed

+19
-6
lines changed

dev/sg/internal/cloud/client.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ func NewDeploymentSpec(name, version, license string) *DeploymentSpec {
6161
}
6262
}
6363

64-
func GetGCloudAccount(ctx context.Context) (string, error) {
65-
return run.Cmd(ctx, "gcloud config get account").Run().String()
66-
}
67-
6864
func NewClient(ctx context.Context, email, endpoint string) (*Client, error) {
6965
// have to use IDENTITY token not ACCESS token!
7066
token, err := run.Cmd(ctx, "gcloud auth print-identity-token").Run().String()

dev/sg/internal/cloud/common.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/sourcegraph/run"
99

1010
"github.com/sourcegraph/sourcegraph/dev/sg/internal/repo"
11+
"github.com/sourcegraph/sourcegraph/dev/sg/internal/std"
1112
"github.com/sourcegraph/sourcegraph/lib/errors"
1213
)
1314

@@ -52,6 +53,15 @@ func oneOfEquals(value string, i ...string) bool {
5253
return false
5354
}
5455

55-
func getGCloudAccount(ctx context.Context) (string, error) {
56-
return run.Cmd(ctx, "gcloud", "config", "get", "account").Run().String()
56+
func GetGCloudAccount(ctx context.Context) (string, error) {
57+
return run.Cmd(ctx, "gcloud", "auth", "list", "--filter", "status:ACTIVE", "--format", "value(account)").Run().String()
58+
}
59+
60+
func writeGCloudErrorSuggestion() {
61+
msg := "Failed to determine your gcloud account to get your email address. This might indicate that there is a problem with your local gcloud configuration"
62+
suggestion := "Try the following steps:\n"
63+
suggestion += "1. `gcloud auth login` should open a browser window and prompt you to log in with your Google account - ensure you login with your sourcegraph address!\n"
64+
suggestion += "\nIf the steps above don't work please reach out to #discuss-dev-infra\n"
65+
std.Out.WriteWarningf(msg)
66+
std.Out.WriteMarkdown(withFAQ(suggestion))
5767
}

dev/sg/internal/cloud/dashboard_command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var opsDashboardEphemeralCommand = cli.Command{
3939
func showCloudEphemeralOps(ctx *cli.Context) error {
4040
email, err := GetGCloudAccount(ctx.Context)
4141
if err != nil {
42+
writeGCloudErrorSuggestion()
4243
return err
4344
}
4445

dev/sg/internal/cloud/delete_command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var deleteEphemeralCommand = cli.Command{
2828
func deleteCloudEphemeral(ctx *cli.Context) error {
2929
email, err := GetGCloudAccount(ctx.Context)
3030
if err != nil {
31+
writeGCloudErrorSuggestion()
3132
return err
3233
}
3334

dev/sg/internal/cloud/deploy_command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ Please make sure you have either pushed or pulled the latest changes before tryi
261261
}
262262
email, err := GetGCloudAccount(ctx.Context)
263263
if err != nil {
264+
writeGCloudErrorSuggestion()
264265
return err
265266
}
266267

dev/sg/internal/cloud/lease_command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func calcLeaseEnd(currentLeaseTime time.Time, extension, reduction time.Duration
7171
func leaseCloudEphemeral(ctx *cli.Context) error {
7272
email, err := GetGCloudAccount(ctx.Context)
7373
if err != nil {
74+
writeGCloudErrorSuggestion()
7475
return err
7576
}
7677

dev/sg/internal/cloud/list_command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var listEphemeralCommand = cli.Command{
3535
func listCloudEphemeral(ctx *cli.Context) error {
3636
email, err := GetGCloudAccount(ctx.Context)
3737
if err != nil {
38+
writeGCloudErrorSuggestion()
3839
return err
3940
}
4041

dev/sg/internal/cloud/status_command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var statusEphemeralCommand = cli.Command{
3636
func statusCloudEphemeral(ctx *cli.Context) error {
3737
email, err := GetGCloudAccount(ctx.Context)
3838
if err != nil {
39+
writeGCloudErrorSuggestion()
3940
return err
4041
}
4142

dev/sg/internal/cloud/upgrade_command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func upgradeCloudEphemeral(ctx *cli.Context) error {
9292
}
9393
email, err := GetGCloudAccount(ctx.Context)
9494
if err != nil {
95+
writeGCloudErrorSuggestion()
9596
return err
9697
}
9798
deploymentName := determineDeploymentName(ctx.String("name"), version, email, currentBranch)

0 commit comments

Comments
 (0)