Skip to content

Commit

Permalink
fix: introduce new BlobId#toGsUtilUriWithGeneration (#1998)
Browse files Browse the repository at this point in the history
When BlobId#toGsUtilUri was updated to output generation if defined, this broken older clients ability to parse the value via BlobId#fromGsUtilUri. This adds the new method toGsUtilUriWithGeneration to explicitly opt in to generation being okay in the output.

Related to #1928
Related to #1929
  • Loading branch information
BenWhitehead committed Apr 26, 2023
1 parent b7fb037 commit 68de5c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,21 @@ public Long getGeneration() {
return generation;
}

/** Returns this blob's Storage url which can be used with gsutil */
/**
* Returns this blob's Storage url which can be used with gsutil. If {@link #generation} is
* non-null it will not be included in the uri.
*/
public String toGsUtilUri() {
return "gs://" + bucket + "/" + name;
}

/**
* Returns this blob's Storage url which can be used with gsutil. If {@link #generation} is
* non-null it will be included in the uri
*
* @since 2.23.0
*/
public String toGsUtilUriWithGeneration() {
return "gs://" + bucket + "/" + name + (generation == null ? "" : ("#" + generation));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public void testToFromGsUtilUriWithGeneration() {
assertEquals("bucket", blobId.getBucket());
assertEquals("path/to/blob", blobId.getName());
assertEquals(Long.valueOf(1360887697105000L), blobId.getGeneration());
assertEquals("gs://bucket/path/to/blob#1360887697105000", blobId.toGsUtilUri());
assertEquals("gs://bucket/path/to/blob", blobId.toGsUtilUri());
assertEquals("gs://bucket/path/to/blob#1360887697105000", blobId.toGsUtilUriWithGeneration());
}

@Test
Expand Down

0 comments on commit 68de5c7

Please sign in to comment.