Skip to content

Commit

Permalink
Update to use new vhost syntax
Browse files Browse the repository at this point in the history
googleapis/google-cloud-java#6183 was merged
into google-cloud-java, and it changed some of the syntax (e.g. the
method name for virtual hosted urls changed, and explicitly specifying
the virtual hostname is no longer possible with that method). The syntax
updates have been reflected in the main-module examples.

This also updates the google-cloud-java submodule to use the merged
"master" branch ("master" of my fork is up-to-date with "master" of the
googleapis upstream as of today), along with changing main module to
depend on the newly-updated version google-cloud-storage
(1.93.1-SNAPSHOT).
  • Loading branch information
houglum committed Oct 2, 2019
1 parent 06f7882 commit 02a92fe
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 19 deletions.
2 changes: 1 addition & 1 deletion google-cloud-java
2 changes: 1 addition & 1 deletion main-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>1.89.1-SNAPSHOT</version>
<version>1.93.1-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public static void main(String[] args) {
String bucketName = args[0];
String objectNameForGet = args[1];
String objectNameForPut = args[2];
String vhostname = "https://" + bucketName + ".storage.googleapis.com";

BlobId blobIdForGet = BlobId.of(bucketName, objectNameForGet);
BlobInfo blobInfoForGet =
Expand All @@ -42,23 +41,33 @@ public static void main(String[] args) {
blobInfoForGet,
6,
TimeUnit.DAYS,
Storage.SignUrlOption.withVirtualHostName(vhostname),
Storage.SignUrlOption.withVirtualHostedStyle(),
Storage.SignUrlOption.withV4Signature()));
// Same thing, but not supplying the hostname explicitly
// V4 with virtual hostname, specifying explicit base storage hostname:
urls.add(
storageClient.signUrl(
blobInfoForGet,
6,
TimeUnit.DAYS,
Storage.SignUrlOption.withVirtualHostName(),
Storage.SignUrlOption.withVirtualHostedStyle(),
Storage.SignUrlOption.withHostName("https://storage.googleapis.com"),
Storage.SignUrlOption.withV4Signature()));
// V2 with virtual hostname
// V2 with virtual hostname
urls.add(
storageClient.signUrl(
blobInfoForGet,
6,
TimeUnit.DAYS,
Storage.SignUrlOption.withVirtualHostName(vhostname),
Storage.SignUrlOption.withVirtualHostedStyle(),
Storage.SignUrlOption.withV2Signature()));
// V2 with virtual hostname, specifying explicit base storage hostname:
urls.add(
storageClient.signUrl(
blobInfoForGet,
6,
TimeUnit.DAYS,
Storage.SignUrlOption.withVirtualHostedStyle(),
Storage.SignUrlOption.withHostName("https://storage.googleapis.com"),
Storage.SignUrlOption.withV2Signature()));

System.out.printf("\n[GET] to fetch object bytes\n");
Expand All @@ -79,26 +88,26 @@ public static void main(String[] args) {
6,
TimeUnit.DAYS,
Storage.SignUrlOption.withV4Signature(),
// TODO: Add these back in once we pull in a branch of the google-cloud-java fork that
// that contains this new method.
// TODO(prefix-param): Add these back in once we pull in a branch of the
// google-cloud-java fork that that contains this new method.
// Storage.SignUrlOption.withCanonicalQueryParam("versions", "True"),
// Storage.SignUrlOption.withCanonicalQueryParam("prefix", prefix),
Storage.SignUrlOption.withVirtualHostName(vhostname)));
Storage.SignUrlOption.withVirtualHostedStyle()));
// V4 with virtual hostname
urls.add(
storageClient.signUrl(
blobInfoForList,
6,
TimeUnit.DAYS,
Storage.SignUrlOption.withVirtualHostName(vhostname),
Storage.SignUrlOption.withVirtualHostedStyle(),
Storage.SignUrlOption.withV4Signature()));
// V2 with virtual hostname
urls.add(
storageClient.signUrl(
blobInfoForList,
6,
TimeUnit.DAYS,
Storage.SignUrlOption.withVirtualHostName(vhostname),
Storage.SignUrlOption.withVirtualHostedStyle(),
Storage.SignUrlOption.withV2Signature()));

