Merge SNARK-MR-24: Storage fabric method
This commit is contained in:
commit
f8bcdcaeeb
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ build/
|
||||
|
||||
kotlin-js-store
|
||||
*.iml
|
||||
*.json
|
||||
|
@ -0,0 +1,40 @@
|
||||
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
|
||||
|
||||
private const val DEFAULT_REGION = "arctic-vault"
|
||||
|
||||
public sealed interface Config {
|
||||
public fun build(): Directory
|
||||
}
|
||||
|
||||
public data class LocalConfig(val path: Path) : Config {
|
||||
override fun build(): Directory {
|
||||
return localStorage(path)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ~/.aws/credentials.json file is required
|
||||
*/
|
||||
internal fun buildS3Client(regionSpec: String): S3Client {
|
||||
return S3Client {
|
||||
region = regionSpec
|
||||
}
|
||||
}
|
||||
|
||||
public data class S3BucketConfig(val bucketName: String, val region: String = DEFAULT_REGION) : Config {
|
||||
override fun build(): Directory {
|
||||
return s3Bucket(buildS3Client(region), bucketName)
|
||||
}
|
||||
}
|
||||
|
||||
public data class S3ServiceConfig(val region: String = DEFAULT_REGION) : Config {
|
||||
override fun build(): Directory {
|
||||
return s3Storage(buildS3Client(region))
|
||||
}
|
||||
}
|
@ -20,6 +20,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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,25 @@
|
||||
package space.kscience.snark.storage
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.io.path.createTempDirectory
|
||||
|
||||
class JustCreates {
|
||||
|
||||
@Test
|
||||
fun s3Created() {
|
||||
val dir = Directory.fromConfig(S3ServiceConfig())
|
||||
dir.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun s3BucketCreated() {
|
||||
val dir = Directory.fromConfig(S3BucketConfig("snark-test"))
|
||||
dir.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun localCreated() {
|
||||
val dir = Directory.fromConfig(LocalConfig(createTempDirectory("snark-test")))
|
||||
dir.close()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user