private static boolean isOauthConnector(Connector connector) { return connector.getProperties().values().stream().anyMatch(x -> { return x.getTags().contains(Credentials.CLIENT_ID_TAG); } ); }
private Connector migrateOldConnectorData(Connector existingConnector, Connector newConnector) { Map<String, String> propValues = new TreeMap<>(existingConnector.getConfiguredProperties()); propValues.keySet().retainAll(newConnector.getProperties().keySet()); if (!propValues.isEmpty()) { return new Connector.Builder() .createFrom(newConnector) .putAllConfiguredProperties(propValues) .build(); } return newConnector; }
private Map<String, ConfigurationProperty> getConnectorProperties(String connectorId) { return getDataManager().fetch(Connector.class, connectorId).getProperties(); }
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(); }
@Test public void shouldCreateSecurityConfigurationFromReverbSwagger() throws IOException { final String specification = resource("/swagger/reverb.swagger.yaml"); final ConnectorSettings connectorSettings = new ConnectorSettings.Builder()// .name("Reverb API")// .description("Invokes Reverb API")// .icon("fa-music")// .putConfiguredProperty("specification", specification)// .build(); final Connector generated = generator.generate(SWAGGER_TEMPLATE, connectorSettings); assertThat(generated.getProperties().keySet()).contains("accessToken", "authorizationEndpoint", "tokenEndpoint", "clientId", "clientSecret"); assertThat(generated.getProperties().get("authenticationType").getEnum()) .containsExactly(new ConfigurationProperty.PropertyValue.Builder().value("oauth2").label("OAuth 2.0").build()); }
.containsAllEntriesOf(without(expectedConfiguredProperties, "specification")); assertThat(generated.getProperties().keySet()).as("Expecting the same properties to be generated") .containsOnlyElementsOf(expected.getProperties().keySet()); assertThat(generated.getProperties()).containsAllEntriesOf(expected.getProperties()); assertThat(generated).isEqualToIgnoringGivenFields(expected, "id", "icon", "properties", "configuredProperties", "actions"); assertThat(generated.getIcon()).startsWith("data:image");