GoogleCommon.getJsonFactory(), Preconditions.checkNotNull(credential, "Credential is required")) .setApplicationName(Preconditions.checkNotNull(wuState.getProp(APPLICATION_NAME), "ApplicationName is required")) .build();
/** * Initialize file system helper at most once for this instance. * {@inheritDoc} * @see org.apache.gobblin.source.extractor.filebased.FileBasedSource#initFileSystemHelper(org.apache.gobblin.configuration.State) */ @Override public synchronized void initFileSystemHelper(State state) throws FileBasedHelperException { if (fsHelper == null) { Credential credential = new GoogleCommon.CredentialBuilder(state.getProp(SOURCE_CONN_PRIVATE_KEY), state.getPropAsList(API_SCOPES)) .fileSystemUri(state.getProp(PRIVATE_KEY_FILESYSTEM_URI)) .proxyUrl(state.getProp(SOURCE_CONN_USE_PROXY_URL)) .port(state.getProp(SOURCE_CONN_USE_PROXY_PORT)) .serviceAccountId(state.getProp(SOURCE_CONN_USERNAME)) .build(); Drive driveClient = new Drive.Builder(credential.getTransport(), GoogleCommon.getJsonFactory(), credential) .setApplicationName(Preconditions.checkNotNull(state.getProp(APPLICATION_NAME), "ApplicationName is required")) .build(); this.fsHelper = closer.register(new GoogleDriveFsHelper(state, driveClient)); } }
@Override public synchronized void initialize(URI uri, Configuration conf) throws IOException { if (this.client == null) { super.initialize(uri, conf); State state = HadoopUtils.getStateFromConf(conf); Credential credential = new GoogleCommon.CredentialBuilder(state.getProp(SOURCE_CONN_PRIVATE_KEY), state.getPropAsList(API_SCOPES)) .fileSystemUri(state.getProp(PRIVATE_KEY_FILESYSTEM_URI)) .proxyUrl(state.getProp(SOURCE_CONN_USE_PROXY_URL)) .port(state.getProp(SOURCE_CONN_USE_PROXY_PORT)) .serviceAccountId(state.getProp(SOURCE_CONN_USERNAME)) .build(); this.client = new Drive.Builder(credential.getTransport(), GoogleCommon.getJsonFactory(), credential) .setApplicationName(Preconditions.checkNotNull(state.getProp(APPLICATION_NAME), "ApplicationName is required")) .build(); this.pageSize = state.getPropAsInt(PAGE_SIZE, DEFAULT_PAGE_SIZE); } }
/** * Initialize file system helper at most once for this instance. * {@inheritDoc} * @see org.apache.gobblin.source.extractor.filebased.FileBasedSource#initFileSystemHelper(org.apache.gobblin.configuration.State) */ @Override public synchronized void initFileSystemHelper(State state) throws FileBasedHelperException { if (fsHelper == null) { Credential credential = new GoogleCommon.CredentialBuilder(state.getProp(SOURCE_CONN_PRIVATE_KEY), state.getPropAsList(API_SCOPES)) .fileSystemUri(state.getProp(PRIVATE_KEY_FILESYSTEM_URI)) .proxyUrl(state.getProp(SOURCE_CONN_USE_PROXY_URL)) .port(state.getProp(SOURCE_CONN_USE_PROXY_PORT)) .serviceAccountId(state.getProp(SOURCE_CONN_USERNAME)) .build(); Drive driveClient = new Drive.Builder(credential.getTransport(), GoogleCommon.getJsonFactory(), credential) .setApplicationName(Preconditions.checkNotNull(state.getProp(APPLICATION_NAME), "ApplicationName is required")) .build(); this.fsHelper = closer.register(new GoogleDriveFsHelper(state, driveClient)); } }
@Override public synchronized void initialize(URI uri, Configuration conf) throws IOException { if (this.client == null) { super.initialize(uri, conf); State state = HadoopUtils.getStateFromConf(conf); Credential credential = new GoogleCommon.CredentialBuilder(state.getProp(SOURCE_CONN_PRIVATE_KEY), state.getPropAsList(API_SCOPES)) .fileSystemUri(state.getProp(PRIVATE_KEY_FILESYSTEM_URI)) .proxyUrl(state.getProp(SOURCE_CONN_USE_PROXY_URL)) .port(state.getProp(SOURCE_CONN_USE_PROXY_PORT)) .serviceAccountId(state.getProp(SOURCE_CONN_USERNAME)) .build(); this.client = new Drive.Builder(credential.getTransport(), GoogleCommon.getJsonFactory(), credential) .setApplicationName(Preconditions.checkNotNull(state.getProp(APPLICATION_NAME), "ApplicationName is required")) .build(); this.pageSize = state.getPropAsInt(PAGE_SIZE, DEFAULT_PAGE_SIZE); } }
@Override protected Drive connect(final Proxy proxy, final HostKeyCallback callback, final LoginCallback prompt) { authorizationService = new OAuth2RequestInterceptor(builder.build(proxy, this, prompt).build(), host.getProtocol()) .withRedirectUri(host.getProtocol().getOAuthRedirectUrl()); final HttpClientBuilder configuration = builder.build(proxy, this, prompt); configuration.addInterceptorLast(authorizationService); configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(authorizationService)); this.transport = new ApacheHttpTransport(configuration.build()); return new Drive.Builder(transport, json, new HttpRequestInitializer() { @Override public void initialize(HttpRequest request) { request.setSuppressUserAgentSuffix(true); // OAuth Bearer added in interceptor } }) .setApplicationName(useragent.get()) .build(); }
public Drive getDriveService(String appName, String clientSecretJSON) { try { HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); Credential credential = authorize(clientSecretJSON); return new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential) .setApplicationName(appName) .build(); } catch (Exception e) { throw new IllegalArgumentException(e); } }
public static Drive build(Credential credential) throws Exception { final NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); return new Drive.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build(); }
public Drive getDrive(Credential credential) { if(drive == null) { HttpTransport httpTransport = new NetHttpTransport(); drive = new Drive.Builder(httpTransport, getJsonFactory(), credential).setApplicationName("JDriveSync").build(); } return drive; }
public Drive buildDriveService(GoogleCredential credential) throws IOException, GeneralSecurityException { return new Drive.Builder( GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), credential) .setApplicationName("Sheets API Snippets") .build(); }
public void init() { try { // authorization Credential credential = authorize(); // set up global Drive instance drive = new Drive.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build(); logger.info("Google drive webservice client initialized."); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Build and return an authorized Drive client service. * * @return authorized Drive client service * @throws GeneralSecurityException when credentials fails * @throws IOException when credentials fails */ public Drive getDriveService() throws GeneralSecurityException, IOException { return new Drive.Builder(getHttpTransport(), JacksonFactory.getDefaultInstance(), getCredential()) .setApplicationName(getApplicationName()).build(); }
public void createDriver() throws IOException { try { HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); } catch (GeneralSecurityException e) { logger.error("Create Driver Error", e); } DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR); Credential credential = authorize(); drive = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName( APPLICATION_NAME).build(); }
public Drive buildDriveService(GoogleCredential credential) throws IOException, GeneralSecurityException { return new Drive.Builder( GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), credential) .setApplicationName("Slides API Snippets") .build(); }
public static Drive getService(byte[] credsFile) throws IOException { return new Drive.Builder(getHttpTransport(), getJsonFactory(), authorize(credsFile)) .setApplicationName(getApplicationName()) .build(); } }
public static Drive createDriveService(final Credential credential, final HttpTransport transport) { return new Drive.Builder(transport, JSON_FACTORY, credential) .setApplicationName(APPLICATION_NAME) .build(); }
/** * Build and return an authorized Drive client service. * * @return authorized Drive client service * @throws GeneralSecurityException when credentials fails * @throws IOException when credentials fails */ public Drive getDriveService() throws GeneralSecurityException, IOException { return new Drive.Builder(getHttpTransport(), JacksonFactory.getDefaultInstance(), getCredential()) .setApplicationName(getApplicationName()).build(); }
public static Drive createDriveService(final Credential credential, final HttpTransport transport) { return new Drive.Builder(transport, JSON_FACTORY, credential) .setApplicationName(APPLICATION_NAME) .build(); }
private Drive getDriveService() throws IOException { Credential credential = authorize(); return new Drive.Builder( HTTP_TRANSPORT, JSON_FACTORY, credential ).setApplicationName( APPLICATION_NAME ).build(); }
static synchronized Drive makeDriveInterface( TokensAndUrlAuthData authData, GoogleCredentialFactory credentialFactory) { Credential credential = credentialFactory.createCredential(authData); return new Drive.Builder( credentialFactory.getHttpTransport(), credentialFactory.getJsonFactory(), credential) .setApplicationName(GoogleStaticObjects.APP_NAME) .build(); } }