Skip to content

Commit

Permalink
Update AWS SDK version to latest version (#121)
Browse files Browse the repository at this point in the history
* Update AWS SDK version to latest version

* Improve the region display values in the UI

Before, then looked like this "EU_WEST_2", now they are more readable with the actual location in them: "EU (London): eu-west-2".

Also added a test to cover both the formatting and and value.

* Use improved region formatting for CloudTrail and Logs inputs

* Bump amazon-kinesis-client from 1.9.0 to 1.10.0 (#122)

Bumps [amazon-kinesis-client](https://github.com/awslabs/amazon-kinesis-client) from 1.9.0 to 1.10.0.
- [Release notes](https://github.com/awslabs/amazon-kinesis-client/releases)
- [Changelog](https://github.com/awslabs/amazon-kinesis-client/blob/v1.10.0/CHANGELOG.md)
- [Commits](awslabs/amazon-kinesis-client@v1.9.0...v1.10.0)

Signed-off-by: dependabot[bot] <support@dependabot.com>
  • Loading branch information
Dan Torrey authored and bernd committed Apr 10, 2019
1 parent 7e7bdac commit 2bc458e
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -34,8 +34,8 @@
<maven.deploy.skip>true</maven.deploy.skip>
<maven.site.skip>true</maven.site.skip>
<graylog.version>3.1.0-SNAPSHOT</graylog.version>
<aws-java-sdk.version>1.11.313</aws-java-sdk.version>
<aws-kinesis-client.version>1.9.0</aws-kinesis-client.version>
<aws-java-sdk.version>1.11.534</aws-java-sdk.version>
<aws-kinesis-client.version>1.10.0</aws-kinesis-client.version>
</properties>

<dependencyManagement>
Expand Down
30 changes: 29 additions & 1 deletion src/main/java/org/graylog/aws/AWS.java
@@ -1,9 +1,37 @@
package org.graylog.aws;

import com.amazonaws.regions.Regions;
import com.google.common.collect.Maps;

import java.util.Map;

/**
* A common utils class for the AWS plugin.
*/
public class AWS {

public static final String SOURCE_GROUP_IDENTIFIER = "aws_source";

public static final String FIELD_LOG_GROUP = "aws_log_group";
public static final String FIELD_LOG_STREAM = "aws_log_stream";

// This is a non-instantiable utils class.
private AWS() {
}

/**
* Build a list of region choices with both a value (persisted in configuration) and display value (shown to the user).
*
* The display value is formatted nicely: "EU (London): eu-west-2"
* The value is eventually passed to Regions.fromName() to get the actual region object: eu-west-2
* @return a choices map with configuration value map keys and display value map values.
*/
public static Map<String, String> buildRegionChoices() {
Map<String, String> regions = Maps.newHashMap();
for (Regions region : Regions.values()) {

String displayValue = String.format("%s: %s", region.getDescription(), region.getName());
regions.put(region.getName(), displayValue);
}
return regions;
}
}
Expand Up @@ -8,6 +8,7 @@
import com.google.common.eventbus.Subscribe;
import com.google.inject.assistedinject.Assisted;
import okhttp3.HttpUrl;
import org.graylog.aws.AWS;
import org.graylog.aws.auth.AWSAuthProvider;
import org.graylog.aws.config.AWSPluginConfiguration;
import org.graylog.aws.AWSObjectMapper;
Expand Down Expand Up @@ -166,14 +167,12 @@ public static class Config extends ThrottleableTransport.Config {
public ConfigurationRequest getRequestedConfiguration() {
final ConfigurationRequest r = super.getRequestedConfiguration();

final Map<String, String> regions = Arrays.stream(Regions.values())
.collect(Collectors.toMap(Regions::getName, Regions::toString));

Map<String, String> regionChoices = AWS.buildRegionChoices();
r.addField(new DropdownField(
CK_AWS_SQS_REGION,
"AWS SQS Region",
DEFAULT_REGION.getName(),
regions,
regionChoices,
"The AWS region the SQS queue is in.",
ConfigurationField.Optional.NOT_OPTIONAL
));
Expand All @@ -182,7 +181,7 @@ public ConfigurationRequest getRequestedConfiguration() {
CK_AWS_S3_REGION,
"AWS S3 Region",
DEFAULT_REGION.getName(),
regions,
regionChoices,
"The AWS region the S3 bucket containing CloudTrail logs is in.",
ConfigurationField.Optional.NOT_OPTIONAL
));
Expand Down
Expand Up @@ -9,6 +9,7 @@
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.inject.assistedinject.Assisted;
import okhttp3.HttpUrl;
import org.graylog.aws.AWS;
import org.graylog.aws.AWSObjectMapper;
import org.graylog.aws.auth.AWSAuthProvider;
import org.graylog.aws.config.AWSPluginConfiguration;
Expand Down Expand Up @@ -215,11 +216,6 @@ public static class Config extends ThrottleableTransport.Config {
public ConfigurationRequest getRequestedConfiguration() {
final ConfigurationRequest r = super.getRequestedConfiguration();

Map<String, String> regions = Maps.newHashMap();
for (Regions region : Regions.values()) {
regions.put(region.getName(), region.toString());
}

r.addField(new NumberField(
CK_KINESIS_MAX_THROTTLED_WAIT_MS,
"Throttled wait milliseconds",
Expand All @@ -232,7 +228,7 @@ public ConfigurationRequest getRequestedConfiguration() {
CK_AWS_REGION,
"AWS Region",
Regions.US_EAST_1.getName(),
regions,
AWS.buildRegionChoices(),
"The AWS region the Kinesis stream is running in.",
ConfigurationField.Optional.NOT_OPTIONAL
));
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/org/graylog/aws/AWSTest.java
@@ -0,0 +1,29 @@
package org.graylog.aws;

import org.junit.Test;

import java.util.Map;

import static org.junit.Assert.assertTrue;


public class AWSTest {

// Verify that region choices are correctly built and formatted.
@Test
public void testRegionChoices() {

Map<String, String> regionChoices = AWS.buildRegionChoices();

// Check format of random region.
assertTrue(regionChoices.containsValue("EU (London): eu-west-2"));
assertTrue(regionChoices.containsKey("eu-west-2"));

// Verify that the Gov regions are present.
//"us-gov-west-1" -> "AWS GovCloud (US): us-gov-west-1"
assertTrue(regionChoices.containsValue("AWS GovCloud (US): us-gov-west-1"));
assertTrue(regionChoices.containsKey("us-gov-west-1"));
assertTrue(regionChoices.containsValue("AWS GovCloud (US-East): us-gov-east-1"));
assertTrue(regionChoices.containsKey("us-gov-east-1"));
}
}

0 comments on commit 2bc458e

Please sign in to comment.