[sync] rename type aliases to MD5Hash and RemoteKey

This commit is contained in:
Paul Campbell 2019-05-09 18:29:42 +01:00
parent 24b03f959e
commit e8a656ae4c
5 changed files with 15 additions and 13 deletions

View file

@ -1,8 +1,8 @@
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,
remotePath: RemotePath,
remoteHash: Hash,
remotePath: RemoteKey,
remoteHash: MD5Hash,
remoteLastModified: LastModified)

View file

@ -5,6 +5,7 @@ import java.time.Instant
import cats.effect._
import net.kemitix.s3thorp.Main.putStrLn
import net.kemitix.s3thorp.Sync.{Bucket, LocalFile, RemoteKey}
import net.kemitix.s3thorp.awssdk.S3Client
class Sync(s3Client: S3Client)
@ -13,8 +14,8 @@ class Sync(s3Client: S3Client)
with UploadSelectionFilter
with S3Uploader {
override def objectHead(bucket: String, key: String)=
s3Client.objectHead(bucket, key)
override def objectHead(bucket: Bucket, remoteKey: RemoteKey)=
s3Client.objectHead(bucket, remoteKey)
def run(c: Config): IO[Unit] = for {
_ <- 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 LocalFile = File // the file or directory
type RemotePath = String // path within an S3 bucket
type Hash = String // an MD5 hash
type RemoteKey = String // path within an S3 bucket
type MD5Hash = String // an MD5 hash
type LastModified = Instant // or scala equivalent
}

View file

@ -2,13 +2,13 @@ package net.kemitix.s3thorp
import fs2.Stream
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.io.{File, FileInputStream}
trait UploadSelectionFilter {
private def md5File(localFile: LocalFile): Hash = {
private def md5File(localFile: LocalFile): MD5Hash = {
val buffer = new Array[Byte](8192)
val md5 = MessageDigest.getInstance("MD5")

View file

@ -4,16 +4,17 @@ import cats.effect.IO
import com.github.j5ik2o.reactive.aws.s3.S3AsyncClient
import com.github.j5ik2o.reactive.aws.s3.cats.S3CatsIOClient
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}
private class ReactiveS3Client extends S3Client {
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()
.bucket(bucket)
.key(key)
.key(remoteKey)
.build()
try {
for {

View file

@ -1,11 +1,11 @@
package net.kemitix.s3thorp.awssdk
import cats.effect.IO
import net.kemitix.s3thorp.Sync.{Hash, LastModified}
import net.kemitix.s3thorp.Sync.{Bucket, MD5Hash, LastModified, LocalFile, RemoteKey}
trait S3Client {
def objectHead(bucket: String, key: String): IO[Option[(Hash, LastModified)]]
def objectHead(bucket: Bucket, remoteKey: RemoteKey): IO[Option[(MD5Hash, LastModified)]]
}