Skip to content

Commit 3d7bb3e

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 943 b: refs/heads/master c: e1a50bc h: refs/heads/master i: 941: bc8f135 939: 155639f 935: 7bccad7 927: a5f39c0 v: v3
1 parent 497283b commit 3d7bb3e

9 files changed

Lines changed: 45 additions & 90 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: d8478d7f445682488bcfc60a57be392e299146a1
2+
refs/heads/master: e1a50bc0063c25a4bfa729c8b305f06e061f0497
33
refs/heads/travis: 0fa997e2fc9c6b61b2d91e6d163655aae67d44b6
44
refs/heads/gh-pages: 5a10432ecc75f29812e33a8236c900379509fe99

trunk/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/package-info.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
import org.json.JSONObject;
4141
import org.json.JSONTokener;
4242

43+
import java.net.InetAddress;
44+
import java.net.MalformedURLException;
45+
import java.net.URL;
46+
import java.net.UnknownHostException;
4347
import java.util.HashMap;
4448
import java.util.Map;
4549

@@ -62,14 +66,48 @@ public class DefaultDatastoreRpc implements DatastoreRpc {
6266
}
6367

6468
public DefaultDatastoreRpc(DatastoreOptions options) {
69+
String normalizedHost = normalizeHost(options.host());
6570
client = DatastoreFactory.get().create(
6671
new Builder()
6772
.dataset(options.projectId())
68-
.host(options.host())
73+
.host(normalizedHost)
6974
.initializer(options.httpRequestInitializer())
7075
.build());
7176
}
7277

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

trunk/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreOptionsTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static org.junit.Assert.assertSame;
2323
import static org.junit.Assert.assertTrue;
2424

25-
import com.google.gcloud.datastore.testing.LocalGcdHelper;
2625
import com.google.gcloud.spi.DatastoreRpc;
2726
import com.google.gcloud.spi.DatastoreRpcFactory;
2827

trunk/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import com.google.gcloud.datastore.StructuredQuery.OrderBy;
3434
import com.google.gcloud.datastore.StructuredQuery.Projection;
3535
import com.google.gcloud.datastore.StructuredQuery.PropertyFilter;
36-
import com.google.gcloud.datastore.testing.LocalGcdHelper;
3736
import com.google.gcloud.spi.DatastoreRpc;
3837
import com.google.gcloud.spi.DatastoreRpc.DatastoreRpcException.Reason;
3938
import com.google.gcloud.spi.DatastoreRpcFactory;

trunk/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/LocalGcdHelper.java renamed to trunk/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.gcloud.datastore.testing;
17+
package com.google.gcloud.datastore;
1818

1919
import static java.nio.charset.StandardCharsets.UTF_8;
2020

trunk/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/package-info.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import static org.junit.Assert.fail;
2525

2626
import com.google.common.collect.ImmutableList;
27-
import com.google.gcloud.storage.testing.RemoteGcsHelper;
2827

2928
import java.io.ByteArrayInputStream;
3029
import java.io.IOException;

trunk/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java renamed to trunk/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelper.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.gcloud.storage.testing;
17+
package com.google.gcloud.storage;
1818

1919
import com.google.common.collect.ImmutableMap;
2020
import com.google.gcloud.AuthCredentials;
21-
import com.google.gcloud.storage.BlobInfo;
22-
import com.google.gcloud.storage.Storage;
23-
import com.google.gcloud.storage.StorageException;
24-
import com.google.gcloud.storage.StorageOptions;
25-
import com.google.gcloud.storage.testing.RemoteGcsHelper.Option.KeyFromClasspath;
21+
import com.google.gcloud.storage.RemoteGcsHelper.Option.KeyFromClasspath;
2622

2723
import java.io.FileInputStream;
2824
import java.io.FileNotFoundException;
@@ -57,7 +53,7 @@ private RemoteGcsHelper(StorageOptions options) {
5753
}
5854

5955
/**
60-
* Returns a {@link StorageOptions} object to be used for testing.
56+
* Returns a {@StorageOptions} object to be used for testing.
6157
*/
6258
public StorageOptions options() {
6359
return options;
@@ -100,7 +96,7 @@ public static String generateBucketName() {
10096
*
10197
* @param options creation options
10298
* @return A {@code RemoteGcsHelper} object for the provided options.
103-
* @throws com.google.gcloud.storage.testing.RemoteGcsHelper.GcsHelperException if environment variables
99+
* @throws com.google.gcloud.storage.RemoteGcsHelper.GcsHelperException if environment variables
104100
* {@code GCLOUD_TESTS_PROJECT_ID} and {@code GCLOUD_TESTS_KEY} are not set or if the file
105101
* pointed by {@code GCLOUD_TESTS_KEY} does not exist
106102
*/

0 commit comments

Comments
 (0)