2727import com .google .api .client .http .javanet .NetHttpTransport ;
2828import com .google .auth .http .HttpCredentialsAdapter ;
2929import com .google .common .collect .Iterables ;
30+ import com .google .common .io .Files ;
3031import com .google .gcloud .spi .ServiceRpcFactory ;
3132
3233import java .io .BufferedReader ;
4243import java .lang .reflect .Method ;
4344import java .net .HttpURLConnection ;
4445import java .net .URL ;
46+ import java .nio .charset .Charset ;
4547import java .util .Enumeration ;
4648import java .util .Locale ;
4749import java .util .Objects ;
@@ -381,6 +383,18 @@ protected String defaultProject() {
381383 return projectId != null ? projectId : googleCloudProjectId ();
382384 }
383385
386+ private static String activeGoogleCloudConfig (File configDir ) {
387+ String activeGoogleCloudConfig = null ;
388+ try {
389+ activeGoogleCloudConfig =
390+ Files .readFirstLine (new File (configDir , "active_config" ), Charset .defaultCharset ());
391+ } catch (IOException ex ) {
392+ // ignore
393+ }
394+ // if reading active_config failed or the file is empty we try default
395+ return firstNonNull (activeGoogleCloudConfig , "default" );
396+ }
397+
384398 protected static String googleCloudProjectId () {
385399 File configDir ;
386400 if (System .getenv ().containsKey ("CLOUDSDK_CONFIG" )) {
@@ -390,9 +404,10 @@ protected static String googleCloudProjectId() {
390404 } else {
391405 configDir = new File (System .getProperty ("user.home" ), ".config/gcloud" );
392406 }
407+ String activeConfig = activeGoogleCloudConfig (configDir );
393408 FileReader fileReader = null ;
394409 try {
395- fileReader = new FileReader (new File (configDir , "configurations/config_default" ));
410+ fileReader = new FileReader (new File (configDir , "configurations/config_" + activeConfig ));
396411 } catch (FileNotFoundException newConfigFileNotFoundEx ) {
397412 try {
398413 fileReader = new FileReader (new File (configDir , "properties" ));
0 commit comments