Skip to content

Commit

Permalink
google-common: Improve log messages for application default credentia…
Browse files Browse the repository at this point in the history
…ls (akka#2667)
  • Loading branch information
armanbilge committed May 13, 2021
1 parent 622364d commit c3e5847
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package akka.stream.alpakka.google.auth

import akka.actor.ClassicActorSystemProvider
import akka.annotation.DoNotInherit
import akka.event.Logging
import akka.http.scaladsl.model.headers.HttpCredentials
import akka.stream.alpakka.google.RequestSettings
import akka.util.JavaDurationConverters._
Expand All @@ -25,15 +26,22 @@ object Credentials {
*/
def apply(c: Config)(implicit system: ClassicActorSystemProvider): Credentials = c.getString("provider") match {
case "application-default" =>
val log = Logging(system.classicSystem, getClass)
try {
parseServiceAccount(c)
val creds = parseServiceAccount(c)
log.info("Using service account credentials")
creds
} catch {
case NonFatal(ex1) =>
try {
parseComputeEngine(c)
val creds = parseComputeEngine(c)
log.info("Using Compute Engine credentials")
creds
} catch {
case NonFatal(ex2) =>
system.classicSystem.log.warning("Unable to find application default credentials", ex1, ex2)
log.warning("Unable to find Application Default Credentials for Google APIs")
log.warning("Service account: {}", ex1.getMessage)
log.warning("Compute Engine: {}", ex2.getMessage)
parseNone(c) // TODO Once credentials are guaranteed to be managed centrally we can throw an error instead
}
}
Expand Down

0 comments on commit c3e5847

Please sign in to comment.