Skip to content

Commit

Permalink
renamed settings to dodge strict validation and allowed using Instanc…
Browse files Browse the repository at this point in the history
…eProfile credentials
  • Loading branch information
pecollet committed Jan 31, 2024
1 parent 35e3628 commit dd4707e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ Note: there could be changes to the plugin API.

**Settings**

- `dbms.cluster.discovery.resolver_type=EC2-ASG`
- `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").
- `discovery.aws.asg_name=<asg_name>` : the name of the Auto-scaling group
- `discovery.aws.region=<region>` : the AWS region hosting the Auto-scaling group (ex: "eu-west-1")

- `dbms.aws.asg_name=<asg_name>` : the name of the Auto-scaling group
- `dbms.aws.region=<region>` : the AWS region hosting the Auto-scaling group (ex: "eu-west-1")
- `dbms.aws.key=<key>` : the Access Key of the user connecting to the AWS API.
- `dbms.aws.secret=<secret>` : the Secret Key of the user connecting to the AWS API
Optionally :
- `discovery.aws.key=<key>` : the Access Key of the user connecting to the AWS API.
- `discovery.aws.secret=<secret>` : the Secret Key of the user connecting to the AWS API
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.

**Permissions**

The AWS User requires the following permissions :
The Role/User requires the following permissions :
- "ec2:DescribeInstances",
- "autoscaling:DescribeAutoScalingGroups"

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.neo4j</groupId>
<artifactId>aws-ec2-asg-discovery</artifactId>
<version>0.1.1</version>
<version>0.2.0</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/cs/neo4j/AwsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.autoscaling.AutoScalingClient;
import software.amazon.awssdk.services.autoscaling.model.AutoScalingGroup;
Expand All @@ -18,20 +20,28 @@

public class AwsClient extends LifecycleAdapter {

public static String accessKey;
public static String secretKey;
public static String region;
private static String accessKey;
private static String secretKey;
private static String region;


private AutoScalingClient autoScalingClient;
private Ec2Client ec2Client;

public AwsClient(String region) {
this.region=region;
createClients();
}

public AwsClient(String accessKey, String secretKey, String region) {
this.accessKey=accessKey;
this.secretKey=secretKey;
this.region=region;

createClients();
}

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

private AwsCredentialsProvider awsCredentialsProvider() {
return () -> AwsBasicCredentials.create(accessKey, secretKey);
if (accessKey != null && secretKey != null) {
return () -> AwsBasicCredentials.create(accessKey, secretKey);
} else {
return InstanceProfileCredentialsProvider.builder().build();
}
}

private AutoScalingGroup getAsgByName(String nameSelector) {
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/cs/neo4j/Ec2Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@ public class Ec2Settings implements SettingsDeclaration {

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

@Description("AWS access key")
public static final Setting<String> aws_key = newBuilder(
"dbms.aws.key", STRING, null)
"discovery.aws.key", STRING, null)
.build();

@Description("AWS secret")
public static final Setting<String> aws_secret = newBuilder(
"dbms.aws.secret", STRING, null)
"discovery.aws.secret", STRING, null)
.build();


@Description("AWS region")
public static final Setting<String> aws_region = newBuilder(
"dbms.aws.region", STRING, null)
"discovery.aws.region", STRING, null)
.build();
}

0 comments on commit dd4707e

Please sign in to comment.