Skip to content

Commit 36d3ac6

Browse files
committed
Merge update for branch
Merge update for branch
1 parent 0e5485e commit 36d3ac6

File tree

3 files changed

+14
-48
lines changed

3 files changed

+14
-48
lines changed

src/main/java/software/aws/mcs/auth/SigV4AuthProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ public String getPath() {
130130
* Unused for this plugin.
131131
*/
132132
public SigV4AuthProvider(DriverContext driverContext) {
133-
this(DefaultAWSCredentialsProviderChain.getInstance(),
134-
(driverContext.getConfig().getDefaultProfile().getString(REGION_OPTION, null)));
133+
this(driverContext.getConfig().getDefaultProfile().getString(REGION_OPTION, null));
135134
}
136135

137136
/**

src/test/java/software/aws/mcs/auth/TestSigV4.java

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
* #L%
2121
*/
2222

23-
import com.amazonaws.SDKGlobalConfiguration;
24-
import com.datastax.oss.driver.api.core.CqlSession;
25-
import com.datastax.oss.driver.api.core.cql.*;
26-
27-
import software.aws.mcs.auth.SigV4AuthProvider;
2823
import java.net.InetSocketAddress;
2924
import java.util.ArrayList;
3025
import javax.net.ssl.SSLContext;
@@ -55,28 +50,16 @@ public static void main(String[] args) throws Exception {
5550

5651
System.out.println("Using endpoints: " + contactPoints);
5752

58-
String region = null;
59-
if (System.getProperty(SDKGlobalConfiguration.AWS_REGION_SYSTEM_PROPERTY) != null) {
60-
region = System.getProperty(SDKGlobalConfiguration.AWS_REGION_SYSTEM_PROPERTY);
61-
} else {
62-
region = System.getenv(SDKGlobalConfiguration.AWS_REGION_ENV_VAR);
63-
}
64-
if (region == null) {
65-
throw new IllegalStateException(
66-
"When specifying contact points you must specify a localdc. In this sample we use the AWS_REGION env variable, or aws.region system property value as localdc"
67-
);
68-
}
69-
7053
// The CqlSession object is the main entry point of the driver.
7154
// It holds the known state of the actual Cassandra cluster (notably the Metadata).
7255
// This class is thread-safe, you should create a single instance (per target Cassandra cluster), and share
7356
// it throughout your application.
7457
try (CqlSession session = CqlSession.builder()
75-
.addContactPoints(contactPoints)
76-
.withAuthProvider(new SigV4AuthProvider())
77-
.withSslContext(SSLContext.getDefault())
78-
.withLocalDatacenter(region)
79-
.build()) {
58+
.addContactPoints(contactPoints)
59+
.withAuthProvider(new SigV4AuthProvider())
60+
.withSslContext(SSLContext.getDefault())
61+
.withLocalDatacenter("us-west-2")
62+
.build()) {
8063

8164
// We use execute to send a query to Cassandra. This returns a ResultSet, which is essentially a collection
8265
// of Row objects.
@@ -89,4 +72,4 @@ public static void main(String[] args) throws Exception {
8972
System.out.printf("Cassandra version is: %s%n", releaseVersion);
9073
}
9174
}
92-
}
75+
}

src/test/java/software/aws/mcs/auth/TestSigV4Config.java

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* #%L
55
* AWS SigV4 Auth Java Driver 4.x Plugin
66
* %%
7-
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
7+
* Copyright (C) 2020-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
88
* %%
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
@@ -20,20 +20,16 @@
2020
* #L%
2121
*/
2222

23-
import com.amazonaws.SDKGlobalConfiguration;
24-
import com.datastax.oss.driver.api.core.CqlSession;
25-
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
26-
import com.datastax.oss.driver.api.core.cql.ResultSet;
27-
import com.datastax.oss.driver.api.core.cql.Row;
28-
29-
import javax.net.ssl.SSLContext;
3023
import java.io.File;
31-
import java.io.FileInputStream;
32-
import java.io.InputStream;
3324
import java.net.InetSocketAddress;
3425
import java.net.URL;
3526
import java.util.ArrayList;
3627

28+
import com.datastax.oss.driver.api.core.CqlSession;
29+
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
30+
import com.datastax.oss.driver.api.core.cql.ResultSet;
31+
import com.datastax.oss.driver.api.core.cql.Row;
32+
3733
public class TestSigV4Config {
3834
static String[] DEFAULT_CONTACT_POINTS = {"127.0.0.1:9042"};
3935

@@ -56,18 +52,6 @@ public static void main(String[] args) throws Exception {
5652

5753
System.out.println("Using endpoints: " + contactPoints);
5854

59-
String region = null;
60-
if (System.getProperty(SDKGlobalConfiguration.AWS_REGION_SYSTEM_PROPERTY) != null) {
61-
region = System.getProperty(SDKGlobalConfiguration.AWS_REGION_SYSTEM_PROPERTY);
62-
} else {
63-
region = System.getenv(SDKGlobalConfiguration.AWS_REGION_ENV_VAR);
64-
}
65-
if (region == null) {
66-
throw new IllegalStateException(
67-
"When specifying contact points you must specify a localdc. In this sample we use the AWS_REGION env variable, or aws.region system property value as localdc"
68-
);
69-
}
70-
7155
//By default the reference.conf is loaded by the driver which contains all defaults.
7256
//You can override this by providing reference.conf on the classpath
7357
//to isolate test you can load conf with a custom name
@@ -81,7 +65,7 @@ public static void main(String[] args) throws Exception {
8165
try (CqlSession session = CqlSession.builder()
8266
.withConfigLoader(DriverConfigLoader.fromFile(file))
8367
.addContactPoints(contactPoints)
84-
.withLocalDatacenter(region)
68+
.withLocalDatacenter("us-west-2")
8569
.build()) {
8670

8771
// We use execute to send a query to Cassandra. This returns a ResultSet, which is essentially a collection

0 commit comments

Comments
 (0)