lihaosky commented on code in PR #28792:
URL: https://github.com/apache/flink/pull/28792#discussion_r4075113596


##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/DescribeConnectionOperation.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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.operations;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.configuration.GlobalConfiguration;
+import org.apache.flink.configuration.SecurityOptions;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.api.internal.ShowCreateUtil;
+import org.apache.flink.table.api.internal.TableResultInternal;
+import org.apache.flink.table.catalog.CatalogConnection;
+import org.apache.flink.table.catalog.ContextResolvedConnection;
+import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.table.types.DataType;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import static 
org.apache.flink.table.api.internal.TableResultUtils.buildTableResult;
+
+/** Operation to describe a DESCRIBE CONNECTION statement. */
+@Internal
+public class DescribeConnectionOperation implements Operation, 
ExecutableOperation {
+
+    private final ObjectIdentifier connectionIdentifier;
+    private final boolean isExtended;
+
+    public DescribeConnectionOperation(ObjectIdentifier connectionIdentifier, 
boolean isExtended) {
+        this.connectionIdentifier = connectionIdentifier;
+        this.isExtended = isExtended;
+    }
+
+    public ObjectIdentifier getConnectionIdentifier() {
+        return connectionIdentifier;
+    }
+
+    public boolean isExtended() {
+        return isExtended;
+    }
+
+    @Override
+    public String asSummaryString() {
+        Map<String, Object> params = new LinkedHashMap<>();
+        params.put("identifier", connectionIdentifier);
+        params.put("isExtended", isExtended);
+        return OperationUtils.formatWithChildren(
+                "DESCRIBE CONNECTION", params, Collections.emptyList(), 
Operation::asSummaryString);
+    }
+
+    @Override
+    public TableResultInternal execute(Context ctx) {
+        ContextResolvedConnection resolvedConnection =
+                ctx.getCatalogManager()
+                        .getResolvedConnection(connectionIdentifier)
+                        .orElseThrow(
+                                () ->
+                                        new ValidationException(
+                                                String.format(
+                                                        "Connection with 
identifier '%s' does not exist.",
+                                                        
connectionIdentifier.asSummaryString())));
+        return buildTableResult(
+                new String[] {"name", "value"},
+                new DataType[] {DataTypes.STRING(), DataTypes.STRING()},
+                buildRows(
+                        resolvedConnection.getConnection(),
+                        resolvedConnection.isTemporary(),
+                        
ctx.getTableConfig().get(SecurityOptions.ADDITIONAL_SENSITIVE_KEYS)));
+    }
+
+    private Object[][] buildRows(
+            CatalogConnection connection,
+            boolean isTemporary,
+            List<String> additionalSensitiveKeys) {
+        List<Object[]> rows = new ArrayList<>();
+        new 
TreeMap<>(ShowCreateUtil.withoutConnectionInternalOptions(connection.getOptions()))
+                .forEach(
+                        (key, value) -> {
+                            rows.add(
+                                    new Object[] {
+                                        key, maskValue(key, value, 
additionalSensitiveKeys)
+                                    });
+                        });
+        if (connection.getComment() != null && 
!connection.getComment().isEmpty()) {
+            rows.add(new Object[] {"comment", connection.getComment()});

Review Comment:
   What if `comment` is also in options?



##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/DescribeConnectionOperation.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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.operations;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.configuration.GlobalConfiguration;
+import org.apache.flink.configuration.SecurityOptions;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.api.internal.ShowCreateUtil;
+import org.apache.flink.table.api.internal.TableResultInternal;
+import org.apache.flink.table.catalog.CatalogConnection;
+import org.apache.flink.table.catalog.ContextResolvedConnection;
+import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.table.types.DataType;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import static 
org.apache.flink.table.api.internal.TableResultUtils.buildTableResult;
+
+/** Operation to describe a DESCRIBE CONNECTION statement. */
+@Internal
+public class DescribeConnectionOperation implements Operation, 
ExecutableOperation {
+
+    private final ObjectIdentifier connectionIdentifier;
+    private final boolean isExtended;
+
+    public DescribeConnectionOperation(ObjectIdentifier connectionIdentifier, 
boolean isExtended) {
+        this.connectionIdentifier = connectionIdentifier;
+        this.isExtended = isExtended;
+    }
+
+    public ObjectIdentifier getConnectionIdentifier() {
+        return connectionIdentifier;
+    }
+
+    public boolean isExtended() {
+        return isExtended;
+    }
+
+    @Override
+    public String asSummaryString() {
+        Map<String, Object> params = new LinkedHashMap<>();
+        params.put("identifier", connectionIdentifier);
+        params.put("isExtended", isExtended);
+        return OperationUtils.formatWithChildren(
+                "DESCRIBE CONNECTION", params, Collections.emptyList(), 
Operation::asSummaryString);
+    }
+
+    @Override
+    public TableResultInternal execute(Context ctx) {
+        ContextResolvedConnection resolvedConnection =
+                ctx.getCatalogManager()
+                        .getResolvedConnection(connectionIdentifier)
+                        .orElseThrow(
+                                () ->
+                                        new ValidationException(
+                                                String.format(
+                                                        "Connection with 
identifier '%s' does not exist.",
+                                                        
connectionIdentifier.asSummaryString())));
+        return buildTableResult(
+                new String[] {"name", "value"},
+                new DataType[] {DataTypes.STRING(), DataTypes.STRING()},
+                buildRows(
+                        resolvedConnection.getConnection(),
+                        resolvedConnection.isTemporary(),
+                        
ctx.getTableConfig().get(SecurityOptions.ADDITIONAL_SENSITIVE_KEYS)));
+    }
+
+    private Object[][] buildRows(
+            CatalogConnection connection,
+            boolean isTemporary,
+            List<String> additionalSensitiveKeys) {
+        List<Object[]> rows = new ArrayList<>();
+        new 
TreeMap<>(ShowCreateUtil.withoutConnectionInternalOptions(connection.getOptions()))
+                .forEach(
+                        (key, value) -> {
+                            rows.add(
+                                    new Object[] {
+                                        key, maskValue(key, value, 
additionalSensitiveKeys)
+                                    });
+                        });
+        if (connection.getComment() != null && 
!connection.getComment().isEmpty()) {
+            rows.add(new Object[] {"comment", connection.getComment()});
+        }
+        if (isExtended) {

Review Comment:
   I don't see `isExtended` used by other resource to guard output temporary or 
not. Maybe remove this?



##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/DescribeConnectionOperation.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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.operations;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.configuration.GlobalConfiguration;
+import org.apache.flink.configuration.SecurityOptions;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.api.internal.ShowCreateUtil;
+import org.apache.flink.table.api.internal.TableResultInternal;
+import org.apache.flink.table.catalog.CatalogConnection;
+import org.apache.flink.table.catalog.ContextResolvedConnection;
+import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.table.types.DataType;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import static 
org.apache.flink.table.api.internal.TableResultUtils.buildTableResult;
+
+/** Operation to describe a DESCRIBE CONNECTION statement. */
+@Internal
+public class DescribeConnectionOperation implements Operation, 
ExecutableOperation {
+
+    private final ObjectIdentifier connectionIdentifier;
+    private final boolean isExtended;
+
+    public DescribeConnectionOperation(ObjectIdentifier connectionIdentifier, 
boolean isExtended) {
+        this.connectionIdentifier = connectionIdentifier;
+        this.isExtended = isExtended;
+    }
+
+    public ObjectIdentifier getConnectionIdentifier() {
+        return connectionIdentifier;
+    }
+
+    public boolean isExtended() {
+        return isExtended;
+    }
+
+    @Override
+    public String asSummaryString() {
+        Map<String, Object> params = new LinkedHashMap<>();
+        params.put("identifier", connectionIdentifier);
+        params.put("isExtended", isExtended);
+        return OperationUtils.formatWithChildren(
+                "DESCRIBE CONNECTION", params, Collections.emptyList(), 
Operation::asSummaryString);
+    }
+
+    @Override
+    public TableResultInternal execute(Context ctx) {
+        ContextResolvedConnection resolvedConnection =
+                ctx.getCatalogManager()
+                        .getResolvedConnection(connectionIdentifier)
+                        .orElseThrow(
+                                () ->
+                                        new ValidationException(
+                                                String.format(
+                                                        "Connection with 
identifier '%s' does not exist.",
+                                                        
connectionIdentifier.asSummaryString())));
+        return buildTableResult(
+                new String[] {"name", "value"},
+                new DataType[] {DataTypes.STRING(), DataTypes.STRING()},
+                buildRows(
+                        resolvedConnection.getConnection(),
+                        resolvedConnection.isTemporary(),
+                        
ctx.getTableConfig().get(SecurityOptions.ADDITIONAL_SENSITIVE_KEYS)));
+    }
+
+    private Object[][] buildRows(
+            CatalogConnection connection,
+            boolean isTemporary,
+            List<String> additionalSensitiveKeys) {
+        List<Object[]> rows = new ArrayList<>();
+        new 
TreeMap<>(ShowCreateUtil.withoutConnectionInternalOptions(connection.getOptions()))
+                .forEach(
+                        (key, value) -> {
+                            rows.add(
+                                    new Object[] {
+                                        key, maskValue(key, value, 
additionalSensitiveKeys)

Review Comment:
   why do we need to mask value? I think the connection returned by 
getConnection is already encrypted and sensitive key/values are gone. Even if 
we need to mask, we can't mask by GlobalConfig, we need to mask by 
`ConnectionFactory`'s sensitive keys.



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