From 028cf631f45bc266b6013fd0e16a3b2fdaf0e34c Mon Sep 17 00:00:00 2001 From: Kirill Grachev Date: Mon, 15 May 2023 18:07:12 +0300 Subject: [PATCH] SNRK-76: Add regions --- .../kotlin/space/kscience/snark/storage/Config.kt | 13 +++++++++---- .../space/kscience/snark/storage/JustCreates.kt | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/Config.kt b/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/Config.kt index 0b870eb..5cf24de 100644 --- a/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/Config.kt +++ b/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/Config.kt @@ -6,6 +6,8 @@ import space.kscience.snark.storage.s3.s3Bucket import space.kscience.snark.storage.s3.s3Storage import java.nio.file.Path +private const val DEFAULT_REGION = "arctic-vault" + public sealed interface Config { public fun build(): Directory } @@ -16,20 +18,23 @@ public data class LocalConfig(val path: Path): Config { } } +/* + * `~/.aws/credentials.json file is required + */ internal fun buildS3Client(regionSpec: String): S3Client { return S3Client { region = regionSpec } } -public data class S3BucketConfig(val bucketName: String): Config { +public data class S3BucketConfig(val bucketName: String, val region: String = DEFAULT_REGION): Config { override fun build(): Directory { - return s3Bucket(buildS3Client("eu-east"), bucketName) + return s3Bucket(buildS3Client(region), bucketName) } } -public object S3ServiceConfig: Config { +public data class S3ServiceConfig(val region: String = DEFAULT_REGION): Config { override fun build(): Directory { - return s3Storage(buildS3Client("eu-east")) + return s3Storage(buildS3Client(region)) } } diff --git a/snark-storage-driver/src/test/kotlin/space/kscience/snark/storage/JustCreates.kt b/snark-storage-driver/src/test/kotlin/space/kscience/snark/storage/JustCreates.kt index ef9478a..43e8144 100644 --- a/snark-storage-driver/src/test/kotlin/space/kscience/snark/storage/JustCreates.kt +++ b/snark-storage-driver/src/test/kotlin/space/kscience/snark/storage/JustCreates.kt @@ -7,7 +7,7 @@ class JustCreates { @Test fun s3Created() { - val dir = Directory.fromConfig(S3ServiceConfig) + val dir = Directory.fromConfig(S3ServiceConfig()) dir.close() }