lasdf1234 commented on code in PR #12751:
URL: https://github.com/apache/gravitino/pull/12751#discussion_r3903929847
##########
core/src/main/java/org/apache/gravitino/connector/HiddenPropertyMaskUtils.java:
##########
@@ -71,53 +79,79 @@ public static void validateNoMaskedPlaceholders(Map<String,
String> properties)
}
/**
- * Returns a mutable copy of {@code properties} with values for {@code
keysToMask} replaced by
- * {@link #MASKED_VALUE}. Entries with null keys or values are dropped.
+ * Classifies property keys for API responses.
*
- * <p>The returned map is always mutable so callers can add defaults such as
{@code in-use}.
+ * @return entry of {@code (keysToMask, keysToOmit)}
*/
- public static Map<String, String> maskHiddenProperties(
- Map<String, String> properties, Set<String> keysToMask) {
+ public static Map.Entry<Set<String>, Set<String>> classifyHiddenProperties(
+ @Nullable Map<String, String> properties, PropertiesMetadata metadata) {
+ Objects.requireNonNull(metadata, "metadata");
if (properties == null || properties.isEmpty()) {
- return new HashMap<>();
+ return Map.entry(Collections.emptySet(), Collections.emptySet());
}
- Set<String> mask = keysToMask == null ? Collections.emptySet() :
keysToMask;
- Map<String, String> result = new HashMap<>(properties.size());
+
+ Set<String> keysToMask = new HashSet<>();
+ Set<String> keysToOmit = new HashSet<>();
for (Map.Entry<String, String> entry : properties.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (key == null || value == null) {
continue;
}
- result.put(key, mask.contains(key) ? MASKED_VALUE : value);
+ boolean hidden = metadata.isHiddenProperty(key);
+ boolean reserved = metadata.isReservedProperty(key);
+ if (hidden && reserved) {
+ keysToOmit.add(key);
+ } else if (hidden || SecretPropertyUtils.isSecretProperty(key, value)) {
+ keysToMask.add(key);
+ }
}
- return result;
+ return Map.entry(Set.copyOf(keysToMask), Set.copyOf(keysToOmit));
}
/**
- * Returns a mutable API-response copy of {@code properties}.
+ * Returns a mutable copy of {@code properties} with values for {@code
keysToMask} replaced by
+ * {@link #MASKED_VALUE}. Entries with null keys or values are dropped. No
keys are omitted.
*
- * <p>Values are replaced with {@link #MASKED_VALUE} when {@link
- * PropertiesMetadata#isHiddenProperty(String)} is true (credential and
other sensitive keys) or
- * {@link SecretPropertyUtils#isSecretProperty(String, String)} is true.
Reserved keys are not
- * removed.
+ * <p>The returned map is always mutable so callers can add defaults such as
{@code in-use}.
*/
public static Map<String, String> maskHiddenProperties(
- Map<String, String> properties, PropertiesMetadata metadata) {
+ Map<String, String> properties, Set<String> keysToMask) {
+ return maskHiddenProperties(properties, keysToMask,
Collections.emptySet());
+ }
+
+ /**
+ * Like {@link #maskHiddenProperties(Map, Set)}, and also drops {@code
keysToOmit} from the
+ * result.
+ */
+ public static Map<String, String> maskHiddenProperties(
+ Map<String, String> properties,
+ @Nullable Set<String> keysToMask,
+ @Nullable Set<String> keysToOmit) {
if (properties == null || properties.isEmpty()) {
return new HashMap<>();
}
+ Set<String> mask = keysToMask == null ? Collections.emptySet() :
keysToMask;
+ Set<String> omit = keysToOmit == null ? Collections.emptySet() :
keysToOmit;
Map<String, String> result = new HashMap<>(properties.size());
for (Map.Entry<String, String> entry : properties.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
- if (key == null || value == null) {
+ if (key == null || value == null || omit.contains(key)) {
continue;
}
- boolean shouldMask =
- metadata.isHiddenProperty(key) ||
SecretPropertyUtils.isSecretProperty(key, value);
- result.put(key, shouldMask ? MASKED_VALUE : value);
+ result.put(key, mask.contains(key) ? MASKED_VALUE : value);
}
return result;
}
+
+ /**
+ * Returns a mutable API-response copy of {@code properties}:
reserved+hidden keys are omitted;
+ * other hidden keys and secret-manager URN values are replaced with {@link
#MASKED_VALUE}.
+ */
+ public static Map<String, String> maskHiddenProperties(
+ Map<String, String> properties, PropertiesMetadata metadata) {
+ Map.Entry<Set<String>, Set<String>> classified =
classifyHiddenProperties(properties, metadata);
+ return maskHiddenProperties(properties, classified.getKey(),
classified.getValue());
+ }
Review Comment:
Thank you very much for your review. I have modified PR's description and
removed the non-existent "PropertyResponsePolicy" / "forApiResponse(...)"
sections.
--
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]