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 Object
A factory for creating
GoogleCredentials
.- Since:
- 1.0
- Author:
- graemerocher, Ray Tsang
-
Constructor Summary
ConstructorDescriptionGoogleCredentialsFactory
(@NonNull GoogleCredentialsConfiguration configuration) Deprecated.GoogleCredentialsFactory
(@NonNull GoogleCredentialsConfiguration configuration, @Nullable com.google.auth.http.HttpTransportFactory httpTransportFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected com.google.auth.oauth2.GoogleCredentials
Method used to return the defaultGoogleCredentials
and provide it as a bean.
-
Constructor Details
-
GoogleCredentialsFactory
@Deprecated public GoogleCredentialsFactory(@NonNull @NonNull GoogleCredentialsConfiguration configuration) Deprecated.Default constructor.- Parameters:
configuration
- The configuration
-
GoogleCredentialsFactory
@Inject public GoogleCredentialsFactory(@NonNull @NonNull GoogleCredentialsConfiguration configuration, @Nullable @Nullable com.google.auth.http.HttpTransportFactory httpTransportFactory)
-
-
Method Details
-
defaultGoogleCredentials
@Requires(classes=com.google.auth.oauth2.GoogleCredentials.class) @Requires(property="gcp.credentials.enabled",value="true",defaultValue="true") @Primary @Singleton protected com.google.auth.oauth2.GoogleCredentials defaultGoogleCredentials() throws IOExceptionMethod 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:
IOException
- An exception if an error occurs
- If
-
GoogleCredentialsFactory(GoogleCredentialsConfiguration, HttpTransportFactory)
instead.