Skip to content

Commit

Permalink
Update Credentials.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
adamfilipow92 authored and mergify-bot committed May 21, 2021
1 parent b3e1772 commit 0d8f2e0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions test_runner/src/main/kotlin/ftl/client/google/Credentials.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ val credential: GoogleCredentials by lazy {
}.getOrElse {
when {
isWindows -> loadCredentialsWindows()
UserAuth.exists() -> UserAuth.load()
else -> throw FlankGeneralError("Error: Failed to read service account credential.\n${it.message}")
else -> loadUserAuth(it.message.orEmpty())
}
}
}
Expand All @@ -33,8 +32,7 @@ val credential: GoogleCredentials by lazy {
private fun loadCredentialsWindows() = runCatching {
loadGoogleAccountCredentials()
}.getOrElse {
if (UserAuth.exists()) UserAuth.load()
else throw FlankGeneralError("Error: Failed to read service account credential.\n${it.message}")
loadUserAuth(it.message.orEmpty())
}

private fun loadGoogleAccountCredentials(): GoogleCredentials = try {
Expand All @@ -43,6 +41,10 @@ private fun loadGoogleAccountCredentials(): GoogleCredentials = try {
throw FlankGeneralError("Error: Failed to read service account credential.\n${e.message}")
}

private fun loadUserAuth(topLevelErrorMessage: String) =
if (UserAuth.exists()) UserAuth.load()
else throw FlankGeneralError("Error: Failed to read service account credential.\n$topLevelErrorMessage")

val httpCredential: HttpRequestInitializer by lazy {
if (FtlConstants.useMock) {
HttpRequestInitializer {}
Expand Down

0 comments on commit 0d8f2e0

Please # to comment.