Search in sources :

Example 1 with AppCredentials

use of org.datatransferproject.types.transfer.auth.AppCredentials in project data-transfer-project by google.

the class AzureKeyVaultStore method getAppCredentials.

@Override
public AppCredentials getAppCredentials(String keyName, String secretName) throws IOException {
    String normalizedKey = normalize(keyName);
    SecretBundle keyBundle = vaultClient.getSecret(vaultUrl, normalizedKey);
    if (keyBundle == null) {
        throw new IOException(("Key not found: " + secretName));
    }
    String keyValue = keyBundle.value();
    String normalizedSecret = normalize(secretName);
    SecretBundle secretBundle = vaultClient.getSecret(vaultUrl, normalizedSecret);
    if (secretBundle == null) {
        throw new IOException(("Key not found: " + secretName));
    }
    String secretValue = secretBundle.value();
    return new AppCredentials(keyValue, secretValue);
}
Also used : SecretBundle(com.microsoft.azure.keyvault.models.SecretBundle) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) IOException(java.io.IOException)

Example 2 with AppCredentials

use of org.datatransferproject.types.transfer.auth.AppCredentials in project data-transfer-project by google.

the class TwitterTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    Monitor monitor = context.getMonitor();
    monitor.debug(() -> "Starting Twitter initialization");
    if (initialized) {
        monitor.severe(() -> "TwitterTransferExtension already initialized.");
        return;
    }
    AppCredentials appCredentials;
    try {
        appCredentials = context.getService(AppCredentialStore.class).getAppCredentials(TWITTER_KEY, TWITTER_SECRET);
    } catch (IOException e) {
        monitor.info(() -> format("Unable to retrieve Twitter AppCredentials. Did you set %s and %s?", TWITTER_KEY, TWITTER_SECRET), e);
        return;
    }
    exporter = new TwitterPhotosExporter(appCredentials, monitor);
    importer = new TwitterPhotosImporter(appCredentials, monitor);
    initialized = true;
}
Also used : Monitor(org.datatransferproject.api.launcher.Monitor) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) IOException(java.io.IOException)

Example 3 with AppCredentials

use of org.datatransferproject.types.transfer.auth.AppCredentials in project data-transfer-project by google.

the class GoogleAppCredentialStore method getAppCredentials.

public AppCredentials getAppCredentials(String keyName, String secretName) throws IOException {
    String key;
    String secret;
    try {
        key = keys.get(keyName);
    } catch (ExecutionException e) {
        throw new IOException("Couldn't lookup key: " + keyName, e);
    }
    try {
        secret = secrets.get(secretName);
    } catch (ExecutionException e) {
        throw new IOException("Couldn't lookup secret: " + secretName, e);
    }
    return new AppCredentials(key, secret);
}
Also used : AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with AppCredentials

use of org.datatransferproject.types.transfer.auth.AppCredentials in project data-transfer-project by google.

the class SmugMugTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    Monitor monitor = context.getMonitor();
    if (initialized) {
        monitor.severe(() -> "SmugMugTransferExtension already initailized.");
        return;
    }
    TemporaryPerJobDataStore jobStore = context.getService(TemporaryPerJobDataStore.class);
    AppCredentials appCredentials;
    try {
        appCredentials = context.getService(AppCredentialStore.class).getAppCredentials(SMUGMUG_KEY, SMUGMUG_SECRET);
    } catch (IOException e) {
        monitor.info(() -> format("Unable to retrieve SmugMug AppCredentials. Did you set %s and %s?", SMUGMUG_KEY, SMUGMUG_SECRET), e);
        return;
    }
    ObjectMapper mapper = context.getService(TypeManager.class).getMapper();
    exporter = new SmugMugPhotosExporter(appCredentials, mapper, jobStore, monitor);
    importer = new SmugMugPhotosImporter(jobStore, appCredentials, mapper, monitor);
    initialized = true;
}
Also used : TemporaryPerJobDataStore(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore) Monitor(org.datatransferproject.api.launcher.Monitor) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) TypeManager(org.datatransferproject.api.launcher.TypeManager) SmugMugPhotosImporter(org.datatransferproject.transfer.smugmug.photos.SmugMugPhotosImporter) SmugMugPhotosExporter(org.datatransferproject.transfer.smugmug.photos.SmugMugPhotosExporter) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with AppCredentials

use of org.datatransferproject.types.transfer.auth.AppCredentials in project data-transfer-project by google.

the class BloggerTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    // times.
    if (initialized) {
        return;
    }
    Monitor monitor = context.getMonitor();
    AppCredentials appCredentials;
    try {
        appCredentials = context.getService(AppCredentialStore.class).getAppCredentials("GOOGLEBLOGGER_KEY", "GOOGLEBLOGGER_SECRET");
    } catch (IOException e) {
        monitor.info(() -> "Unable to retrieve Google AppCredentials. " + "Did you set GOOGLEBLOGGER_KEY and GOOGLEBLOGGER_SECRET?");
        return;
    }
    HttpTransport httpTransport = context.getService(HttpTransport.class);
    JsonFactory jsonFactory = context.getService(JsonFactory.class);
    // Create the GoogleCredentialFactory with the given {@link AppCredentials}.
    GoogleCredentialFactory credentialFactory = new GoogleCredentialFactory(httpTransport, jsonFactory, appCredentials, monitor);
    ImmutableMap.Builder<String, Importer> importerBuilder = ImmutableMap.builder();
    importerBuilder.put("SOCIAL-POSTS", new GoogleBloggerImporter(credentialFactory));
    importerMap = importerBuilder.build();
    ImmutableMap.Builder<String, Exporter> exporterBuilder = ImmutableMap.builder();
    exporterMap = exporterBuilder.build();
    initialized = true;
}
Also used : AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) JsonFactory(com.google.api.client.json.JsonFactory) IOException(java.io.IOException) GoogleCredentialFactory(org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory) Exporter(org.datatransferproject.spi.transfer.provider.Exporter) ImmutableMap(com.google.common.collect.ImmutableMap) HttpTransport(com.google.api.client.http.HttpTransport) Monitor(org.datatransferproject.api.launcher.Monitor) GoogleBloggerImporter(org.datatransferproject.datatransfer.google.blogger.GoogleBloggerImporter) GoogleBloggerImporter(org.datatransferproject.datatransfer.google.blogger.GoogleBloggerImporter) Importer(org.datatransferproject.spi.transfer.provider.Importer)

Aggregations

AppCredentials (org.datatransferproject.types.transfer.auth.AppCredentials)16 IOException (java.io.IOException)12 Monitor (org.datatransferproject.api.launcher.Monitor)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 Exporter (org.datatransferproject.spi.transfer.provider.Exporter)5 Importer (org.datatransferproject.spi.transfer.provider.Importer)5 HttpTransport (com.google.api.client.http.HttpTransport)4 JsonFactory (com.google.api.client.json.JsonFactory)4 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)3 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 OkHttpClient (okhttp3.OkHttpClient)2 GoogleCredentialFactory (org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory)2 JobStore (org.datatransferproject.spi.cloud.storage.JobStore)2 TemporaryPerJobDataStore (org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore)2 ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)2 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)2 TokenSecretAuthData (org.datatransferproject.types.transfer.auth.TokenSecretAuthData)2 Before (org.junit.Before)2