Skip to content

Commit dd4707e

Browse files
committed
renamed settings to dodge strict validation and allowed using InstanceProfile credentials
1 parent 35e3628 commit dd4707e

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ Note: there could be changes to the plugin API.
2323

2424
**Settings**
2525

26-
- `dbms.cluster.discovery.resolver_type=EC2-ASG`
27-
- `server.config.strict_validation.enabled=false` : to disable strict settings validation, which will allow the usage of the following plugin-specific settings (You'll still get Warnings : "Unrecognized setting").
26+
- `discovery.aws.asg_name=<asg_name>` : the name of the Auto-scaling group
27+
- `discovery.aws.region=<region>` : the AWS region hosting the Auto-scaling group (ex: "eu-west-1")
2828

29-
- `dbms.aws.asg_name=<asg_name>` : the name of the Auto-scaling group
30-
- `dbms.aws.region=<region>` : the AWS region hosting the Auto-scaling group (ex: "eu-west-1")
31-
- `dbms.aws.key=<key>` : the Access Key of the user connecting to the AWS API.
32-
- `dbms.aws.secret=<secret>` : the Secret Key of the user connecting to the AWS API
29+
Optionally :
30+
- `discovery.aws.key=<key>` : the Access Key of the user connecting to the AWS API.
31+
- `discovery.aws.secret=<secret>` : the Secret Key of the user connecting to the AWS API
32+
If not set, the plugin will try to use any InstanceProfile role attached to the EC2 instance. That can be defined in the ASG's LaunchTemplate.
3333

3434
**Permissions**
3535

36-
The AWS User requires the following permissions :
36+
The Role/User requires the following permissions :
3737
- "ec2:DescribeInstances",
3838
- "autoscaling:DescribeAutoScalingGroups"
3939

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.neo4j</groupId>
88
<artifactId>aws-ec2-asg-discovery</artifactId>
9-
<version>0.1.1</version>
9+
<version>0.2.0</version>
1010

1111
<properties>
1212
<maven.compiler.source>17</maven.compiler.source>

src/main/java/cs/neo4j/AwsClient.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
99
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
10+
import software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider;
11+
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
1012
import software.amazon.awssdk.regions.Region;
1113
import software.amazon.awssdk.services.autoscaling.AutoScalingClient;
1214
import software.amazon.awssdk.services.autoscaling.model.AutoScalingGroup;
@@ -18,20 +20,28 @@
1820

1921
public class AwsClient extends LifecycleAdapter {
2022

21-
public static String accessKey;
22-
public static String secretKey;
23-
public static String region;
23+
private static String accessKey;
24+
private static String secretKey;
25+
private static String region;
2426

2527

2628
private AutoScalingClient autoScalingClient;
2729
private Ec2Client ec2Client;
2830

31+
public AwsClient(String region) {
32+
this.region=region;
33+
createClients();
34+
}
35+
2936
public AwsClient(String accessKey, String secretKey, String region) {
3037
this.accessKey=accessKey;
3138
this.secretKey=secretKey;
3239
this.region=region;
3340

41+
createClients();
42+
}
3443

44+
private void createClients(){
3545
this.autoScalingClient = AutoScalingClient.builder()
3646
.region(Region.of(region))
3747
.credentialsProvider(awsCredentialsProvider())
@@ -44,7 +54,11 @@ public AwsClient(String accessKey, String secretKey, String region) {
4454
}
4555

4656
private AwsCredentialsProvider awsCredentialsProvider() {
47-
return () -> AwsBasicCredentials.create(accessKey, secretKey);
57+
if (accessKey != null && secretKey != null) {
58+
return () -> AwsBasicCredentials.create(accessKey, secretKey);
59+
} else {
60+
return InstanceProfileCredentialsProvider.builder().build();
61+
}
4862
}
4963

5064
private AutoScalingGroup getAsgByName(String nameSelector) {

src/main/java/cs/neo4j/Ec2Settings.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,21 @@ public class Ec2Settings implements SettingsDeclaration {
1818

1919
@Description("Auto-scaling group name")
2020
public static final Setting<String> asg_name = newBuilder(
21-
"dbms.aws.asg_name", STRING, null)
21+
"discovery.aws.asg_name", STRING, null)
2222
.build();
2323

2424
@Description("AWS access key")
2525
public static final Setting<String> aws_key = newBuilder(
26-
"dbms.aws.key", STRING, null)
26+
"discovery.aws.key", STRING, null)
2727
.build();
2828

2929
@Description("AWS secret")
3030
public static final Setting<String> aws_secret = newBuilder(
31-
"dbms.aws.secret", STRING, null)
31+
"discovery.aws.secret", STRING, null)
3232
.build();
3333

34-
3534
@Description("AWS region")
3635
public static final Setting<String> aws_region = newBuilder(
37-
"dbms.aws.region", STRING, null)
36+
"discovery.aws.region", STRING, null)
3837
.build();
3938
}

0 commit comments

Comments
 (0)