Skip to content

Commit

Permalink
improve default live to accept any AWS credentials (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
regis-leray authored Oct 30, 2022
1 parent 9b45d38 commit 30bcfeb
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/main/scala/zio/s3/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import software.amazon.awssdk.services.s3.S3AsyncClient
import software.amazon.awssdk.services.s3.model.S3Exception
import zio.nio.file.{ Path => ZPath }
import zio.s3.S3Bucket.S3BucketListing
import zio.s3.providers.{ basic, const }
import zio.s3.providers.const
import zio.stream.ZStream

import java.net.URI
Expand All @@ -31,6 +31,9 @@ import java.util.concurrent.CompletableFuture
package object s3 {
type S3Stream[A] = ZStream[S3, S3Exception, A]

def settings[R](region: Region, cred: ZIO[R, S3Exception, AwsCredentials]): ZLayer[R, S3Exception, S3Settings] =
ZLayer(cred.flatMap(S3Settings.from(region, _)))

def live(region: Region, credentials: AwsCredentials, uriEndpoint: Option[URI] = None): Layer[S3Exception, S3] =
liveZIO(region, const(credentials), uriEndpoint)

Expand All @@ -45,13 +48,8 @@ package object s3 {
.flatMap(Live.connect[R](_, provider, uriEndpoint))
)

def settings[R](region: Region, cred: ZIO[R, S3Exception, AwsCredentials]): ZLayer[R, S3Exception, S3Settings] =
ZLayer(cred.flatMap(S3Settings.from(region, _)))

val live: ZLayer[S3Settings, ConnectionError, S3] = ZLayer.scoped(
ZIO.serviceWithZIO[S3Settings](s =>
Live.connect(s.s3Region, basic(s.credentials.accessKeyId, s.credentials.secretAccessKey), None)
)
ZIO.serviceWithZIO[S3Settings](s => Live.connect(s.s3Region, const(s.credentials), None))
)

def stub(path: ZPath): ZLayer[Any, Nothing, S3] =
Expand Down

0 comments on commit 30bcfeb

Please sign in to comment.