Skip to content

Commit

Permalink
Merge pull request #45 from oheyadam/allow-using-aws-profiles
Browse files Browse the repository at this point in the history
Allow using a specific AWS profile to auth
  • Loading branch information
liutikas authored Feb 9, 2024
2 parents ff6ef9c + f354cf2 commit 6ff6573
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 @@ -104,6 +101,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 6ff6573

Please sign in to comment.