SNRK-76: Add regions
This commit is contained in:
parent
f06182ee1d
commit
028cf631f4
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ class JustCreates {
|
||||
|
||||
@Test
|
||||
fun s3Created() {
|
||||
val dir = Directory.fromConfig(S3ServiceConfig)
|
||||
val dir = Directory.fromConfig(S3ServiceConfig())
|
||||
dir.close()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user