From 37b0ba932d61f758b06f1635c56cdb8206558466 Mon Sep 17 00:00:00 2001 From: davidzhao98 Date: Fri, 7 Jun 2019 11:49:48 -0700 Subject: [PATCH 1/2] chore: upgrade java client to 7.0.1 --- build.gradle | 1 + gradle/dependencies.gradle | 2 +- gradle/integration.gradle | 42 +++++++ gradle/wrapper/gradle-wrapper.properties | 20 +-- ...berusSpringBootClientIntegrationTests.java | 114 ++++++++++++++++++ .../testapp/IntegrationTestSpringApp.java | 34 ++++++ .../IntegrationTestSpringAppConfig.java | 15 +++ ...CerberusClientSpringBootConfiguration.java | 9 +- .../CerberusClientSpringBootProperties.java | 18 ++- 9 files changed, 233 insertions(+), 22 deletions(-) create mode 100644 gradle/integration.gradle create mode 100644 src/integration/java/com/nike/cerberus/springboot/CerberusSpringBootClientIntegrationTests.java create mode 100644 src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringApp.java create mode 100644 src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringAppConfig.java diff --git a/build.gradle b/build.gradle index 15d18e2..8403987 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,7 @@ targetCompatibility = 1.8 apply from: file('gradle/dependencies.gradle') apply from: file('gradle/check.gradle') +apply from: file('gradle/integration.gradle') apply from: file('gradle/bintray.gradle') group = groupId diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 9c4be3b..c0fb48f 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -25,7 +25,7 @@ dependencies { compile "org.springframework.boot:spring-boot-autoconfigure:1.5.2.RELEASE" // Cerberus dependencies - compile "com.nike:cerberus-client:6.1.0" + compile "com.nike:cerberus-client:7.0.1" // Test dependencies testRuntime 'org.slf4j:slf4j-simple:1.7.25' diff --git a/gradle/integration.gradle b/gradle/integration.gradle new file mode 100644 index 0000000..9b8f466 --- /dev/null +++ b/gradle/integration.gradle @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2017 Nike, Inc. + * + * 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. + */ + +sourceSets { + integration { + java.srcDir file('src/integration/java') + resources.srcDir file('src/integration/resources') + } +} + +task integration(type: Test, description: 'Runs integration tests') { + testClassesDir = sourceSets.integration.output.classesDir + classpath = sourceSets.integration.runtimeClasspath +} + +dependencies { + integrationCompile sourceSets.main.output + integrationCompile configurations.testCompile + integrationCompile sourceSets.test.output + integrationCompile 'com.fieldju:commons:1.1.0' + integrationCompile group: 'org.projectlombok', name: 'lombok', version: '1.18.8' + integrationRuntime configurations.testRuntime +} + +integration { + testLogging { + showStandardStreams = true + } +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d6a4f0f..2253e21 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,22 +1,6 @@ -# -# Copyright (c) 2017 Nike, Inc. -# -# 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. -# - -#Mon Aug 29 15:51:55 PDT 2016 +#Thu Jun 06 14:24:12 PDT 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip diff --git a/src/integration/java/com/nike/cerberus/springboot/CerberusSpringBootClientIntegrationTests.java b/src/integration/java/com/nike/cerberus/springboot/CerberusSpringBootClientIntegrationTests.java new file mode 100644 index 0000000..9da8062 --- /dev/null +++ b/src/integration/java/com/nike/cerberus/springboot/CerberusSpringBootClientIntegrationTests.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2019 Nike, Inc. + * + * 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 com.nike.cerberus.springboot; + +import com.fieldju.commons.EnvUtils; +import com.nike.cerberus.client.CerberusClient; +import com.nike.cerberus.client.CerberusServerException; +import com.nike.cerberus.client.model.CerberusListResponse; +import com.nike.cerberus.client.model.CerberusResponse; +import com.nike.cerberus.springboot.testapp.IntegrationTestSpringApp; +import org.apache.commons.lang3.RandomStringUtils; +import org.junit.*; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class CerberusSpringBootClientIntegrationTests { + + private IntegrationTestSpringApp app; + + private String cerberusRootSdbPath; + private String secretPath; + private String sdbFullSecretPath; + private Map secretData; + private ExecutorService executorService = Executors.newSingleThreadExecutor(); + + @Before + public void before() { + EnvUtils.getRequiredEnv("CERBERUS_URL"); + EnvUtils.getRequiredEnv("CERBERUS_REGION"); + cerberusRootSdbPath = EnvUtils.getRequiredEnv("SDB_ROOT_PATH"); + + secretPath = UUID.randomUUID().toString(); + sdbFullSecretPath = cerberusRootSdbPath + secretPath; + + String key = RandomStringUtils.randomAlphabetic(15); + String value = RandomStringUtils.randomAlphabetic(25); + secretData = new HashMap<>(); + secretData.put(key, value); + + app = new IntegrationTestSpringApp(); + + executorService.submit(() -> app.run()); + } + + @After + public void after() { + app.shutdown(); + } + + @Test + public void test_that_the_cerberus_springboot_client_can_be_used_in_a_spring_app() { + CerberusClient cerberusClient = app.getApplicationContext().getBean(CerberusClient.class); + + // create secret + cerberusClient.write(sdbFullSecretPath, secretData); + + // read secret + CerberusResponse cerberusReadResponse = cerberusClient.read(sdbFullSecretPath); + assertEquals(secretData, cerberusReadResponse.getData()); + + // list secrets + CerberusListResponse cerberusListResponse = cerberusClient.list(cerberusRootSdbPath); + assertTrue(cerberusListResponse.getKeys().contains(secretPath)); + + // update secret + Map newSecretData = generateNewSecretData(); + cerberusClient.write(sdbFullSecretPath, newSecretData); + secretData = newSecretData; + + // confirm updated secret data + CerberusResponse cerberusReadResponseUpdated = cerberusClient.read(sdbFullSecretPath); + assertEquals(newSecretData, cerberusReadResponseUpdated.getData()); + + // delete secret + cerberusClient.delete(sdbFullSecretPath); + + // confirm secret is deleted + try { + cerberusClient.read(sdbFullSecretPath); + } catch (CerberusServerException cse) { + assertEquals(404, cse.getCode()); + } + } + + private Map generateNewSecretData() { + String key = RandomStringUtils.randomAlphabetic(20); + String value = RandomStringUtils.randomAlphabetic(30); + Map newSecretData = new HashMap<>(); + newSecretData.put(key, value); + + return newSecretData; + } +} diff --git a/src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringApp.java b/src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringApp.java new file mode 100644 index 0000000..866e769 --- /dev/null +++ b/src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringApp.java @@ -0,0 +1,34 @@ +package com.nike.cerberus.springboot.testapp; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +@Slf4j +public class IntegrationTestSpringApp { + + private final ApplicationContext applicationContext; + private boolean isRunning = true; + + public ApplicationContext getApplicationContext() { + return applicationContext; + } + + public void shutdown() { + isRunning = false; + } + + public void run() { + while (isRunning) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + throw new RuntimeException("Sleep interrupted"); + } + } + } + + public IntegrationTestSpringApp() { + applicationContext = new AnnotationConfigApplicationContext("com.nike.cerberus.springboot.testapp"); + } +} diff --git a/src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringAppConfig.java b/src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringAppConfig.java new file mode 100644 index 0000000..7323670 --- /dev/null +++ b/src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringAppConfig.java @@ -0,0 +1,15 @@ +package com.nike.cerberus.springboot.testapp; + +import com.nike.cerberus.springboot.CerberusClientSpringBootConfiguration; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +@Slf4j +@Configuration +@Import(CerberusClientSpringBootConfiguration.class) +public class IntegrationTestSpringAppConfig { + public IntegrationTestSpringAppConfig() { + log.info("IntegrationTestSpringAppConfig Loaded"); + } +} diff --git a/src/main/java/com/nike/cerberus/springboot/CerberusClientSpringBootConfiguration.java b/src/main/java/com/nike/cerberus/springboot/CerberusClientSpringBootConfiguration.java index 269800e..0284cca 100644 --- a/src/main/java/com/nike/cerberus/springboot/CerberusClientSpringBootConfiguration.java +++ b/src/main/java/com/nike/cerberus/springboot/CerberusClientSpringBootConfiguration.java @@ -27,9 +27,10 @@ * Spring configuration class that provides a CerberusClient for interacting with Cerberus. *

* This class is configured via {@link CerberusClientSpringBootProperties} which has - * one required setting for accessing Cerberus, e.g. in your {@code application.properties}: + * two required settings for accessing Cerberus, e.g. in your {@code application.properties}: *

  *     cerberus.url=https://test.cerberus.example.com
+ *     cerberus.region=us-west-2
  * 
* * @see Cerberus Quick Start Guide @@ -53,10 +54,14 @@ public CerberusClientSpringBootConfiguration(CerberusClientSpringBootProperties @Bean public CerberusClient cerberusClient() { String url = cerberusClientProperties.getUrl(); + String region = cerberusClientProperties.getRegion(); if (url == null || url.isEmpty()) { throw new IllegalArgumentException("cerberus.url setting is required! " + "E.g. Your application needs a configuration property like 'cerberus.url=https://test.cerberus.example.com'"); + } else if (region == null || region.isEmpty()) { + throw new IllegalArgumentException("cerberus.region setting is required! " + + "E.g. Your application needs a configuration property like 'cerberus.region=us-west-2'"); } - return DefaultCerberusClientFactory.getClient(url); + return DefaultCerberusClientFactory.getClient(url, region); } } diff --git a/src/main/java/com/nike/cerberus/springboot/CerberusClientSpringBootProperties.java b/src/main/java/com/nike/cerberus/springboot/CerberusClientSpringBootProperties.java index 06e3428..2635ab9 100644 --- a/src/main/java/com/nike/cerberus/springboot/CerberusClientSpringBootProperties.java +++ b/src/main/java/com/nike/cerberus/springboot/CerberusClientSpringBootProperties.java @@ -22,9 +22,10 @@ /** * A {@link ConfigurationProperties} companion for {@link CerberusClientSpringBootProperties}. *

- * This class has one required setting for accessing Cerberus, e.g. in your {@code application.properties}: + * This class has two required settings for accessing Cerberus, e.g. in your {@code application.properties}: *

  *     cerberus.url=https://test.cerberus.example.com
+ *     cerberus.region=us-west-2
  * 
* * @see Cerberus Quick Start Guide @@ -33,6 +34,7 @@ public class CerberusClientSpringBootProperties { private String url; + private String region; /** * Cerberus URL, e.g. https://test.cerberus.example.com @@ -47,4 +49,18 @@ public String getUrl() { public void setUrl(String url) { this.url = url; } + + /** + * Cerberus region for sts auth, e.g. us-west-2 + */ + public String getRegion() { + return region; + } + + /** + * Cerberus region for sts auth, e.g. us-west-2 + */ + public void setRegion(String region) { + this.region = region; + } } From 5e958fb5d7e50a59604c33b79fcf8b82544af56f Mon Sep 17 00:00:00 2001 From: davidzhao98 Date: Fri, 7 Jun 2019 11:54:12 -0700 Subject: [PATCH 2/2] chore: bump version and add license headers --- gradle.properties | 2 +- gradle/dependencies.gradle | 2 +- gradle/integration.gradle | 2 +- .../testapp/IntegrationTestSpringApp.java | 16 ++++++++++++++++ .../testapp/IntegrationTestSpringAppConfig.java | 16 ++++++++++++++++ .../CerberusClientSpringBootConfiguration.java | 2 +- .../CerberusClientSpringBootProperties.java | 2 +- 7 files changed, 37 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index 40ca8d2..1e8e35c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,6 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -version=2.0.0 +version=3.0.0 groupId=com.nike artifactId=cerberus-spring-boot-client diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index c0fb48f..76207c4 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Nike, Inc. + * Copyright (c) 2019 Nike, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/gradle/integration.gradle b/gradle/integration.gradle index 9b8f466..661a642 100644 --- a/gradle/integration.gradle +++ b/gradle/integration.gradle @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Nike, Inc. + * Copyright (c) 2019 Nike, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringApp.java b/src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringApp.java index 866e769..6b25b9e 100644 --- a/src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringApp.java +++ b/src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringApp.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2019 Nike, Inc. + * + * 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 com.nike.cerberus.springboot.testapp; import lombok.extern.slf4j.Slf4j; diff --git a/src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringAppConfig.java b/src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringAppConfig.java index 7323670..3c5d6fa 100644 --- a/src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringAppConfig.java +++ b/src/integration/java/com/nike/cerberus/springboot/testapp/IntegrationTestSpringAppConfig.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2019 Nike, Inc. + * + * 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 com.nike.cerberus.springboot.testapp; import com.nike.cerberus.springboot.CerberusClientSpringBootConfiguration; diff --git a/src/main/java/com/nike/cerberus/springboot/CerberusClientSpringBootConfiguration.java b/src/main/java/com/nike/cerberus/springboot/CerberusClientSpringBootConfiguration.java index 0284cca..3a31b3e 100644 --- a/src/main/java/com/nike/cerberus/springboot/CerberusClientSpringBootConfiguration.java +++ b/src/main/java/com/nike/cerberus/springboot/CerberusClientSpringBootConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Nike, Inc. + * Copyright (c) 2019 Nike, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/com/nike/cerberus/springboot/CerberusClientSpringBootProperties.java b/src/main/java/com/nike/cerberus/springboot/CerberusClientSpringBootProperties.java index 2635ab9..ce5a137 100644 --- a/src/main/java/com/nike/cerberus/springboot/CerberusClientSpringBootProperties.java +++ b/src/main/java/com/nike/cerberus/springboot/CerberusClientSpringBootProperties.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Nike, Inc. + * Copyright (c) 2019 Nike, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.