Skip to content

Commit

Permalink
Allow using a specific AWS profile to auth
Browse files Browse the repository at this point in the history
  • Loading branch information
oheyadam committed Feb 8, 2024
1 parent 84256cb commit f354cf2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion s3buildcache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit f354cf2

Please sign in to comment.