-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* zio-config-zio-aws for 2.x * Upgrade Scala 3 version to match zio-aws's
- Loading branch information
Showing
6 changed files
with
129 additions
and
8 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
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
17 changes: 17 additions & 0 deletions
17
zio-aws/shared/src/main/scala/zio/config/aws/parameterstore/ParameterStoreConfig.scala
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,17 @@ | ||
package zio.config.aws.parameterstore | ||
|
||
import io.github.vigoo.zioaws.ssm.Ssm | ||
import zio.config.{ReadError, _} | ||
import zio.{Has, Tag, ZIO, ZLayer} | ||
|
||
object ParameterStoreConfig { | ||
def from[A]( | ||
configDescriptor: ConfigDescriptor[A], | ||
basePath: String | ||
)(implicit tag: Tag[A]): ZLayer[Ssm, ReadError[String], Has[A]] = | ||
ZConfig.fromConfigDescriptorM( | ||
ZIO.service[Ssm.Service].map { ssm => | ||
configDescriptor from ParameterStoreConfigSource.from(basePath, ssm) | ||
} | ||
) | ||
} |
58 changes: 58 additions & 0 deletions
58
zio-aws/shared/src/main/scala/zio/config/aws/parameterstore/ParameterStoreConfigSource.scala
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,58 @@ | ||
package zio.config.aws.parameterstore | ||
|
||
import io.github.vigoo.zioaws.ssm.Ssm | ||
import io.github.vigoo.zioaws.ssm.model.{GetParametersByPathRequest, Parameter} | ||
import zio.config.{PropertyTreePath, ReadError, _} | ||
import zio.{Chunk, ZIO, ZManaged} | ||
|
||
import ConfigSource._ | ||
|
||
object ParameterStoreConfigSource { | ||
def from( | ||
basePath: String, | ||
ssm: Ssm.Service | ||
): ConfigSource = { | ||
val effect: MemoizableManagedReader = | ||
ZManaged.succeed { | ||
ZManaged | ||
.fromEffect( | ||
ssm | ||
.getParametersByPath( | ||
GetParametersByPathRequest(path = basePath, recursive = Some(true), withDecryption = Some(true)) | ||
) | ||
.runCollect | ||
.map { result => | ||
ConfigSource | ||
.getPropertyTreeFromMap( | ||
convertParameterListToMap(result, basePath), | ||
keyDelimiter = Some('/') | ||
) | ||
} | ||
.mapBoth( | ||
throwable => ReadError.SourceError(throwable.toString): ReadError[String], | ||
tree => (path: PropertyTreePath[String]) => ZIO.succeed(tree.at(path)) | ||
) | ||
) | ||
} | ||
|
||
ConfigSource | ||
.Reader( | ||
Set(ConfigSourceName("parameter-store")), | ||
effect | ||
) | ||
} | ||
|
||
private[config] def convertParameterListToMap( | ||
list: Chunk[Parameter.ReadOnly], | ||
basePath: String | ||
): Map[String, String] = { | ||
val str = s"$basePath/" | ||
list.flatMap { parameter => | ||
parameter.nameValue.flatMap { name => | ||
parameter.valueValue.map { value => | ||
name.replaceFirst(str, "") -> value | ||
} | ||
} | ||
}.toMap | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
zio-aws/shared/src/main/scala/zio/config/aws/parameterstore/package.scala
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,24 @@ | ||
package zio.config.aws | ||
|
||
import io.github.vigoo.zioaws.ssm.Ssm | ||
import izumi.reflect.Tag | ||
import zio.config._ | ||
import zio.{Has, ZLayer} | ||
|
||
package object parameterstore { | ||
implicit class FromConfigTypesafe(c: ZConfig.type) { | ||
def fromParameterStore[A]( | ||
configDescriptor: ConfigDescriptor[A], | ||
basePath: String | ||
)(implicit tag: Tag[A]): ZLayer[Ssm, ReadError[String], Has[A]] = | ||
ParameterStoreConfig.from(configDescriptor, basePath) | ||
} | ||
|
||
implicit class FromConfigSourceTypesafe(c: ConfigSource.type) { | ||
def fromParameterStore( | ||
basePath: String, | ||
ssm: Ssm.Service | ||
): ConfigSource = | ||
ParameterStoreConfigSource.from(basePath, ssm) | ||
} | ||
} |