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 new file mode 100644 index 0000000..0b870eb --- /dev/null +++ b/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/Config.kt @@ -0,0 +1,35 @@ +package space.kscience.snark.storage + +import aws.sdk.kotlin.services.s3.S3Client +import space.kscience.snark.storage.local.localStorage +import space.kscience.snark.storage.s3.s3Bucket +import space.kscience.snark.storage.s3.s3Storage +import java.nio.file.Path + +public sealed interface Config { + public fun build(): Directory +} + +public data class LocalConfig(val path: Path): Config { + override fun build(): Directory { + return localStorage(path) + } +} + +internal fun buildS3Client(regionSpec: String): S3Client { + return S3Client { + region = regionSpec + } +} + +public data class S3BucketConfig(val bucketName: String): Config { + override fun build(): Directory { + return s3Bucket(buildS3Client("eu-east"), bucketName) + } +} + +public object S3ServiceConfig: Config { + override fun build(): Directory { + return s3Storage(buildS3Client("eu-east")) + } +} diff --git a/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/Driver.kt b/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/Driver.kt index 902aa23..caccf06 100644 --- a/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/Driver.kt +++ b/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/Driver.kt @@ -1,5 +1,7 @@ package space.kscience.snark.storage +import space.kscience.snark.storage.local.localStorage +import space.kscience.snark.storage.s3.s3Bucket import java.nio.file.Path import kotlin.io.path.Path @@ -20,6 +22,12 @@ public interface Directory : AutoCloseable { @Deprecated("Not a good idea") public val path: Path + + public companion object { + public fun fromConfig(config: Config): Directory { + return config.build() + } + } }