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

Modify ARN toString to print a valid ARN when there's no region or acountId #4944

Merged

Conversation

Madrigal
Copy link
Contributor

Fixes #2416

Motivation and Context

Certain ARNs, like S3 or IAM, don't have to include region or accountId. This constructs a valid ARN

Arn.builder()
    .partition("aws")
    .service("s3")
    .resource("bucket")
    .build();

However, when toString() is called in this method, region and account are printed as literal null' so the ARN becomes

arn:aws:s3:null:null:bucket

instead of the valid

arn:aws:s3:::bucket

This causes the problem that ARNs produced by toString cannot be used as identifiers when passed to other services,since this ARN is not valid.

Modifications

Don't print null on Arn.toString() if region or accountId are not set.

Testing

Added unit tests to verify this behavior. Additionally, this has the nice property that the ARNs produced by toString() can be parsed by Arn.fromString().

Screenshots (if appropriate)

N/A

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

@Madrigal Madrigal requested a review from a team as a code owner February 20, 2024 05:17
Copy link

sonarcloud bot commented Mar 7, 2024

@cenedhryn cenedhryn merged commit 5b7ec50 into aws:master Mar 7, 2024
9 of 17 checks passed
@Madrigal Madrigal deleted the fix/allow-empty-account-id-region-arn branch March 12, 2024 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

It would be nice if there were a way to create a canonical arn String from an Arn instance
2 participants