Skip to content

Commit 27c66f0

Browse files
committed
---
yaml --- r: 7113 b: refs/heads/tswast-patch-1 c: 5fea95f h: refs/heads/master i: 7111: b41d42b
1 parent 5c87892 commit 27c66f0

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: 8df138b0aba5dbfa0a5b8dc07a1dc6541b4d2bac
60+
refs/heads/tswast-patch-1: 5fea95fcd9f7d98aa7ff682664686fa06321f07a
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.api.client.http.javanet.NetHttpTransport;
2828
import com.google.auth.http.HttpCredentialsAdapter;
2929
import com.google.common.collect.Iterables;
30+
import com.google.common.io.Files;
3031
import com.google.gcloud.spi.ServiceRpcFactory;
3132

3233
import java.io.BufferedReader;
@@ -42,6 +43,7 @@
4243
import java.lang.reflect.Method;
4344
import java.net.HttpURLConnection;
4445
import java.net.URL;
46+
import java.nio.charset.Charset;
4547
import java.util.Enumeration;
4648
import java.util.Locale;
4749
import 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

Comments
 (0)