private static boolean isOauthConnector(Connector connector) { return connector.getProperties().values().stream().anyMatch(x -> { return x.getTags().contains(Credentials.CLIENT_ID_TAG); } ); }
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; }
protected final Connector basicConnector(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) { final Swagger swagger = parseSpecification(connectorSettings, false).getModel(); // could be either JSON of the Swagger specification or a URL to one final String specification = requiredSpecification(connectorSettings); if (specification.startsWith("http")) { swagger.vendorExtension(URL_EXTENSION, URI.create(specification)); } final Connector baseConnector = baseConnectorFrom(connectorTemplate, connectorSettings); final Connector.Builder builder = new Connector.Builder().createFrom(baseConnector); final Map<String, String> alreadyConfiguredProperties = builder.build().getConfiguredProperties(); connectorTemplate.getConnectorProperties().forEach((propertyName, template) -> { final Optional<ConfigurationProperty> maybeProperty = PropertyGenerators.createProperty(propertyName, swagger, template); maybeProperty.ifPresent(property -> { builder.putProperty(propertyName, property); if (!alreadyConfiguredProperties.containsKey(propertyName)) { final String defaultValue = property.getDefaultValue(); if (defaultValue != null) { builder.putConfiguredProperty(propertyName, defaultValue); } } }); }); return builder.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()); }
protected final Connector basicConnector(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) { final Swagger swagger = parseSpecification(connectorSettings, false).getModel(); // could be either JSON of the Swagger specification or a URL to one final String specification = requiredSpecification(connectorSettings); if (specification.startsWith("http")) { swagger.vendorExtension(URL_EXTENSION, URI.create(specification)); } final Connector baseConnector = baseConnectorFrom(connectorTemplate, connectorSettings); final Connector.Builder builder = new Connector.Builder().createFrom(baseConnector); final Map<String, String> alreadyConfiguredProperties = builder.build().getConfiguredProperties(); connectorTemplate.getConnectorProperties().forEach((propertyName, template) -> { final Optional<ConfigurationProperty> maybeProperty = PropertyGenerators.createProperty(propertyName, swagger, template); maybeProperty.ifPresent(property -> { builder.putProperty(propertyName, property); if (!alreadyConfiguredProperties.containsKey(propertyName)) { final String defaultValue = property.getDefaultValue(); if (defaultValue != null) { builder.putConfiguredProperty(propertyName, defaultValue); } } }); }); return builder.build(); }