Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

belugabehr
Copy link
Contributor

@belugabehr belugabehr commented Jan 11, 2023

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 a resource-id. So, from the top-level Arn 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

  • Deprecate resource attribute -> resourceId
  • Update toString() to produce a properly formed output
  • Allow for specifying a legacy '/' character to separate resoure-type and resource-id

Testing

Added new unit tests

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@belugabehr belugabehr requested a review from a team as a code owner January 11, 2023 19:49
@debora-ito debora-ito added the needs-review This issue or PR needs review from the team. label Jan 23, 2023
@@ -57,8 +59,16 @@ public Optional<String> resourceType() {
/**
* @return the entire resource as a string
*/
@Deprecated
Copy link
Contributor

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() {
Copy link
Contributor

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();
Copy link
Contributor

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);

@debora-ito
Copy link
Member

@belugabehr let us know if you want to keep this PR open.

@debora-ito debora-ito added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. needs-review This issue or PR needs review from the team. and removed needs-review This issue or PR needs review from the team. labels Apr 19, 2023
@belugabehr
Copy link
Contributor Author

@debora-ito Other priorities keeping me from finishing - but my intent is to see it through. Thanks for the patience.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Apr 21, 2023
@cenedhryn
Copy link
Contributor

@belugabehr Any updates? Saw you updated that other PR :-)

@belugabehr belugabehr force-pushed the arn-build-qualifier branch from 5c334d2 to 49ccea5 Compare June 23, 2023 03:32
@belugabehr
Copy link
Contributor Author

belugabehr commented Jun 23, 2023

@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.

int qualifierColonIndex = resource.indexOf(splitter, resourceColonIndex + 1);

Comment on lines -113 to +114
verifyArnResource(arn.resource());
assertThat(arn.resource().qualifier().get()).isEqualTo("1");
assertThat(arn.resource().qualifier()).isEqualTo(Optional.empty());
Copy link
Contributor Author

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());
Copy link
Contributor Author

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());
Copy link
Contributor Author

@belugabehr belugabehr Jun 23, 2023

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()

aws-sdk-java-automation added a commit that referenced this pull request Feb 24, 2025
…e6f04ae87

Pull request: release <- staging/464ee5ef-a5af-45c3-ad48-294e6f04ae87
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-review This issue or PR needs review from the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants