chia7712 commented on code in PR #21548:
URL: https://github.com/apache/kafka/pull/21548#discussion_r2891620988


##########
server/src/main/java/org/apache/kafka/server/config/AbstractKafkaConfig.java:
##########
@@ -350,4 +355,178 @@ private static String parseListenerName(String 
connectionString) {
      * @param reconfigurable the component to unregister
      */
     public abstract void removeReconfigurable(Reconfigurable reconfigurable);
+
+    /**
+     * Determines whether a config entry might be sensitive based on its type.
+     * If the type cannot be determined, the config is treated as sensitive
+     * to be safe.
+     *
+     * @param configType the config entry type, or empty if unknown
+     * @return true if the config might be sensitive
+     */
+    public static boolean maybeSensitive(Optional<ConfigDef.Type> configType) {
+        return configType.isEmpty()
+                || configType.get() == ConfigDef.Type.PASSWORD;
+    }
+
+    /**
+     * Looks up the type for a config key by name directly from
+     * {@link #CONFIG_DEF}.
+     *
+     * @param name the config key name
+     * @return the type if found, or empty
+     */
+    public static Optional<ConfigDef.Type> configDefTypeOf(String name) {
+        ConfigDef.ConfigKey key = CONFIG_DEF.configKeys().get(name);
+        return key != null
+                ? Optional.of(key.type)
+                : Optional.empty();
+    }
+
+    /**
+     * Looks up the type for a config key by exact name, checking both
+     * the static config definition and the dynamic broker config keys.
+     *
+     * @param exactName the exact config key name
+     * @return the type if found, or empty
+     */
+    public static Optional<ConfigDef.Type> configTypeExact(String exactName) {
+        Optional<ConfigDef.Type> t = configDefTypeOf(exactName);
+        if (t.isPresent()) {
+            return t;
+        }
+        ConfigDef.ConfigKey configKey =
+                DynamicConfig.Broker.configKeys().get(exactName);
+        if (configKey != null) {
+            return Optional.of(configKey.type);
+        }
+        return Optional.empty();
+    }
+
+    /**
+     * Resolves the {@link ConfigDef.Type} for a given config name.
+     * First tries an exact match, then falls back to checking broker
+     * config synonyms.
+     *
+     * @param configName the config name to look up
+     * @return the type if found, or empty
+     */
+    public static Optional<ConfigDef.Type> configType(String configName) {
+        Optional<ConfigDef.Type> exact = configTypeExact(configName);
+        if (exact.isPresent()) {
+            return exact;
+        }
+        Optional<ConfigDef.Type> t = configDefTypeOf(configName);
+        if (t.isPresent()) {
+            return t;
+        }
+        return DynamicBrokerConfig
+                .brokerConfigSynonyms(configName, true)
+                .stream()
+                .map(AbstractKafkaConfig::configDefTypeOf)
+                .filter(Optional::isPresent)
+                .map(Optional::get)
+                .findFirst();
+    }
+
+    /**
+     * Returns the loggable form of a config value. Sensitive values
+     * are replaced with {@link Password#HIDDEN}.
+     *
+     * @param resourceType the config resource type
+     * @param name         the config name
+     * @param value        the config value
+     * @return the value suitable for logging
+     */
+    public static String loggableValue(ConfigResource.Type resourceType,
+                                       String name,
+                                       String value) {
+        boolean sensitive;
+        switch (resourceType) {

Review Comment:
   ```java
       public static String loggableValue(ConfigResource.Type resourceType,
                                          String name,
                                          String value) {
           boolean sensitive = switch (resourceType) {
               case BROKER -> maybeSensitive(configType(name));
               case TOPIC -> maybeSensitive(LogConfig.configType(name));
               case GROUP -> maybeSensitive(GroupConfig.configType(name));
               case BROKER_LOGGER, CLIENT_METRICS -> false;
               default -> true;
           };
           return sensitive ? Password.HIDDEN : value;
       }
   ```



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