@@ -109,12 +109,6 @@ public HttpTransport create() {
109109 // Maybe not on App Engine
110110 }
111111 }
112- // Consider Compute
113- try {
114- return AuthCredentials .getComputeCredential ().getTransport ();
115- } catch (Exception e ) {
116- // Maybe not on GCE
117- }
118112 return new NetHttpTransport ();
119113 }
120114 }
@@ -342,7 +336,7 @@ protected boolean projectIdRequired() {
342336 }
343337
344338 private static AuthCredentials defaultAuthCredentials () {
345- // Consider App Engine. This will not be needed once issue #21 is fixed.
339+ // Consider App Engine.
346340 if (appEngineAppId () != null ) {
347341 try {
348342 return AuthCredentials .createForAppEngine ();
@@ -354,16 +348,8 @@ private static AuthCredentials defaultAuthCredentials() {
354348 try {
355349 return AuthCredentials .createApplicationDefaults ();
356350 } catch (Exception ex ) {
357- // fallback to old-style
351+ return AuthCredentials . noCredentials ();
358352 }
359-
360- // Consider old-style Compute. This will not be needed once issue #21 is fixed.
361- try {
362- return AuthCredentials .createForComputeEngine ();
363- } catch (Exception ignore ) {
364- // Maybe not on GCE
365- }
366- return AuthCredentials .noCredentials ();
367353 }
368354
369355 protected static String appEngineAppId () {
@@ -383,19 +369,6 @@ protected String defaultProject() {
383369 }
384370
385371 protected static String googleCloudProjectId () {
386- try {
387- URL url = new URL ("http://metadata/computeMetadata/v1/project/project-id" );
388- HttpURLConnection connection = (HttpURLConnection ) url .openConnection ();
389- connection .setRequestProperty ("X-Google-Metadata-Request" , "True" );
390- InputStream input = connection .getInputStream ();
391- if (connection .getResponseCode () == 200 ) {
392- try (BufferedReader reader = new BufferedReader (new InputStreamReader (input , UTF_8 ))) {
393- return reader .readLine ();
394- }
395- }
396- } catch (IOException ignore ) {
397- // ignore
398- }
399372 File configDir ;
400373 if (System .getenv ().containsKey ("CLOUDSDK_CONFIG" )) {
401374 configDir = new File (System .getenv ("CLOUDSDK_CONFIG" ));
@@ -404,38 +377,52 @@ protected static String googleCloudProjectId() {
404377 } else {
405378 configDir = new File (System .getProperty ("user.home" ), ".config/gcloud" );
406379 }
407- FileReader fileReader ;
380+ FileReader fileReader = null ;
408381 try {
409382 fileReader = new FileReader (new File (configDir , "configurations/config_default" ));
410383 } catch (FileNotFoundException newConfigFileNotFoundEx ) {
411384 try {
412385 fileReader = new FileReader (new File (configDir , "properties" ));
413386 } catch (FileNotFoundException oldConfigFileNotFoundEx ) {
414- // return null if we can't find config file
415- return null ;
387+ // ignore
416388 }
417389 }
418- try (BufferedReader reader = new BufferedReader (fileReader )) {
419- String line ;
420- String section = null ;
421- Pattern projectPattern = Pattern .compile ("^project\\ s*=\\ s*(.*)$" );
422- Pattern sectionPattern = Pattern .compile ("^\\ [(.*)\\ ]$" );
423- while ((line = reader .readLine ()) != null ) {
424- if (line .isEmpty () || line .startsWith (";" )) {
425- continue ;
426- }
427- line = line .trim ();
428- Matcher matcher = sectionPattern .matcher (line );
429- if (matcher .matches ()) {
430- section = matcher .group (1 );
431- } else if (section == null || section .equals ("core" )) {
432- matcher = projectPattern .matcher (line );
390+ if (fileReader != null ) {
391+ try (BufferedReader reader = new BufferedReader (fileReader )) {
392+ String line ;
393+ String section = null ;
394+ Pattern projectPattern = Pattern .compile ("^project\\ s*=\\ s*(.*)$" );
395+ Pattern sectionPattern = Pattern .compile ("^\\ [(.*)\\ ]$" );
396+ while ((line = reader .readLine ()) != null ) {
397+ if (line .isEmpty () || line .startsWith (";" )) {
398+ continue ;
399+ }
400+ line = line .trim ();
401+ Matcher matcher = sectionPattern .matcher (line );
433402 if (matcher .matches ()) {
434- return matcher .group (1 );
403+ section = matcher .group (1 );
404+ } else if (section == null || section .equals ("core" )) {
405+ matcher = projectPattern .matcher (line );
406+ if (matcher .matches ()) {
407+ return matcher .group (1 );
408+ }
435409 }
436410 }
411+ } catch (IOException ex ) {
412+ // ignore
413+ }
414+ }
415+ try {
416+ URL url = new URL ("http://metadata/computeMetadata/v1/project/project-id" );
417+ HttpURLConnection connection = (HttpURLConnection ) url .openConnection ();
418+ connection .setRequestProperty ("X-Google-Metadata-Request" , "True" );
419+ InputStream input = connection .getInputStream ();
420+ if (connection .getResponseCode () == 200 ) {
421+ try (BufferedReader reader = new BufferedReader (new InputStreamReader (input , UTF_8 ))) {
422+ return reader .readLine ();
423+ }
437424 }
438- } catch (IOException ex ) {
425+ } catch (IOException ignore ) {
439426 // ignore
440427 }
441428 // return null if can't determine
0 commit comments