Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for s3 express one zone #53

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ abstract class S3BuildCache : RemoteGradleBuildCache() {

/**
* Whether to use reduced redundancy.
* When using S3 Express One Zone, set to false
* @see <a href="https://aws.amazon.com/s3/reduced-redundancy/">Reduced Redundancy</a>
* */
var reducedRedundancy: Boolean = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ import androidx.build.gradle.core.FileHandleInputStream
import androidx.build.gradle.core.FileHandleInputStream.Companion.handleInputStream
import androidx.build.gradle.core.StorageService
import org.gradle.api.logging.Logging
import software.amazon.awssdk.core.exception.SdkClientException
import software.amazon.awssdk.core.exception.SdkException
import software.amazon.awssdk.core.exception.SdkServiceException
import software.amazon.awssdk.core.sync.RequestBody
import software.amazon.awssdk.services.s3.S3Client
import software.amazon.awssdk.services.s3.model.DeleteObjectRequest
import software.amazon.awssdk.services.s3.model.GetObjectRequest
import software.amazon.awssdk.services.s3.model.HeadBucketRequest
import software.amazon.awssdk.services.s3.model.NoSuchBucketException
import software.amazon.awssdk.services.s3.model.PutObjectRequest
import software.amazon.awssdk.services.s3.model.StorageClass.REDUCED_REDUNDANCY
import software.amazon.awssdk.services.s3.model.StorageClass.STANDARD
import java.io.InputStream
import kotlin.io.path.outputStream

Expand Down Expand Up @@ -74,7 +78,11 @@ class S3StorageService(
val request = PutObjectRequest.builder()
.bucket(bucketName)
.key(cacheKey)
.storageClass(if (reducedRedundancy) REDUCED_REDUNDANCY else STANDARD)
.apply {
if (reducedRedundancy) {
storageClass(REDUCED_REDUNDANCY)
}
}
.build()
logger.info("Storing $cacheKey via $request")
return store(client, request, contents)
Expand All @@ -101,11 +109,13 @@ class S3StorageService(

override fun validateConfiguration() {
try {
val buckets = client.listBuckets().buckets()
if (buckets.none { bucket -> bucket.name() == bucketName }) {
throw Exception("Bucket $bucketName under project $region cannot be found or is not accessible using the provided credentials")
}
} catch (e: Exception) {
client.headBucket(HeadBucketRequest.builder().bucket(bucketName).build())
liutikas marked this conversation as resolved.
Show resolved Hide resolved
} catch(e: NoSuchBucketException) {
throw Exception("Bucket $bucketName in $region cannot be found: ${e.message}")
} catch (e: SdkServiceException ) {
throw Exception("AWS SDK exception on validating access to $bucketName in $region: ${e::class.simpleName} - ${e.message}")
}
catch (e: Exception) {
logger.warn("Couldn't validate S3 client config: ${e.message}")
}
}
Expand Down
Loading