use of io.cdap.cdap.api.macro.MacroParserOptions in project cdap by caskdata.
the class RemoteConnectionTaskBase method getConnector.
/**
* Returns {@link Connector} after evaluating macros
*
* @param systemAppContext {@link SystemAppTaskContext}
* @param configurer {@link ServicePluginConfigurer}
* @param pluginInfo {@link PluginInfo}
* @param namespace namespace string
* @param pluginSelector {@link TrackedPluginSelector}
* @return {@link Connector}
* @throws Exception
*/
protected Connector getConnector(SystemAppTaskContext systemAppContext, ServicePluginConfigurer configurer, PluginInfo pluginInfo, String namespace, TrackedPluginSelector pluginSelector) throws Exception {
Map<String, String> arguments = systemAppContext.getPreferencesForNamespace(namespace, true);
Map<String, MacroEvaluator> evaluators = ImmutableMap.of(SecureStoreMacroEvaluator.FUNCTION_NAME, new SecureStoreMacroEvaluator(namespace, systemAppContext), OAuthMacroEvaluator.FUNCTION_NAME, new OAuthMacroEvaluator(systemAppContext));
MacroEvaluator macroEvaluator = new DefaultMacroEvaluator(new BasicArguments(arguments), evaluators, Collections.singleton(OAuthMacroEvaluator.FUNCTION_NAME));
MacroParserOptions options = MacroParserOptions.builder().setEscaping(false).setFunctionWhitelist(evaluators.keySet()).build();
return ConnectionUtils.getConnector(configurer, pluginInfo, pluginSelector, macroEvaluator, options);
}
use of io.cdap.cdap.api.macro.MacroParserOptions in project cdap by caskdata.
the class ValidationUtilsTest method getPluginConfigurer.
// Mock PluginConfigurer
private PluginConfigurer getPluginConfigurer(PluginClass pluginClass) {
return new PluginConfigurer() {
@Override
public <T> T usePlugin(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) {
String tableName = properties.getProperties().get("tableName");
if (tableName == null || tableName.isEmpty()) {
throw new InvalidPluginConfigException(pluginClass, Collections.singleton("tableName"), new HashSet<>());
}
MockSource.Config config = new MockSource.Config();
MockSource.ConnectionConfig connectionConfig = new MockSource.ConnectionConfig();
String schema = properties.getProperties().get("schema");
String sleep = properties.getProperties().get("sleepInMillis");
connectionConfig.setTableName(tableName);
config.setConfig(connectionConfig, schema, null, sleep == null ? null : Long.parseLong(sleep));
return (T) new MockSource(config);
}
@Override
public <T> Class<T> usePluginClass(String pluginType, String pluginName, String pluginId, PluginProperties properties, PluginSelector selector) {
return null;
}
@Override
public Map<String, String> evaluateMacros(Map<String, String> properties, MacroEvaluator evaluator, MacroParserOptions options) throws InvalidMacroException {
return null;
}
};
}
Aggregations