Skip to content

Commit ea97ea1

Browse files
committed
fix issue with AwsClient not reading system variables
1 parent ce3ee30 commit ea97ea1

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

AwsClient.scala

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,18 @@ object AwsClient {
145145
}
146146

147147
inline def initializeWithProperties(
148-
map: Map[String, String]
148+
map: Map[String, String],
149+
includeEnvironmentVariables: Boolean = true
149150
): AwsClient =
150-
initializeWithProperties(map.get)
151+
initializeWithProperties { key =>
152+
map
153+
.get(key)
154+
.orElse(
155+
if (includeEnvironmentVariables)
156+
then scala.util.Try(System.getenv(key)).toOption
157+
else None
158+
)
159+
}
151160

152161
/** Creates new instance of the AwsClient for the given region using a function to retrieve system properties
153162
*/
@@ -160,8 +169,8 @@ object AwsClient {
160169

161170
if (isDebugMode)
162171
then
163-
println(
164-
s"${AnsiColor.YELLOW}[AwsClient]${AnsiColor.RESET}${AnsiColor.CYAN} Starting ...${AnsiColor.RESET}"
172+
print(
173+
s"${AnsiColor.YELLOW}[AwsClient]${AnsiColor.RESET}${AnsiColor.CYAN} Starting"
165174
)
166175

167176
val httpClientBuilder: UrlConnectionHttpClient.Builder =
@@ -173,11 +182,6 @@ object AwsClient {
173182
secretAccessKey <- maybeProperty("AWS_SECRET_ACCESS_KEY")
174183
sessionToken <- maybeProperty("AWS_SESSION_TOKEN")
175184
} yield {
176-
if (isDebugMode)
177-
then
178-
println(
179-
s"${AnsiColor.YELLOW}[AwsClient]${AnsiColor.RESET}${AnsiColor.CYAN} Credentials has been initialized${AnsiColor.RESET}"
180-
)
181185
new AwsCredentialsProvider {
182186
override def resolveCredentials(): AwsCredentials =
183187
AwsSessionCredentials.create(
@@ -193,9 +197,14 @@ object AwsClient {
193197

194198
if (isDebugMode)
195199
then
196-
println(
197-
s"${AnsiColor.YELLOW}[AwsClient]${AnsiColor.RESET}${AnsiColor.CYAN} Running in region $currentRegion${AnsiColor.RESET}"
198-
)
200+
if (maybeCredentialsProvider.isDefined)
201+
println(
202+
s", ${AnsiColor.CYAN}credentials set up.${AnsiColor.RESET}${AnsiColor.CYAN} Default region $currentRegion.${AnsiColor.RESET}"
203+
)
204+
else
205+
println(
206+
s", ${AnsiColor.RED}credentials NOT found!${AnsiColor.RED}${AnsiColor.CYAN} Default region $currentRegion.${AnsiColor.RESET}"
207+
)
199208

200209
final lazy val iam: IamClient =
201210
createIamClient(currentRegion, httpClientBuilder, maybeCredentialsProvider)

0 commit comments

Comments
 (0)