Remove spring-credhub-cloud-connector module.

This commit is contained in:
Scott Frederick
2019-11-27 11:14:57 -06:00
parent aa2ae34aa5
commit ef9967e66b
5 changed files with 0 additions and 334 deletions

View File

@@ -1,36 +0,0 @@
/*
* Copyright 2016-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
dependencyManagement {
imports {
mavenBom "org.springframework:spring-framework-bom:${springVersion}"
mavenBom "io.projectreactor:reactor-bom:${reactorVersion}"
}
}
description = 'Spring CredHub Cloud Connector'
dependencies {
compile project(':spring-credhub-core')
compile "org.springframework:spring-core"
compile "org.springframework.cloud:spring-cloud-cloudfoundry-connector:${springCloudConnectorsVersion}"
testImplementation("org.springframework:spring-test")
testImplementation("junit:junit")
testImplementation("org.mockito:mockito-core")
testImplementation("org.assertj:assertj-core:${assertJVersion}")
}

View File

@@ -1,136 +0,0 @@
/*
* Copyright 2016-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.credhub.cloud;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.cloud.cloudfoundry.CloudFoundryRawServiceData;
import org.springframework.cloud.cloudfoundry.ServiceDataPostProcessor;
import org.springframework.credhub.configuration.CredHubTemplateFactory;
import org.springframework.credhub.core.interpolation.CredHubInterpolationOperations;
import org.springframework.credhub.core.CredHubOperations;
import org.springframework.credhub.core.CredHubProperties;
import org.springframework.credhub.support.ClientOptions;
import org.springframework.credhub.support.ServicesData;
/**
* A Spring Cloud Connectors {@link ServiceDataPostProcessor} that post-processes service
* data from {@literal VCAP_SERVICES} using the CredHub interpolation API.
*
* @author Scott Frederick
* @author Daniel Lavoie
*/
public class CredHubInterpolationServiceDataPostProcessor
implements ServiceDataPostProcessor {
private Logger logger = Logger
.getLogger(CredHubInterpolationServiceDataPostProcessor.class.getName());
private CredHubInterpolationOperations credHubOperations;
/**
* Initialize the service data post-processor.
*/
public CredHubInterpolationServiceDataPostProcessor() {
try {
CredHubTemplateFactory credHubTemplateFactory = new CredHubTemplateFactory();
CredHubProperties credHubProperties = new CredHubProperties();
credHubProperties.setUrl(System.getProperty("spring.credhub.url"));
if (credHubProperties.getUrl() != null
&& !credHubProperties.getUrl().isEmpty()) {
credHubOperations = credHubTemplateFactory.credHubTemplate(
credHubProperties,
new ClientOptions())
.interpolation();
}
else {
logger.log(Level.WARNING,
"System property spring.credhub.url is undefined. CredHubOperations cannot be initialized, disabling processing of service data");
}
}
catch (Exception e) {
logger.log(Level.WARNING, "CredHubOperations cannot be initialized, "
+ "disabling processing of service data", e);
}
}
/**
* Initialize the service data post-processor using the provided
* {@link CredHubOperations}. Intended for internal use.
*
* @param credHubOperations the CredHubOperations to use
*/
CredHubInterpolationServiceDataPostProcessor(CredHubInterpolationOperations credHubOperations) {
this.credHubOperations = credHubOperations;
}
/**
* Process the provided {@literal serviceData} parsed from {@literal VCAP_SERVICES} by
* Spring Cloud Connectors using the
* {@link CredHubInterpolationOperations#interpolateServiceData(ServicesData)} API.
*
* @param serviceData raw service data parsed from {@literal VCAP_SERVICES}
* @return serviceData with CredHub references replaced by stored credentials
*/
@Override
public CloudFoundryRawServiceData process(CloudFoundryRawServiceData serviceData) {
if (credHubOperations == null) {
return serviceData;
}
try {
ServicesData interpolatedData = credHubOperations
.interpolateServiceData(connectorsToCredHub(serviceData));
return credHubToConnectors(interpolatedData);
}
catch (Exception e) {
logger.log(Level.WARNING, "Error interpolating service data from CredHub.",
e);
return serviceData;
}
}
/**
* Convert from the Spring Cloud Connectors service data structure to the Spring
* Credhub data structure.
*
* @param rawServiceData the Spring Cloud Connectors data structure
* @return the equivalent Spring CredHub data structure
*/
private ServicesData connectorsToCredHub(CloudFoundryRawServiceData rawServiceData) {
ServicesData servicesData = new ServicesData();
servicesData.putAll(rawServiceData);
return servicesData;
}
/**
* Convert from the Spring Credhub service data structure to the Spring Cloud
* Connectors data structure.
*
* @param interpolatedData the Spring CredHub data structure
* @return the equivalent Spring Cloud Connectors data structure
*/
private CloudFoundryRawServiceData credHubToConnectors(
ServicesData interpolatedData) {
CloudFoundryRawServiceData rawServicesData = new CloudFoundryRawServiceData();
rawServicesData.putAll(interpolatedData);
return rawServicesData;
}
}

