-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat: Handle MRAP URI #19609
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
base: master
Are you sure you want to change the base?
feat: Handle MRAP URI #19609
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |
|
|
||
| import java.net.URI; | ||
| import java.util.Objects; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| /** | ||
| * Common type for 'bucket' and 'path' concept of cloud objects to allow code sharing between cloud specific | ||
|
|
@@ -46,6 +47,8 @@ | |
| */ | ||
| public class CloudObjectLocation | ||
| { | ||
| private static final Pattern S3_ARN = Pattern.compile("^arn:(aws|aws-cn|aws-us-gov):s3:[a-z0-9-]*:\\d{12}:accesspoint[:/][A-Za-z0-9.-]+$"); | ||
|
|
||
| public static URI validateUriScheme(String scheme, URI uri) | ||
| { | ||
| if (!scheme.equalsIgnoreCase(uri.getScheme())) { | ||
|
|
@@ -60,20 +63,37 @@ public static URI validateUriScheme(String scheme, URI uri) | |
| @JsonCreator | ||
| public CloudObjectLocation(@JsonProperty("bucket") String bucket, @JsonProperty("path") String path) | ||
| { | ||
| this.bucket = Preconditions.checkNotNull(StringUtils.maybeRemoveTrailingSlash(bucket), | ||
| this.bucket = Preconditions.checkNotNull(normalizeBucket(bucket), | ||
| "bucket name cannot be null. Please verify if bucket name adheres to naming rules"); | ||
| this.path = Preconditions.checkNotNull(StringUtils.maybeRemoveLeadingSlash(path)); | ||
| Preconditions.checkArgument( | ||
| this.bucket.equals(StringUtils.urlEncode(this.bucket)), | ||
| "bucket must follow DNS-compliant naming conventions" | ||
| this.bucket.equals(StringUtils.urlEncode(this.bucket)) || isS3Arn(this.bucket), | ||
| "bucket must follow DNS-compliant naming conventions or be a valid S3 Access Point ARN" | ||
| + " or S3 Multi-Region Access Point ARN" | ||
| ); | ||
| } | ||
|
|
||
| private static String normalizeBucket(String bucket) | ||
| { | ||
| String trimmed = StringUtils.maybeRemoveTrailingSlash(bucket); | ||
|
|
||
| if (trimmed != null && isS3Arn(trimmed)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Handle slash-form MRAP ARNs before URI splitting This normalization only works when the full ARN is already passed as the bucket string. For a URI like |
||
| return trimmed.replace('/', ':'); | ||
| } | ||
|
|
||
| return trimmed; | ||
| } | ||
|
|
||
| public CloudObjectLocation(URI uri) | ||
| { | ||
| this(uri.getHost() != null ? uri.getHost() : uri.getAuthority(), uri.getPath()); | ||
| } | ||
|
|
||
| private static boolean isS3Arn(String value) | ||
| { | ||
| return value != null && S3_ARN.matcher(value).matches(); | ||
| } | ||
|
|
||
| /** | ||
| * Given a scheme, encode {@link #bucket} and {@link #path} into a {@link URI}. | ||
| * | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.