-
Notifications
You must be signed in to change notification settings - Fork 877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make ARN Resource builder more expressive. Implement proper toString() #3683
base: master
Are you sure you want to change the base?
Conversation
@@ -57,8 +59,16 @@ public Optional<String> resourceType() { | |||
/** | |||
* @return the entire resource as a string | |||
*/ | |||
@Deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of deprecating it, could we clarify it in the Javadoc?
builder.qualifier(resource.substring(qualifierColonIndex + 1)); | ||
} | ||
if (splitter.equals('/')) { | ||
builder.usingSlashSeperator(); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
|
||
@Override | ||
public String toString() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may potentially break customers who rely on existing behavior. Can we introduce a new method, toStringPretty
or toStringFormatted
?
* | ||
* @return Returns a reference to this builder | ||
*/ | ||
Builder usingSlashSeperator(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just take a character as separator?
Builder seperator(Character char);
@belugabehr let us know if you want to keep this PR open. |
@debora-ito Other priorities keeping me from finishing - but my intent is to see it through. Thanks for the patience. |
@belugabehr Any updates? Saw you updated that other PR :-) |
5c334d2
to
49ccea5
Compare
@cenedhryn Hello - better late than never. I made the the requested changes. However, I noticed a small bug that is also fixed in this PR. The qualifier of an ARN is always preceded by a colon ':'. However, the current code allows it to be a colon or a slash - this is incorrect. aws-sdk-java-v2/core/arns/src/main/java/software/amazon/awssdk/arns/ArnResource.java Line 104 in c2db6af
|
verifyArnResource(arn.resource()); | ||
assertThat(arn.resource().qualifier().get()).isEqualTo("1"); | ||
assertThat(arn.resource().qualifier()).isEqualTo(Optional.empty()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As seen here, this is a valid S3 path, yet it is being treated as a qualifier.
@@ -31,7 +33,6 @@ public void arnWithBasicResource_ParsesCorrectly() { | |||
assertThat(arn.region()).hasValue("us-east-1"); | |||
assertThat(arn.accountId()).hasValue("12345678910"); | |||
assertThat(arn.resourceAsString()).isEqualTo("myresource"); | |||
System.out.println(arn.resource()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General cleanup
@Test | ||
public void toString_resourceIdOnly() { | ||
ArnResource arnResource = ArnResource.builder().resourceId("resource").build(); | ||
assertThat("null:resource:null").isEqualTo(arnResource.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add unit test to demonstrate the unexpected 'null' behavior here of the toString
and how it differs from toStringFormatted()
…e6f04ae87 Pull request: release <- staging/464ee5ef-a5af-45c3-ad48-294e6f04ae87
Motivation and Context
The modeling in
ArnResource
does not well match the spec. [1]The toString() method of the
ArnResource
does not produce a proper (i.e., to spec) value.The current implementation uses the phrase
resource
whereas the spec calls it aresource-id
. So, from the top-levelArn
class, it's a bit awkward to access it:myArn.getResource().getResource()
.The code currently does not support legacy '/' resource values. I currently have a case where I am trying to strip off the qualifier off an ARN with this legacy '/' and it fails when using the API. The '/' is replaced with a colon ':' and therefore the ARN produced removes the qualifier, but does not otherwise match the original ARN that I am passing into the API.
[1] https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html
Modifications
resource
attribute ->resourceId
resoure-type
andresource-id
Testing
Added new unit tests
Types of changes
Checklist
mvn install
succeedsscripts/new-change
script and following the instructions. Commit the new file created by the script in.changes/next-release
with your changes.License