-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move credentials providers inside zio.s3.providers object * sbt build file remove deprecated warning
- Loading branch information
1 parent
7a27e4c
commit 141d4e4
Showing
8 changed files
with
215 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ inThisBuild( | |
Developer("regis-leray", "Regis Leray", "[email protected]", url("https://github.com/regis-leray")) | ||
), | ||
Test / fork := true, | ||
parallelExecution in Test := false, | ||
(Test / parallelExecution) := false, | ||
pgpPassphrase := sys.env.get("PGP_PASSWORD").map(_.toArray), | ||
pgpPublicRing := file("/tmp/public.asc"), | ||
pgpSecretRing := file("/tmp/secret.asc"), | ||
|
@@ -46,18 +46,18 @@ lazy val `zio-s3` = project | |
lazy val docs = project | ||
.in(file("zio-s3-docs")) | ||
.settings( | ||
skip.in(publish) := true, | ||
skip / publish := true, | ||
moduleName := "zio-s3-docs", | ||
scalacOptions -= "-Yno-imports", | ||
scalacOptions -= "-Xfatal-warnings", | ||
libraryDependencies ++= Seq( | ||
"dev.zio" %% "zio" % zioVersion | ||
), | ||
unidocProjectFilter in (ScalaUnidoc, unidoc) := inProjects(`zio-s3`), | ||
target in (ScalaUnidoc, unidoc) := (baseDirectory in LocalRootProject).value / "website" / "static" / "api", | ||
cleanFiles += (target in (ScalaUnidoc, unidoc)).value, | ||
docusaurusCreateSite := docusaurusCreateSite.dependsOn(unidoc in Compile).value, | ||
docusaurusPublishGhpages := docusaurusPublishGhpages.dependsOn(unidoc in Compile).value | ||
(ScalaUnidoc / unidoc / unidocProjectFilter) := inProjects(`zio-s3`), | ||
ScalaUnidoc / unidoc / target := (LocalRootProject / baseDirectory).value / "website" / "static" / "api", | ||
cleanFiles += (ScalaUnidoc / unidoc / target).value, | ||
docusaurusCreateSite := docusaurusCreateSite.dependsOn(Compile / unidoc).value, | ||
docusaurusPublishGhpages := docusaurusPublishGhpages.dependsOn(Compile / unidoc).value | ||
) | ||
.dependsOn(`zio-s3`) | ||
.enablePlugins(MdocPlugin, DocusaurusPlugin, ScalaUnidocPlugin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package zio.s3 | ||
|
||
import software.amazon.awssdk.auth.credentials.{ | ||
AwsBasicCredentials, | ||
AwsCredentialsProvider, | ||
ContainerCredentialsProvider, | ||
DefaultCredentialsProvider, | ||
EnvironmentVariableCredentialsProvider, | ||
InstanceProfileCredentialsProvider, | ||
ProfileCredentialsProvider, | ||
SystemPropertyCredentialsProvider, | ||
WebIdentityTokenFileCredentialsProvider | ||
} | ||
import zio.blocking.{ Blocking, effectBlocking } | ||
import zio.{ IO, Managed, UManaged, ZIO, ZManaged } | ||
|
||
object providers { | ||
|
||
def const(accessKeyId: String, secretAccessKey: String): UManaged[AwsCredentialsProvider] = | ||
ZManaged.succeedNow[AwsCredentialsProvider](() => AwsBasicCredentials.create(accessKeyId, secretAccessKey)) | ||
|
||
val system: Managed[InvalidCredentials, SystemPropertyCredentialsProvider] = | ||
ZManaged | ||
.succeed(SystemPropertyCredentialsProvider.create()) | ||
.tapM(c => ZIO(c.resolveCredentials())) | ||
.mapError(err => InvalidCredentials(err.getMessage)) | ||
|
||
val env: Managed[InvalidCredentials, EnvironmentVariableCredentialsProvider] = | ||
ZManaged | ||
.succeed(EnvironmentVariableCredentialsProvider.create()) | ||
.tapM(c => | ||
ZIO | ||
.effect(c.resolveCredentials()) | ||
.mapError(err => InvalidCredentials(err.getMessage)) | ||
) | ||
|
||
val profile: ZManaged[Blocking, InvalidCredentials, ProfileCredentialsProvider] = | ||
ZManaged | ||
.fromAutoCloseable(IO.succeed(ProfileCredentialsProvider.create())) | ||
.tapM(c => | ||
effectBlocking(c.resolveCredentials()) | ||
.mapError(err => InvalidCredentials(err.getMessage)) | ||
) | ||
|
||
val container: ZManaged[Blocking, InvalidCredentials, ContainerCredentialsProvider] = | ||
ZManaged | ||
.fromAutoCloseable( | ||
IO.succeed( | ||
ContainerCredentialsProvider | ||
.builder() | ||
.build() | ||
) | ||
) | ||
.tapM(c => effectBlocking(c.resolveCredentials())) | ||
.mapError(err => InvalidCredentials(err.getMessage)) | ||
|
||
val instanceProfile: ZManaged[Blocking, InvalidCredentials, InstanceProfileCredentialsProvider] = | ||
ZManaged | ||
.fromAutoCloseable( | ||
IO.succeed( | ||
InstanceProfileCredentialsProvider | ||
.create() | ||
) | ||
) | ||
.tapM(c => effectBlocking(c.resolveCredentials())) | ||
.mapError(err => InvalidCredentials(err.getMessage)) | ||
|
||
/** | ||
* Use of this layer requires the awssdk sts module to be on the classpath, | ||
* by default zio-s3 required this library | ||
*/ | ||
val webIdentity: ZManaged[Blocking, InvalidCredentials, WebIdentityTokenFileCredentialsProvider] = | ||
ZManaged | ||
.succeed( | ||
WebIdentityTokenFileCredentialsProvider | ||
.create() | ||
) | ||
.tapM(c => effectBlocking(c.resolveCredentials())) | ||
.mapError(err => InvalidCredentials(err.getMessage)) | ||
|
||
/** | ||
* Use default chaining strategy to fetch credentials | ||
*/ | ||
val default: ZManaged[Blocking, InvalidCredentials, AwsCredentialsProvider] = | ||
ZManaged.fromAutoCloseable( | ||
IO.succeed(DefaultCredentialsProvider.create()) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package zio.s3 | ||
|
||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials | ||
import software.amazon.awssdk.regions.Region | ||
import zio.s3.providers._ | ||
import zio.test.Assertion._ | ||
import zio.test.TestAspect._ | ||
import zio.test._ | ||
import zio.{ UIO, ZIO } | ||
|
||
object S3ProvidersTest extends DefaultRunnableSpec { | ||
|
||
def setProps(props: (String, String)*): UIO[Unit] = | ||
UIO { | ||
props.foreach { | ||
case (k, v) => | ||
System.setProperty(k, v) | ||
} | ||
} | ||
|
||
def unsetProps(keys: String*): UIO[Unit] = | ||
UIO { | ||
keys.foreach(System.clearProperty) | ||
} | ||
|
||
def spec = | ||
suite("Providers")( | ||
testM("cred with const") { | ||
assertM(const("k", "v").useNow.map(_.resolveCredentials()))( | ||
equalTo(AwsBasicCredentials.create("k", "v")) | ||
) | ||
}, | ||
testM("cred with default fallback const") { | ||
assertM( | ||
(env <> const("k", "v")).useNow.map(_.resolveCredentials()) | ||
)(equalTo(AwsBasicCredentials.create("k", "v"))) | ||
}, | ||
testM("cred in system properties") { | ||
for { | ||
cred <- system.use(p => ZIO(p.resolveCredentials())) | ||
} yield assert(cred)(equalTo(AwsBasicCredentials.create("k1", "s1"))) | ||
} @@ flaky @@ around_( | ||
setProps(("aws.accessKeyId", "k1"), ("aws.secretAccessKey", "s1")), | ||
unsetProps("aws.accessKeyId", "aws.secretAccessKey") | ||
), | ||
testM("no cred in system properties") { | ||
for { | ||
failure <- system.useNow.flip.map(_.getMessage) | ||
} yield assert(failure)(isNonEmptyString) | ||
} @@ around_( | ||
unsetProps("aws.accessKeyId", "aws.secretAccessKey"), | ||
UIO.unit | ||
), | ||
testM("no cred in environment properties") { | ||
for { | ||
failure <- env.useNow.flip.map(_.getMessage) | ||
} yield assert(failure)(isNonEmptyString) | ||
}, | ||
testM("no cred in profile") { | ||
for { | ||
failure <- profile.useNow.flip.map(_.getMessage) | ||
} yield assert(failure)(isNonEmptyString) | ||
}, | ||
testM("no cred in container") { | ||
for { | ||
failure <- container.useNow.flip.map(_.getMessage) | ||
} yield assert(failure)(isNonEmptyString) | ||
}, | ||
testM("no cred in instance profile credentials") { | ||
for { | ||
failure <- instanceProfile.useNow.flip.map(_.getMessage) | ||
} yield assert(failure)(isNonEmptyString) | ||
}, | ||
testM("no cred in webidentity credentials") { | ||
for { | ||
failure <- webIdentity.useNow.flip.map(_.getMessage) | ||
} yield assert(failure)(isNonEmptyString) | ||
}, | ||
testM("settings from invalid creds") { | ||
for { | ||
failure <- settings( | ||
Region.AF_SOUTH_1, | ||
system.useNow.map(_.resolveCredentials()) | ||
).build.useNow.flip | ||
} yield assert(failure.getMessage)(isNonEmptyString) | ||
}, | ||
testM("no cred when chain all providers") { | ||
for { | ||
failure <- default.use(c => ZIO.effect(c.resolveCredentials())).flip.map(_.getMessage) | ||
} yield assert(failure)(isNonEmptyString) | ||
} | ||
) @@ sequential | ||
} |
Oops, something went wrong.