dimas-b commented on code in PR #259:
URL: https://github.com/apache/polaris-tools/pull/259#discussion_r3639230966


##########
polaris-synchronizer/api/src/main/java/org/apache/polaris/tools/sync/polaris/access/CredentialWriter.java:
##########
@@ -0,0 +1,43 @@
+/*
+ * 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.tools.sync.polaris.access;
+
+import java.util.Map;
+import org.apache.polaris.core.admin.model.PrincipalWithCredentials;
+
+/**
+ * Generic interface to output newly generated/rotated principal credentials. 
This allows the
+ * destination of the credentials to be completely independent from the tool.
+ */
+public interface CredentialWriter extends AutoCloseable {
+
+  /**
+   * Used to initialize the instance for use. Should be called prior to 
calling any methods.
+   *
+   * @param properties properties to configure instance with
+   */
+  void initialize(Map<String, String> properties);

Review Comment:
   This looks like a factory concern. "Users" of `CredentialWriter` should not 
need to worry about initializing it. The factory should return a pre-configured 
instance.



##########
polaris-synchronizer/cli/src/main/java/org/apache/polaris/tools/sync/polaris/CredentialWriterFactory.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * 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.tools.sync.polaris;
+
+import org.apache.polaris.tools.sync.polaris.access.CredentialWriter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Factory class to construct configurable {@link CredentialWriter} 
implementations.
+ */
+public class CredentialWriterFactory {
+
+    /**
+     * Property that will hold class name for custom {@link CredentialWriter} 
implementation.
+     */
+    public static final String CUSTOM_CLASS_NAME_PROPERTY = "custom-impl";
+
+    private CredentialWriterFactory() {}
+
+    /**
+     * Recognized types of {@link CredentialWriter} implementations
+     */
+    public enum Type {
+        CONSOLE,
+        FILE,
+        CUSTOM
+    }
+
+    /**
+     * Construct a new {@link CredentialWriter} instance.
+     * @param type the recognized type of the {@link CredentialWriter} to 
construct
+     * @param properties properties to use when initializing the {@link 
CredentialWriter}
+     * @return the constructed and initialized {@link CredentialWriter}
+     */
+    public static CredentialWriter createCredentialWriter(Type type, 
Map<String, String> properties) {
+        try {
+            properties = properties == null ? new HashMap<>() : properties;
+
+            CredentialWriter writer = switch (type) {
+                case CONSOLE -> new ConsoleCredentialWriter();
+                case FILE -> new JsonFileCredentialWriter();
+                case CUSTOM -> {
+                    String customWriterClassname = 
properties.get(CUSTOM_CLASS_NAME_PROPERTY);
+
+                    if (customWriterClassname == null) {
+                        throw new IllegalArgumentException("Missing required 
property " + CUSTOM_CLASS_NAME_PROPERTY);
+                    }
+
+                    Object custom = 
Class.forName(customWriterClassname).getDeclaredConstructor().newInstance();

Review Comment:
   For custom code, `java.util.ServiceLoader` is probably a superior 
alternative. The main Polaris codebase has examples for using it. WDYT?



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