use of io.syndesis.common.model.connection.ConfigurationProperty in project syndesis by syndesisio.
the class ProjectGenerator method generateApplicationProperties.
@SuppressWarnings("PMD")
@Override
public Properties generateApplicationProperties(final Integration integrationDefinition) {
final Integration integration = sanitize(integrationDefinition, resourceManager);
final Properties properties = new Properties();
final List<? extends Step> steps = integration.getSteps();
for (int i = 0; i < steps.size(); i++) {
final Step step = steps.get(i);
// Check if a step is of supported type.
if (StepKind.endpoint != step.getStepKind()) {
continue;
}
// Check if a step has the required options
if (step.getAction().filter(ConnectorAction.class::isInstance).isPresent() && step.getConnection().isPresent()) {
final String index = Integer.toString(i + 1);
final Connection connection = step.getConnection().get();
final ConnectorAction action = ConnectorAction.class.cast(step.getAction().get());
final ConnectorDescriptor descriptor = action.getDescriptor();
final Connector connector = resourceManager.loadConnector(connection).orElseThrow(() -> new IllegalArgumentException("No connector with id: " + connection.getConnectorId()));
if (connector.getComponentScheme().isPresent() || descriptor.getComponentScheme().isPresent()) {
// Grab the component scheme from the component descriptor or
// from the connector
final String componentScheme = Optionals.first(descriptor.getComponentScheme(), connector.getComponentScheme()).get();
final Map<String, ConfigurationProperty> configurationProperties = CollectionsUtils.aggregate(connector.getProperties(), action.getProperties());
// Workaround for https://github.com/syndesisio/syndesis/issues/1713
for (Map.Entry<String, ConfigurationProperty> entry : configurationProperties.entrySet()) {
if (entry.getValue() != null && entry.getValue().getDefaultValue() != null && !entry.getValue().getDefaultValue().isEmpty()) {
if (connector.isSecret(entry.getKey()) || action.isSecret(entry.getKey())) {
addDecryptedKeyProperty(properties, index, componentScheme, entry.getKey(), entry.getValue().getDefaultValue());
}
}
}
for (Map.Entry<String, String> entry : connection.getConfiguredProperties().entrySet()) {
if (connector.isSecret(entry) || action.isSecret(entry)) {
addDecryptedKeyProperty(properties, index, componentScheme, entry.getKey(), entry.getValue());
}
}
for (Map.Entry<String, String> entry : step.getConfiguredProperties().entrySet()) {
if (connector.isSecret(entry) || action.isSecret(entry)) {
addDecryptedKeyProperty(properties, index, componentScheme, entry.getKey(), entry.getValue());
}
}
} else {
// The component scheme is defined as camel connector prefix
// for 'old' style connectors.
final String componentScheme = descriptor.getCamelConnectorPrefix();
// endpoint secrets
Stream.of(connector, connection, step).filter(WithConfiguredProperties.class::isInstance).map(WithConfiguredProperties.class::cast).map(WithConfiguredProperties::getConfiguredProperties).flatMap(map -> map.entrySet().stream()).filter(Predicates.or(connector::isEndpointProperty, action::isEndpointProperty)).filter(Predicates.or(connector::isSecret, action::isSecret)).forEach(e -> {
addDecryptedKeyProperty(properties, index, componentScheme, e.getKey(), e.getValue());
});
// Component properties triggers connectors aliasing so we
// can have multiple instances of the same connectors
Stream.of(connector, connection, step).filter(WithConfiguredProperties.class::isInstance).map(WithConfiguredProperties.class::cast).map(WithConfiguredProperties::getConfiguredProperties).flatMap(map -> map.entrySet().stream()).filter(Predicates.or(connector::isComponentProperty, action::isComponentProperty)).forEach(e -> {
String propKeyPrefix = String.format("%s.configurations.%s", componentScheme, componentScheme);
addDecryptedKeyProperty(properties, index, propKeyPrefix, e.getKey(), e.getValue());
});
}
}
}
return properties;
}
use of io.syndesis.common.model.connection.ConfigurationProperty in project syndesis by syndesisio.
the class CustomConnectorHandlerTest method shouldCreateNewConnectorsBasedOnConnectorTemplates.
@Test
public void shouldCreateNewConnectorsBasedOnConnectorTemplates() {
final Map<String, ConfigurationProperty> properties = new HashMap<>();
properties.put("prop1", new ConfigurationProperty.Builder().build());
final Map<String, ConfigurationProperty> connectorProperties = new HashMap<>();
connectorProperties.put("prop2", new ConfigurationProperty.Builder().build());
connectorProperties.put("prop3", new ConfigurationProperty.Builder().build());
final ConnectorGroup group = new ConnectorGroup.Builder().name("connector template group").build();
final ConnectorTemplate connectorTemplate = //
new ConnectorTemplate.Builder().id(//
"connector-template-id").name(//
"connector template").properties(properties).connectorProperties(//
connectorProperties).connectorGroup(//
group).build();
final ConnectorAction action = new ConnectorAction.Builder().name("action").build();
when(dataManager.fetch(ConnectorTemplate.class, "connector-template-id")).thenReturn(connectorTemplate);
when(dataManager.create(any(Connector.class))).thenAnswer(invocation -> invocation.getArgumentAt(0, Connector.class));
when(applicationContext.getBean("connector-template-id", ConnectorGenerator.class)).thenReturn(new ConnectorGenerator() {
@Override
public Connector generate(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) {
return new Connector.Builder().createFrom(baseConnectorFrom(connectorTemplate, connectorSettings)).putAllProperties(connectorProperties).putConfiguredProperty("prop1", "value1").addAction(action).build();
}
@Override
public ConnectorSummary info(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) {
return null;
}
});
final Connector created = //
new CustomConnectorHandler(dataManager, applicationContext, iconDao).create(//
new ConnectorSettings.Builder().connectorTemplateId(//
"connector-template-id").name(//
"new connector").description(//
"new connector description").icon(//
"new connector icon").putConfiguredProperty("prop1", //
"value1").putConfiguredProperty("unknown-prop", //
"unknown-value").build());
final Connector expected = //
new Connector.Builder().id(//
created.getId()).name(//
"new connector").description(//
"new connector description").icon(//
"new connector icon").connectorGroup(//
group).properties(//
connectorProperties).putConfiguredProperty("prop1", //
"value1").addAction(//
action).build();
assertThat(created).isEqualTo(expected);
}
use of io.syndesis.common.model.connection.ConfigurationProperty in project syndesis by syndesisio.
the class EncryptionComponent method encryptPropertyValues.
public Map<String, String> encryptPropertyValues(Map<String, String> values, Map<String, ConfigurationProperty> properties) {
final Map<String, String> result = new HashMap<>(values);
if (textEncryptor != null) {
// Let encrypt all the secrets
for (Map.Entry<String, String> entry : values.entrySet()) {
ConfigurationProperty property = properties.get(entry.getKey());
if (property == null || !property.isSecret()) {
continue;
}
result.put(entry.getKey(), encrypt(entry.getValue()));
}
}
return result;
}
use of io.syndesis.common.model.connection.ConfigurationProperty in project syndesis by syndesisio.
the class ConnectionHandler method create.
@Override
public Connection create(@Context SecurityContext sec, @ConvertGroup(from = Default.class, to = AllValidations.class) final Connection connection) {
final Date rightNow = new Date();
// Lets make sure we store encrypt secrets.
Map<String, String> configuredProperties = connection.getConfiguredProperties();
Map<String, ConfigurationProperty> connectorProperties = getConnectorProperties(connection.getConnectorId());
configuredProperties = encryptionComponent.encryptPropertyValues(configuredProperties, connectorProperties);
final Connection updatedConnection = new Connection.Builder().createFrom(connection).createdDate(rightNow).lastUpdated(rightNow).configuredProperties(configuredProperties).userId(sec.getUserPrincipal().getName()).build();
final Set<CredentialFlowState> flowStates = CredentialFlowState.Builder.restoreFrom(state::restoreFrom, request);
final Connection connectionToCreate = flowStates.stream().map(s -> {
final Cookie removal = new Cookie(s.persistenceKey(), "");
removal.setPath("/");
removal.setMaxAge(0);
response.addCookie(removal);
return credentials.apply(updatedConnection, s);
}).findFirst().orElse(updatedConnection);
return Creator.super.create(sec, connectionToCreate);
}
use of io.syndesis.common.model.connection.ConfigurationProperty in project syndesis by syndesisio.
the class AbstractResourceUpdateHandler method computePropertiesDiffMessages.
// *********************
// Simple Bulletin
// *********************
protected List<LeveledMessage> computePropertiesDiffMessages(Supplier<LeveledMessage.Builder> supplier, Map<String, ConfigurationProperty> left, Map<String, ConfigurationProperty> right) {
final List<LeveledMessage> messages = new ArrayList<>();
final MapDifference<String, ConfigurationProperty> diff = Maps.difference(left, right);
for (Map.Entry<String, MapDifference.ValueDifference<ConfigurationProperty>> entry : diff.entriesDiffering().entrySet()) {
final MapDifference.ValueDifference<ConfigurationProperty> value = entry.getValue();
final ConfigurationProperty leftValue = value.leftValue();
final ConfigurationProperty rightValue = value.rightValue();
// Special handling because of dynamic metadata
if (!equals(leftValue, rightValue)) {
messages.add(supplier.get().level(LeveledMessage.Level.INFO).code(LeveledMessage.Code.SYNDESIS001).build());
break;
}
}
if (!diff.entriesOnlyOnLeft().isEmpty() || !diff.entriesOnlyOnRight().isEmpty()) {
messages.add(supplier.get().level(LeveledMessage.Level.WARN).code(LeveledMessage.Code.SYNDESIS002).build());
}
return messages;
}
Aggregations