twalthr commented on code in PR #28085:
URL: https://github.com/apache/flink/pull/28085#discussion_r3281928185


##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/DefaultConnectionFactory.java:
##########
@@ -0,0 +1,194 @@
+/*
+ * 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.flink.table.factories;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.catalog.CatalogConnection;
+import org.apache.flink.table.catalog.SensitiveConnection;
+import org.apache.flink.table.secret.ReadableSecretStore;
+import org.apache.flink.table.secret.WritableSecretStore;
+import org.apache.flink.table.secret.exceptions.SecretException;
+import org.apache.flink.table.secret.exceptions.SecretNotFoundException;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Default implementation of {@link ConnectionFactory} that identifies 
sensitive fields by a
+ * predefined whitelist of field names.
+ *
+ * <p>During {@link #createConnection}, sensitive fields are extracted from 
the connection options
+ * and stored as a single secret in the {@link WritableSecretStore}. A 
reference key ({@value
+ * #SECRET_REFERENCE_KEY}) pointing to the stored secret is added to the 
returned {@link
+ * CatalogConnection}.
+ *
+ * <p>During {@link #resolveConnection}, the secret reference is used to 
retrieve the sensitive
+ * fields from the {@link ReadableSecretStore} and merge them back into the 
options.
+ *
+ * <p>The following field names are treated as sensitive by default: {@code 
password}, {@code
+ * secret}, {@code fs.azure.account.key}, {@code apikey}, {@code api-key}, 
{@code auth-params},
+ * {@code service-key}, {@code token}, {@code basic-auth}, {@code 
jaas.config}, {@code
+ * http-headers}.

Review Comment:
   keep docs short and avoid duplicate code, have one source of truth (the 
field below)



##########
flink-table/flink-table-common/src/main/resources/META-INF/services/org.apache.flink.table.factories.Factory:
##########
@@ -14,3 +14,4 @@
 # limitations under the License.
 
 org.apache.flink.table.module.CoreModuleFactory
+org.apache.flink.table.factories.DefaultConnectionFactory

Review Comment:
   ```suggestion
   org.apache.flink.table.catalog.DefaultConnectionFactory
   ```



##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/ConnectionFactory.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.flink.table.factories;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.table.catalog.CatalogConnection;
+import org.apache.flink.table.catalog.SensitiveConnection;
+import org.apache.flink.table.secret.ReadableSecretStore;
+import org.apache.flink.table.secret.WritableSecretStore;
+import org.apache.flink.table.secret.exceptions.SecretException;
+
+/**
+ * Factory for creating and resolving connections, handling the encryption and 
decryption of
+ * sensitive connection fields.
+ *
+ * <p>A {@code ConnectionFactory} is responsible for:
+ *
+ * <ul>
+ *   <li>Extracting sensitive fields from a {@link SensitiveConnection} and 
storing them in a {@link
+ *       WritableSecretStore}, returning a {@link CatalogConnection} that is 
safe to persist in a
+ *       catalog.
+ *   <li>Resolving a {@link CatalogConnection} from a catalog by retrieving 
its secrets from a
+ *       {@link ReadableSecretStore} and returning a complete {@link 
SensitiveConnection}.
+ * </ul>
+ *
+ * @see org.apache.flink.table.factories.DefaultConnectionFactory
+ */
+@PublicEvolving
+public interface ConnectionFactory extends Factory {
+
+    /**
+     * The option key that identifies the connection type in a {@link 
SensitiveConnection}'s or
+     * {@link CatalogConnection}'s options. The value of this option is 
matched against the {@link
+     * #factoryIdentifier()} of registered {@code ConnectionFactory} 
implementations to discover the
+     * factory that handles a given connection (see FLIP-529).
+     */
+    String CONNECTION_TYPE_KEY = "type";

Review Comment:
   We could make this a ConfigOption instead with a 
`DefaultConnectionFactory.IDENTIFIER` as default. 



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