Skip to content

Commit dae43e9

Browse files
committed
---
yaml --- r: 949 b: refs/heads/master c: c23b9a2 h: refs/heads/master i: 947: 8cf8e62 v: v3
1 parent fc7c579 commit dae43e9

4 files changed

Lines changed: 27 additions & 81 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
2-
refs/heads/master: 234f96414d6c404f09b752cf3cb2f714439ddb80
2+
refs/heads/master: c23b9a230a34af229d2bde99036a2bcd64505b04
33
refs/heads/travis: 0fa997e2fc9c6b61b2d91e6d163655aae67d44b6
44
refs/heads/gh-pages: 5a10432ecc75f29812e33a8236c900379509fe99

trunk/gcloud-java-datastore/src/main/java/com/google/gcloud/spi/DefaultDatastoreRpc.java

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.google.api.services.datastore.client.DatastoreException;
3333
import com.google.api.services.datastore.client.DatastoreFactory;
3434
import com.google.api.services.datastore.client.DatastoreOptions.Builder;
35-
import com.google.common.base.Preconditions;
3635
import com.google.common.collect.ImmutableMap;
3736
import com.google.gcloud.datastore.DatastoreOptions;
3837
import com.google.gcloud.spi.DatastoreRpc.DatastoreRpcException.Reason;
@@ -41,10 +40,6 @@
4140
import org.json.JSONObject;
4241
import org.json.JSONTokener;
4342

44-
import java.net.InetAddress;
45-
import java.net.MalformedURLException;
46-
import java.net.URL;
47-
import java.net.UnknownHostException;
4843
import java.util.HashMap;
4944
import java.util.Map;
5045

@@ -67,45 +62,14 @@ public class DefaultDatastoreRpc implements DatastoreRpc {
6762
}
6863

6964
public DefaultDatastoreRpc(DatastoreOptions options) {
70-
String normalizedHost = normalizeHost(options.host());
7165
client = DatastoreFactory.get().create(
7266
new Builder()
7367
.dataset(options.projectId())
74-
.host(normalizedHost)
68+
.host(options.host())
7569
.initializer(options.httpRequestInitializer())
7670
.build());
7771
}
7872

