mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Use standard java thread factory instead of the AppEngine flavor
With Java 8 in GAE standard environment, we can now use standard java thread factory to run the metric reporter in the background in daemon mode, which would not interfere with basic scaling idle timeout as App Engine thread would. Because the thread is not created by ThreadManager, no App Engine APIs can be called from it. We therefore use GoogleCredential instead of AppIdentityCredential as HttpRequestInitializer, and NetHttpTransport instead of UlrFetchTransport as HttpTransport. MetricReporter is lazy injected because it depends on jsonCredential retrieved from CloudKms, which is not available in a test environment, causing FrontendServletTest and BackendServletTest to fail. Some minor re-formatting with google-java-format on edited files. Lastly removed moe comments in import statement, which makes the linter unhappy. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=172896227
This commit is contained in:
parent
b01fa6b4c9
commit
c702b4486c
8 changed files with 151 additions and 118 deletions
|
@ -15,9 +15,9 @@
|
||||||
package google.registry.module.backend;
|
package google.registry.module.backend;
|
||||||
|
|
||||||
import dagger.Component;
|
import dagger.Component;
|
||||||
|
import dagger.Lazy;
|
||||||
import google.registry.bigquery.BigqueryModule;
|
import google.registry.bigquery.BigqueryModule;
|
||||||
import google.registry.config.RegistryConfig.ConfigModule;
|
import google.registry.config.RegistryConfig.ConfigModule;
|
||||||
import google.registry.dns.writer.VoidDnsWriterModule;
|
|
||||||
import google.registry.export.DriveModule;
|
import google.registry.export.DriveModule;
|
||||||
import google.registry.export.sheet.SheetsServiceModule;
|
import google.registry.export.sheet.SheetsServiceModule;
|
||||||
import google.registry.gcs.GcsServiceModule;
|
import google.registry.gcs.GcsServiceModule;
|
||||||
|
@ -36,6 +36,7 @@ import google.registry.request.Modules.DatastoreServiceModule;
|
||||||
import google.registry.request.Modules.GoogleCredentialModule;
|
import google.registry.request.Modules.GoogleCredentialModule;
|
||||||
import google.registry.request.Modules.Jackson2Module;
|
import google.registry.request.Modules.Jackson2Module;
|
||||||
import google.registry.request.Modules.ModulesServiceModule;
|
import google.registry.request.Modules.ModulesServiceModule;
|
||||||
|
import google.registry.request.Modules.NetHttpTransportModule;
|
||||||
import google.registry.request.Modules.URLFetchServiceModule;
|
import google.registry.request.Modules.URLFetchServiceModule;
|
||||||
import google.registry.request.Modules.UrlFetchTransportModule;
|
import google.registry.request.Modules.UrlFetchTransportModule;
|
||||||
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
||||||
|
@ -67,6 +68,7 @@ import javax.inject.Singleton;
|
||||||
KeyringModule.class,
|
KeyringModule.class,
|
||||||
KmsModule.class,
|
KmsModule.class,
|
||||||
ModulesServiceModule.class,
|
ModulesServiceModule.class,
|
||||||
|
NetHttpTransportModule.class,
|
||||||
SheetsServiceModule.class,
|
SheetsServiceModule.class,
|
||||||
StackdriverModule.class,
|
StackdriverModule.class,
|
||||||
SystemClockModule.class,
|
SystemClockModule.class,
|
||||||
|
@ -75,9 +77,11 @@ import javax.inject.Singleton;
|
||||||
UrlFetchTransportModule.class,
|
UrlFetchTransportModule.class,
|
||||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||||
UserServiceModule.class,
|
UserServiceModule.class,
|
||||||
VoidDnsWriterModule.class,
|
google.registry.dns.writer.VoidDnsWriterModule.class,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
interface BackendComponent {
|
interface BackendComponent {
|
||||||
BackendRequestHandler requestHandler();
|
BackendRequestHandler requestHandler();
|
||||||
MetricReporter metricReporter();
|
|
||||||
|
Lazy<MetricReporter> metricReporter();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
package google.registry.module.backend;
|
package google.registry.module.backend;
|
||||||
|
|
||||||
import com.google.appengine.api.LifecycleManager;
|
import com.google.appengine.api.LifecycleManager;
|
||||||
import com.google.appengine.api.LifecycleManager.ShutdownHook;
|
import dagger.Lazy;
|
||||||
import google.registry.monitoring.metrics.MetricReporter;
|
import google.registry.monitoring.metrics.MetricReporter;
|
||||||
import google.registry.util.FormattingLogger;
|
import google.registry.util.FormattingLogger;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -32,7 +32,7 @@ public final class BackendServlet extends HttpServlet {
|
||||||
|
|
||||||
private static final BackendComponent component = DaggerBackendComponent.create();
|
private static final BackendComponent component = DaggerBackendComponent.create();
|
||||||
private static final BackendRequestHandler requestHandler = component.requestHandler();
|
private static final BackendRequestHandler requestHandler = component.requestHandler();
|
||||||
private static final MetricReporter metricReporter = component.metricReporter();
|
private static final Lazy<MetricReporter> metricReporter = component.metricReporter();
|
||||||
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,7 +40,7 @@ public final class BackendServlet extends HttpServlet {
|
||||||
Security.addProvider(new BouncyCastleProvider());
|
Security.addProvider(new BouncyCastleProvider());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
metricReporter.startAsync().awaitRunning(10, TimeUnit.SECONDS);
|
metricReporter.get().startAsync().awaitRunning(10, TimeUnit.SECONDS);
|
||||||
logger.info("Started up MetricReporter");
|
logger.info("Started up MetricReporter");
|
||||||
} catch (TimeoutException timeoutException) {
|
} catch (TimeoutException timeoutException) {
|
||||||
logger.severefmt("Failed to initialize MetricReporter: %s", timeoutException);
|
logger.severefmt("Failed to initialize MetricReporter: %s", timeoutException);
|
||||||
|
@ -48,16 +48,13 @@ public final class BackendServlet extends HttpServlet {
|
||||||
|
|
||||||
LifecycleManager.getInstance()
|
LifecycleManager.getInstance()
|
||||||
.setShutdownHook(
|
.setShutdownHook(
|
||||||
new ShutdownHook() {
|
() -> {
|
||||||
@Override
|
|
||||||
public void shutdown() {
|
|
||||||
try {
|
try {
|
||||||
metricReporter.stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
|
metricReporter.get().stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
|
||||||
logger.info("Shut down MetricReporter");
|
logger.info("Shut down MetricReporter");
|
||||||
} catch (TimeoutException timeoutException) {
|
} catch (TimeoutException timeoutException) {
|
||||||
logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
|
logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
package google.registry.module.frontend;
|
package google.registry.module.frontend;
|
||||||
|
|
||||||
import dagger.Component;
|
import dagger.Component;
|
||||||
|
import dagger.Lazy;
|
||||||
import google.registry.braintree.BraintreeModule;
|
import google.registry.braintree.BraintreeModule;
|
||||||
import google.registry.config.RegistryConfig.ConfigModule;
|
import google.registry.config.RegistryConfig.ConfigModule;
|
||||||
import google.registry.flows.ServerTridProviderModule;
|
import google.registry.flows.ServerTridProviderModule;
|
||||||
|
@ -26,8 +27,10 @@ import google.registry.module.frontend.FrontendRequestComponent.FrontendRequestC
|
||||||
import google.registry.monitoring.metrics.MetricReporter;
|
import google.registry.monitoring.metrics.MetricReporter;
|
||||||
import google.registry.monitoring.whitebox.StackdriverModule;
|
import google.registry.monitoring.whitebox.StackdriverModule;
|
||||||
import google.registry.request.Modules.AppIdentityCredentialModule;
|
import google.registry.request.Modules.AppIdentityCredentialModule;
|
||||||
|
import google.registry.request.Modules.GoogleCredentialModule;
|
||||||
import google.registry.request.Modules.Jackson2Module;
|
import google.registry.request.Modules.Jackson2Module;
|
||||||
import google.registry.request.Modules.ModulesServiceModule;
|
import google.registry.request.Modules.ModulesServiceModule;
|
||||||
|
import google.registry.request.Modules.NetHttpTransportModule;
|
||||||
import google.registry.request.Modules.UrlFetchTransportModule;
|
import google.registry.request.Modules.UrlFetchTransportModule;
|
||||||
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
||||||
import google.registry.request.Modules.UserServiceModule;
|
import google.registry.request.Modules.UserServiceModule;
|
||||||
|
@ -49,11 +52,13 @@ import javax.inject.Singleton;
|
||||||
CustomLogicFactoryModule.class,
|
CustomLogicFactoryModule.class,
|
||||||
FrontendMetricsModule.class,
|
FrontendMetricsModule.class,
|
||||||
FrontendRequestComponentModule.class,
|
FrontendRequestComponentModule.class,
|
||||||
|
GoogleCredentialModule.class,
|
||||||
Jackson2Module.class,
|
Jackson2Module.class,
|
||||||
KeyModule.class,
|
KeyModule.class,
|
||||||
KeyringModule.class,
|
KeyringModule.class,
|
||||||
KmsModule.class,
|
KmsModule.class,
|
||||||
ModulesServiceModule.class,
|
ModulesServiceModule.class,
|
||||||
|
NetHttpTransportModule.class,
|
||||||
ServerTridProviderModule.class,
|
ServerTridProviderModule.class,
|
||||||
StackdriverModule.class,
|
StackdriverModule.class,
|
||||||
SystemClockModule.class,
|
SystemClockModule.class,
|
||||||
|
@ -61,8 +66,10 @@ import javax.inject.Singleton;
|
||||||
UrlFetchTransportModule.class,
|
UrlFetchTransportModule.class,
|
||||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||||
UserServiceModule.class,
|
UserServiceModule.class,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
interface FrontendComponent {
|
interface FrontendComponent {
|
||||||
FrontendRequestHandler requestHandler();
|
FrontendRequestHandler requestHandler();
|
||||||
MetricReporter metricReporter();
|
|
||||||
|
Lazy<MetricReporter> metricReporter();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
package google.registry.module.frontend;
|
package google.registry.module.frontend;
|
||||||
|
|
||||||
import com.google.appengine.api.LifecycleManager;
|
import com.google.appengine.api.LifecycleManager;
|
||||||
import com.google.appengine.api.LifecycleManager.ShutdownHook;
|
import dagger.Lazy;
|
||||||
import google.registry.monitoring.metrics.MetricReporter;
|
import google.registry.monitoring.metrics.MetricReporter;
|
||||||
import google.registry.util.FormattingLogger;
|
import google.registry.util.FormattingLogger;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -32,7 +32,7 @@ public final class FrontendServlet extends HttpServlet {
|
||||||
|
|
||||||
private static final FrontendComponent component = DaggerFrontendComponent.create();
|
private static final FrontendComponent component = DaggerFrontendComponent.create();
|
||||||
private static final FrontendRequestHandler requestHandler = component.requestHandler();
|
private static final FrontendRequestHandler requestHandler = component.requestHandler();
|
||||||
private static final MetricReporter metricReporter = component.metricReporter();
|
private static final Lazy<MetricReporter> metricReporter = component.metricReporter();
|
||||||
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,7 +40,7 @@ public final class FrontendServlet extends HttpServlet {
|
||||||
Security.addProvider(new BouncyCastleProvider());
|
Security.addProvider(new BouncyCastleProvider());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
metricReporter.startAsync().awaitRunning(10, TimeUnit.SECONDS);
|
metricReporter.get().startAsync().awaitRunning(10, TimeUnit.SECONDS);
|
||||||
logger.info("Started up MetricReporter");
|
logger.info("Started up MetricReporter");
|
||||||
} catch (TimeoutException timeoutException) {
|
} catch (TimeoutException timeoutException) {
|
||||||
logger.severefmt("Failed to initialize MetricReporter: %s", timeoutException);
|
logger.severefmt("Failed to initialize MetricReporter: %s", timeoutException);
|
||||||
|
@ -48,16 +48,13 @@ public final class FrontendServlet extends HttpServlet {
|
||||||
|
|
||||||
LifecycleManager.getInstance()
|
LifecycleManager.getInstance()
|
||||||
.setShutdownHook(
|
.setShutdownHook(
|
||||||
new ShutdownHook() {
|
() -> {
|
||||||
@Override
|
|
||||||
public void shutdown() {
|
|
||||||
try {
|
try {
|
||||||
metricReporter.stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
|
metricReporter.get().stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
|
||||||
logger.info("Shut down MetricReporter");
|
logger.info("Shut down MetricReporter");
|
||||||
} catch (TimeoutException timeoutException) {
|
} catch (TimeoutException timeoutException) {
|
||||||
logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
|
logger.severefmt("Failed to stop MetricReporter: %s", timeoutException);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ import google.registry.request.Modules.DatastoreServiceModule;
|
||||||
import google.registry.request.Modules.GoogleCredentialModule;
|
import google.registry.request.Modules.GoogleCredentialModule;
|
||||||
import google.registry.request.Modules.Jackson2Module;
|
import google.registry.request.Modules.Jackson2Module;
|
||||||
import google.registry.request.Modules.ModulesServiceModule;
|
import google.registry.request.Modules.ModulesServiceModule;
|
||||||
|
import google.registry.request.Modules.NetHttpTransportModule;
|
||||||
import google.registry.request.Modules.UrlFetchTransportModule;
|
import google.registry.request.Modules.UrlFetchTransportModule;
|
||||||
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
||||||
import google.registry.request.Modules.UserServiceModule;
|
import google.registry.request.Modules.UserServiceModule;
|
||||||
|
@ -60,6 +61,7 @@ import javax.inject.Singleton;
|
||||||
KeyringModule.class,
|
KeyringModule.class,
|
||||||
KmsModule.class,
|
KmsModule.class,
|
||||||
ModulesServiceModule.class,
|
ModulesServiceModule.class,
|
||||||
|
NetHttpTransportModule.class,
|
||||||
ServerTridProviderModule.class,
|
ServerTridProviderModule.class,
|
||||||
SystemClockModule.class,
|
SystemClockModule.class,
|
||||||
SystemSleeperModule.class,
|
SystemSleeperModule.class,
|
||||||
|
@ -67,7 +69,8 @@ import javax.inject.Singleton;
|
||||||
UrlFetchTransportModule.class,
|
UrlFetchTransportModule.class,
|
||||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||||
UserServiceModule.class,
|
UserServiceModule.class,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
interface ToolsComponent {
|
interface ToolsComponent {
|
||||||
ToolsRequestHandler requestHandler();
|
ToolsRequestHandler requestHandler();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ java_library(
|
||||||
"//java/google/registry/request/auth",
|
"//java/google/registry/request/auth",
|
||||||
"//java/google/registry/util",
|
"//java/google/registry/util",
|
||||||
"//third_party/java/objectify:objectify-v4_1",
|
"//third_party/java/objectify:objectify-v4_1",
|
||||||
|
"@com_google_api_client",
|
||||||
"@com_google_apis_google_api_services_bigquery",
|
"@com_google_apis_google_api_services_bigquery",
|
||||||
"@com_google_apis_google_api_services_monitoring",
|
"@com_google_apis_google_api_services_monitoring",
|
||||||
"@com_google_appengine_api_1_0_sdk",
|
"@com_google_appengine_api_1_0_sdk",
|
||||||
|
|
|
@ -14,16 +14,16 @@
|
||||||
|
|
||||||
package google.registry.monitoring.whitebox;
|
package google.registry.monitoring.whitebox;
|
||||||
|
|
||||||
import com.google.api.client.http.HttpRequestInitializer;
|
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
|
||||||
import com.google.api.client.http.HttpTransport;
|
import com.google.api.client.http.javanet.NetHttpTransport;
|
||||||
import com.google.api.client.json.JsonFactory;
|
import com.google.api.client.json.JsonFactory;
|
||||||
import com.google.api.services.monitoring.v3.Monitoring;
|
import com.google.api.services.monitoring.v3.Monitoring;
|
||||||
import com.google.api.services.monitoring.v3.MonitoringScopes;
|
import com.google.api.services.monitoring.v3.MonitoringScopes;
|
||||||
import com.google.api.services.monitoring.v3.model.MonitoredResource;
|
import com.google.api.services.monitoring.v3.model.MonitoredResource;
|
||||||
import com.google.appengine.api.ThreadManager;
|
|
||||||
import com.google.appengine.api.modules.ModulesService;
|
import com.google.appengine.api.modules.ModulesService;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
import google.registry.config.RegistryConfig.Config;
|
import google.registry.config.RegistryConfig.Config;
|
||||||
|
@ -43,9 +43,9 @@ public final class StackdriverModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
static Monitoring provideMonitoring(
|
static Monitoring provideMonitoring(
|
||||||
HttpTransport transport,
|
NetHttpTransport transport,
|
||||||
JsonFactory jsonFactory,
|
JsonFactory jsonFactory,
|
||||||
Function<Set<String>, ? extends HttpRequestInitializer> credential,
|
Function<Set<String>, GoogleCredential> credential,
|
||||||
@Config("projectId") String projectId) {
|
@Config("projectId") String projectId) {
|
||||||
return new Monitoring.Builder(transport, jsonFactory, credential.apply(MonitoringScopes.all()))
|
return new Monitoring.Builder(transport, jsonFactory, credential.apply(MonitoringScopes.all()))
|
||||||
.setApplicationName(projectId)
|
.setApplicationName(projectId)
|
||||||
|
@ -87,6 +87,8 @@ public final class StackdriverModule {
|
||||||
static MetricReporter provideMetricReporter(
|
static MetricReporter provideMetricReporter(
|
||||||
MetricWriter metricWriter, @Config("metricsWriteInterval") Duration writeInterval) {
|
MetricWriter metricWriter, @Config("metricsWriteInterval") Duration writeInterval) {
|
||||||
return new MetricReporter(
|
return new MetricReporter(
|
||||||
metricWriter, writeInterval.getStandardSeconds(), ThreadManager.backgroundThreadFactory());
|
metricWriter,
|
||||||
|
writeInterval.getStandardSeconds(),
|
||||||
|
new ThreadFactoryBuilder().setDaemon(true).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,10 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
import com.google.api.client.extensions.appengine.http.UrlFetchTransport;
|
import com.google.api.client.extensions.appengine.http.UrlFetchTransport;
|
||||||
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
|
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
|
||||||
import com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential;
|
import com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential;
|
||||||
|
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
|
||||||
import com.google.api.client.http.HttpRequestInitializer;
|
import com.google.api.client.http.HttpRequestInitializer;
|
||||||
import com.google.api.client.http.HttpTransport;
|
import com.google.api.client.http.HttpTransport;
|
||||||
|
import com.google.api.client.http.javanet.NetHttpTransport;
|
||||||
import com.google.api.client.json.JsonFactory;
|
import com.google.api.client.json.JsonFactory;
|
||||||
import com.google.api.client.json.jackson2.JacksonFactory;
|
import com.google.api.client.json.jackson2.JacksonFactory;
|
||||||
import com.google.appengine.api.datastore.DatastoreService;
|
import com.google.appengine.api.datastore.DatastoreService;
|
||||||
|
@ -117,6 +119,24 @@ public final class Modules {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dagger module that provides standard {@link NetHttpTransport}. Used in non App Engine
|
||||||
|
* environment.
|
||||||
|
*/
|
||||||
|
@Module
|
||||||
|
public static final class NetHttpTransportModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
static NetHttpTransport provideNetHttpTransport() {
|
||||||
|
try {
|
||||||
|
return GoogleNetHttpTransport.newTrustedTransport();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dagger module providing {@link AppIdentityCredential}.
|
* Dagger module providing {@link AppIdentityCredential}.
|
||||||
*
|
*
|
||||||
|
@ -140,8 +160,8 @@ public final class Modules {
|
||||||
@Module
|
@Module
|
||||||
public abstract static class UseAppIdentityCredentialForGoogleApisModule {
|
public abstract static class UseAppIdentityCredentialForGoogleApisModule {
|
||||||
@Binds
|
@Binds
|
||||||
abstract Function<Set<String>, ? extends HttpRequestInitializer>
|
abstract Function<Set<String>, ? extends HttpRequestInitializer> provideHttpRequestInitializer(
|
||||||
provideHttpRequestInitializer(Function<Set<String>, AppIdentityCredential> credential);
|
Function<Set<String>, AppIdentityCredential> credential);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -155,8 +175,8 @@ public final class Modules {
|
||||||
@Module
|
@Module
|
||||||
public abstract static class UseGoogleCredentialForGoogleApisModule {
|
public abstract static class UseGoogleCredentialForGoogleApisModule {
|
||||||
@Binds
|
@Binds
|
||||||
abstract Function<Set<String>, ? extends HttpRequestInitializer>
|
abstract Function<Set<String>, ? extends HttpRequestInitializer> provideHttpRequestInitializer(
|
||||||
provideHttpRequestInitializer(Function<Set<String>, GoogleCredential> credential);
|
Function<Set<String>, GoogleCredential> credential);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -181,12 +201,14 @@ public final class Modules {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
static GoogleCredential provideGoogleCredential(
|
static GoogleCredential provideGoogleCredential(
|
||||||
HttpTransport httpTransport,
|
NetHttpTransport netHttpTransport,
|
||||||
JsonFactory jsonFactory,
|
JsonFactory jsonFactory,
|
||||||
@Key("jsonCredential") String jsonCredential) {
|
@Key("jsonCredential") String jsonCredential) {
|
||||||
try {
|
try {
|
||||||
return GoogleCredential.fromStream(
|
return GoogleCredential.fromStream(
|
||||||
new ByteArrayInputStream(jsonCredential.getBytes(UTF_8)), httpTransport, jsonFactory);
|
new ByteArrayInputStream(jsonCredential.getBytes(UTF_8)),
|
||||||
|
netHttpTransport,
|
||||||
|
jsonFactory);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue