use of org.datatransferproject.launcher.types.TypeManagerImpl in project data-transfer-project by google.
the class ApiMain method initializeHttps.
public void initializeHttps(TrustManagerFactory trustManagerFactory, KeyManagerFactory keyManagerFactory, KeyStore keyStore) {
// TODO init with types
TypeManager typeManager = new TypeManagerImpl();
typeManager.registerTypes(TokenAuthData.class, TokensAndUrlAuthData.class, TokenSecretAuthData.class);
SettingsExtension settingsExtension = getSettingsExtension();
settingsExtension.initialize();
ApiExtensionContext extensionContext = new ApiExtensionContext(typeManager, settingsExtension, monitor);
if (trustManagerFactory != null) {
extensionContext.registerService(TrustManagerFactory.class, trustManagerFactory);
}
if (keyManagerFactory != null) {
extensionContext.registerService(KeyManagerFactory.class, keyManagerFactory);
}
if (keyStore != null) {
extensionContext.registerService(KeyStore.class, keyStore);
}
extensionContext.registerService(HttpTransport.class, new NetHttpTransport());
extensionContext.registerService(JsonFactory.class, new JacksonFactory());
// Services that need to be shared between authServiceExtensions or load types in the
// typemanager get initialized first.
serviceExtensions = new ArrayList<>();
ServiceLoader.load(ServiceExtension.class).iterator().forEachRemaining(serviceExtensions::add);
serviceExtensions.forEach((se) -> se.initialize(extensionContext));
CloudExtension cloudExtension = getCloudExtension();
cloudExtension.initialize(extensionContext);
// Needed for GoogleAuthServiceExtension
extensionContext.registerService(HttpTransport.class, new NetHttpTransport());
extensionContext.registerService(JobStore.class, cloudExtension.getJobStore());
extensionContext.registerService(TemporaryPerJobDataStore.class, cloudExtension.getJobStore());
extensionContext.registerService(AppCredentialStore.class, cloudExtension.getAppCredentialStore());
// TODO: Load up only "enabled" services
List<AuthServiceExtension> authServiceExtensions = new ArrayList<>();
ServiceLoader.load(AuthServiceExtension.class).iterator().forEachRemaining((authServiceExtension) -> {
authServiceExtension.initialize(extensionContext);
authServiceExtensions.add(authServiceExtension);
});
// TODO: make configurable
SymmetricKeyGenerator keyGenerator = new AesSymmetricKeyGenerator(monitor);
TokenManager tokenManager;
try {
// TODO: we store the JWT Token with the application credentials, but dont need to have a key
// consider using a blobstore type of thing or allowing the AppCredentialStore to return a
// cred that doesn't contain a key.
tokenManager = new JWTTokenManager(cloudExtension.getAppCredentialStore().getAppCredentials(JWTTokenManager.JWT_KEY_NAME, JWTTokenManager.JWT_SECRET_NAME).getSecret(), monitor);
} catch (IOException e) {
monitor.info(() -> "Unable to initialize JWTTokenManager, did you specify a JWT_KEY and JWT_SECRET?", e);
throw new RuntimeException(e);
}
Injector injector;
try {
injector = Guice.createInjector(new ApiServicesModule(typeManager, cloudExtension.getJobStore(), keyGenerator, trustManagerFactory, keyManagerFactory, authServiceExtensions, tokenManager, extensionContext));
} catch (Exception e) {
monitor.info(() -> "Error initializing Guice", e);
throw e;
}
extensionContext.registerService(Injector.class, injector);
bindActions(injector, extensionContext);
}
Aggregations