79-
private static String normalizeHost(String host) {
80-
host = host.toLowerCase();
81-
if (includesScheme(host)) {
82-
Preconditions.checkArgument(!(host.startsWith("https://") && isLocalHost(host)),
83-
"\"https\" is not supported for localhost. Use \"http\" instead.");
84-
return host;
85-
}
86-
return "http://" + host;
87-
}
88-
89-
private static boolean isLocalHost(String host) {
90-
if (host != null) {
91-
try {
92-
String normalizedHost = host;
93-
if (!includesScheme(normalizedHost)) {
94-
normalizedHost = "http://" + normalizedHost;
95-
}
96-
InetAddress hostAddr = InetAddress.getByName(new URL(normalizedHost).getHost());
97-
return hostAddr.isAnyLocalAddress() || hostAddr.isLoopbackAddress();
98-
} catch (UnknownHostException | MalformedURLException e) {
99-
// ignore
100-
}
101-
}
102-
return false;
103-
}
104-
105-
private static boolean includesScheme(String url) {
106-
return url.startsWith("http://") || url.startsWith("https://");
107-
}
108-
10973
private static DatastoreRpcException translate(DatastoreException exception) {
11074
String message = exception.getMessage();
11175
String reasonStr = "";

trunk/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static void beforeClass() {
6666
@AfterClass
6767
public static void afterClass()
6868
throws ExecutionException, TimeoutException, InterruptedException {
69-
if (!RemoteGcsHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS)) {
69+
if (storage != null && !RemoteGcsHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS)) {
7070
if (log.isLoggable(Level.WARNING)) {
7171
log.log(Level.WARNING, "Deletion of bucket {0} timed out, bucket is not empty", bucket);
7272
}

trunk/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelper.java

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import com.google.common.collect.ImmutableMap;
2020
import com.google.gcloud.AuthCredentials;
21-
import com.google.gcloud.RetryParams;
2221
import com.google.gcloud.storage.RemoteGcsHelper.Option.KeyFromClasspath;
2322

2423
import java.io.FileInputStream;
@@ -93,37 +92,50 @@ public static String generateBucketName() {
9392
}
9493

9594
/**
96-
* Creates a {@code RemoteGcsHelper} object for the given project id and JSON key path.
95+
* Creates a {@code RemoteGcsHelper} object.
9796
*
98-
* @param projectId id of the project to be used for running the tests
99-
* @param keyPath path to the JSON key to be used for running the tests
10097
* @param options creation options
10198
* @return A {@code RemoteGcsHelper} object for the provided options.
102-
* @throws com.google.gcloud.storage.RemoteGcsHelper.GcsHelperException if the file pointed by
103-
* {@code keyPath} does not exist
99+
* @throws com.google.gcloud.storage.RemoteGcsHelper.GcsHelperException if environment variables
100+
* {@code GCLOUD_TESTS_PROJECT_ID} and {@code GCLOUD_TESTS_KEY} are not set or if the file
101+
* pointed by {@code GCLOUD_TESTS_KEY} does not exist
104102
*/
105-
public static RemoteGcsHelper create(String projectId, String keyPath, Option... options)
106-
throws GcsHelperException {
103+
public static RemoteGcsHelper create(Option... options) throws GcsHelperException {
107104
boolean keyFromClassPath = false;
108105
Map<Class<? extends Option>, Option> optionsMap = Option.asImmutableMap(options);
109106
if (optionsMap.containsKey(KeyFromClasspath.class)) {
110107
keyFromClassPath =
111108
((KeyFromClasspath) optionsMap.get(KeyFromClasspath.class)).keyFromClasspath();
112109
}
110+
String projectId = System.getenv(PROJECT_ID_ENV_VAR);
111+
String stringKeyPath = System.getenv(PRIVATE_KEY_ENV_VAR);
112+
if (projectId == null) {
113+
String message = "Environment variable " + PROJECT_ID_ENV_VAR + " not set";
114+
if (log.isLoggable(Level.WARNING)) {
115+
log.log(Level.WARNING, message);
116+
}
117+
throw new GcsHelperException(message);
118+
}
119+
if (stringKeyPath == null) {
120+
String message = "Environment variable " + PRIVATE_KEY_ENV_VAR + " not set";
121+
if (log.isLoggable(Level.WARNING)) {
122+
log.log(Level.WARNING, message);
123+
}
124+
throw new GcsHelperException(message);
125+
}
113126
try {
114127
InputStream keyFileStream;
115128
if (keyFromClassPath) {
116-
keyFileStream = RemoteGcsHelper.class.getResourceAsStream(keyPath);
129+
keyFileStream = RemoteGcsHelper.class.getResourceAsStream(stringKeyPath);
117130
if (keyFileStream == null) {
118-
throw new FileNotFoundException(keyPath + " not found in classpath");
131+
throw new FileNotFoundException(stringKeyPath + " not found in classpath");
119132
}
120133
} else {
121-
keyFileStream = new FileInputStream(keyPath);
134+
keyFileStream = new FileInputStream(stringKeyPath);
122135
}
123136
StorageOptions storageOptions = StorageOptions.builder()
124137
.authCredentials(AuthCredentials.createForJson(keyFileStream))
125138
.projectId(projectId)
126-
.retryParams(RetryParams.getDefaultInstance())
127139
.build();
128140
return new RemoteGcsHelper(storageOptions);
129141
} catch (FileNotFoundException ex) {
@@ -139,36 +151,6 @@ public static RemoteGcsHelper create(String projectId, String keyPath, Option...
139151
}
140152
}
141153

142-
/**
143-
* Creates a {@code RemoteGcsHelper} object. Project id and path to JSON key are read from two
144-
* environment variables: {@code GCLOUD_TESTS_PROJECT_ID} and {@code GCLOUD_TESTS_KEY}.
145-
*
146-
* @param options creation options
147-
* @return A {@code RemoteGcsHelper} object for the provided options.
148-
* @throws com.google.gcloud.storage.RemoteGcsHelper.GcsHelperException if environment variables
149-
* {@code GCLOUD_TESTS_PROJECT_ID} and {@code GCLOUD_TESTS_KEY} are not set or if the file
150-
* pointed by {@code GCLOUD_TESTS_KEY} does not exist
151-
*/
152-
public static RemoteGcsHelper create(Option... options) throws GcsHelperException {
153-
String projectId = System.getenv(PROJECT_ID_ENV_VAR);
154-
String keyPath = System.getenv(PRIVATE_KEY_ENV_VAR);
155-
if (projectId == null) {
156-
String message = "Environment variable " + PROJECT_ID_ENV_VAR + " not set";
157-
if (log.isLoggable(Level.WARNING)) {
158-
log.log(Level.WARNING, message);
159-
}
160-
throw new GcsHelperException(message);
161-
}
162-
if (keyPath == null) {
163-
String message = "Environment variable " + PRIVATE_KEY_ENV_VAR + " not set";
164-
if (log.isLoggable(Level.WARNING)) {
165-
log.log(Level.WARNING, message);
166-
}
167-
throw new GcsHelperException(message);
168-
}
169-
return create(projectId, keyPath, options);
170-
}
171-
172154
private static class DeleteBucketTask implements Callable<Boolean> {
173155

174156
private Storage storage;

0 commit comments

Comments
 (0)