private static Connector resolveConnector(Connection connection, DataManager dataManager) { final Connector connector; if (connection.getConnector().isPresent()) { connector = connection.getConnector().get(); } else { connector = dataManager.fetch(Connector.class, connection.getConnectorId().get()); if (connector == null) { throw new IllegalArgumentException("No connector with id: " + connection.getConnectorId().get()); } } return connector; } }
public ConnectionActionHandler(final Connection connection, final VerificationConfigurationProperties config, EncryptionComponent encryptionComponent) { this.connection = connection; this.config = config; this.encryptionComponent = encryptionComponent; final Optional<Connector> maybeConnector = connection.getConnector(); connector = maybeConnector.orElseThrow(() -> new EntityNotFoundException( "Connection with id `" + connection.getId() + "` does not have a Connector defined")); actions = connector.getActions().stream() .filter(ConnectorAction.class::isInstance) .map(ConnectorAction.class::cast) .collect(Collectors.toList()); }
public String getIcon() { return value.getIcon(); } }
private Connection recreateConnection(Connection existingConnection, Connector newConnector) { Optional<Connector> connectorToUse = existingConnection.getConnector().map(old -> newConnector); Map<String, String> confProperties = new TreeMap<>(existingConnection.getConfiguredProperties()); confProperties.keySet().retainAll(newConnector.getProperties().keySet()); return new Connection.Builder() .createFrom(existingConnection) .connector(connectorToUse) .icon(newConnector.getIcon()) .configuredProperties(confProperties) .build(); }
@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(); if( connection.getConnectorId().isPresent() ) { Map<String, ConfigurationProperty> connectorProperties = getConnectorProperties(connection.getConnectorId().get()); 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); }
.filter(c -> !c.getConnector().isPresent()) .flatMap(Connection::getConnectorId) .flatMap(this::loadConnector)
@SuppressWarnings("unchecked") private io.syndesis.integration.model.steps.Step createEndpoint(StepVisitorContext visitorContext, Step step, Connection connection, Connector connector, ConnectorAction action) { final Map<String, String> configuredProperties = aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties()); final Map<String, String> properties = aggregate(connector.filterEndpointProperties(configuredProperties), action.filterEndpointProperties(configuredProperties)); final String componentScheme = action.getDescriptor().getCamelConnectorPrefix(); // if the option is marked as secret use property placeholder as the // value is added to the integration secret. if (visitorContext.getGeneratorContext().getGeneratorProperties().isSecretMaskingEnabled()) { properties.entrySet() .stream() .filter(Predicates.or(connector::isEndpointProperty, action::isEndpointProperty)) .filter(Predicates.or(connector::isSecret, action::isSecret)) .forEach(e -> e.setValue(String.format("{{%s-%d.%s}}", componentScheme, visitorContext.getIndex(), e.getKey()))); } // any configuredProperties on action descriptor are considered final ConnectorDescriptor descriptor = action.getDescriptor(); properties.putAll(descriptor.getConfiguredProperties()); if (hasComponentProperties(configuredProperties, connector, action)) { return new io.syndesis.integration.model.steps.Endpoint(String.format("%s-%d", componentScheme, visitorContext.getIndex()), Map.class.cast(properties)); } else { return new io.syndesis.integration.model.steps.Endpoint(componentScheme, Map.class.cast(properties)); } }
public Optional<String> getConnectorId() { return value.getConnectorId(); }
public Connection toCurrentConnection(Connection c) { Connection connection = getDataManager().fetch(Connection.class, c.getId().get()); if (connection.getConnectorId().isPresent()) { final Connector connector = getDataManager().fetch(Connector.class, connection.getConnectorId().get()); connection = new Connection.Builder().createFrom(connection).connector(connector).build(); } return connection; }
public Optional<String> getId() { return value.getId(); }
public String getName() { return value.getName(); }
connection.getConnector().ifPresent(connector -> { Connector current = getDataManager().fetch(Connector.class, connector.getId().get()); if (current == null) { Map<String, String> configuredProperties = encryptionComponent.decrypt(connection.getConfiguredProperties()); if (configuredProperties.values().contains(null)) { messages.add(LeveledMessage.of(ERROR, "Configuration missing"));
@Override public void update(final String id, @ConvertGroup(from = Default.class, to = AllValidations.class) final Connection connection) { // Lets make sure we store encrypt secrets. Map<String, String> configuredProperties = connection.getConfiguredProperties(); if( connection.getConnectorId().isPresent() ) { Map<String, ConfigurationProperty> connectorProperties = getConnectorProperties(connection.getConnectorId().get()); configuredProperties = encryptionComponent.encryptPropertyValues(configuredProperties, connectorProperties); } final Connection updatedConnection = new Connection.Builder() .createFrom(connection) .configuredProperties(configuredProperties) .lastUpdated(new Date()) .build(); Updater.super.update(id, updatedConnection); // TODO: do this async perhaps.. // We may need to trigger creating bulletins for some integrations. for (String integrationId : getDataManager().fetchIds(Integration.class)) { integrationHandler.updateBulletinBoard(integrationId); } }
@Override public boolean canHandle(Step step) { if (!"endpoint".equals(step.getStepKind()) && !"connector".equals(step.getStepKind())) { return false; } if (!step.getConnection().isPresent()) { return false; } if (!step.getConnection().get().getConnector().isPresent()) { return false; } if (!step.getAction().filter(ConnectorAction.class::isInstance).isPresent()) { return false; } return !Optionals.first( step.getAction().filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).get().getDescriptor().getComponentScheme(), step.getConnection().get().getConnector().get().getComponentScheme() ).isPresent(); }
@SuppressWarnings("unchecked") private io.syndesis.integration.model.steps.Step createConnector(StepVisitorContext visitorContext, Step step, Connection connection, Connector connector, ConnectorAction action) { final Map<String, String> properties = aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties()); final String scheme = Optionals.first(action.getDescriptor().getComponentScheme(), connector.getComponentScheme()).get(); // if the option is marked as secret use property placeholder as the // value is added to the integration secret. if (visitorContext.getGeneratorContext().getGeneratorProperties().isSecretMaskingEnabled()) { properties.entrySet() .stream() .filter(Predicates.or(connector::isSecret, action::isSecret)) .forEach(e -> e.setValue(String.format("{{%s-%d.%s}}", scheme, visitorContext.getIndex(), e.getKey()))); } //Connector/Action properties have the precedence connector.getConfiguredProperties().forEach(properties::put); action.getDescriptor().getConfiguredProperties().forEach(properties::put); return new io.syndesis.camel.component.proxy.runtime.Connector( scheme + "-" + visitorContext.getIndex(), scheme, Map.class.cast(properties), Optionals.first(action.getDescriptor().getConnectorFactory(), connector.getConnectorFactory()).orElse(null), action.getDescriptor().getConnectorCustomizers() ); }
private List<Connection> findAssociatedConnections(Connector connector) { return dataManager.fetchAll(Connection.class).getItems().stream() .filter(c -> connector.getId().equals(c.getConnectorId())) .collect(Collectors.toList()); }
private void doDeleteRelatedObjects(Extension extension) { Optional<Connector> connector = findAssociatedConnector(extension); if (connector.isPresent()) { List<Connection> connections = findAssociatedConnections(connector.get()); for (Connection connection : connections) { if (connection.getId().isPresent()) { dataManager.delete(Connection.class, connection.getId().get()); } } if (connector.get().getId().isPresent()) { dataManager.delete(Connector.class, connector.get().getId().get()); } } }
final Connector connector = connection.getConnector().get(); final ConnectorAction action = step.getAction().filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).get(); final ConnectorDescriptor descriptor = action.getDescriptor(); final Map<String, String> configuredProperties = CollectionsUtils.aggregate(connection.getConfiguredProperties(), step.getConfiguredProperties()); final Map<String, String> properties = CollectionsUtils.aggregate(connector.filterEndpointProperties(configuredProperties), action.filterEndpointProperties(configuredProperties));
private static Connector resolveConnector(Connection connection, DataManager dataManager) { final Connector connector; if (connection.getConnector().isPresent()) { connector = connection.getConnector().get(); } else { connector = dataManager.fetch(Connector.class, connection.getConnectorId().get()); if (connector == null) { throw new IllegalArgumentException("No connector with id: " + connection.getConnectorId().get()); } } return connector; } }
@Override public boolean canHandle(Step step) { if (!"endpoint".equals(step.getStepKind()) && !"connector".equals(step.getStepKind())) { return false; } if (!step.getConnection().isPresent()) { return false; } if (!step.getConnection().get().getConnector().isPresent()) { return false; } if (!step.getAction().filter(ConnectorAction.class::isInstance).isPresent()) { return false; } return Optionals.first( step.getAction().filter(ConnectorAction.class::isInstance).map(ConnectorAction.class::cast).get().getDescriptor().getComponentScheme(), step.getConnection().get().getConnector().get().getComponentScheme() ).isPresent(); }