Dynamic variables #4763
Replies: 3 comments 7 replies
-
Hi @mattcasters, an idea would the decryption/deobfuscations of variable with encrypted passwords. I actually have already implemented it as a "mapping" transform (check this post for rough details) |
Beta Was this translation helpful? Give feedback.
-
May be using placeholders with default value can be nice for example like: |
Beta Was this translation helpful? Give feedback.
-
I tried to build a quick secret lookup plugin for GCP Secret Manager and after some library shenanigans... I'll try to spend some time over the weekend to give a number of Google libraries and Beam an update. @Getter
@Setter
@GuiPlugin
@VariableResolverPlugin(
id = "Variable-Resolver-GoogleSecretManager",
name = "Google Secret Manager Variable Resolver",
description = "Automatically look up values of secrets in Google Secret Manager",
documentationUrl =
"/variables/resolvers/google-secret-manager.html" // TODO: write this documentation
)
public class GooleSecretManagerVariableResolver implements IVariableResolver {
/** The name of the variable that will contain the expression in the pipeline. */
@GuiWidgetElement(
id = "projectId",
order = "0!",
label =
"i18n:org.apache.hop.core.variables.resolver:GooleSecretManagerVariableResolver.label.ProjectId",
type = GuiElementType.TEXT,
parentId = VariableResolver.GUI_PLUGIN_ELEMENT_PARENT_ID)
@HopMetadataProperty
private String projectId;
/** The name of the variable that will contain the expression in the pipeline. */
@GuiWidgetElement(
id = "locationId",
order = "02",
label =
"i18n:org.apache.hop.core.variables.resolver:GooleSecretManagerVariableResolver.label.LocationId",
type = GuiElementType.TEXT,
parentId = VariableResolver.GUI_PLUGIN_ELEMENT_PARENT_ID)
@HopMetadataProperty
private String locationId;
@Override
public void init() {
// Not used at this time. If performance is too bad for the client construction we can still do
// it.
// For now we assume that it's all just using web services anyway.
}
@Override
public String resolve(String secretId, IVariables variables) throws HopException {
if (StringUtils.isEmpty(secretId)) {
return secretId;
}
try {
SecretManagerServiceSettings.Builder settingsBuilder =
SecretManagerServiceSettings.newBuilder();
if (StringUtils.isNotEmpty(locationId)) {
String apiEndpoint = String.format("secretmanager.%s.rep.googleapis.com:443", locationId);
settingsBuilder.setEndpoint(apiEndpoint);
}
SecretManagerServiceSettings settings = settingsBuilder.build();
try (SecretManagerServiceClient client = SecretManagerServiceClient.create(settings)) {
String actualLocationId = variables.resolve(locationId);
String actualProjectId = variables.resolve(projectId);
// Get the secret version name.
//
SecretVersionName secretName;
if (StringUtils.isEmpty(actualLocationId)) {
secretName =
SecretVersionName.ofProjectSecretSecretVersionName(
actualProjectId, secretId, "latest");
} else {
secretName =
SecretVersionName.ofProjectLocationSecretSecretVersionName(
actualProjectId, actualLocationId, secretId, "latest");
}
// Get the payload for this version
//
AccessSecretVersionResponse response = client.accessSecretVersion(secretName);
// Create the secret.
return response.getPayload().getData().toStringUtf8();
}
} catch (Exception e) {
throw new HopException(
"Error looking up secret key '" + secretId + "' in Google Secret Manager", e);
}
}
@Override
public void setPluginId() {
// Nothing to set
}
@Override
public String getPluginId() {
return "Variable-Resolver-GoogleSecretManager";
}
@Override
public void setPluginName(String pluginName) {
// Nothing to set
}
@Override
public String getPluginName() {
return "Google Secret Manager Variable Resolver";
}
} |
Beta Was this translation helpful? Give feedback.
-
So, what if we had a way to dynamically resolve variables. That was the main theme of the discussion under issue #3454.
The idea is simple enough but perhaps hard to explain in text form and so it got snowed under for a while.
Well, suppose you would be able to build plugins to resolve variables with metadata.
We could introduce a new syntax:
#{resolver-name:variable}
.For example:
#{pipeline:hop}
withpipeline
: being the name of the Variable Resolver metadata objecthop
: the name of the variable or expression you would like to see resolved.The pipeline variable resolver would look something like this:
You could then make a pipeline to resolve a variable value. Here is an example with static data...
The pipeline gets the expression (or variable name) via the specified variable and looks up the actual value. In the simple scenario above we're using hardcoded value. You could also store the names and values in a database table or a file somewhere.
Other use cases would include the lookup of JSON Web Tokens, interactions with secret vaults and so on.
If you want to try this out, build pull request 4761
What resolver plugins or features did you think of? Let me know!
Cheers,
Matt
Beta Was this translation helpful? Give feedback.
All reactions