SNRK-76: Add configs and method
This commit is contained in:
parent
167037e276
commit
80deddc412
@ -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"))
|
||||
}
|
||||
}
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user