shunping commented on code in PR #39940:
URL: https://github.com/apache/beam/pull/39940#discussion_r3925633451
##########
sdks/java/core/src/main/java/org/apache/beam/sdk/util/Secret.java:
##########
@@ -152,38 +172,23 @@ public static Secret fromJson(@Nullable String spec,
@Nullable String secretMana
mapper.configure(com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_SINGLE_QUOTES,
true);
specMap = mapper.readValue(spec, new TypeReference<Map<String,
String>>() {});
} catch (Exception e) {
- logger.debug("Failed to parse secret spec as JSON map", e);
+ LOG.debug("Failed to parse secret spec as JSON map", e);
}
}
if (smManager != null) {
- switch (smManager.toLowerCase()) {
- case "googlecloudsecretmanager":
- case "gcpsecret":
- if (specMap != null) {
- return GcpSecret.fromMap(specMap);
- } else if (spec != null) {
- return new GcpSecret(spec);
- } else {
- throw new IllegalArgumentException("Invalid spec for GcpSecret");
- }
- case "googlecloudhsmgeneratedsecretmanager":
- case "gcphsmgeneratedsecret":
- if (specMap != null) {
- return GcpHsmGeneratedSecret.fromMap(specMap);
- } else {
- throw new IllegalArgumentException("Invalid spec for
GcpHsmGeneratedSecret");
- }
- default:
- throw new IllegalArgumentException(
- String.format(
- "Unsupported secret manager: '%s'. Currently supported
options: 'GoogleCloudSecretManager', 'GoogleCloudHsmGeneratedSecretManager'.",
- smManager));
+ SecretRegistrar.SecretFactory factory =
SECRET_FACTORIES.get(smManager.toLowerCase());
+ if (factory != null) {
+ return factory.createSecret(specMap != null ? specMap :
Collections.emptyMap());
Review Comment:
The new behavior is correct.
For fromJson(), we only initiate secret manager classes (except for
RawSecret) via their fromMap function, which has parameter validation.
GcpSecret(spec) is only used as a shortcut for testing or when users want to
directly initialize GcpSecret (not via Secret factory 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]