Search in sources :

Example 1 with CloudExtension

use of org.dataportabilityproject.spi.cloud.extension.CloudExtension in project data-transfer-project by google.

the class WorkerMain method initialize.

public void initialize() {
    SettingsExtension settingsExtension = getSettingsExtension();
    settingsExtension.initialize(null);
    WorkerExtensionContext extensionContext = new WorkerExtensionContext(settingsExtension);
    // TODO this should be moved into a service extension
    extensionContext.registerService(HttpTransport.class, new NetHttpTransport());
    ServiceLoader.load(ServiceExtension.class).iterator().forEachRemaining(serviceExtension -> serviceExtension.initialize(extensionContext));
    // TODO: verify that this is the cloud extension that is specified in the configuration
    CloudExtension cloudExtension = getCloudExtension();
    cloudExtension.initialize(extensionContext);
    logger.info("Using CloudExtension: {} ", cloudExtension.getClass().getName());
    JobStore jobStore = cloudExtension.getJobStore();
    extensionContext.registerService(JobStore.class, jobStore);
    AppCredentialStore appCredentialStore = cloudExtension.getAppCredentialStore();
    extensionContext.registerService(AppCredentialStore.class, appCredentialStore);
    List<TransferExtension> transferExtensions = getTransferExtensions();
    // TODO: make configurable
    SymmetricKeyGenerator symmetricKeyGenerator = new AesSymmetricKeyGenerator();
    AsymmetricKeyGenerator asymmetricKeyGenerator = new RsaSymmetricKeyGenerator();
    Injector injector = Guice.createInjector(new WorkerModule(extensionContext, cloudExtension, transferExtensions, symmetricKeyGenerator, asymmetricKeyGenerator));
    worker = injector.getInstance(Worker.class);
}
Also used : AppCredentialStore(org.dataportabilityproject.spi.cloud.storage.AppCredentialStore) JobStore(org.dataportabilityproject.spi.cloud.storage.JobStore) SettingsExtension(org.dataportabilityproject.config.extension.SettingsExtension) CloudExtension(org.dataportabilityproject.spi.cloud.extension.CloudExtension) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) SymmetricKeyGenerator(org.dataportabilityproject.security.SymmetricKeyGenerator) RsaSymmetricKeyGenerator(org.dataportabilityproject.security.RsaSymmetricKeyGenerator) AesSymmetricKeyGenerator(org.dataportabilityproject.security.AesSymmetricKeyGenerator) Injector(com.google.inject.Injector) TransferExtension(org.dataportabilityproject.spi.transfer.extension.TransferExtension) AsymmetricKeyGenerator(org.dataportabilityproject.security.AsymmetricKeyGenerator) AesSymmetricKeyGenerator(org.dataportabilityproject.security.AesSymmetricKeyGenerator) RsaSymmetricKeyGenerator(org.dataportabilityproject.security.RsaSymmetricKeyGenerator)

Example 2 with CloudExtension

use of org.dataportabilityproject.spi.cloud.extension.CloudExtension in project data-transfer-project by google.

the class ApiMain method initializeHttps.

public void initializeHttps(TrustManagerFactory trustManagerFactory, KeyManagerFactory keyManagerFactory) {
    // TODO init with types
    TypeManager typeManager = new TypeManagerImpl();
    typeManager.registerTypes(TokenAuthData.class, TokensAndUrlAuthData.class, TokenSecretAuthData.class);
    SettingsExtension settingsExtension = getSettingsExtension();
    settingsExtension.initialize(null);
    ApiExtensionContext extensionContext = new ApiExtensionContext(typeManager, settingsExtension);
    // Services that need to be shared between authServiceExtensions or load types in the
    // typemanager get initialized first.
    ServiceLoader.load(ServiceExtension.class).iterator().forEachRemaining(serviceExtension -> serviceExtension.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(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();
    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());
    } catch (IOException e) {
        logger.error("Unable to initialize JWTTokenManager, did you specify a JWT_KEY and JWT_SECRET?");
        throw new RuntimeException(e);
    }
    Injector injector = Guice.createInjector(new ApiServicesModule(typeManager, cloudExtension.getJobStore(), keyGenerator, trustManagerFactory, keyManagerFactory, authServiceExtensions, tokenManager), new ReferenceApiModule(extensionContext));
    // Launch the application
    // TODO: Support other server implementations, e.g. Jetty, Tomcat
    server = injector.getInstance(ReferenceApiServer.class);
}
Also used : ArrayList(java.util.ArrayList) JWTTokenManager(org.dataportabilityproject.gateway.reference.JWTTokenManager) TypeManagerImpl(org.dataportabilityproject.launcher.impl.TypeManagerImpl) IOException(java.io.IOException) ReferenceApiServer(org.dataportabilityproject.gateway.reference.ReferenceApiServer) SettingsExtension(org.dataportabilityproject.config.extension.SettingsExtension) CloudExtension(org.dataportabilityproject.spi.cloud.extension.CloudExtension) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) SymmetricKeyGenerator(org.dataportabilityproject.security.SymmetricKeyGenerator) AesSymmetricKeyGenerator(org.dataportabilityproject.security.AesSymmetricKeyGenerator) Injector(com.google.inject.Injector) TypeManager(org.dataportabilityproject.api.launcher.TypeManager) AesSymmetricKeyGenerator(org.dataportabilityproject.security.AesSymmetricKeyGenerator) AuthServiceExtension(org.dataportabilityproject.spi.gateway.auth.extension.AuthServiceExtension) TokenManager(org.dataportabilityproject.gateway.reference.TokenManager) JWTTokenManager(org.dataportabilityproject.gateway.reference.JWTTokenManager) ReferenceApiModule(org.dataportabilityproject.gateway.reference.ReferenceApiModule)

Aggregations

NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)2 Injector (com.google.inject.Injector)2 SettingsExtension (org.dataportabilityproject.config.extension.SettingsExtension)2 AesSymmetricKeyGenerator (org.dataportabilityproject.security.AesSymmetricKeyGenerator)2 SymmetricKeyGenerator (org.dataportabilityproject.security.SymmetricKeyGenerator)2 CloudExtension (org.dataportabilityproject.spi.cloud.extension.CloudExtension)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 TypeManager (org.dataportabilityproject.api.launcher.TypeManager)1 JWTTokenManager (org.dataportabilityproject.gateway.reference.JWTTokenManager)1 ReferenceApiModule (org.dataportabilityproject.gateway.reference.ReferenceApiModule)1 ReferenceApiServer (org.dataportabilityproject.gateway.reference.ReferenceApiServer)1 TokenManager (org.dataportabilityproject.gateway.reference.TokenManager)1 TypeManagerImpl (org.dataportabilityproject.launcher.impl.TypeManagerImpl)1 AsymmetricKeyGenerator (org.dataportabilityproject.security.AsymmetricKeyGenerator)1 RsaSymmetricKeyGenerator (org.dataportabilityproject.security.RsaSymmetricKeyGenerator)1 AppCredentialStore (org.dataportabilityproject.spi.cloud.storage.AppCredentialStore)1 JobStore (org.dataportabilityproject.spi.cloud.storage.JobStore)1 AuthServiceExtension (org.dataportabilityproject.spi.gateway.auth.extension.AuthServiceExtension)1 TransferExtension (org.dataportabilityproject.spi.transfer.extension.TransferExtension)1