Skip to content

Commit 5537bbe

Browse files
committed
review
1 parent 6070126 commit 5537bbe

File tree

5 files changed

+33
-26
lines changed

5 files changed

+33
-26
lines changed

polaris-core/src/main/java/org/apache/polaris/core/persistence/bootstrap/RootCredentialsSet.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package org.apache.polaris.core.persistence.bootstrap;
2020

21+
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
22+
2123
import com.fasterxml.jackson.annotation.JsonAnyGetter;
2224
import com.fasterxml.jackson.annotation.JsonAnySetter;
2325
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -110,6 +112,9 @@ static RootCredentialsSet fromList(List<String> credentialsList) {
110112
* # etc.
111113
* </pre>
112114
*
115+
* Multiple YAMl documents are also supported; all documents will be merged into a single set of
116+
* credentials.
117+
*
113118
* <p>The expected JSON format is:
114119
*
115120
* <pre>
@@ -126,9 +131,15 @@ static RootCredentialsSet fromList(List<String> credentialsList) {
126131
* </pre>
127132
*/
128133
static RootCredentialsSet fromUrl(URL url) {
129-
try {
130-
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
131-
return mapper.readValue(url, RootCredentialsSet.class);
134+
YAMLFactory factory = new YAMLFactory();
135+
ObjectMapper mapper = new ObjectMapper(factory).configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
136+
try (var parser = factory.createParser(url)) {
137+
var values = mapper.readValues(parser, RootCredentialsSet.class);
138+
var builder = ImmutableRootCredentialsSet.builder();
139+
while (values.hasNext()) {
140+
builder.putAllCredentials(values.next().credentials());
141+
}
142+
return builder.build();
132143
} catch (Exception e) {
133144
throw new IllegalArgumentException("Failed to read credentials file: " + url, e);
134145
}

polaris-core/src/test/java/org/apache/polaris/core/persistence/bootstrap/RootCredentialsSetTest.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,21 @@ void getSecretsValidSystemProperty() {
9090

9191
@Test
9292
void getSecretsValidJson() {
93-
URL resource =
94-
getClass().getResource("/org/apache/polaris/core/persistence/bootstrap/credentials.json");
93+
URL resource = getClass().getResource("credentials.json");
9594
RootCredentialsSet set = RootCredentialsSet.fromUrl(resource);
9695
assertCredentials(set);
9796
}
9897

9998
@Test
10099
void getSecretsValidYaml() {
101-
URL resource =
102-
getClass().getResource("/org/apache/polaris/core/persistence/bootstrap/credentials.yaml");
100+
URL resource = getClass().getResource("credentials.yaml");
103101
RootCredentialsSet set = RootCredentialsSet.fromUrl(resource);
104102
assertCredentials(set);
105103
}
106104

107105
@Test
108106
void getSecretsInvalidJson() {
109-
URL resource =
110-
getClass()
111-
.getResource("/org/apache/polaris/core/persistence/bootstrap/credentials-invalid.json");
107+
URL resource = getClass().getResource("credentials-invalid.json");
112108
assertThatThrownBy(() -> RootCredentialsSet.fromUrl(resource))
113109
.isInstanceOf(IllegalArgumentException.class)
114110
.hasMessageContaining("Failed to read credentials file")
@@ -120,9 +116,7 @@ void getSecretsInvalidJson() {
120116

121117
@Test
122118
void getSecretsInvalidYaml() {
123-
URL resource =
124-
getClass()
125-
.getResource("/org/apache/polaris/core/persistence/bootstrap/credentials-invalid.yaml");
119+
URL resource = getClass().getResource("credentials-invalid.yaml");
126120
assertThatThrownBy(() -> RootCredentialsSet.fromUrl(resource))
127121
.isInstanceOf(IllegalArgumentException.class)
128122
.hasMessageContaining("Failed to read credentials file")

polaris-core/src/test/resources/org/apache/polaris/core/persistence/bootstrap/credentials.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
},
66
"realm2": {
77
"client-id": "client2",
8-
"client-secret": "secret2"
8+
"client-secret": "secret2",
9+
"extra-field": "extra-value"
910
}
1011
}

polaris-core/src/test/resources/org/apache/polaris/core/persistence/bootstrap/credentials.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
realm1:
2121
client-id: client1
2222
client-secret: secret1
23+
---
2324
realm2:
2425
client-id: client2
25-
client-secret: secret2
26+
client-secret: secret2
27+
extra-field: extra-value

quarkus/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
import java.net.URL;
3636
import java.nio.file.Files;
3737
import java.nio.file.Path;
38-
import java.nio.file.StandardCopyOption;
3938
import java.util.Objects;
4039
import org.junit.jupiter.api.BeforeAll;
4140
import org.junit.jupiter.api.Test;
41+
import org.junit.jupiter.api.io.TempDir;
4242

4343
@QuarkusMainTest
4444
@WithTestResource(
@@ -51,9 +51,9 @@ class BootstrapCommandTest {
5151
private static Path yaml;
5252

5353
@BeforeAll
54-
static void prepareFiles() throws IOException {
55-
json = copyResource("/org/apache/polaris/admintool/credentials.json");
56-
yaml = copyResource("/org/apache/polaris/admintool/credentials.yaml");
54+
static void prepareFiles(@TempDir Path temp) throws IOException {
55+
json = copyResource(temp, "credentials.json");
56+
yaml = copyResource(temp, "credentials.yaml");
5757
}
5858

5959
@Test
@@ -132,13 +132,12 @@ public void testBootstrapFromInvalidFile(QuarkusMainLauncher launcher) {
132132
.contains("Bootstrap encountered errors during operation.");
133133
}
134134

135-
private static Path copyResource(String resource) throws IOException {
136-
URL jsonSource = Objects.requireNonNull(BootstrapCommandTest.class.getResource(resource));
137-
Path file = Files.createTempFile("credentials", "tmp");
138-
file.toFile().deleteOnExit();
139-
try (InputStream is = jsonSource.openStream()) {
140-
Files.copy(is, file, StandardCopyOption.REPLACE_EXISTING);
135+
private static Path copyResource(Path temp, String resource) throws IOException {
136+
URL source = Objects.requireNonNull(BootstrapCommandTest.class.getResource(resource));
137+
Path dest = temp.resolve(resource);
138+
try (InputStream in = source.openStream()) {
139+
Files.copy(in, dest);
141140
}
142-
return file;
141+
return dest;
143142
}
144143
}

0 commit comments

Comments
 (0)