From f354cf273167c318e38d30aac2348cb22e509b4d Mon Sep 17 00:00:00 2001 From: Adam Ahmed Date: Thu, 8 Feb 2024 16:52:59 +0000 Subject: [PATCH] Allow using a specific AWS profile to auth --- s3buildcache/README.md | 2 +- .../build/gradle/s3buildcache/S3BuildCacheService.kt | 6 ++---- .../androidx/build/gradle/s3buildcache/S3Credentials.kt | 7 ++++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/s3buildcache/README.md b/s3buildcache/README.md index b327ea1..7717212 100644 --- a/s3buildcache/README.md +++ b/s3buildcache/README.md @@ -27,7 +27,7 @@ buildCache { ``` - `region`, `bucketName` are required. -- `credentials` defaults to `DefaultS3Credentials`, but can also be set to `ExportedS3Credentials`, or `SpecificCredentialsProvider`. +- `credentials` defaults to `DefaultS3Credentials`, but can also be set to `ExportedS3Credentials`, `ProfileS3Credentials`, or `SpecificCredentialsProvider`. - `isPush` defaults to `false`. --- diff --git a/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3BuildCacheService.kt b/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3BuildCacheService.kt index ccfd549..f5266b6 100644 --- a/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3BuildCacheService.kt +++ b/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3BuildCacheService.kt @@ -24,10 +24,7 @@ import org.gradle.caching.BuildCacheEntryReader import org.gradle.caching.BuildCacheEntryWriter import org.gradle.caching.BuildCacheKey import org.gradle.caching.BuildCacheService -import software.amazon.awssdk.auth.credentials.AwsBasicCredentials -import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider -import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider -import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider +import software.amazon.awssdk.auth.credentials.* import software.amazon.awssdk.regions.Region import software.amazon.awssdk.services.s3.S3Client import java.io.ByteArrayOutputStream @@ -103,6 +100,7 @@ class S3BuildCacheService( return when (s3Credentials) { DefaultS3Credentials -> DefaultCredentialsProvider.create() is SpecificCredentialsProvider -> s3Credentials.provider + is ProfileS3Credentials -> ProfileCredentialsProvider.create(s3Credentials.profile) is ExportedS3Credentials -> StaticCredentialsProvider.create( AwsBasicCredentials.create(s3Credentials.awsAccessKeyId, s3Credentials.awsSecretKey) ) diff --git a/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3Credentials.kt b/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3Credentials.kt index 2dd1960..9c9628e 100644 --- a/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3Credentials.kt +++ b/s3buildcache/src/main/kotlin/androidx/build/gradle/s3buildcache/S3Credentials.kt @@ -28,7 +28,7 @@ sealed interface S3Credentials : Credentials /** * Use DefaultCredentialsProvider to authenticate to AWS. */ -object DefaultS3Credentials : S3Credentials +data object DefaultS3Credentials : S3Credentials /** * Use a specific credentials provider @@ -40,3 +40,8 @@ class SpecificCredentialsProvider(val provider: AwsCredentialsProvider) : S3Cred * Use provided keys to authenticate to AWS. */ class ExportedS3Credentials(val awsAccessKeyId: String, val awsSecretKey: String) : S3Credentials + +/** + * Ensure that we load this profile to authenticate to AWS + */ +class ProfileS3Credentials(val profile: String) : S3Credentials