lasdf1234 commented on code in PR #12798:
URL: https://github.com/apache/gravitino/pull/12798#discussion_r3912400276


##########
core/src/main/java/org/apache/gravitino/secret/SecretAlterChanges.java:
##########
@@ -90,6 +92,58 @@ public static Pair<CatalogChange[], List<SecretMaterial>> 
prepareCatalogChanges(
     }
   }
 
+  /**
+   * Prepares catalog changes for a connection test without writing or 
deleting secret material.
+   *
+   * <p>Write-through bindings are validated but represented by their 
plaintext only in the
+   * temporary catalog configuration. External references are converted to 
reference URNs so the
+   * temporary catalog resolves them through the configured provider.
+   *
+   * @param secretManager secret manager
+   * @param entityId catalog entity id
+   * @param changes proposed catalog changes
+   * @return effective changes for a temporary catalog entity
+   */
+  public static CatalogChange[] prepareCatalogChangesForTest(
+      SecretManager secretManager, long entityId, CatalogChange... changes) {
+    Preconditions.checkArgument(secretManager != null, "secretManager must not 
be null");
+    Preconditions.checkArgument(changes != null, "changes must not be null");
+
+    List<CatalogChange> out = new ArrayList<>(changes.length);
+    for (CatalogChange change : changes) {
+      if (change instanceof CatalogChange.SetSecretBinding) {
+        CatalogChange.SetSecretBinding c = (CatalogChange.SetSecretBinding) 
change;
+        String property = c.getProperty();
+        SecretBinding binding = c.getBinding();
+        Preconditions.checkArgument(StringUtils.isNotBlank(property), 
"property must not be blank");
+        Preconditions.checkArgument(binding != null, "binding must not be 
null");
+        
SecretPropertyUtils.validateAlterSecretBindingPlaintext(binding.plaintext());
+        secretManager.buildSecretBindingUrns("catalog", entityId, 
Map.of(property, binding));

Review Comment:
   secretManager.buildSecretBindingUrns("catalog", entityId, Map.of(property, 
binding)); This line of code discards the obtained urn. The fundamental reason 
for this is to verify the legality of the entityType, entityId, property, and 
binding. Therefore, the buildSecretBindingUrns method was used.
   This verification is necessary, but the code's readability is poor.
   So, could the explicit validate method be extracted from SecretManager? 
Extract a validateSecretBindingUrns method.
   And buildSecretBindingUrns, will call the validateSecretBindingUrns method 
for verification.
   This part can also be replaced with the validateSecretBindingUrns method.



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