SNRK-76: Add configs and method

This commit is contained in:
Kirill Grachev 2023-05-15 17:59:53 +03:00
parent 167037e276
commit 80deddc412
2 changed files with 43 additions and 0 deletions

View File

@ -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"))
}
}

View File

@ -1,5 +1,7 @@
package space.kscience.snark.storage 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 java.nio.file.Path
import kotlin.io.path.Path import kotlin.io.path.Path
@ -20,6 +22,12 @@ public interface Directory : AutoCloseable {
@Deprecated("Not a good idea") @Deprecated("Not a good idea")
public val path: Path public val path: Path
public companion object {
public fun fromConfig(config: Config): Directory {
return config.build()
}
}
} }