Skip to content

Commit e38ac99

Browse files
vaibhavsawhneyashishagg
authored andcommitted
Improvements (#15)
* Scope change for dependencies in haystack-blobs * Added STS Assume role for S3Dispatcher * Version bump to 1.0.3-SNAPSHOT * Scope change for grpc dependencies * Version bump to 1.0.3-SNAPSHOT(all modules)
1 parent f7d8b33 commit e38ac99

File tree

13 files changed

+87
-37
lines changed

13 files changed

+87
-37
lines changed

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>blobs</artifactId>
66
<groupId>com.expedia.www</groupId>
7-
<version>1.0.0-SNAPSHOT</version>
7+
<version>1.0.3-SNAPSHOT</version>
88
</parent>
99

1010
<modelVersion>4.0.0</modelVersion>

haystack-blobs/blobs-agent-client/pom.xml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>haystack-blobs</artifactId>
77
<groupId>com.expedia.www</groupId>
8-
<version>1.0.0-SNAPSHOT</version>
8+
<version>1.0.3-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>blobs-agent-client</artifactId>
@@ -37,25 +37,19 @@
3737
<artifactId>protobuf-java</artifactId>
3838
<version>${protobuf.version}</version>
3939
</dependency>
40+
41+
<!-- grpc -->
4042
<dependency>
4143
<groupId>io.grpc</groupId>
42-
<artifactId>grpc-core</artifactId>
43-
<version>${grpc.version}</version>
44-
</dependency>
45-
<dependency>
46-
<groupId>io.grpc</groupId>
47-
<artifactId>grpc-protobuf</artifactId>
48-
<version>${grpc.version}</version>
49-
</dependency>
50-
<dependency>
51-
<groupId>io.grpc</groupId>
52-
<artifactId>grpc-stub</artifactId>
44+
<artifactId>grpc-all</artifactId>
5345
<version>${grpc.version}</version>
46+
<scope>provided</scope>
5447
</dependency>
5548
<dependency>
5649
<groupId>io.grpc</groupId>
5750
<artifactId>grpc-netty-shaded</artifactId>
5851
<version>${grpc.version}</version>
52+
<scope>provided</scope>
5953
</dependency>
6054

6155
<!-- test -->
@@ -99,7 +93,7 @@
9993
<dependency>
10094
<groupId>com.expedia.www</groupId>
10195
<artifactId>blobs-grpc-models</artifactId>
102-
<version>1.0.0-SNAPSHOT</version>
96+
<version>${parent.version}</version>
10397
<scope>compile</scope>
10498
</dependency>
10599
</dependencies>

haystack-blobs/blobs-agent-dispatchers/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>haystack-blobs</artifactId>
77
<groupId>com.expedia.www</groupId>
8-
<version>1.0.0-SNAPSHOT</version>
8+
<version>1.0.3-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>blobs-agent-dispatchers</artifactId>

haystack-blobs/blobs-agent-dispatchers/src/main/java/com/expedia/www/haystack/agent/blobs/dispatcher/s3/S3Dispatcher.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import com.amazonaws.auth.AWSStaticCredentialsProvider;
2222
import com.amazonaws.auth.BasicAWSCredentials;
2323
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
24+
import com.amazonaws.auth.profile.internal.securitytoken.RoleInfo;
25+
import com.amazonaws.auth.profile.internal.securitytoken.STSProfileCredentialsServiceProvider;
2426
import com.amazonaws.client.builder.AwsClientBuilder;
2527
import com.amazonaws.services.s3.AmazonS3;
2628
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
@@ -73,6 +75,8 @@ public class S3Dispatcher implements BlobDispatcher, AutoCloseable {
7375
private final static String AWS_SERVICE_ENDPOINT = "service.endpoint";
7476
private final static String AWS_PATH_STYLE_ACCESS_ENABLED = "path.style.access.enabled";
7577
private final static String AWS_DISABLE_CHUNKED_ENCODING = "disable.chunked.encoding";
78+
private final static String AWS_USE_STS_ARN = "use.sts.arn";
79+
private final static String AWS_STS_ARN_ROLE = "sts.arn.role";
7680

7781
private final static String SHOULD_WAIT_FOR_UPLOAD = "should.wait.for.upload";
7882

@@ -271,7 +275,15 @@ private static AmazonS3 getS3Client(Config config, ClientConfiguration clientCon
271275

272276
@VisibleForTesting
273277
static AWSCredentialsProvider buildCredentialProvider(final Config config) {
274-
if (config.hasPath(AWS_ACCESS_KEY) && config.hasPath(AWS_SECRET_KEY)) {
278+
if (config.hasPath(AWS_USE_STS_ARN) && config.getBoolean(AWS_USE_STS_ARN)) {
279+
LOGGER.info("using STS profile credential service provider");
280+
Validate.isTrue(config.hasPath(AWS_STS_ARN_ROLE), "AWS STS Assume-Role should be present when enabled");
281+
282+
return new STSProfileCredentialsServiceProvider(
283+
new RoleInfo().withRoleArn(config.getString(AWS_STS_ARN_ROLE))
284+
.withRoleSessionName("haystack-monitoring-blobs-agent"));
285+
286+
} else if (config.hasPath(AWS_ACCESS_KEY) && config.hasPath(AWS_SECRET_KEY)) {
275287
LOGGER.info("using static aws credential provider with access and secret key for s3 dispatcher");
276288
return new AWSStaticCredentialsProvider(
277289
new BasicAWSCredentials(config.getString(AWS_ACCESS_KEY), config.getString(AWS_SECRET_KEY)));

haystack-blobs/blobs-agent-dispatchers/src/test/scala/com/expedia/www/haystack/agent/blobs/dispatcher/s3/S3DispatcherSpec.scala

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.expedia.www.haystack.agent.blobs.dispatcher.s3
33
import java.io.{ByteArrayInputStream, InputStream}
44
import java.util.Optional
55

6+
import com.amazonaws.auth.profile.internal.securitytoken.STSProfileCredentialsServiceProvider
67
import com.amazonaws.auth.{AWSStaticCredentialsProvider, DefaultAWSCredentialsProviderChain}
78
import com.amazonaws.services.s3.AmazonS3Client
89
import com.amazonaws.services.s3.model.{ObjectMetadata, PutObjectRequest, S3Object, S3ObjectInputStream}
@@ -259,6 +260,42 @@ class S3DispatcherSpec extends FunSpec with GivenWhenThen with BeforeAndAfter wi
259260
caught.getMessage should include("RateLimit is hit with outstanding(pending) requests=0")
260261
}
261262

263+
it("should throw error while building the credential provider using unavailable STS assume-role") {
264+
When("given the complete configuration")
265+
val config = ConfigFactory.parseString(
266+
"""
267+
|bucket.name = "haystack"
268+
|max.outstanding.requests = 50
269+
|should.wait.for.upload = false
270+
|use.sts.arn = true
271+
""".stripMargin)
272+
273+
And("credential provider is build")
274+
val caught = intercept[Exception]{
275+
S3Dispatcher.buildCredentialProvider(config)
276+
}
277+
caught should not be null
278+
caught.getMessage should include("AWS STS Assume-Role should be present when enabled")
279+
}
280+
281+
it("should build the credential provider using STS assume-role") {
282+
When("given the complete configuration")
283+
val config = ConfigFactory.parseString(
284+
"""
285+
|bucket.name = "haystack"
286+
|max.outstanding.requests = 50
287+
|should.wait.for.upload = false
288+
|use.sts.arn = true
289+
|sts.arn.role = "role/tempArnRole"
290+
""".stripMargin)
291+
292+
And("credential provider is build")
293+
val provider = S3Dispatcher.buildCredentialProvider(config)
294+
295+
Then("it should be the instance of STSProfileCredentialsServiceProvider")
296+
provider.isInstanceOf[STSProfileCredentialsServiceProvider] shouldBe true
297+
}
298+
262299
it("should build the credential provider using access and secret key") {
263300
When("given the complete configuration")
264301
val config = ConfigFactory.parseString(

haystack-blobs/blobs-agent-server/pom.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>haystack-blobs</artifactId>
77
<groupId>com.expedia.www</groupId>
8-
<version>1.0.0-SNAPSHOT</version>
8+
<version>1.0.3-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>blobs-agent-server</artifactId>
@@ -41,6 +41,20 @@
4141
<artifactId>FastInfoset</artifactId>
4242
</dependency>
4343

44+
<!--grpc-->
45+
<dependency>
46+
<groupId>io.grpc</groupId>
47+
<artifactId>grpc-services</artifactId>
48+
<version>${grpc.version}</version>
49+
<scope>provided</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>io.grpc</groupId>
53+
<artifactId>grpc-all</artifactId>
54+
<version>${grpc.version}</version>
55+
<scope>provided</scope>
56+
</dependency>
57+
4458
<!--Test-->
4559
<dependency>
4660
<groupId>org.scala-lang</groupId>

haystack-blobs/blobs-grpc-models/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>haystack-blobs</artifactId>
77
<groupId>com.expedia.www</groupId>
8-
<version>1.0.0-SNAPSHOT</version>
8+
<version>1.0.3-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>blobs-grpc-models</artifactId>
@@ -19,6 +19,12 @@
1919
<version>3.3.1</version>
2020
<scope>provided</scope>
2121
</dependency>
22+
<dependency>
23+
<groupId>io.grpc</groupId>
24+
<artifactId>grpc-all</artifactId>
25+
<version>${grpc.version}</version>
26+
<scope>compile</scope>
27+
</dependency>
2228
</dependencies>
2329

2430
<build>

haystack-blobs/pom.xml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>blobs</artifactId>
77
<groupId>com.expedia.www</groupId>
8-
<version>1.0.0-SNAPSHOT</version>
8+
<version>1.0.3-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -38,19 +38,6 @@
3838
<artifactId>commons-lang3</artifactId>
3939
</dependency>
4040

41-
<!-- grpc -->
42-
<dependency>
43-
<groupId>io.grpc</groupId>
44-
<artifactId>grpc-all</artifactId>
45-
<version>${grpc.version}</version>
46-
</dependency>
47-
48-
<dependency>
49-
<groupId>io.grpc</groupId>
50-
<artifactId>grpc-services</artifactId>
51-
<version>${grpc.version}</version>
52-
</dependency>
53-
5441
<dependency>
5542
<groupId>org.easymock</groupId>
5643
<artifactId>easymock</artifactId>

haystack-blobs/span-blob-context/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>haystack-blobs</artifactId>
77
<groupId>com.expedia.www</groupId>
8-
<version>1.0.0-SNAPSHOT</version>
8+
<version>1.0.3-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>span-blob-context</artifactId>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.expedia.www</groupId>
77
<artifactId>blobs</artifactId>
8-
<version>1.0.0-SNAPSHOT</version>
8+
<version>1.0.3-SNAPSHOT</version>
99
<packaging>pom</packaging>
1010

1111
<modules>

0 commit comments

Comments
 (0)