dimas-b commented on code in PR #461:
URL: https://github.com/apache/polaris/pull/461#discussion_r1936527885


##########
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:
   I think, in this case it would be fine to accept JSON with extra fields. 
However, in that case, the parsing code should probably not attempt to validate 
(or even interpret) the fields it does not use.



-- 
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]

Reply via email to