Add InfoOperations and version operation. Put operations into subpackages.

This commit is contained in:
Scott Frederick
2018-10-23 15:37:58 -05:00
parent 43998d942d
commit 8a1cc78d75
36 changed files with 502 additions and 112 deletions

View File

@@ -22,7 +22,7 @@ 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.CredHubInterpolationOperations;
import org.springframework.credhub.core.interpolation.CredHubInterpolationOperations;
import org.springframework.credhub.core.CredHubOperations;
import org.springframework.credhub.core.CredHubProperties;
import org.springframework.credhub.support.ServicesData;
@@ -82,7 +82,7 @@ public class CredHubInterpolationServiceDataPostProcessor
/**
* Process the provided {@literal serviceData} parsed from {@literal VCAP_SERVICES} by
* Spring Cloud Connectors using the
* {@link org.springframework.credhub.core.CredHubInterpolationOperations#interpolateServiceData(ServicesData)} API.
* {@link CredHubInterpolationOperations#interpolateServiceData(ServicesData)} API.
*
* @param serviceData raw service data parsed from {@literal VCAP_SERVICES}
* @return serviceData with CredHub references replaced by stored credentials

View File

@@ -29,7 +29,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.cloud.cloudfoundry.CloudFoundryRawServiceData;
import org.springframework.credhub.core.CredHubException;
import org.springframework.credhub.core.CredHubInterpolationOperations;
import org.springframework.credhub.core.interpolation.CredHubInterpolationOperations;
import org.springframework.credhub.support.ServicesData;
import org.springframework.http.HttpStatus;

View File

@@ -16,6 +16,11 @@
package org.springframework.credhub.core;
import org.springframework.credhub.core.certificate.CredHubCertificateOperations;
import org.springframework.credhub.core.credential.CredHubCredentialOperations;
import org.springframework.credhub.core.info.CredHubInfoOperations;
import org.springframework.credhub.core.interpolation.CredHubInterpolationOperations;
import org.springframework.credhub.core.permission.CredHubPermissionOperations;
import org.springframework.web.client.RestTemplate;
/**
@@ -29,14 +34,14 @@ public interface CredHubOperations {
*
* @return the credentials operations
*/
CredHubCredentialsOperations credentials();
CredHubCredentialOperations credentials();
/**
* Get the operations for adding, retrieving, and deleting credential permissions.
*
* @return the permissions operations
*/
CredHubPermissionsOperations permissions();
CredHubPermissionOperations permissions();
/**
* Get the operations for retrieving, regenerating, and updating certificates.
@@ -46,12 +51,19 @@ public interface CredHubOperations {
CredHubCertificateOperations certificates();
/**
* Get the operations interpolating service binding credentials.
* Get the operations for interpolating service binding credentials.
*
* @return the interpolation operations
*/
CredHubInterpolationOperations interpolation();
/**
* Get the operations for retrieving CredHub server information.
*
* @return the info operations
*/
CredHubInfoOperations info();
/**
* Allow interaction with the configured {@link RestTemplate} not provided
* by other methods.

View File

@@ -16,6 +16,16 @@
package org.springframework.credhub.core;
import org.springframework.credhub.core.certificate.CredHubCertificateOperations;
import org.springframework.credhub.core.certificate.CredHubCertificateTemplate;
import org.springframework.credhub.core.credential.CredHubCredentialOperations;
import org.springframework.credhub.core.credential.CredHubCredentialTemplate;
import org.springframework.credhub.core.info.CredHubInfoOperations;
import org.springframework.credhub.core.info.CredHubInfoTemplate;
import org.springframework.credhub.core.interpolation.CredHubInterpolationOperations;
import org.springframework.credhub.core.interpolation.CredHubInterpolationTemplate;
import org.springframework.credhub.core.permission.CredHubPermissionOperations;
import org.springframework.credhub.core.permission.CredHubPermissionTemplate;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.util.Assert;
import org.springframework.web.client.HttpStatusCodeException;
@@ -35,7 +45,7 @@ public class CredHubTemplate implements CredHubOperations {
*
* @param restTemplate the {@link RestTemplate} to use for interactions with CredHub
*/
CredHubTemplate(RestTemplate restTemplate) {
public CredHubTemplate(RestTemplate restTemplate) {
Assert.notNull(restTemplate, "restTemplate must not be null");
this.restTemplate = restTemplate;
@@ -64,8 +74,8 @@ public class CredHubTemplate implements CredHubOperations {
* @return the credentials operations
*/
@Override
public CredHubCredentialsOperations credentials() {
return new CredHubCredentialsTemplate(this);
public CredHubCredentialOperations credentials() {
return new CredHubCredentialTemplate(this);
}
/**
@@ -74,8 +84,8 @@ public class CredHubTemplate implements CredHubOperations {
* @return the permissions operations
*/
@Override
public CredHubPermissionsOperations permissions() {
return new CredHubPermissionsTemplate(this);
public CredHubPermissionOperations permissions() {
return new CredHubPermissionTemplate(this);
}
/**
@@ -89,7 +99,7 @@ public class CredHubTemplate implements CredHubOperations {
}
/**
* Get the operations interpolating service binding credentials.
* Get the operations for interpolating service binding credentials.
*
* @return the interpolation operations
*/
@@ -98,6 +108,16 @@ public class CredHubTemplate implements CredHubOperations {
return new CredHubInterpolationTemplate(this);
}
/**
* Get the operations for retrieving CredHub server information.
*
* @return the info operations
*/
@Override
public CredHubInfoOperations info() {
return new CredHubInfoTemplate(this);
}
/**
* Allow interaction with the configured {@link RestTemplate} not provided
* by other methods.

View File

@@ -20,14 +20,14 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
class ExceptionUtils {
public class ExceptionUtils {
/**
* Helper method to throw an appropriate exception if a request to CredHub
* returns with an error code.
*
* @param response a {@link ResponseEntity} returned from {@link RestTemplate}
*/
static void throwExceptionOnError(ResponseEntity<?> response) {
public static void throwExceptionOnError(ResponseEntity<?> response) {
if (!response.getStatusCode().equals(HttpStatus.OK)) {
throw new CredHubException(response.getStatusCode());
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.certificate;
import org.springframework.credhub.support.CertificateSummary;
import org.springframework.credhub.support.CredentialName;

View File

@@ -14,8 +14,11 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.certificate;
import org.springframework.credhub.core.CredHubOperations;
import org.springframework.credhub.core.ExceptionUtils;
import org.springframework.credhub.core.RestOperationsCallback;
import org.springframework.credhub.support.CertificateSummary;
import org.springframework.credhub.support.CertificateSummaryData;
import org.springframework.credhub.support.CredentialName;
@@ -42,7 +45,7 @@ public class CredHubCertificateTemplate implements CredHubCertificateOperations
*
* @param credHubOperations the {@link CredHubOperations} to use for interactions with CredHub
*/
CredHubCertificateTemplate(CredHubOperations credHubOperations) {
public CredHubCertificateTemplate(CredHubOperations credHubOperations) {
this.credHubOperations = credHubOperations;
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.credential;
import org.springframework.credhub.support.CredentialDetails;
import org.springframework.credhub.support.CredentialName;
@@ -31,7 +31,7 @@ import java.util.List;
*
* @author Scott Frederick
*/
public interface CredHubCredentialsOperations {
public interface CredHubCredentialOperations {
/**
* Write a new credential to CredHub, or overwrite an existing credential with a new
* value.

View File

@@ -14,9 +14,12 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.credential;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.credhub.core.CredHubOperations;
import org.springframework.credhub.core.ExceptionUtils;
import org.springframework.credhub.core.RestOperationsCallback;
import org.springframework.credhub.support.CredentialDetails;
import org.springframework.credhub.support.CredentialDetailsData;
import org.springframework.credhub.support.CredentialName;
@@ -45,7 +48,7 @@ import static org.springframework.http.HttpMethod.PUT;
*
* @author Scott Frederick
*/
public class CredHubCredentialsTemplate implements CredHubCredentialsOperations {
public class CredHubCredentialTemplate implements CredHubCredentialOperations {
static final String BASE_URL_PATH = "/api/v1/data";
static final String ID_URL_PATH = BASE_URL_PATH + "/{id}";
static final String NAME_URL_QUERY = BASE_URL_PATH + "?name={name}";
@@ -59,11 +62,11 @@ public class CredHubCredentialsTemplate implements CredHubCredentialsOperations
private CredHubOperations credHubOperations;
/**
* Create a new {@link CredHubCredentialsTemplate}.
* Create a new {@link CredHubCredentialTemplate}.
*
* @param credHubOperations the {@link CredHubOperations} to use for interactions with CredHub
*/
CredHubCredentialsTemplate(CredHubOperations credHubOperations) {
public CredHubCredentialTemplate(CredHubOperations credHubOperations) {
this.credHubOperations = credHubOperations;
}

View File

@@ -0,0 +1,35 @@
/*
* 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
*
* http://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.core.info;
import org.springframework.credhub.support.info.VersionInfo;
/**
* Specifies the interactions with CredHub for retrieving server information.
*
* @author Scott Frederick
*/
public interface CredHubInfoOperations {
/**
* Retrieve the version information from the CredHub server.
*
* @return the server version information
*/
VersionInfo version();
}

View File

@@ -0,0 +1,64 @@
/*
* 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
*
* http://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.core.info;
import org.springframework.credhub.core.CredHubOperations;
import org.springframework.credhub.core.ExceptionUtils;
import org.springframework.credhub.core.RestOperationsCallback;
import org.springframework.credhub.support.info.VersionInfo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestOperations;
/**
* Implements the interaction with CredHub retrieve server information.
*
* @author Scott Frederick
*/
public class CredHubInfoTemplate implements CredHubInfoOperations {
static final String VERSION_URL_PATH = "/version";
private CredHubOperations credHubOperations;
/**
* Create a new {@link CredHubInfoTemplate}.
*
* @param credHubOperations the {@link CredHubOperations} to use for interactions with CredHub
*/
public CredHubInfoTemplate(CredHubOperations credHubOperations) {
this.credHubOperations = credHubOperations;
}
/**
* Retrieve the version information from the CredHub server.
*
* @return the server version information
*/
@Override
public VersionInfo version() {
return credHubOperations.doWithRest(new RestOperationsCallback<VersionInfo>() {
@Override
public VersionInfo doWithRestOperations(RestOperations restOperations) {
ResponseEntity<VersionInfo> response = restOperations
.getForEntity(VERSION_URL_PATH, VersionInfo.class);
ExceptionUtils.throwExceptionOnError(response);
return response.getBody();
}
});
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.interpolation;
import org.springframework.credhub.support.ServicesData;

View File

@@ -14,8 +14,11 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.interpolation;
import org.springframework.credhub.core.CredHubOperations;
import org.springframework.credhub.core.ExceptionUtils;
import org.springframework.credhub.core.RestOperationsCallback;
import org.springframework.credhub.support.ServicesData;
import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity;
@@ -39,7 +42,7 @@ public class CredHubInterpolationTemplate implements CredHubInterpolationOperati
*
* @param credHubOperations the {@link CredHubOperations} to use for interactions with CredHub
*/
CredHubInterpolationTemplate(CredHubOperations credHubOperations) {
public CredHubInterpolationTemplate(CredHubOperations credHubOperations) {
this.credHubOperations = credHubOperations;
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.permission;
import org.springframework.credhub.support.CredentialName;
import org.springframework.credhub.support.permissions.Actor;
@@ -27,7 +27,7 @@ import java.util.List;
*
* @author Scott Frederick
*/
public interface CredHubPermissionsOperations {
public interface CredHubPermissionOperations {
/**
* Get the permissions associated with a credential.
*

View File

@@ -14,8 +14,10 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.permission;
import org.springframework.credhub.core.CredHubOperations;
import org.springframework.credhub.core.RestOperationsCallback;
import org.springframework.credhub.support.CredentialName;
import org.springframework.credhub.support.CredentialPermissions;
import org.springframework.credhub.support.permissions.Actor;
@@ -35,7 +37,7 @@ import static org.springframework.http.HttpMethod.POST;
*
* @author Scott Frederick
*/
public class CredHubPermissionsTemplate implements CredHubPermissionsOperations {
public class CredHubPermissionTemplate implements CredHubPermissionOperations {
static final String PERMISSIONS_URL_PATH = "/api/v1/permissions";
static final String PERMISSIONS_URL_QUERY = PERMISSIONS_URL_PATH + "?credential_name={name}";
static final String PERMISSIONS_ACTOR_URL_QUERY = PERMISSIONS_URL_QUERY + "&actor={actor}";
@@ -43,11 +45,11 @@ public class CredHubPermissionsTemplate implements CredHubPermissionsOperations
private CredHubOperations credHubOperations;
/**
* Create a new {@link CredHubPermissionsTemplate}.
* Create a new {@link CredHubPermissionTemplate}.
*
* @param credHubOperations the {@link CredHubOperations} to use for interactions with CredHub
*/
CredHubPermissionsTemplate(CredHubOperations credHubOperations) {
public CredHubPermissionTemplate(CredHubOperations credHubOperations) {
this.credHubOperations = credHubOperations;
}

View File

@@ -0,0 +1,69 @@
/*
* 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
*
* http://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.support.info;
/**
* Version information about a CredHub server.
*
* @author Scott Frederick
*/
public class VersionInfo {
private final String version;
@SuppressWarnings("unused")
VersionInfo() {
this.version = "";
}
/**
* Create a new {@literal VersionInfo} containing the specified version string. Intended for
* internal use. Clients will get {@literal VersionInfo} objects populated from
* CredHub responses.
*
* @param version a version string
*/
public VersionInfo(String version) {
this.version = version;
}
/**
* Get the value of the version string returned from the CredHub server.
*
* @return the version string
*/
public String getVersion() {
return this.version;
}
/**
* Determine if the CredHub server implements the v1 API.
*
* @return {@code true} if the server implements the CredHub v1 API; {@code false} otherwise
*/
public boolean isVersion1() {
return this.version.startsWith("1.");
}
/**
* Determine if the CredHub server implements the v2 API.
*
* @return {@code true} if the server implements the CredHub v2 API; {@code false} otherwise
*/
public boolean isVersion2() {
return this.version.startsWith("2.");
}
}

View File

@@ -14,13 +14,14 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.certificate;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.credhub.core.CredHubTemplate;
import org.springframework.credhub.support.CertificateSummary;
import org.springframework.credhub.support.CertificateSummaryData;
import org.springframework.credhub.support.SimpleCredentialName;
@@ -31,8 +32,8 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import static org.springframework.credhub.core.CredHubCertificateTemplate.BASE_URL_PATH;
import static org.springframework.credhub.core.CredHubCertificateTemplate.NAME_URL_QUERY;
import static org.springframework.credhub.core.certificate.CredHubCertificateTemplate.BASE_URL_PATH;
import static org.springframework.credhub.core.certificate.CredHubCertificateTemplate.NAME_URL_QUERY;
import static org.springframework.http.HttpStatus.OK;
@RunWith(MockitoJUnitRunner.class)

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.credential;
import java.util.List;
@@ -24,6 +24,7 @@ import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
import org.springframework.credhub.core.CredHubException;
import org.springframework.credhub.support.CredentialSummary;
import org.springframework.credhub.support.CredentialSummaryData;
import org.springframework.http.ResponseEntity;
@@ -31,13 +32,13 @@ import org.springframework.http.ResponseEntity;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.when;
import static org.springframework.credhub.core.CredHubCredentialsTemplate.NAME_LIKE_URL_QUERY;
import static org.springframework.credhub.core.CredHubCredentialsTemplate.PATH_URL_QUERY;
import static org.springframework.credhub.core.credential.CredHubCredentialTemplate.NAME_LIKE_URL_QUERY;
import static org.springframework.credhub.core.credential.CredHubCredentialTemplate.PATH_URL_QUERY;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.HttpStatus.UNAUTHORIZED;
@RunWith(Theories.class)
public class CredHubCredentialsTemplateSummaryUnitTests extends CredHubCredentialsTemplateUnitTestsBase {
public class CredHubCredentialTemplateSummaryUnitTests extends CredHubCredentialTemplateUnitTestsBase {
@DataPoint("responses")
public static ResponseEntity<CredentialSummaryData> successfulResponse =
new ResponseEntity<>(new CredentialSummaryData(new CredentialSummary(NAME)), OK);

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.credential;
import org.junit.Test;
@@ -29,12 +29,12 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.credhub.core.CredHubCredentialsTemplate.NAME_URL_QUERY;
import static org.springframework.credhub.core.CredHubCredentialsTemplate.SHOW_ALL_URL_QUERY;
import static org.springframework.credhub.core.credential.CredHubCredentialTemplate.NAME_URL_QUERY;
import static org.springframework.credhub.core.credential.CredHubCredentialTemplate.SHOW_ALL_URL_QUERY;
import static org.springframework.http.HttpStatus.OK;
@RunWith(MockitoJUnitRunner.class)
public class CredHubCredentialsTemplateUnitTests extends CredHubCredentialsTemplateUnitTestsBase {
public class CredHubCredentialTemplateUnitTests extends CredHubCredentialTemplateUnitTestsBase {
@Test
public void getAllPaths() {
when(restTemplate.getForEntity(SHOW_ALL_URL_QUERY, CredentialPathData.class))

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.credential;
import org.junit.Before;
import org.junit.Rule;
@@ -23,10 +23,11 @@ import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.mockito.quality.Strictness;
import org.springframework.credhub.core.CredHubTemplate;
import org.springframework.credhub.support.SimpleCredentialName;
import org.springframework.web.client.RestTemplate;
public abstract class CredHubCredentialsTemplateUnitTestsBase {
public abstract class CredHubCredentialTemplateUnitTestsBase {
protected static final SimpleCredentialName NAME = new SimpleCredentialName("example", "credential");
@Rule
@@ -35,7 +36,7 @@ public abstract class CredHubCredentialsTemplateUnitTestsBase {
@Mock
protected RestTemplate restTemplate;
protected CredHubCredentialsOperations credHubTemplate;
protected CredHubCredentialOperations credHubTemplate;
@Before
public void setUpCredHubTemplateUnitTests() {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.credential;
import java.util.List;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.credential;
import java.util.List;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.credential;
import java.util.List;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.credential;
import java.util.List;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.credential;
import java.util.List;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.credential;
import java.util.Arrays;
import java.util.HashMap;
@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.credhub.core.CredHubException;
import org.springframework.credhub.support.CredentialDetails;
import org.springframework.credhub.support.CredentialDetailsData;
import org.springframework.credhub.support.CredentialRequest;
@@ -37,12 +38,12 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.when;
import static org.springframework.credhub.core.CredHubCredentialsTemplate.BASE_URL_PATH;
import static org.springframework.credhub.core.CredHubCredentialsTemplate.ID_URL_PATH;
import static org.springframework.credhub.core.CredHubCredentialsTemplate.NAME_URL_QUERY;
import static org.springframework.credhub.core.CredHubCredentialsTemplate.NAME_URL_QUERY_CURRENT;
import static org.springframework.credhub.core.CredHubCredentialsTemplate.NAME_URL_QUERY_VERSIONS;
import static org.springframework.credhub.core.CredHubCredentialsTemplate.REGENERATE_URL_PATH;
import static org.springframework.credhub.core.credential.CredHubCredentialTemplate.BASE_URL_PATH;
import static org.springframework.credhub.core.credential.CredHubCredentialTemplate.ID_URL_PATH;
import static org.springframework.credhub.core.credential.CredHubCredentialTemplate.NAME_URL_QUERY;
import static org.springframework.credhub.core.credential.CredHubCredentialTemplate.NAME_URL_QUERY_CURRENT;
import static org.springframework.credhub.core.credential.CredHubCredentialTemplate.NAME_URL_QUERY_VERSIONS;
import static org.springframework.credhub.core.credential.CredHubCredentialTemplate.REGENERATE_URL_PATH;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.POST;
import static org.springframework.http.HttpMethod.PUT;
@@ -50,7 +51,7 @@ import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.HttpStatus.UNAUTHORIZED;
@SuppressWarnings("unchecked")
public abstract class CredHubTemplateDetailUnitTestsBase<T, P> extends CredHubCredentialsTemplateUnitTestsBase {
public abstract class CredHubTemplateDetailUnitTestsBase<T, P> extends CredHubCredentialTemplateUnitTestsBase {
private static final String CREDENTIAL_ID = "1111-1111-1111-1111";
protected abstract Class<T> getType();

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.credential;
import java.util.List;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.credential;
import java.util.List;

View File

@@ -0,0 +1,63 @@
/*
* 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
*
* http://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.core.info;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.MockitoRule;
import org.mockito.quality.Strictness;
import org.springframework.credhub.core.CredHubTemplate;
import org.springframework.credhub.support.info.VersionInfo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import static org.springframework.credhub.core.info.CredHubInfoTemplate.VERSION_URL_PATH;
import static org.springframework.http.HttpStatus.OK;
@RunWith(MockitoJUnitRunner.class)
public class CredHubInfoTemplateUnitTests {
@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule().strictness(Strictness.STRICT_STUBS);
@Mock
private RestTemplate restTemplate;
private CredHubInfoOperations credHubTemplate;
@Before
public void setUp() {
credHubTemplate = new CredHubTemplate(restTemplate).info();
}
@Test
public void getVersion() {
when(restTemplate.getForEntity(VERSION_URL_PATH, VersionInfo.class))
.thenReturn(new ResponseEntity<>(new VersionInfo("2.0.0"), OK));
VersionInfo response = credHubTemplate.version();
assertThat(response.getVersion()).isEqualTo("2.0.0");
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.interpolation;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Before;
@@ -26,6 +26,7 @@ import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.MockitoRule;
import org.mockito.quality.Strictness;
import org.springframework.credhub.core.CredHubTemplate;
import org.springframework.credhub.support.ServiceInstanceCredentialName;
import org.springframework.credhub.support.ServicesData;
import org.springframework.credhub.support.utils.JsonUtils;
@@ -37,7 +38,7 @@ import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import static org.springframework.credhub.core.CredHubInterpolationTemplate.INTERPOLATE_URL_PATH;
import static org.springframework.credhub.core.interpolation.CredHubInterpolationTemplate.INTERPOLATE_URL_PATH;
import static org.springframework.http.HttpMethod.POST;
import static org.springframework.http.HttpStatus.OK;

View File

@@ -14,13 +14,14 @@
* limitations under the License.
*/
package org.springframework.credhub.core;
package org.springframework.credhub.core.permission;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.credhub.core.CredHubTemplate;
import org.springframework.credhub.support.CredentialPermissions;
import org.springframework.credhub.support.SimpleCredentialName;
import org.springframework.credhub.support.permissions.Actor;
@@ -36,9 +37,9 @@ import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.credhub.core.CredHubPermissionsTemplate.PERMISSIONS_ACTOR_URL_QUERY;
import static org.springframework.credhub.core.CredHubPermissionsTemplate.PERMISSIONS_URL_PATH;
import static org.springframework.credhub.core.CredHubPermissionsTemplate.PERMISSIONS_URL_QUERY;
import static org.springframework.credhub.core.permission.CredHubPermissionTemplate.PERMISSIONS_ACTOR_URL_QUERY;
import static org.springframework.credhub.core.permission.CredHubPermissionTemplate.PERMISSIONS_URL_PATH;
import static org.springframework.credhub.core.permission.CredHubPermissionTemplate.PERMISSIONS_URL_QUERY;
import static org.springframework.http.HttpMethod.POST;
import static org.springframework.http.HttpStatus.OK;
@@ -49,7 +50,7 @@ public class CredHubPermissionsTemplateUnitTests {
@Mock
private RestTemplate restTemplate;
private CredHubPermissionsOperations credHubTemplate;
private CredHubPermissionOperations credHubTemplate;
@Before
public void setUp() {

View File

@@ -0,0 +1,50 @@
/*
* 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
*
* http://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.support.info;
import org.junit.Test;
import org.springframework.credhub.support.JsonParsingUnitTestsBase;
import static org.assertj.core.api.Assertions.assertThat;
public class VersionInfoTests extends JsonParsingUnitTestsBase {
@Test
public void deserializeWithV1() {
String json = "{\n" +
" \"version\": \"1.9.0\"\n" +
"}";
VersionInfo versionInfo = parseResponse(json, VersionInfo.class);
assertThat(versionInfo.getVersion()).isEqualTo("1.9.0");
assertThat(versionInfo.isVersion1()).isTrue();
assertThat(versionInfo.isVersion2()).isFalse();
}
@Test
public void deserializeWithV2() {
String json = "{\n" +
" \"version\": \"2.0.2\"\n" +
"}";
VersionInfo versionInfo = parseResponse(json, VersionInfo.class);
assertThat(versionInfo.getVersion()).isEqualTo("2.0.2");
assertThat(versionInfo.isVersion1()).isFalse();
assertThat(versionInfo.isVersion2()).isTrue();
}
}

View File

@@ -0,0 +1,24 @@
package org.springframework.credhub.integration;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.credhub.autoconfig.CredHubAutoConfiguration;
import org.springframework.credhub.autoconfig.CredHubOAuth2TemplateAutoConfiguration;
import org.springframework.credhub.autoconfig.CredHubTemplateAutoConfiguration;
import org.springframework.credhub.core.CredHubOperations;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {TestApplication.class,
CredHubAutoConfiguration.class,
CredHubTemplateAutoConfiguration.class,
CredHubOAuth2TemplateAutoConfiguration.class})
@ActiveProfiles("test")
public abstract class CredHubIntegrationTests {
@Autowired
protected CredHubOperations operations;
}

View File

@@ -1,43 +1,41 @@
/*
* 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
*
* http://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.integration;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.credhub.autoconfig.CredHubAutoConfiguration;
import org.springframework.credhub.autoconfig.CredHubOAuth2TemplateAutoConfiguration;
import org.springframework.credhub.autoconfig.CredHubTemplateAutoConfiguration;
import org.springframework.credhub.core.CredHubCredentialsOperations;
import org.springframework.credhub.core.CredHubOperations;
import org.springframework.credhub.core.credential.CredHubCredentialOperations;
import org.springframework.credhub.support.CredentialDetails;
import org.springframework.credhub.support.CredentialSummary;
import org.springframework.credhub.support.CredentialType;
import org.springframework.credhub.support.SimpleCredentialName;
import org.springframework.credhub.support.value.ValueCredential;
import org.springframework.credhub.support.value.ValueCredentialRequest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {TestApplication.class,
CredHubAutoConfiguration.class,
CredHubTemplateAutoConfiguration.class,
CredHubOAuth2TemplateAutoConfiguration.class})
@ActiveProfiles("test")
public class CredentialIntegrationTests {
public class CredentialIntegrationTests extends CredHubIntegrationTests {
private static final SimpleCredentialName CREDENTIAL_NAME =
new SimpleCredentialName("spring-credhub", "integration-test", "test-value-credential");
private static final String CREDENTIAL_VALUE = "test-value";
@Autowired
private CredHubOperations operations;
private CredHubCredentialsOperations credentials;
private CredHubCredentialOperations credentials;
@Before
public void setUp() {

View File

@@ -0,0 +1,40 @@
/*
* 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
*
* http://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.integration;
import org.junit.Before;
import org.junit.Test;
import org.springframework.credhub.core.info.CredHubInfoOperations;
import org.springframework.credhub.support.info.VersionInfo;
import static org.assertj.core.api.Assertions.assertThat;
public class InfoIntegrationTests extends CredHubIntegrationTests {
private CredHubInfoOperations info;
@Before
public void setUp() {
info = operations.info();
}
@Test
public void getInfo() {
VersionInfo version = info.version();
assertThat(version.getVersion()).isNotNull();
}
}

View File

@@ -1,44 +1,42 @@
/*
* 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
*
* http://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.integration;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.credhub.autoconfig.CredHubAutoConfiguration;
import org.springframework.credhub.autoconfig.CredHubOAuth2TemplateAutoConfiguration;
import org.springframework.credhub.autoconfig.CredHubTemplateAutoConfiguration;
import org.springframework.credhub.core.CredHubCredentialsOperations;
import org.springframework.credhub.core.CredHubOperations;
import org.springframework.credhub.core.CredHubPermissionsOperations;
import org.springframework.credhub.core.credential.CredHubCredentialOperations;
import org.springframework.credhub.core.permission.CredHubPermissionOperations;
import org.springframework.credhub.support.SimpleCredentialName;
import org.springframework.credhub.support.permissions.Actor;
import org.springframework.credhub.support.permissions.CredentialPermission;
import org.springframework.credhub.support.permissions.Operation;
import org.springframework.credhub.support.value.ValueCredentialRequest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {TestApplication.class,
CredHubAutoConfiguration.class,
CredHubTemplateAutoConfiguration.class,
CredHubOAuth2TemplateAutoConfiguration.class})
@ActiveProfiles("test")
public class PermissionsIntegrationTests {
public class PermissionIntegrationTests extends CredHubIntegrationTests {
private static final SimpleCredentialName CREDENTIAL_NAME =
new SimpleCredentialName("spring-credhub", "integration-test", "test-permissions-credential");
private static final String CREDENTIAL_VALUE = "test-value";
@Autowired
private CredHubOperations operations;
private CredHubCredentialsOperations credentials;
private CredHubPermissionsOperations permissions;
private CredHubCredentialOperations credentials;
private CredHubPermissionOperations permissions;
@Before
public void setUp() {