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


##########
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));
+        out.add(CatalogChange.setProperty(property, binding.plaintext()));
+      } else if (change instanceof CatalogChange.SetSecretReference) {
+        CatalogChange.SetSecretReference c = 
(CatalogChange.SetSecretReference) change;
+        String property = c.getProperty();
+        SecretReference reference = c.getReference();
+        Preconditions.checkArgument(StringUtils.isNotBlank(property), 
"property must not be blank");
+        Preconditions.checkArgument(reference != null, "reference must not be 
null");
+        SecretUrn urn = 
secretManager.buildSecretReferenceUrns(Map.of(property, reference)).get(0);
+        out.add(CatalogChange.setProperty(property, urn.toString()));
+      } else if (change instanceof CatalogChange.SetProperty) {
+        CatalogChange.SetProperty c = (CatalogChange.SetProperty) change;
+        SecretPropertyUtils.validateAlterSetPropertyValue(c.getProperty(), 
c.getValue());
+        out.add(change);
+      } else if (change instanceof CatalogChange.RemoveProperty) {
+        CatalogChange.RemoveProperty c = (CatalogChange.RemoveProperty) change;
+        Preconditions.checkArgument(
+            StringUtils.isNotBlank(c.getProperty()), "property must not be 
blank");
+        out.add(change);
+      } else {
+        out.add(change);
+      }
+    }
+    return out.toArray(new CatalogChange[0]);
+  }

Review Comment:
   @lasdf1234, can you please review this part?



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