Skip to content

Commit

Permalink
Expose S3AsyncClientBuilder in Live.connect() (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
regis-leray authored Jan 7, 2022
1 parent 8cda290 commit bae927d
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/main/scala/zio/s3/Live.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package zio.s3
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider
import software.amazon.awssdk.core.async.{ AsyncRequestBody, AsyncResponseTransformer, SdkPublisher }
import software.amazon.awssdk.core.exception.SdkException
import software.amazon.awssdk.services.s3.S3AsyncClient
import software.amazon.awssdk.services.s3.{ S3AsyncClient, S3AsyncClientBuilder }
import software.amazon.awssdk.services.s3.model._
import zio._
import zio.interop.reactivestreams._
Expand Down Expand Up @@ -236,21 +236,23 @@ object Live {
provider: RManaged[R, AwsCredentialsProvider],
uriEndpoint: Option[URI]
): ZManaged[R, ConnectionError, S3.Service] =
(for {
credentials <- provider
s <- ZManaged
.fromAutoCloseable(
Task {
val builder = S3AsyncClient
.builder()
.credentialsProvider(credentials)
.region(region.region)
uriEndpoint.foreach(builder.endpointOverride)
builder.build()
}
)
.map(new Live(_))
} yield s)
for {
credentials <- provider.mapError(e => ConnectionError(e.getMessage, e.getCause))
builder <- ZManaged.succeed {
val builder = S3AsyncClient
.builder()
.credentialsProvider(credentials)
.region(region.region)
uriEndpoint.foreach(builder.endpointOverride)
builder
}
service <- connect(builder)
} yield service

def connect[R](builder: S3AsyncClientBuilder): ZManaged[R, ConnectionError, S3.Service] =
ZManaged
.fromAutoCloseable(Task(builder.build()))
.map(new Live(_))
.mapError(e => ConnectionError(e.getMessage, e.getCause))

type StreamResponse = ZStream[Any, Throwable, Chunk[Byte]]
Expand Down

0 comments on commit bae927d

Please sign in to comment.