Skip to content

Commit 02c79e2

Browse files
committed
Add additional storage config property in PolarisCredentialProperty
1 parent 50ef1bc commit 02c79e2

File tree

3 files changed

+126
-1
lines changed

3 files changed

+126
-1
lines changed

polaris-core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ dependencies {
9696

9797
testFixturesApi(platform(libs.junit.bom))
9898
testFixturesApi("org.junit.jupiter:junit-jupiter")
99+
testFixturesApi("org.junit.jupiter:junit-jupiter-params")
99100
testFixturesApi(libs.assertj.core)
100101
testFixturesApi(libs.mockito.core)
101102
testFixturesApi("com.fasterxml.jackson.core:jackson-core")

polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisCredentialProperty.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ public enum PolarisCredentialProperty {
4141
"the azure storage account host",
4242
"the azure account name + endpoint that will append to the ADLS_SAS_TOKEN_PREFIX"),
4343
EXPIRATION_TIME(
44-
Long.class, "expiration-time", "the expiration time for the access token, in milliseconds");
44+
Long.class, "expiration-time", "the expiration time for the access token, in milliseconds"),
45+
ADDITIONAL_STORAGE_CONFIG(
46+
String.class,
47+
"additional-storage-config",
48+
"the additional storage config for the cloud storage"),
49+
;
4550

4651
private final Class valueType;
4752
private final String propertyName;
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.polaris.core.storage.cache;
20+
21+
import static org.apache.polaris.core.storage.PolarisCredentialVendor.*;
22+
23+
import java.util.EnumMap;
24+
import java.util.Map;
25+
import java.util.stream.Stream;
26+
import org.apache.iceberg.aws.s3.S3FileIOProperties;
27+
import org.apache.iceberg.azure.AzureProperties;
28+
import org.apache.iceberg.gcp.GCPProperties;
29+
import org.apache.polaris.core.persistence.*;
30+
import org.apache.polaris.core.storage.PolarisCredentialProperty;
31+
import org.assertj.core.api.Assertions;
32+
import org.junit.jupiter.api.Test;
33+
import org.junit.jupiter.params.ParameterizedTest;
34+
import org.junit.jupiter.params.provider.Arguments;
35+
import org.junit.jupiter.params.provider.MethodSource;
36+
37+
public class StorageCredentialCacheEntryTest {
38+
39+
public StorageCredentialCacheEntryTest() {}
40+
41+
@Test
42+
public void testBadResult() {
43+
ScopedCredentialsResult badResult =
44+
new ScopedCredentialsResult(
45+
BaseResult.ReturnStatus.SUBSCOPE_CREDS_ERROR, "extra_error_info");
46+
StorageCredentialCacheEntry cacheEntry = new StorageCredentialCacheEntry(badResult);
47+
Assertions.assertThatThrownBy(() -> cacheEntry.convertToMapOfString())
48+
.isInstanceOf(NullPointerException.class)
49+
.hasMessageContaining("because \"this.credsMap\" is null");
50+
}
51+
52+
@ParameterizedTest
53+
@MethodSource("testConvertToMapOfStringParams")
54+
public void testConvertToMapOfString(
55+
Map<PolarisCredentialProperty, String> original, Map<String, String> expected) {
56+
EnumMap<PolarisCredentialProperty, String> props =
57+
new EnumMap<>(PolarisCredentialProperty.class);
58+
props.putAll(original);
59+
60+
ScopedCredentialsResult goodResult = new ScopedCredentialsResult(props);
61+
StorageCredentialCacheEntry cacheEntry = new StorageCredentialCacheEntry(goodResult);
62+
Map<String, String> properties = cacheEntry.convertToMapOfString();
63+
Assertions.assertThat(properties).isEqualTo(expected);
64+
System.out.println(properties);
65+
}
66+
67+
private static Stream<Arguments> testConvertToMapOfStringParams() {
68+
return Stream.of(
69+
Arguments.of(
70+
Map.of(
71+
PolarisCredentialProperty.AWS_KEY_ID,
72+
"aws_key_id",
73+
PolarisCredentialProperty.AWS_SECRET_KEY,
74+
"aws_secret_access_key",
75+
PolarisCredentialProperty.AWS_TOKEN,
76+
"aws_session_token"),
77+
Map.of(
78+
S3FileIOProperties.ACCESS_KEY_ID,
79+
"aws_key_id",
80+
S3FileIOProperties.SECRET_ACCESS_KEY,
81+
"aws_secret_access_key",
82+
S3FileIOProperties.SESSION_TOKEN,
83+
"aws_session_token")),
84+
Arguments.of(
85+
Map.of(
86+
PolarisCredentialProperty.GCS_ACCESS_TOKEN,
87+
"gcs_oauth2_token",
88+
PolarisCredentialProperty.GCS_ACCESS_TOKEN_EXPIRES_AT,
89+
"gcs_token_expires_at"),
90+
Map.of(
91+
GCPProperties.GCS_OAUTH2_TOKEN,
92+
"gcs_oauth2_token",
93+
GCPProperties.GCS_OAUTH2_TOKEN_EXPIRES_AT,
94+
"gcs_token_expires_at")),
95+
Arguments.of(
96+
Map.of(
97+
PolarisCredentialProperty.AZURE_ACCOUNT_HOST,
98+
"azure_storage_account",
99+
PolarisCredentialProperty.AZURE_SAS_TOKEN,
100+
"azure_sas_token"),
101+
Map.of(
102+
AzureProperties.ADLS_SAS_TOKEN_PREFIX + "azure_storage_account",
103+
"azure_sas_token")),
104+
Arguments.of(
105+
Map.of(PolarisCredentialProperty.AZURE_ACCESS_TOKEN, "azure_access_token"),
106+
Map.of("", "azure_access_token")),
107+
Arguments.of(
108+
Map.of(PolarisCredentialProperty.EXPIRATION_TIME, "expiration_time"),
109+
Map.of("expiration-time", "expiration_time")),
110+
Arguments.of(
111+
Map.of(
112+
PolarisCredentialProperty.ADDITIONAL_STORAGE_CONFIG,
113+
"{\"s3.session-token-expires-at-ms\": \"expires_at\"}"),
114+
Map.of(
115+
"additional-storage-config",
116+
"{\"s3.session-token-expires-at-ms\": \"expires_at\"}")),
117+
Arguments.of(Map.of(), Map.of()));
118+
}
119+
}

0 commit comments

Comments
 (0)