Package io.micronaut.gcp.credentials
Class GoogleCredentialsFactory
- java.lang.Object
-
- io.micronaut.gcp.credentials.GoogleCredentialsFactory
-
@Factory @Requires(classes=com.google.auth.oauth2.GoogleCredentials.class) public class GoogleCredentialsFactory extends java.lang.Object
A factory for creatingGoogleCredentials
.- Since:
- 1.0
- Author:
- graemerocher, Ray Tsang
-
-
Constructor Summary
Constructors Constructor Description GoogleCredentialsFactory(GoogleCredentialsConfiguration configuration)
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected com.google.auth.oauth2.GoogleCredentials
defaultGoogleCredentials()
Method used to return the defaultGoogleCredentials
and provide it as a bean.
-
-
-
Constructor Detail
-
GoogleCredentialsFactory
public GoogleCredentialsFactory(@Nonnull GoogleCredentialsConfiguration configuration)
Default constructor.- Parameters:
configuration
- The configuration
-
-
Method Detail
-
defaultGoogleCredentials
@Requires(missingBeans=com.google.auth.oauth2.GoogleCredentials.class) @Requires(classes=com.google.auth.oauth2.GoogleCredentials.class) @Primary @Singleton protected com.google.auth.oauth2.GoogleCredentials defaultGoogleCredentials() throws java.io.IOException
Method used to return the defaultGoogleCredentials
and provide it as a bean. It will determine which credential in the following way:- If
gcp.credentials.location
is specified, use its location - Otherwise, if
gcp.credentials.encodedKey
is specified, decode it and use its content - None of the 2 properties were specified, use Application Default credential resolution. See
Google Cloud Java authentication.
This will resolve credential in the following order:
- The credentials file pointed to by the
GOOGLE_APPLICATION_CREDENTIALS
environment variable - Credentials provided by the Google Cloud SDK
gcloud auth application-default login
command - Google App Engine built-in credentials when running inside of Google App Engine
- Google Cloud Shell built-in credentials when running inside of Google Cloud Shell
- Google Compute Engine built-in credentials when running inside of Google Compute Engine or Kubernetes Engine
- The credentials file pointed to by the
- Returns:
- The
GoogleCredentials
- Throws:
java.io.IOException
- An exception if an error occurs
- If
-
-