Skip to content

Commit

Permalink
Moved impl to RIO
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris V.Kuznetsov committed Jan 21, 2020
1 parent 05d05d9 commit 255b731
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
val zioVersion = "1.0.0-RC17"
val awsVersion = "2.10.52"
val awsVersion = "2.10.53"

// *****************************************************************************
// Projects
Expand Down
1 change: 0 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.0")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.0.0")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.3.1")
addSbtPlugin("com.dwijnand" % "sbt-travisci" % "1.2.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8.1")
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.10")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8.1")
3 changes: 1 addition & 2 deletions src/main/scala/AwsLink.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package zio_aws_s3
import java.nio.file.{ Paths }
import java.util.concurrent.CompletableFuture
import java.net.URI
// import scala.jdk.CollectionConverters._
import scala.collection.JavaConverters._

import zio.{ IO, Task }
Expand Down Expand Up @@ -100,7 +99,7 @@ class AwsLink extends GenericLink {
s3.listObjectsV2(
ListObjectsV2Request.builder
.bucket(buck)
// .maxKeys(10)
.maxKeys(20)
.prefix(prefix)
.build
)
Expand Down
43 changes: 22 additions & 21 deletions src/main/scala/GenericLink.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package zio_aws_s3

import zio.{ Task }
import zio.{ RIO }
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.s3.S3AsyncClient
import software.amazon.awssdk.services.s3.model.{
Expand All @@ -42,6 +42,7 @@ trait GenericLink {

object GenericLink {
trait Service[R] {
type AwsTask[+A] = RIO[R, A]

/**
*
Expand All @@ -51,22 +52,22 @@ object GenericLink {
/**
* Create an async S3 client.
*/
def createClient(region: Region, endpoint: String): Task[S3AsyncClient]
def createClient(region: Region, endpoint: String): AwsTask[S3AsyncClient]

/**
* Create S3 bucket with the given name.
*/
def createBucket(buck: String)(implicit s3: S3AsyncClient): Task[CreateBucketResponse]
def createBucket(buck: String)(implicit s3: S3AsyncClient): AwsTask[CreateBucketResponse]

/**
* Delete the bucket with the given name.
*/
def delBucket(buck: String)(implicit s3: S3AsyncClient): Task[DeleteBucketResponse]
def delBucket(buck: String)(implicit s3: S3AsyncClient): AwsTask[DeleteBucketResponse]

/**
* Obtain a list of all buckets owned by the authenticated sender.
*/
def listBuckets(implicit s3: S3AsyncClient): Task[ListBucketsResponse]
def listBuckets(implicit s3: S3AsyncClient): AwsTask[ListBucketsResponse]

/**
*
Expand All @@ -76,92 +77,92 @@ object GenericLink {
/**
* List all objects in a Bucket
*/
def listBucketObjects(buck: String, prefix: String)(implicit s3: S3AsyncClient): Task[ListObjectsV2Response]
def listBucketObjects(buck: String, prefix: String)(implicit s3: S3AsyncClient): AwsTask[ListObjectsV2Response]

/**
* List all object keys in a Bucket
*/
def listObjectsKeys(buck: String, prefix: String)(implicit s3: S3AsyncClient): Task[List[String]]
def listObjectsKeys(buck: String, prefix: String)(implicit s3: S3AsyncClient): AwsTask[List[String]]

/**
* Look up for an object. True if present
*/
def lookupObject(buck: String, prefix: String, key: String)(implicit s3: S3AsyncClient): Task[Boolean]
def lookupObject(buck: String, prefix: String, key: String)(implicit s3: S3AsyncClient): AwsTask[Boolean]

/**
* Setup redirection for a single object
*/
def redirectObject(buck: String, prefix: String, key: String, url: String)(
implicit s3: S3AsyncClient
): Task[CopyObjectResponse]
): AwsTask[CopyObjectResponse]

/**
* Setup redirection for all objects with a common prefix
*/
def redirectPack(buck: String, prefix: String, url: String)(
implicit s3: S3AsyncClient
): Task[Unit]
): AwsTask[Unit]

/**
* Copy an object
*/
def copyObject(buck: String, dstPrefix: String, srcKey: String, dstKey: String)(
implicit s3: S3AsyncClient
): Task[CopyObjectResponse]
): AwsTask[CopyObjectResponse]

/**
* Put a file with a key into a Bucket
*/
def putObject(buck: String, key: String, file: String)(implicit s3: S3AsyncClient): Task[PutObjectResponse]
def putObject(buck: String, key: String, file: String)(implicit s3: S3AsyncClient): AwsTask[PutObjectResponse]

/**
* Get a file with a key from a Bucket
*/
def getObject(buck: String, key: String, file: String)(implicit s3: S3AsyncClient): Task[GetObjectResponse]
def getObject(buck: String, key: String, file: String)(implicit s3: S3AsyncClient): AwsTask[GetObjectResponse]

/**
* Delete object by key from a Bucket
*/
def delObject(buck: String, key: String)(implicit s3: S3AsyncClient): Task[DeleteObjectResponse]
def delObject(buck: String, key: String)(implicit s3: S3AsyncClient): AwsTask[DeleteObjectResponse]

/**
* Delete all objects
*/
def delAllObjects(buck: String, prefix: String)(implicit s3: S3AsyncClient): Task[Unit]
def delAllObjects(buck: String, prefix: String)(implicit s3: S3AsyncClient): AwsTask[Unit]

/**
* get current ACL settings
*/
def getObjectAcl(buck: String, key: String)(implicit s3: S3AsyncClient): Task[GetObjectAclResponse]
def getObjectAcl(buck: String, key: String)(implicit s3: S3AsyncClient): AwsTask[GetObjectAclResponse]

/**
* put new ACL settings
*/
def putObjectAcl(buck: String, key: String, owner: Owner, grants: JList[Grant])(
implicit s3: S3AsyncClient
): Task[PutObjectAclResponse]
): AwsTask[PutObjectAclResponse]

/**
* Block all objects with ACL remove permission for a group of objects under the common path
*/
def blockPack(buck: String, prefix: String)(implicit s3: S3AsyncClient): Task[Unit]
def blockPack(buck: String, prefix: String)(implicit s3: S3AsyncClient): AwsTask[Unit]

/**
* Unblock all objects with ACL remove permission for a group of objects under the common path
*/
def unblockPack(buck: String, prefix: String)(implicit s3: S3AsyncClient): Task[Unit]
def unblockPack(buck: String, prefix: String)(implicit s3: S3AsyncClient): AwsTask[Unit]

/**
* Get ACL for each object in a path
*/
def getPackAcl(buck: String, prefix: String)(implicit s3: S3AsyncClient): Task[List[GetObjectAclResponse]]
def getPackAcl(buck: String, prefix: String)(implicit s3: S3AsyncClient): AwsTask[List[GetObjectAclResponse]]

/**
* Put ACL for each object in a path
*/
def putPackAcl(buck: String, prefix: String, block: Boolean)(
implicit s3: S3AsyncClient
): Task[List[PutObjectAclResponse]]
): AwsTask[List[PutObjectAclResponse]]

}
}
6 changes: 2 additions & 4 deletions src/test/scala/BaseSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ object Tests {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.getPackAcl(bucket, prefix)(s3)
// _ = out.foreach(println)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")), equalTo("ok"))
Expand All @@ -110,7 +109,6 @@ object Tests {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
out <- aws.service.putPackAcl(bucket, prefix, false)(s3)
// _ = out.foreach(println)
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")), equalTo("ok"))
Expand All @@ -125,7 +123,7 @@ object Tests {
} yield out

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")), equalTo("ok"))
} @@ timeout(10.seconds) @@ ignore,
} @@ timeout(10.seconds),
testM("block content pack by adding ACL grant") {
val res = for {
s3 <- aws.service.createClient(region, endpoint).mapError(_ => new IOException("S3 client creation failed"))
Expand All @@ -134,7 +132,7 @@ object Tests {

assertM(res.foldM(_ => ZIO.fail("failed"), _ => ZIO.succeed("ok")), equalTo("ok"))
} @@ timeout(10.seconds)
)
) @@ ignore
}

object BuckSpec extends DefaultRunnableSpec(suite("Bucket Spec")(Tests.bucketsSuite))
Expand Down

0 comments on commit 255b731

Please sign in to comment.