shunping commented on code in PR #39806:
URL: https://github.com/apache/beam/pull/39806#discussion_r3807547234


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/util/GcpHsmGeneratedSecret.java:
##########
@@ -62,6 +73,47 @@ public GcpHsmGeneratedSecret(
     this.secretId = "HsmGeneratedSecret_" + jobName;
   }
 
+  /** Initialize GcpHsmGeneratedSecret from a map specification. */
+  static GcpHsmGeneratedSecret fromMap(Map<String, String> specMap) {
+    Set<String> allowedKeys =
+        new HashSet<>(
+            Arrays.asList("project_id", "location_id", "key_ring_id", 
"key_id", "job_name"));
+    Set<String> missing = new HashSet<>();
+    for (String key : allowedKeys) {
+      if (!specMap.containsKey(key) || 
Strings.isNullOrEmpty(specMap.get(key))) {
+        missing.add(key);
+      }
+    }
+    if (!missing.isEmpty()) {
+      List<String> sortedMissing = new ArrayList<>(missing);
+      Collections.sort(sortedMissing);
+      throw new IllegalArgumentException(
+          "Missing required parameter(s) for GcpHsmGeneratedSecret: " + 
sortedMissing);
+    }
+    Set<String> invalid = new HashSet<>(specMap.keySet());
+    invalid.removeAll(allowedKeys);
+    if (!invalid.isEmpty()) {
+      List<String> sortedInvalid = new ArrayList<>(invalid);
+      Collections.sort(sortedInvalid);
+      throw new IllegalArgumentException(
+          "Invalid secret parameter " + String.join(", ", sortedInvalid));
+    }
+    return new GcpHsmGeneratedSecret(
+        Preconditions.checkNotNull(

Review Comment:
   I slightly change the validation, PTAL.
   
   But yes, `GcpHsmGeneratedSecret` requires nonnull parameters.



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