forked from googleapis/java-datastore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: LocalDatastoreHelper uses DATASTORE_EMULATOR_URL and ACCESS_TOKE…
…N environment variables values if provided Fixes googleapis#376
- Loading branch information
1 parent
1651b88
commit 386cd84
Showing
20 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
handlers = java.util.logging.ConsoleHandler | ||
.level = FINE | ||
java.util.logging.ConsoleHandler.level = FINE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+128 KB
...d-datastore/repo/com/google/cloud/google-cloud-core/1.94.11/google-cloud-core-1.94.11.jar
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...tastore/repo/com/google/cloud/google-cloud-core/1.94.11/google-cloud-core-1.94.11.jar.md5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
e40a2fb462bb524f00c714c26e560c64 |
1 change: 1 addition & 0 deletions
1
...astore/repo/com/google/cloud/google-cloud-core/1.94.11/google-cloud-core-1.94.11.jar.sha1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
baba77a593a13ad92390c4c307c7f088d2531b07 |
8 changes: 8 additions & 0 deletions
8
...d-datastore/repo/com/google/cloud/google-cloud-core/1.94.11/google-cloud-core-1.94.11.pom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>google-cloud-core</artifactId> | ||
<version>1.94.11</version> | ||
</project> |
1 change: 1 addition & 0 deletions
1
...tastore/repo/com/google/cloud/google-cloud-core/1.94.11/google-cloud-core-1.94.11.pom.md5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
092229fa201870319488320a99d0e14f |
1 change: 1 addition & 0 deletions
1
...astore/repo/com/google/cloud/google-cloud-core/1.94.11/google-cloud-core-1.94.11.pom.sha1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
140b944ab02619f6a42bfe0857fed565f2b227d2 |
Binary file added
BIN
+128 KB
...oud-datastore/repo/com/google/cloud/google-cloud-core/1.94.9/google-cloud-core-1.94.9.jar
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...datastore/repo/com/google/cloud/google-cloud-core/1.94.9/google-cloud-core-1.94.9.jar.md5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a57f5515c93ae5a848e05be96666eab1 |
1 change: 1 addition & 0 deletions
1
...atastore/repo/com/google/cloud/google-cloud-core/1.94.9/google-cloud-core-1.94.9.jar.sha1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
c8981b05e1f3415429827a2002e61b40672cf44f |
8 changes: 8 additions & 0 deletions
8
...oud-datastore/repo/com/google/cloud/google-cloud-core/1.94.9/google-cloud-core-1.94.9.pom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>google-cloud-core</artifactId> | ||
<version>1.94.9</version> | ||
</project> |
1 change: 1 addition & 0 deletions
1
...datastore/repo/com/google/cloud/google-cloud-core/1.94.9/google-cloud-core-1.94.9.pom.md5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a86a2939b39da47efb639be335f4a375 |
1 change: 1 addition & 0 deletions
1
...atastore/repo/com/google/cloud/google-cloud-core/1.94.9/google-cloud-core-1.94.9.pom.sha1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7ce264115cd6c8070d5cd06c943d7128b18a7234 |
14 changes: 14 additions & 0 deletions
14
google-cloud-datastore/repo/com/google/cloud/google-cloud-core/maven-metadata.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<metadata> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>google-cloud-core</artifactId> | ||
<versioning> | ||
<release>1.94.11</release> | ||
<versions> | ||
<version>1.94.9</version> | ||
<version>1.94.10</version> | ||
<version>1.94.11</version> | ||
</versions> | ||
<lastUpdated>20210509194813</lastUpdated> | ||
</versioning> | ||
</metadata> |
1 change: 1 addition & 0 deletions
1
google-cloud-datastore/repo/com/google/cloud/google-cloud-core/maven-metadata.xml.md5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
f49ad83269869787d14e8b418c6fb867 |
1 change: 1 addition & 0 deletions
1
google-cloud-datastore/repo/com/google/cloud/google-cloud-core/maven-metadata.xml.sha1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
d52675b5566c14311f7a890df8862b0901556cf1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
google-cloud-datastore/src/test/java/com/google/cloud/datastore/EmulatorDownloadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.datastore; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import com.google.auth.oauth2.GoogleCredentials; | ||
import com.google.cloud.datastore.testing.LocalDatastoreHelper; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.net.URL; | ||
import java.net.URLConnection; | ||
import java.nio.channels.Channels; | ||
import java.nio.channels.ReadableByteChannel; | ||
import java.util.logging.Logger; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
public class EmulatorDownloadTest { | ||
private static final Logger LOGGER = Logger.getLogger(EmulatorDownloadTest.class.getName()); | ||
|
||
@Test | ||
public void testLDHEmulatorDownloadWithAuth() throws Exception { | ||
assertNotNull(System.getenv("DATASTORE_EMULATOR_URL")); | ||
LOGGER.info("DATASTORE_EMULATOR_URL = " + System.getenv("DATASTORE_EMULATOR_URL")); | ||
LocalDatastoreHelper helper = LocalDatastoreHelper.create(); | ||
helper.start(); | ||
} | ||
|
||
// @Ignore | ||
@Test | ||
public void testEmulatorDownloadWithInjectedAccessToken() throws Exception { | ||
assertNotNull(System.getenv("FAKE_DATASTORE_EMULATOR_URL_WITH_AUTH")); | ||
assertNotNull(System.getenv("ACCESS_TOKEN")); | ||
URL emulatorUrl = new URL(System.getenv("FAKE_DATASTORE_EMULATOR_URL_WITH_AUTH")); | ||
String accessToken = System.getenv("ACCESS_TOKEN"); | ||
LOGGER.info("FAKE_DATASTORE_EMULATOR_URL_WITH_AUTH = " + emulatorUrl); | ||
LOGGER.info("ACCESS_TOKEN = " + accessToken); | ||
File zipFile = new File(System.getProperty("java.io.tmpdir"), "datastore-emulator.zip"); | ||
downloadFile(zipFile, emulatorUrl, accessToken); | ||
assertTrue(zipFile.exists()); | ||
} | ||
|
||
// @Ignore | ||
@Test | ||
public void testEmulatorDownload() throws Exception { | ||
assertNotNull(System.getenv("FAKE_DATASTORE_EMULATOR_URL_WITH_AUTH")); | ||
URL emulatorUrl = new URL(System.getenv("FAKE_DATASTORE_EMULATOR_URL_WITH_AUTH")); | ||
LOGGER.info("FAKE_DATASTORE_EMULATOR_URL_WITH_AUTH = " + emulatorUrl); | ||
GoogleCredentials googleCredentials = GoogleCredentials.getApplicationDefault().createScoped( | ||
"https://www.googleapis.com/auth/devstorage.read_only"); | ||
googleCredentials.refreshIfExpired(); | ||
String accessToken = googleCredentials.getAccessToken().getTokenValue(); | ||
LOGGER.info("local accessToken = " + accessToken); | ||
File zipFile = new File(System.getProperty("java.io.tmpdir"), "datastore-emulator.zip"); | ||
downloadFile(zipFile, emulatorUrl, accessToken); | ||
assertTrue(zipFile.exists()); | ||
} | ||
|
||
private void downloadFile(File file, URL fileUrl, String accessToken) throws Exception { | ||
if (file.exists()) file.delete(); | ||
URLConnection urlConnection = fileUrl.openConnection(); | ||
urlConnection.setRequestProperty("Authorization", "Bearer " + accessToken); | ||
ReadableByteChannel rbc = Channels.newChannel(urlConnection.getInputStream()); | ||
try (FileOutputStream fos = new FileOutputStream(file)) { | ||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters