SNRK-76: Add regions

This commit is contained in:
Kirill Grachev 2023-05-15 18:07:12 +03:00
parent f06182ee1d
commit 028cf631f4
2 changed files with 10 additions and 5 deletions

View File

@ -6,6 +6,8 @@ import space.kscience.snark.storage.s3.s3Bucket
import space.kscience.snark.storage.s3.s3Storage import space.kscience.snark.storage.s3.s3Storage
import java.nio.file.Path import java.nio.file.Path
private const val DEFAULT_REGION = "arctic-vault"
public sealed interface Config { public sealed interface Config {
public fun build(): Directory 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 { internal fun buildS3Client(regionSpec: String): S3Client {
return S3Client { return S3Client {
region = regionSpec 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 { 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 { override fun build(): Directory {
return s3Storage(buildS3Client("eu-east")) return s3Storage(buildS3Client(region))
} }
} }

View File

@ -7,7 +7,7 @@ class JustCreates {
@Test @Test
fun s3Created() { fun s3Created() {
val dir = Directory.fromConfig(S3ServiceConfig) val dir = Directory.fromConfig(S3ServiceConfig())
dir.close() dir.close()
} }