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


##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/factories/DefaultConnectionFactory.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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}.
+ */
+@Internal
+public class DefaultConnectionFactory implements ConnectionFactory {
+
+    /**
+     * Reserved option key used to store the reference to secrets in the 
secret store. The
+     * surrounding double underscores make collision with user-supplied option 
names unlikely; user
+     * options containing this key will be rejected at create-time.
+     */
+    public static final String SECRET_REFERENCE_KEY = 
"__flink.encrypted_secret_key__";
+
+    private static final Set<String> SENSITIVE_FIELD_NAMES =
+            Collections.unmodifiableSet(
+                    new HashSet<>(
+                            Arrays.asList(
+                                    "password",

Review Comment:
   A comment would definitely help.



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