use of com.google.auth.http.HttpTransportFactory in project nifi by apache.
the class AbstractGCSProcessor method getServiceOptions.
@Override
protected StorageOptions getServiceOptions(ProcessContext context, GoogleCredentials credentials) {
final String projectId = context.getProperty(PROJECT_ID).getValue();
final Integer retryCount = context.getProperty(RETRY_COUNT).asInteger();
final String proxyHost = context.getProperty(PROXY_HOST).getValue();
final Integer proxyPort = context.getProperty(PROXY_PORT).asInteger();
StorageOptions.Builder storageOptionsBuilder = StorageOptions.newBuilder().setCredentials(credentials).setProjectId(projectId).setRetryParams(RetryParams.newBuilder().setRetryMaxAttempts(retryCount).setRetryMinAttempts(retryCount).build());
if (!StringUtils.isBlank(proxyHost) && proxyPort > 0) {
storageOptionsBuilder.setHttpTransportFactory(new HttpTransportFactory() {
@Override
public HttpTransport create() {
final HttpTransport transport = new NetHttpTransport.Builder().setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort))).build();
return transport;
}
});
}
return storageOptionsBuilder.build();
}
use of com.google.auth.http.HttpTransportFactory in project grpc-java by grpc.
the class GoogleAuthLibraryCallCredentialsTest method serviceAccountToJwt.
@Test
public void serviceAccountToJwt() throws Exception {
KeyPair pair = KeyPairGenerator.getInstance("RSA").generateKeyPair();
HttpTransportFactory factory = Mockito.mock(HttpTransportFactory.class);
Mockito.when(factory.create()).thenThrow(new AssertionError());
ServiceAccountCredentials credentials = ServiceAccountCredentials.newBuilder().setClientEmail("test-email@example.com").setPrivateKey(pair.getPrivate()).setPrivateKeyId("test-private-key-id").setHttpTransportFactory(factory).build();
GoogleAuthLibraryCallCredentials callCredentials = new GoogleAuthLibraryCallCredentials(credentials);
callCredentials.applyRequestMetadata(new RequestInfoImpl(), executor, applier);
assertEquals(0, runPendingRunnables());
verify(applier).apply(headersCaptor.capture());
Metadata headers = headersCaptor.getValue();
String[] authorization = Iterables.toArray(headers.getAll(AUTHORIZATION), String.class);
assertEquals(1, authorization.length);
assertTrue(authorization[0], authorization[0].startsWith("Bearer "));
// JWT is reasonably long. Normal tokens aren't.
assertTrue(authorization[0], authorization[0].length() > 300);
}
Aggregations