From cbfbc33b88b6dbc53eaa342f3d424fb64628ec03 Mon Sep 17 00:00:00 2001 From: dmitry-fa Date: Thu, 20 Feb 2020 15:20:32 +0300 Subject: [PATCH 1/2] feat: examples of creating a signed url for a blob with generation --- .../main/java/com/google/cloud/storage/Blob.java | 7 +++++++ .../main/java/com/google/cloud/storage/Storage.java | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java index 914b571ba..e98ddcd8d 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java @@ -779,6 +779,13 @@ public WriteChannel writer(BlobWriteOption... options) { * ServiceAccountCredentials.fromStream(new FileInputStream(keyPath)))); * } * + *

Example of creating a signed URL for a blob generation. + * + *

{@code
+   * URL signedUrl = blob.signUrl(1, TimeUnit.HOURS,
+   *     SignUrlOption.withQueryParams(ImmutableMap.of("generation", "1576656755290328")));
+   * }
+ * * @param duration time until the signed URL expires, expressed in {@code unit}. The finer * granularity supported is 1 second, finer granularities will be truncated * @param unit time unit of the {@code duration} parameter diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java index 527848747..60943ec71 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java @@ -2498,6 +2498,19 @@ Blob create( *

Note that the {@link ServiceAccountSigner} may require additional configuration to enable * URL signing. See the documentation for the implementation for more details. * + *

Example of creating a signed URL for a blob with generation. + * + *

{@code
+   * String bucketName = "my-unique-bucket";
+   * String blobName = "my-blob-name";
+   * long generation = 1576656755290328L;
+   *
+   * URL signedUrl = storage.signUrl(
+   *     BlobInfo.newBuilder(bucketName, blobName, generation).build(),
+   *     7, TimeUnit.DAYS,
+   *     SignUrlOption.withQueryParams(ImmutableMap.of("generation", String.valueOf(generation))));
+   * }
+ * * @param blobInfo the blob associated with the signed URL * @param duration time until the signed URL expires, expressed in {@code unit}. The finest * granularity supported is 1 second, finer granularities will be truncated From 35562a8e4041fd0cfdbee180d92afdadca5a84bc Mon Sep 17 00:00:00 2001 From: dmitry-fa Date: Wed, 26 Feb 2020 17:08:43 +0300 Subject: [PATCH 2/2] feat: examples of creating a signed url for a blob with generation --- .../src/main/java/com/google/cloud/storage/Blob.java | 6 +++--- .../src/main/java/com/google/cloud/storage/Storage.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java index e98ddcd8d..27e626264 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/Blob.java @@ -764,14 +764,14 @@ public WriteChannel writer(BlobWriteOption... options) { * * *

Example of creating a signed URL for the blob that is valid for 2 weeks, using the default - * credentials for signing the URL. + * credentials for signing the URL: * *

{@code
    * URL signedUrl = blob.signUrl(14, TimeUnit.DAYS);
    * }
* *

Example of creating a signed URL for the blob passing the {@link - * SignUrlOption#signWith(ServiceAccountSigner)} option, that will be used to sign the URL. + * SignUrlOption#signWith(ServiceAccountSigner)} option, that will be used to sign the URL: * *

{@code
    * String keyPath = "/path/to/key.json";
@@ -779,7 +779,7 @@ public WriteChannel writer(BlobWriteOption... options) {
    *     ServiceAccountCredentials.fromStream(new FileInputStream(keyPath))));
    * }
* - *

Example of creating a signed URL for a blob generation. + *

Example of creating a signed URL for a blob generation: * *

{@code
    * URL signedUrl = blob.signUrl(1, TimeUnit.HOURS,
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java
index 60943ec71..6c1949f38 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/Storage.java
@@ -2483,7 +2483,7 @@ Blob create(
    * }
* *

Example of creating a signed URL passing the {@link - * SignUrlOption#signWith(ServiceAccountSigner)} option, that will be used for signing the URL. + * SignUrlOption#signWith(ServiceAccountSigner)} option, that will be used for signing the URL: * *

{@code
    * String bucketName = "my-unique-bucket";
@@ -2498,7 +2498,7 @@ Blob create(
    * 

Note that the {@link ServiceAccountSigner} may require additional configuration to enable * URL signing. See the documentation for the implementation for more details. * - *

Example of creating a signed URL for a blob with generation. + *

Example of creating a signed URL for a blob with generation: * *

{@code
    * String bucketName = "my-unique-bucket";