@@ -81,10 +81,9 @@ can be removed automatically by this program.`)
8181 token = flag .String ("token" , "" , "When set, the proxy uses this Bearer token for authorization." )
8282 tokenFile = flag .String ("credential_file" , "" , `If provided, this json file will be used to retrieve Service Account credentials.
8383You may set the GOOGLE_APPLICATION_CREDENTIALS environment variable for the same effect.` )
84-
85- // Set when gcloud execution failed.
86- gcloudErrStr string
8784
85+ // Set when gcloud execution failed.
86+ gcloudErrStr string
8887)
8988
9089const (
@@ -332,36 +331,36 @@ func listInstances(ctx context.Context, cl *http.Client, projects []string) ([]s
332331}
333332
334333func gcloudProject () []string {
335- const gcloudResultErrStr = "gcloud failed to get project list. See log for detail."
336- buf := new (bytes.Buffer )
337- cmd := exec .Command ("gcloud" , "--format" , "json" , "config" , "list" , "core/project" )
338- cmd .Stdout = buf
339-
340- if err := cmd .Run (); err != nil {
341- if strings .Contains (err .Error (), "executable file not found" ) {
342- gcloudErrStr = "gcloud could not be found in the system path"
343- return nil
344- }
345- gcloudErrStr = gcloudResultErrStr
346- logging .Errorf ("Error detecting gcloud project: %v" , err )
347- return nil
348- }
349-
350- var data struct {
351- Core struct {
352- Project string
353- }
354- }
355-
356- if err := json .Unmarshal (buf .Bytes (), & data ); err != nil {
357- gcloudErrStr = gcloudResultErrStr
358- logging .Errorf ("Failed to unmarshal bytes from gcloud: %v" , err )
359- logging .Errorf (" gcloud returned:\n %s" , buf )
360- return nil
361- }
362-
363- logging .Infof ("Using gcloud's active project: %v" , data .Core .Project )
364- return []string {data .Core .Project }
334+ const gcloudResultErrStr = "gcloud failed to get project list. See log for detail."
335+ buf := new (bytes.Buffer )
336+ cmd := exec .Command ("gcloud" , "--format" , "json" , "config" , "list" , "core/project" )
337+ cmd .Stdout = buf
338+
339+ if err := cmd .Run (); err != nil {
340+ if strings .Contains (err .Error (), "executable file not found" ) {
341+ gcloudErrStr = "gcloud could not be found in the system path"
342+ return nil
343+ }
344+ gcloudErrStr = gcloudResultErrStr
345+ logging .Errorf ("Error detecting gcloud project: %v" , err )
346+ return nil
347+ }
348+
349+ var data struct {
350+ Core struct {
351+ Project string
352+ }
353+ }
354+
355+ if err := json .Unmarshal (buf .Bytes (), & data ); err != nil {
356+ gcloudErrStr = gcloudResultErrStr
357+ logging .Errorf ("Failed to unmarshal bytes from gcloud: %v" , err )
358+ logging .Errorf (" gcloud returned:\n %s" , buf )
359+ return nil
360+ }
361+
362+ logging .Infof ("Using gcloud's active project: %v" , data .Core .Project )
363+ return []string {data .Core .Project }
365364}
366365
367366// Main executes the main function of the proxy, allowing it to be called from tests.
0 commit comments