eric-maynard commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1960323739
##########
quarkus/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTest.java:
##########
@@ -32,16 +34,35 @@ class BootstrapCommandTest {
@Launch(
value = {
"bootstrap",
- "-r",
- "realm1",
- "-r",
- "realm2",
"-c",
- "realm1,root,s3cr3t",
- "-c",
- "realm2,root,s3cr3t"
+
"[{\"realm\":\"realm1\",\"principal\":\"root\",\"clientId\":\"root\",\"clientSecret\":\"s3cr3t\"}]"
})
public void testBootstrap(LaunchResult result) {
assertThat(result.getOutput()).contains("Bootstrap completed
successfully.");
}
+
+ @Test
+ @Launch(
+ value = {
+ "bootstrap",
+ "-c",
+
"[{\"realm\":\"realm1\",\"principal\":\"root\",\"clientId\":\"root\",\"clientSecret\":\"s3cr3t\"}]",
Review Comment:
The new JSON format exactly matches the format used in the `-f` argument, so
hopefully that makes this less treacherous for users
##########
polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisCredentialsBootstrap.java:
##########
@@ -63,6 +66,42 @@ public static PolarisCredentialsBootstrap
fromString(@Nullable String credential
: EMPTY;
}
+ /**
+ * Parse a JSON array of credentials. Example: """ [ {"realm": "a",
"principal": "root",
+ * "clientId": "abc123", "clientSecret": "xyz987"}, {"realm": "b",
"principal": "boot",
+ * "clientId": "boot-id", "clientSecret": "boot-secret"}, ] """
+ */
+ public static PolarisCredentialsBootstrap fromJson(String json) {
+ ObjectMapper objectMapper = new ObjectMapper();
+ List<Map<String, String>> credentialsList = new ArrayList<>();
+ try {
+ credentialsList = objectMapper.readValue(json, new TypeReference<>() {});
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Could not parse credentials JSON: "
+ json, e);
+ }
+ Map<String, Map.Entry<String, String>> credentials = new HashMap<>();
+ for (Map<String, String> entry : credentialsList) {
+ String realm = entry.get("realm");
+ String principal = entry.get("principal");
+ String clientId = entry.get("clientId");
+ String clientSecret = entry.get("clientSecret");
+ if (realm == null || principal == null || clientId == null ||
clientSecret == null) {
+ throw new IllegalArgumentException("Failed to find credentials in: " +
json);
+ } else if
(!principal.equals(PolarisEntityConstants.ROOT_PRINCIPAL_NAME)) {
+ throw new IllegalArgumentException(
+ String.format(
+ "Invalid principal %s. Expected %s.",
Review Comment:
Added a test to cover this behavior
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]