From be4f02a0694182d4df159b8d6126210f0dd625c0 Mon Sep 17 00:00:00 2001 From: Todd Underwood Date: Mon, 10 Aug 2020 09:40:31 -0700 Subject: [PATCH] feat: Enable AWS China Regions (#51) * feat: Enable AWS China Regions --- gradle.properties | 2 +- gradle/dependencies.gradle | 4 ++-- .../cerberus/client/CerberusClientFactory.java | 2 +- .../aws/StsCerberusCredentialsProvider.java | 17 +++++++++++------ 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/gradle.properties b/gradle.properties index d4b58df..81312f6 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=7.2.2 +version=7.3.0 groupId=com.nike artifactId=cerberus-client diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index e12da87..83e18a0 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -29,8 +29,8 @@ configurations.all { force "net.sourceforge.pmd:pmd-java:6.21.0" dependencySubstitution { - substitute module("org.mortbay.jetty:jetty") with module("org.eclipse.jetty:jetty-server:9.4.28.v20200408") - substitute module("org.mortbay.jetty:jetty-util") with module("org.eclipse.jetty:jetty-util:9.4.28.v20200408") + substitute module("org.mortbay.jetty:jetty") with module("org.eclipse.jetty:jetty-server:9.4.31.v20200723") + substitute module("org.mortbay.jetty:jetty-util") with module("org.eclipse.jetty:jetty-util:9.4.31.v20200723") substitute module("dom4j:dom4j:1.6.1") with module("org.dom4j:dom4j:2.1.3") } } diff --git a/src/main/java/com/nike/cerberus/client/CerberusClientFactory.java b/src/main/java/com/nike/cerberus/client/CerberusClientFactory.java index a33b406..db6a801 100644 --- a/src/main/java/com/nike/cerberus/client/CerberusClientFactory.java +++ b/src/main/java/com/nike/cerberus/client/CerberusClientFactory.java @@ -37,7 +37,7 @@ */ public class CerberusClientFactory { - public static final int DEFAULT_TIMEOUT = 15_000; + public static final int DEFAULT_TIMEOUT = 30_000; public static final TimeUnit DEFAULT_TIMEOUT_UNIT = TimeUnit.MILLISECONDS; /** diff --git a/src/main/java/com/nike/cerberus/client/auth/aws/StsCerberusCredentialsProvider.java b/src/main/java/com/nike/cerberus/client/auth/aws/StsCerberusCredentialsProvider.java index 65a0e36..64f88d4 100644 --- a/src/main/java/com/nike/cerberus/client/auth/aws/StsCerberusCredentialsProvider.java +++ b/src/main/java/com/nike/cerberus/client/auth/aws/StsCerberusCredentialsProvider.java @@ -41,10 +41,7 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Provider for allowing users to authenticate with Cerberus with the STS auth endpoint. @@ -57,6 +54,12 @@ public class StsCerberusCredentialsProvider extends BaseAwsCredentialsProvider { private static final Logger LOGGER = LoggerFactory.getLogger(BaseAwsCredentialsProvider.class); + private final List CHINA_REGIONS = new ArrayList( + Arrays.asList( + "cn-north-1", + "cn-northwest-1") + ); + private final Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .create(); @@ -160,8 +163,10 @@ private void signRequest(com.amazonaws.Request request, AWSCredentials credentia */ protected Map getSignedHeaders(){ - final String url = "https://sts." + regionName + ".amazonaws.com"; - + String url = "https://sts." + regionName + ".amazonaws.com"; + if(CHINA_REGIONS.contains(regionName)) { + url += ".cn"; + } URI endpoint = null; try {