-
Notifications
You must be signed in to change notification settings - Fork 367
Fixed #214 - Added support for s3a scheme
#1932
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
Changes from all commits
09de4c8
a2a7a84
36151b2
a971766
53989d4
b12f461
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
eric-maynard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.polaris.core.storage.aws; | ||
|
|
||
| import jakarta.annotation.Nonnull; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
| import org.apache.polaris.core.storage.StorageLocation; | ||
|
|
||
| public class S3Location extends StorageLocation { | ||
| private static final Pattern URI_PATTERN = Pattern.compile("^(s3a?):(.+)$"); | ||
| private final String scheme; | ||
| private final String locationWithoutScheme; | ||
|
|
||
| public S3Location(@Nonnull String location) { | ||
| super(location); | ||
| Matcher matcher = URI_PATTERN.matcher(location); | ||
| if (!matcher.matches()) { | ||
| throw new IllegalArgumentException("Invalid S3 location uri " + location); | ||
| } | ||
| this.scheme = matcher.group(1); | ||
| this.locationWithoutScheme = matcher.group(2); | ||
| } | ||
|
|
||
| public static boolean isS3Location(String location) { | ||
| if (location == null) { | ||
| return false; | ||
| } | ||
| Matcher matcher = URI_PATTERN.matcher(location); | ||
| return matcher.matches(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isChildOf(StorageLocation potentialParent) { | ||
| if (potentialParent instanceof S3Location) { | ||
| S3Location that = (S3Location) potentialParent; | ||
| // Given that S3 and S3A are to be treated similarly, the parent check ignores the prefix | ||
| String slashTerminatedObjectKey = ensureTrailingSlash(this.locationWithoutScheme); | ||
| String slashTerminatedObjectKeyThat = ensureTrailingSlash(that.locationWithoutScheme); | ||
| return slashTerminatedObjectKey.startsWith(slashTerminatedObjectKeyThat); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public String getScheme() { | ||
| return scheme; | ||
| } | ||
|
|
||
| @Override | ||
| public String withoutScheme() { | ||
| return locationWithoutScheme; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.polaris.core.storage.aws; | ||
|
|
||
| import org.apache.polaris.core.storage.StorageLocation; | ||
| import org.assertj.core.api.Assertions; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.CsvSource; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
|
|
||
| class S3LocationTest { | ||
eric-maynard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = {"s3a", "s3"}) | ||
| public void testLocation(String scheme) { | ||
| String locInput = scheme + "://bucket/schema1/table1"; | ||
| StorageLocation loc = StorageLocation.of(locInput); | ||
| Assertions.assertThat(loc).isInstanceOf(S3Location.class); | ||
| S3Location s3Loc = (S3Location) loc; | ||
| Assertions.assertThat(s3Loc.getScheme()).isEqualTo(scheme); | ||
| Assertions.assertThat(s3Loc.withoutScheme()).isEqualTo("//bucket/schema1/table1"); | ||
| Assertions.assertThat(s3Loc.withoutScheme()).doesNotStartWith(scheme); | ||
| Assertions.assertThat(scheme + ":" + s3Loc.withoutScheme()).isEqualTo(locInput); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @CsvSource({"s3,s3a", "s3a,s3"}) | ||
| public void testPrefixValidationIgnoresScheme(String parentScheme, String childScheme) { | ||
| StorageLocation loc1 = StorageLocation.of(childScheme + "://bucket/schema1/table1"); | ||
| StorageLocation loc2 = StorageLocation.of(parentScheme + "://bucket/schema1"); | ||
| Assertions.assertThat(loc1.isChildOf(loc2)).isTrue(); | ||
|
|
||
| StorageLocation loc3 = StorageLocation.of(childScheme + "://bucket/schema1"); | ||
| Assertions.assertThat(loc2.equals(loc3)).isFalse(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,8 +64,9 @@ class AwsCredentialsStorageIntegrationTest extends BaseStorageIntegrationTest { | |
| .build(); | ||
| public static final String AWS_PARTITION = "aws"; | ||
|
|
||
| @Test | ||
| public void testGetSubscopedCreds() { | ||
| @ParameterizedTest | ||
| @ValueSource(strings = {"s3a", "s3"}) | ||
| public void testGetSubscopedCreds(String scheme) { | ||
| StsClient stsClient = Mockito.mock(StsClient.class); | ||
| String roleARN = "arn:aws:iam::012345678901:role/jdoe"; | ||
| String externalId = "externalId"; | ||
|
|
@@ -76,10 +77,13 @@ public void testGetSubscopedCreds() { | |
| .isInstanceOf(AssumeRoleRequest.class) | ||
| .asInstanceOf(InstanceOfAssertFactories.type(AssumeRoleRequest.class)) | ||
| .returns(externalId, AssumeRoleRequest::externalId) | ||
| .returns(roleARN, AssumeRoleRequest::roleArn); | ||
| .returns(roleARN, AssumeRoleRequest::roleArn) | ||
| // ensure that the policy content does not refer to S3A | ||
| .extracting(AssumeRoleRequest::policy) | ||
| .doesNotMatch(s -> s.contains("s3a")); | ||
| return ASSUME_ROLE_RESPONSE; | ||
| }); | ||
| String warehouseDir = "s3://bucket/path/to/warehouse"; | ||
| String warehouseDir = scheme + "://bucket/path/to/warehouse"; | ||
|
||
| EnumMap<StorageAccessProperty, String> credentials = | ||
| new AwsCredentialsStorageIntegration(stsClient) | ||
| .getSubscopedCreds( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.