View File

@@ -1,20 +0,0 @@
/*
* Copyright 2016-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Spring Cloud Connectors support for interpolating credentials from CredHub.
*/
package org.springframework.credhub.cloud;

View File

@@ -1 +0,0 @@
org.springframework.credhub.cloud.CredHubInterpolationServiceDataPostProcessor

View File

@@ -1,141 +0,0 @@
/*
* Copyright 2016-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.credhub.cloud;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.cloud.cloudfoundry.CloudFoundryRawServiceData;
import org.springframework.credhub.core.CredHubException;
import org.springframework.credhub.core.interpolation.CredHubInterpolationOperations;
import org.springframework.credhub.support.ServicesData;
import org.springframework.http.HttpStatus;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(MockitoJUnitRunner.class)
public class CredHubInterpolationServiceDataPostProcessorTests {
@Mock
private CredHubInterpolationOperations credHubOperations;
@Test
public void processServiceData() {
CloudFoundryRawServiceData rawServiceData = buildRawServiceData();
ServicesData interpolatedServiceData = buildInterpolatedServiceData();
when(credHubOperations.interpolateServiceData(argThat(matchesContent(rawServiceData))))
.thenReturn(interpolatedServiceData);
CredHubInterpolationServiceDataPostProcessor processor =
new CredHubInterpolationServiceDataPostProcessor(credHubOperations);
CloudFoundryRawServiceData actual = processor.process(rawServiceData);
assertThat(actual).isEqualTo(interpolatedServiceData);
}
@Test
public void processServiceDataWithCredHubError() {
CloudFoundryRawServiceData rawServiceData = buildRawServiceData();
when(credHubOperations.interpolateServiceData(argThat(matchesContent(rawServiceData))))
.thenThrow(new CredHubException(HttpStatus.UNAUTHORIZED));
CredHubInterpolationServiceDataPostProcessor processor =
new CredHubInterpolationServiceDataPostProcessor(credHubOperations);
CloudFoundryRawServiceData actual = processor.process(rawServiceData);
assertThat(actual).isEqualTo(rawServiceData);
}
@Test
public void processServiceDataWithInitializationError() {
CredHubInterpolationServiceDataPostProcessor processor =
new CredHubInterpolationServiceDataPostProcessor(null);
processor.process(new CloudFoundryRawServiceData());
verifyZeroInteractions(credHubOperations);
}
private ArgumentMatcher<ServicesData> matchesContent(final CloudFoundryRawServiceData expected) {
return new ArgumentMatcher<ServicesData>() {
@Override
public boolean matches(ServicesData actual) {
return mapsAreEquivalent(actual, expected);
}
};
}
private boolean mapsAreEquivalent(Map<String, ?> actual, Map<String, ?> expected) {
return expected.equals(actual);
}
private CloudFoundryRawServiceData buildRawServiceData() {
HashMap<String, String> credentials = new HashMap<String, String>() {
{
put("credhub-ref",
"((/c/service-broker/service-offering/1111-2222-3333-4444/credentials))");
}
};
HashMap<String, List<Map<String, Object>>> rawServiceData = buildRawServiceData(credentials);
return new CloudFoundryRawServiceData(rawServiceData);
}
private ServicesData buildInterpolatedServiceData() {
HashMap<String, String> credentials = new HashMap<String, String>() {
{
put("uri", "https://example.com");
put("username", "user");
put("password", "secret");
}
};
HashMap<String, List<Map<String, Object>>> rawServiceData = buildRawServiceData(credentials);
return new ServicesData(rawServiceData);
}
private HashMap<String, List<Map<String, Object>>> buildRawServiceData(final HashMap<String, String> credentials) {
return new HashMap<String, List<Map<String, Object>>>() {
{
put("service-offering", Collections.<Map<String, Object>> singletonList(
new HashMap<String, Object>() {
{
put("credentials", credentials);
put("label", "service-offering");
put("name", "service-instance");
put("plan", "standard");
}
}));
}
};
}
}