System.out.printf("\n[GET] to list objects in a bucket\n");
Expand All @@ -115,7 +124,7 @@ public static void main(String[] args) {
6,
TimeUnit.DAYS,
Storage.SignUrlOption.httpMethod(HttpMethod.PUT),
Storage.SignUrlOption.withVirtualHostName(vhostname),
Storage.SignUrlOption.withVirtualHostedStyle(),
Storage.SignUrlOption.withV4Signature()));
// V2 with virtual hostname
urls.add(
Expand All @@ -124,7 +133,7 @@ public static void main(String[] args) {
6,
TimeUnit.DAYS,
Storage.SignUrlOption.httpMethod(HttpMethod.PUT),
Storage.SignUrlOption.withVirtualHostName(vhostname),
Storage.SignUrlOption.withVirtualHostedStyle(),
Storage.SignUrlOption.withV2Signature()));

System.out.printf("\n[PUT] to upload object bytes\n");
Expand Down Expand Up @@ -157,13 +166,21 @@ public static void main(String[] args) {
TimeUnit.DAYS,
Storage.SignUrlOption.withHostName("https://storage.googleapis.com"),
Storage.SignUrlOption.withV4Signature()));
// V4 without overridden hostname
// Same, but with path style explicitly specified:
urls.add(
storageClient.signUrl(
blobInfoForGet,
6,
TimeUnit.DAYS,
Storage.SignUrlOption.withHostName("https://storage.googleapis.com"),
Storage.SignUrlOption.withPathStyle(),
Storage.SignUrlOption.withV4Signature()));
// V4 without overridden hostname
urls.add(
storageClient.signUrl(
blobInfoForGet,
6,
TimeUnit.DAYS,
Storage.SignUrlOption.withV4Signature()));
// V2 with overridden hostname
urls.add(
Expand All @@ -173,6 +190,15 @@ public static void main(String[] args) {
TimeUnit.DAYS,
Storage.SignUrlOption.withHostName("https://storage.googleapis.com"),
Storage.SignUrlOption.withV2Signature()));
// Same, but with path style explicitly specified:
urls.add(
storageClient.signUrl(
blobInfoForGet,
6,
TimeUnit.DAYS,
Storage.SignUrlOption.withHostName("https://storage.googleapis.com"),
Storage.SignUrlOption.withPathStyle(),
Storage.SignUrlOption.withV2Signature()));
// V2 without overridden hostname
urls.add(
storageClient.signUrl(
Expand All @@ -197,7 +223,16 @@ public static void main(String[] args) {
TimeUnit.DAYS,
Storage.SignUrlOption.withHostName("https://storage.googleapis.com"),
Storage.SignUrlOption.withV4Signature()));
// V4 with standard hostname
// Same, but with path style explicitly specified:
urls.add(
storageClient.signUrl(
blobInfoForList,
6,
TimeUnit.DAYS,
Storage.SignUrlOption.withHostName("https://storage.googleapis.com"),
Storage.SignUrlOption.withPathStyle(),
Storage.SignUrlOption.withV4Signature()));
// V4 without overridden hostname
urls.add(
storageClient.signUrl(
blobInfoForList,
Expand All @@ -212,7 +247,16 @@ public static void main(String[] args) {
TimeUnit.DAYS,
Storage.SignUrlOption.withHostName("https://storage.googleapis.com"),
Storage.SignUrlOption.withV2Signature()));
// V2 with standard hostname
// Same, but with path style explicitly specified:
urls.add(
storageClient.signUrl(
blobInfoForList,
6,
TimeUnit.DAYS,
Storage.SignUrlOption.withHostName("https://storage.googleapis.com"),
Storage.SignUrlOption.withPathStyle(),
Storage.SignUrlOption.withV2Signature()));
// V2 without overridden hostname
urls.add(
storageClient.signUrl(
blobInfoForList,
Expand Down Expand Up @@ -244,7 +288,6 @@ public static void main(String[] args) {
6,
TimeUnit.DAYS,
Storage.SignUrlOption.httpMethod(HttpMethod.PUT),
Storage.SignUrlOption.withHostName("https://storage.googleapis.com"),
Storage.SignUrlOption.withV4Signature()));
// V2 with overridden hostname
urls.add(
Expand Down

0 comments on commit 02a92fe

Please sign in to comment.