-
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.
Merge branch 'upgrade-scanamo' into pending-pre-scala-2.13-prs
Small conflict between these two PRs on how to create a MediaAtomMakerPermissionsProvider: * #1142 * #1143
- Loading branch information
Showing
20 changed files
with
155 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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 | ||
import software.amazon.awssdk.regions.Region | ||
|
||
object AwsV2Util { | ||
def buildSync[T, B <: AwsClientBuilder[B, T] with AwsSyncClientBuilder[B, T]]( | ||
builder: B, creds: AwsCredentialsProvider, region: Region | ||
): T = builder | ||
.httpClientBuilder(ApacheHttpClient.builder()) | ||
.credentialsProvider(creds) | ||
.region(region) | ||
.build() | ||
} |
48 changes: 48 additions & 0 deletions
48
common/src/main/scala/com/gu/media/aws/CredentialsForBothSdkVersions.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,48 @@ | ||
package com.gu.media.aws | ||
|
||
import com.amazonaws.auth._ | ||
import com.amazonaws.auth.profile.ProfileCredentialsProvider | ||
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder | ||
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 CredentialsForBothSdkVersions( | ||
awsV1Creds: com.amazonaws.auth.AWSCredentialsProvider, | ||
awsV2Creds: software.amazon.awssdk.auth.credentials.AwsCredentialsProvider | ||
) { | ||
def assumeAccountRole(roleArn: String, sessionNameSuffix: String, regionName: String): CredentialsForBothSdkVersions = { | ||
val roleSessionName = s"media-atom-maker-$sessionNameSuffix" | ||
CredentialsForBothSdkVersions( | ||
new STSAssumeRoleSessionCredentialsProvider.Builder(roleArn, roleSessionName) | ||
.withStsClient(AWSSecurityTokenServiceClientBuilder.standard().withCredentials(awsV1Creds).build()).build(), | ||
software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider.builder() | ||
.stsClient(AwsV2Util.buildSync[StsClient, StsClientBuilder](StsClient.builder(), awsV2Creds, Region.of(regionName))) | ||
.refreshRequest(AssumeRoleRequest.builder.roleSessionName(roleSessionName).roleArn(roleArn).build) | ||
.build() | ||
) | ||
} | ||
} | ||
|
||
object CredentialsForBothSdkVersions { | ||
def profile(name: String): CredentialsForBothSdkVersions = CredentialsForBothSdkVersions( | ||
new ProfileCredentialsProvider(name), | ||
awsv2.ProfileCredentialsProvider.create(name) | ||
) | ||
|
||
def instance(): CredentialsForBothSdkVersions = CredentialsForBothSdkVersions( | ||
InstanceProfileCredentialsProvider.getInstance(), | ||
awsv2.InstanceProfileCredentialsProvider.create() | ||
) | ||
|
||
def environmentVariables(): CredentialsForBothSdkVersions = CredentialsForBothSdkVersions( | ||
new EnvironmentVariableCredentialsProvider(), | ||
awsv2.EnvironmentVariableCredentialsProvider.create() | ||
) | ||
|
||
def static(accessKey: String, secretKey: String): CredentialsForBothSdkVersions = CredentialsForBothSdkVersions( | ||
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
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
Oops, something went wrong.