Search in sources :

Example 6 with ConfigurationProperty

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;
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ProjectGeneratorHelper.sanitize(io.syndesis.integration.project.generator.ProjectGeneratorHelper.sanitize) ProjectGeneratorHelper.mandatoryDecrypt(io.syndesis.integration.project.generator.ProjectGeneratorHelper.mandatoryDecrypt) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) ProjectGeneratorHelper.addTarEntry(io.syndesis.integration.project.generator.ProjectGeneratorHelper.addTarEntry) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) MavenProperties(io.syndesis.common.util.MavenProperties) StringUtils(org.apache.commons.lang3.StringUtils) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) WithConfiguredProperties(io.syndesis.common.model.WithConfiguredProperties) PipedInputStream(java.io.PipedInputStream) Connection(io.syndesis.common.model.connection.Connection) Map(java.util.Map) Integration(io.syndesis.common.model.integration.Integration) DefaultMustacheFactory(com.github.mustachejava.DefaultMustacheFactory) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Set(java.util.Set) Connector(io.syndesis.common.model.connection.Connector) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) ProjectGeneratorHelper.addResource(io.syndesis.integration.project.generator.ProjectGeneratorHelper.addResource) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Stream(java.util.stream.Stream) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) MavenGav(io.syndesis.integration.project.generator.mvn.MavenGav) PomContext(io.syndesis.integration.project.generator.mvn.PomContext) Step(io.syndesis.common.model.integration.Step) Mustache(com.github.mustachejava.Mustache) Names(io.syndesis.common.util.Names) TreeSet(java.util.TreeSet) MustacheFactory(com.github.mustachejava.MustacheFactory) CollectionsUtils(io.syndesis.common.util.CollectionsUtils) StepKind(io.syndesis.common.model.integration.StepKind) Optionals(io.syndesis.common.util.Optionals) ExecutorService(java.util.concurrent.ExecutorService) OutputStream(java.io.OutputStream) Properties(java.util.Properties) Logger(org.slf4j.Logger) Files(java.nio.file.Files) IntegrationProjectGenerator(io.syndesis.integration.api.IntegrationProjectGenerator) Predicates(io.syndesis.common.util.Predicates) IOException(java.io.IOException) PipedOutputStream(java.io.PipedOutputStream) Dependency(io.syndesis.common.model.Dependency) ProjectGeneratorHelper.compile(io.syndesis.integration.project.generator.ProjectGeneratorHelper.compile) Paths(java.nio.file.Paths) IntegrationResourceManager(io.syndesis.integration.api.IntegrationResourceManager) Json(io.syndesis.common.util.Json) InputStream(java.io.InputStream) Connector(io.syndesis.common.model.connection.Connector) Integration(io.syndesis.common.model.integration.Integration) WithConfiguredProperties(io.syndesis.common.model.WithConfiguredProperties) Connection(io.syndesis.common.model.connection.Connection) Step(io.syndesis.common.model.integration.Step) MavenProperties(io.syndesis.common.util.MavenProperties) WithConfiguredProperties(io.syndesis.common.model.WithConfiguredProperties) Properties(java.util.Properties) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Map(java.util.Map)

Example 7 with ConfigurationProperty

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);
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Connector(io.syndesis.common.model.connection.Connector) HashMap(java.util.HashMap) ConnectorGenerator(io.syndesis.server.connector.generator.ConnectorGenerator) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) ConnectorSummary(io.syndesis.common.model.connection.ConnectorSummary) ConnectorTemplate(io.syndesis.common.model.connection.ConnectorTemplate) ConnectorGroup(io.syndesis.common.model.connection.ConnectorGroup) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Test(org.junit.Test)

Example 8 with ConfigurationProperty

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;
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with ConfigurationProperty

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);
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Cookie(javax.servlet.http.Cookie) CredentialFlowState(io.syndesis.server.credential.CredentialFlowState) Connection(io.syndesis.common.model.connection.Connection) Date(java.util.Date)

Example 10 with ConfigurationProperty

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;
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) MapDifference(com.google.common.collect.MapDifference) ArrayList(java.util.ArrayList) Map(java.util.Map) LeveledMessage(io.syndesis.common.model.bulletin.LeveledMessage)

Aggregations

ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)10 Connection (io.syndesis.common.model.connection.Connection)4 Connector (io.syndesis.common.model.connection.Connector)4 Map (java.util.Map)4 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)3 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 Swagger (io.swagger.models.Swagger)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 DefaultMustacheFactory (com.github.mustachejava.DefaultMustacheFactory)1 Mustache (com.github.mustachejava.Mustache)1 MustacheFactory (com.github.mustachejava.MustacheFactory)1 MapDifference (com.google.common.collect.MapDifference)1 Parameter (io.swagger.models.parameters.Parameter)1 SwaggerParser (io.swagger.parser.SwaggerParser)1 Dependency (io.syndesis.common.model.Dependency)1 WithConfiguredProperties (io.syndesis.common.model.WithConfiguredProperties)1 LeveledMessage (io.syndesis.common.model.bulletin.LeveledMessage)1 ConnectorGroup (io.syndesis.common.model.connection.ConnectorGroup)1