-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgrade to latest Scanamo version (1.0.0-M28)
Complete Scanamo update - support both v1 and v2 credentials
- Loading branch information
Showing
23 changed files
with
168 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
common/src/main/scala/com/gu/media/aws/AwsCredentialsProvidersForBothSdkVersions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.gu.media.aws | ||
|
||
import com.amazonaws.auth._ | ||
import com.amazonaws.auth.profile.ProfileCredentialsProvider | ||
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder | ||
import com.gu.media.Settings | ||
import com.gu.media.aws.AwsV2Util | ||
import software.amazon.awssdk.auth.{credentials => awsv2} | ||
import software.amazon.awssdk.regions.Region | ||
import software.amazon.awssdk.services.sts.{StsClient, StsClientBuilder} | ||
import software.amazon.awssdk.services.sts.model.AssumeRoleRequest | ||
|
||
case class AwsCredentialsProvidersForBothSdkVersions( | ||
v1: com.amazonaws.auth.AWSCredentialsProvider, | ||
v2: software.amazon.awssdk.auth.credentials.AwsCredentialsProvider | ||
) { | ||
def assumeAccountRole(roleArn: String, sessionNameSuffix: String, regionName: String): AwsCredentialsProvidersForBothSdkVersions = { | ||
val roleSessionName = s"media-atom-maker-$sessionNameSuffix" | ||
AwsCredentialsProvidersForBothSdkVersions( | ||
new STSAssumeRoleSessionCredentialsProvider.Builder(roleArn, roleSessionName) | ||
.withStsClient(AWSSecurityTokenServiceClientBuilder.standard().withCredentials(v1).build()).build(), | ||
software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider.builder() | ||
.stsClient(AwsV2Util.buildSync[StsClient, StsClientBuilder](StsClient.builder(), v2, Region.of(regionName))) | ||
.refreshRequest(AssumeRoleRequest.builder.roleSessionName(roleSessionName).roleArn(roleArn).build) | ||
.build() | ||
) | ||
} | ||
} | ||
|
||
object AwsCredentialsProvidersForBothSdkVersions { | ||
def profile(name: String): AwsCredentialsProvidersForBothSdkVersions = AwsCredentialsProvidersForBothSdkVersions( | ||
new ProfileCredentialsProvider(name), | ||
awsv2.ProfileCredentialsProvider.create(name) | ||
) | ||
|
||
def instance(): AwsCredentialsProvidersForBothSdkVersions = AwsCredentialsProvidersForBothSdkVersions( | ||
InstanceProfileCredentialsProvider.getInstance(), | ||
awsv2.InstanceProfileCredentialsProvider.create() | ||
) | ||
|
||
def environmentVariables(): AwsCredentialsProvidersForBothSdkVersions = AwsCredentialsProvidersForBothSdkVersions( | ||
new EnvironmentVariableCredentialsProvider(), | ||
awsv2.EnvironmentVariableCredentialsProvider.create() | ||
) | ||
|
||
def static(accessKey: String, secretKey: String): AwsCredentialsProvidersForBothSdkVersions = AwsCredentialsProvidersForBothSdkVersions( | ||
new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)), | ||
awsv2.StaticCredentialsProvider.create(awsv2.AwsBasicCredentials.create(accessKey, secretKey)) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.gu.media.aws | ||
|
||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider | ||
import software.amazon.awssdk.awscore.client.builder.{AwsClientBuilder, AwsSyncClientBuilder} | ||
import software.amazon.awssdk.http.apache.ApacheHttpClient | ||
|
||
object AwsV2Util { | ||
def buildSync[T, B <: AwsClientBuilder[B, T] with AwsSyncClientBuilder[B, T]]( | ||
builder: B, creds: AwsCredentialsProvider, region: software.amazon.awssdk.regions.Region | ||
): T = builder | ||
.httpClientBuilder(ApacheHttpClient.builder()) | ||
.credentialsProvider(creds) | ||
.region(region) | ||
.build() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.