[sync] rename type aliases to MD5Hash and RemoteKey
This commit is contained in:
parent
24b03f959e
commit
e8a656ae4c
5 changed files with 15 additions and 13 deletions
|
@ -1,8 +1,8 @@
|
||||||
package net.kemitix.s3thorp
|
package net.kemitix.s3thorp
|
||||||
|
|
||||||
import net.kemitix.s3thorp.Sync.{Hash, LastModified, LocalFile, RemotePath}
|
import net.kemitix.s3thorp.Sync.{MD5Hash, LastModified, LocalFile, RemoteKey}
|
||||||
|
|
||||||
case class S3MetaData(localFile: LocalFile,
|
case class S3MetaData(localFile: LocalFile,
|
||||||
remotePath: RemotePath,
|
remotePath: RemoteKey,
|
||||||
remoteHash: Hash,
|
remoteHash: MD5Hash,
|
||||||
remoteLastModified: LastModified)
|
remoteLastModified: LastModified)
|
|
@ -5,6 +5,7 @@ import java.time.Instant
|
||||||
|
|
||||||
import cats.effect._
|
import cats.effect._
|
||||||
import net.kemitix.s3thorp.Main.putStrLn
|
import net.kemitix.s3thorp.Main.putStrLn
|
||||||
|
import net.kemitix.s3thorp.Sync.{Bucket, LocalFile, RemoteKey}
|
||||||
import net.kemitix.s3thorp.awssdk.S3Client
|
import net.kemitix.s3thorp.awssdk.S3Client
|
||||||
|
|
||||||
class Sync(s3Client: S3Client)
|
class Sync(s3Client: S3Client)
|
||||||
|
@ -13,8 +14,8 @@ class Sync(s3Client: S3Client)
|
||||||
with UploadSelectionFilter
|
with UploadSelectionFilter
|
||||||
with S3Uploader {
|
with S3Uploader {
|
||||||
|
|
||||||
override def objectHead(bucket: String, key: String)=
|
override def objectHead(bucket: Bucket, remoteKey: RemoteKey)=
|
||||||
s3Client.objectHead(bucket, key)
|
s3Client.objectHead(bucket, remoteKey)
|
||||||
|
|
||||||
def run(c: Config): IO[Unit] = for {
|
def run(c: Config): IO[Unit] = for {
|
||||||
_ <- putStrLn(s"Bucket: ${c.bucket}, Prefix: ${c.prefix}, Source: ${c.source}")
|
_ <- putStrLn(s"Bucket: ${c.bucket}, Prefix: ${c.prefix}, Source: ${c.source}")
|
||||||
|
@ -32,8 +33,8 @@ object Sync {
|
||||||
|
|
||||||
type Bucket = String // the S3 bucket name
|
type Bucket = String // the S3 bucket name
|
||||||
type LocalFile = File // the file or directory
|
type LocalFile = File // the file or directory
|
||||||
type RemotePath = String // path within an S3 bucket
|
type RemoteKey = String // path within an S3 bucket
|
||||||
type Hash = String // an MD5 hash
|
type MD5Hash = String // an MD5 hash
|
||||||
type LastModified = Instant // or scala equivalent
|
type LastModified = Instant // or scala equivalent
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,13 @@ package net.kemitix.s3thorp
|
||||||
|
|
||||||
import fs2.Stream
|
import fs2.Stream
|
||||||
import cats.effect.IO
|
import cats.effect.IO
|
||||||
import net.kemitix.s3thorp.Sync.{Hash, LocalFile}
|
import net.kemitix.s3thorp.Sync.{MD5Hash, LocalFile}
|
||||||
import java.security.{MessageDigest, DigestInputStream}
|
import java.security.{MessageDigest, DigestInputStream}
|
||||||
import java.io.{File, FileInputStream}
|
import java.io.{File, FileInputStream}
|
||||||
|
|
||||||
trait UploadSelectionFilter {
|
trait UploadSelectionFilter {
|
||||||
|
|
||||||
private def md5File(localFile: LocalFile): Hash = {
|
private def md5File(localFile: LocalFile): MD5Hash = {
|
||||||
val buffer = new Array[Byte](8192)
|
val buffer = new Array[Byte](8192)
|
||||||
val md5 = MessageDigest.getInstance("MD5")
|
val md5 = MessageDigest.getInstance("MD5")
|
||||||
|
|
||||||
|
|
|
@ -4,16 +4,17 @@ import cats.effect.IO
|
||||||
import com.github.j5ik2o.reactive.aws.s3.S3AsyncClient
|
import com.github.j5ik2o.reactive.aws.s3.S3AsyncClient
|
||||||
import com.github.j5ik2o.reactive.aws.s3.cats.S3CatsIOClient
|
import com.github.j5ik2o.reactive.aws.s3.cats.S3CatsIOClient
|
||||||
import software.amazon.awssdk.services.s3.model.{HeadObjectRequest, NoSuchKeyException}
|
import software.amazon.awssdk.services.s3.model.{HeadObjectRequest, NoSuchKeyException}
|
||||||
|
import net.kemitix.s3thorp.Sync.{Bucket, LocalFile, RemoteKey}
|
||||||
import software.amazon.awssdk.services.s3.{S3AsyncClient => JavaS3AsyncClient}
|
import software.amazon.awssdk.services.s3.{S3AsyncClient => JavaS3AsyncClient}
|
||||||
|
|
||||||
private class ReactiveS3Client extends S3Client {
|
private class ReactiveS3Client extends S3Client {
|
||||||
|
|
||||||
private val s3Client = S3CatsIOClient(S3AsyncClient(JavaS3AsyncClient.create))
|
private val s3Client = S3CatsIOClient(S3AsyncClient(JavaS3AsyncClient.create))
|
||||||
|
|
||||||
override def objectHead(bucket: String, key: String) = {
|
override def objectHead(bucket: Bucket, remoteKey: RemoteKey) = {
|
||||||
val request = HeadObjectRequest.builder()
|
val request = HeadObjectRequest.builder()
|
||||||
.bucket(bucket)
|
.bucket(bucket)
|
||||||
.key(key)
|
.key(remoteKey)
|
||||||
.build()
|
.build()
|
||||||
try {
|
try {
|
||||||
for {
|
for {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package net.kemitix.s3thorp.awssdk
|
package net.kemitix.s3thorp.awssdk
|
||||||
|
|
||||||
import cats.effect.IO
|
import cats.effect.IO
|
||||||
import net.kemitix.s3thorp.Sync.{Hash, LastModified}
|
import net.kemitix.s3thorp.Sync.{Bucket, MD5Hash, LastModified, LocalFile, RemoteKey}
|
||||||
|
|
||||||
trait S3Client {
|
trait S3Client {
|
||||||
|
|
||||||
def objectHead(bucket: String, key: String): IO[Option[(Hash, LastModified)]]
|
def objectHead(bucket: Bucket, remoteKey: RemoteKey): IO[Option[(MD5Hash, LastModified)]]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue