mumrah commented on code in PR #13686:
URL: https://github.com/apache/kafka/pull/13686#discussion_r1187879810


##########
shell/src/main/java/org/apache/kafka/shell/node/printer/ShellNodePrinter.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.kafka.shell.node.printer;
+
+import org.apache.kafka.image.node.printer.MetadataNodePrinter;
+import org.apache.kafka.image.node.printer.MetadataNodeRedactionCriteria;
+
+import java.io.PrintWriter;
+
+
+/**
+ * The Kafka metadata shell.
+ */
+public class ShellNodePrinter implements MetadataNodePrinter {
+    private final PrintWriter writer;
+    private int indentationLevel;
+
+    public ShellNodePrinter(PrintWriter writer) {
+        this.writer = writer;
+    }
+
+    String indentationString() {
+        StringBuilder bld = new StringBuilder();
+        for (int i = 0; i < indentationLevel; i++) {
+            for (int j = 0; j < 2; j++) {
+                bld.append(" ");
+            }
+        }
+        return bld.toString();
+    }
+
+    @Override
+    public MetadataNodeRedactionCriteria redactionCriteria() {
+        return MetadataNodeRedactionCriteria.Disabled.INSTANCE;

Review Comment:
   Ok, so while using the shell, we won't redact anything? Is the this true for 
both interactive and non-interactive usages?



##########
metadata/src/main/java/org/apache/kafka/image/node/printer/MetadataNodeRedactionCriteria.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.kafka.image.node.printer;
+
+import org.apache.kafka.common.config.ConfigResource;
+import org.apache.kafka.metadata.KafkaConfigSchema;
+
+
+public interface MetadataNodeRedactionCriteria {
+    /**
+     * Returns true if SCRAM data should be redacted.
+     */
+    boolean shouldRedactScram();
+
+    /**
+     * Returns true if a configuration should be redacted.
+     *
+     * @param type      The configuration type.
+     * @param key       The configuration key.
+     *
+     * @return          True if the configuration should be redacted.
+     */
+    boolean shouldRedactConfig(ConfigResource.Type type, String key);
+
+    class Strict implements MetadataNodeRedactionCriteria {
+        public static final Strict INSTANCE = new Strict();
+
+        @Override
+        public boolean shouldRedactScram() {
+            return true;
+        }
+
+        @Override
+        public boolean shouldRedactConfig(ConfigResource.Type type, String 
key) {
+            return true;
+        }
+    }
+
+    class Normal implements MetadataNodeRedactionCriteria {

Review Comment:
   Since this one requires KafkaConfigSchema, I'm guessing it's for use by 
QuorumController?



##########
shell/src/main/java/org/apache/kafka/shell/command/FindCommandHandler.java:
##########
@@ -80,28 +84,28 @@ public FindCommandHandler(List<String> paths) {
     }
 
     @Override
-    public void run(Optional<InteractiveShell> shell,
-                    PrintWriter writer,
-                    MetadataNodeManager manager) throws Exception {
+    public void run(
+        Optional<InteractiveShell> shell,
+        PrintWriter writer,
+        MetadataShellState state
+    ) throws Exception {
         for (String path : CommandUtils.getEffectivePaths(paths)) {
-            manager.visit(new GlobVisitor(path, entryOption -> {
+            new GlobVisitor(path, entryOption -> {
                 if (entryOption.isPresent()) {
                     find(writer, path, entryOption.get().node());
                 } else {
                     writer.println("find: " + path + ": no such file or 
directory.");
                 }
-            }));
+            }).accept(state);
         }
     }
 
     private void find(PrintWriter writer, String path, MetadataNode node) {
         writer.println(path);
-        if (node instanceof DirectoryNode) {
-            DirectoryNode directory = (DirectoryNode) node;
-            for (Entry<String, MetadataNode> entry : 
directory.children().entrySet()) {
-                String nextPath = path.equals("/") ?
-                    path + entry.getKey() : path + "/" + entry.getKey();
-                find(writer, nextPath, entry.getValue());
+        if (node.isDirectory()) {

Review Comment:
   The `MetadataNode#child` signature indicates it can return `null`, so should 
we check for null here? 



##########
shell/src/main/java/org/apache/kafka/shell/glob/GlobVisitor.java:
##########
@@ -93,32 +96,33 @@ public String toString() {
     }
 
     @Override
-    public void accept(MetadataNodeManager.Data data) {
+    public void accept(MetadataShellState state) {
         String fullGlob = glob.startsWith("/") ? glob :
-            data.workingDirectory() + "/" + glob;
+            state.workingDirectory() + "/" + glob;
         List<String> globComponents =
             
CommandUtils.stripDotPathComponents(CommandUtils.splitPath(fullGlob));
-        if (!accept(globComponents, 0, data.root(), new String[0])) {
+        if (!accept(globComponents, 0, state.root(), new String[0])) {
             handler.accept(Optional.empty());
         }
     }
 
-    private boolean accept(List<String> globComponents,
-                           int componentIndex,
-                           MetadataNode node,
-                           String[] path) {
+    private boolean accept(
+        List<String> globComponents,
+        int componentIndex,
+        MetadataNode node,
+        String[] path
+    ) {

Review Comment:
   Similar to above, do we need a null check on `node`?



##########
shell/src/main/java/org/apache/kafka/shell/state/MetadataShellState.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.kafka.shell.state;
+
+import org.apache.kafka.image.MetadataImage;
+import org.apache.kafka.image.node.MetadataNode;
+import org.apache.kafka.shell.node.RootShellNode;
+
+import java.util.function.Consumer;
+
+/**
+ * The Kafka metadata shell.

Review Comment:
   Is this javadoc correct?



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to