Skip to content

Commit

Permalink
Merge pull request #1453 from disneystreaming/fix-credentials-parsing
Browse files Browse the repository at this point in the history
Fix a bug in the parsing of AWS credential files
  • Loading branch information
Baccata committed Mar 19, 2024
2 parents de1a36a + ae0d496 commit f65e402
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 0.18.15

* Add support for injecting endpoint-specific middlewares in AWS clients
* Fixes a bug in the parsing of AWS credentials files

# 0.18.14

Expand Down
6 changes: 3 additions & 3 deletions modules/aws-http4s/src/smithy4s/aws/AwsCredentialsFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ object AwsCredentialsFile {
}

private object Profile {
private val profileMatch = "([\\w_-]*)"
private val profileMatch = "(.*)"
object Default {
def unapply(s: String): Option[String] =
if (s == "[default]") Some("default") else None
Expand All @@ -177,15 +177,15 @@ private object Profile {
object Prefixed {
private val reg = s"^\\[profile $profileMatch\\]$$".r
def unapply(s: String): Option[String] = s match {
case reg(first) => Some(first)
case reg(first) => Some(first.trim())
case _ => None
}
}

object NonPrefixed {
private val reg = s"^\\[$profileMatch\\]$$".r
def unapply(s: String): Option[String] = s match {
case reg(first) => Some(first)
case reg(first) => Some(first.trim())
case _ => None
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ object AwsCredentialsFileTest extends FunSuite {
e: Either[Throwable, A]
)(f: A => Expectations): Expectations =
e.fold(
err => failure(s"Got Left but expected a Right. ${err.getMessage}"),
err => {
err.printStackTrace()
failure(s"Got Left but expected a Right. ${err.getMessage}")
},
f
)

Expand Down Expand Up @@ -144,5 +147,20 @@ object AwsCredentialsFileTest extends FunSuite {
}
}

test("profiles can have special characters in them") {
expectRight(
AwsCredentialsFile.processFileLines(
asLines(
"""|[Namespace/User@USER_ID]
|aws_access_key_id = key
|aws_secret_access_key = sec
|aws_session_token = token""".stripMargin
)
)
) { res =>
expect.same(creds, res.profiles("Namespace/User@USER_ID"))
}
}

private def asLines(s: String) = s.split("\\n").toList
}

0 comments on commit f65e402

Please sign in to comment.