@Override @Nonnull public FirestoreOptions build() { if (this.credentials == null && this.credentialsProvider != null) { try { this.setCredentials(credentialsProvider.getCredentials()); } catch (IOException e) { throw new RuntimeException("Failed to obtain credentials", e); } } return new FirestoreOptions(this); } }
@Override public Credentials getCredentials() throws IOException { return this.wrappedCredentialsProvider.getCredentials(); }
@Override @Nonnull public FirestoreOptions build() { if (this.credentials == null && this.credentialsProvider != null) { try { this.setCredentials(credentialsProvider.getCredentials()); } catch (IOException e) { throw new RuntimeException("Failed to obtain credentials", e); } } return new FirestoreOptions(this); } }
public GoogleConfigPropertySourceLocator(GcpProjectIdProvider projectIdProvider, CredentialsProvider credentialsProvider, GcpConfigProperties gcpConfigProperties) throws IOException { Assert.notNull(gcpConfigProperties, "Google Config properties must not be null"); if (gcpConfigProperties.isEnabled()) { Assert.notNull(credentialsProvider, "Credentials provider cannot be null"); Assert.notNull(projectIdProvider, "Project ID provider cannot be null"); this.credentials = gcpConfigProperties.getCredentials().hasKey() ? new DefaultCredentialsProvider(gcpConfigProperties).getCredentials() : credentialsProvider.getCredentials(); this.projectId = (gcpConfigProperties.getProjectId() != null) ? gcpConfigProperties.getProjectId() : projectIdProvider.getProjectId(); Assert.notNull(this.credentials, "Credentials must not be null"); Assert.notNull(this.projectId, "Project ID must not be null"); this.timeout = gcpConfigProperties.getTimeoutMillis(); this.name = gcpConfigProperties.getName(); this.profile = gcpConfigProperties.getProfile(); this.enabled = gcpConfigProperties.isEnabled(); Assert.notNull(this.name, "Config name must not be null"); Assert.notNull(this.profile, "Config profile must not be null"); } }
/** Return {@link io.grpc.Channel} which is used by Cloud Pub/Sub gRPC API's. */ public static Channel getChannel(CredentialsProvider credentialsProvider) throws IOException { ManagedChannel channelImpl = NettyChannelBuilder.forAddress(ENDPOINT, 443) .negotiationType(NegotiationType.TLS) // Maximum Pub/Sub message size is 10MB. .maxInboundMessageSize(10 * 1024 * 1024) .build(); final ClientAuthInterceptor interceptor = new ClientAuthInterceptor( credentialsProvider.getCredentials(), Executors.newCachedThreadPool()); return ClientInterceptors.intercept(channelImpl, interceptor); }
Credentials credentials = credentialsProvider.getCredentials();
Credentials credentials = this.wrappedCredentialsProvider.getCredentials();
@Bean @ConditionalOnMissingBean public static Storage storage(CredentialsProvider credentialsProvider, GcpStorageProperties gcpStorageProperties, GcpProjectIdProvider projectIdProvider) throws IOException { return StorageOptions.newBuilder() .setCredentials(gcpStorageProperties.getCredentials().hasKey() ? new DefaultCredentialsProvider(gcpStorageProperties).getCredentials() : credentialsProvider.getCredentials()) .setHeaderProvider( new UserAgentHeaderProvider(GcpStorageAutoConfiguration.class)) .setProjectId(projectIdProvider.getProjectId()) .build().getService(); } }
GcpDatastoreAutoConfiguration(GcpDatastoreProperties gcpDatastoreProperties, GcpProjectIdProvider projectIdProvider, CredentialsProvider credentialsProvider) throws IOException { this.credentials = (gcpDatastoreProperties.getCredentials().hasKey() ? new DefaultCredentialsProvider(gcpDatastoreProperties) : credentialsProvider).getCredentials(); this.projectId = (gcpDatastoreProperties.getProjectId() != null) ? gcpDatastoreProperties.getProjectId() : projectIdProvider.getProjectId(); this.namespace = gcpDatastoreProperties.getNamespace(); }
@Test public void createMetricServiceClient() throws IOException { MetricServiceClient client; synchronized (StackdriverStatsExporter.monitor) { client = StackdriverStatsExporter.createMetricServiceClient(FAKE_CREDENTIALS); } assertThat(client.getSettings().getCredentialsProvider().getCredentials()) .isEqualTo(FAKE_CREDENTIALS); assertThat(client.getSettings().getTransportChannelProvider()) .isInstanceOf(InstantiatingGrpcChannelProvider.class); // There's no way to get HeaderProvider from TransportChannelProvider. assertThat(client.getSettings().getTransportChannelProvider().needsHeaders()).isFalse(); }
@Test public void customCredentials() throws IOException { Credentials credentials = Mockito.mock(Credentials.class); FakeStubSettings settings = FakeStubSettings.newBuilder() .setCredentialsProvider(FixedCredentialsProvider.create(credentials)) .build(); TransportChannelProvider actualChannelProvider = settings.getTransportChannelProvider(); Truth.assertThat(actualChannelProvider).isInstanceOf(InstantiatingGrpcChannelProvider.class); InstantiatingGrpcChannelProvider actualInstChPr = (InstantiatingGrpcChannelProvider) actualChannelProvider; Truth.assertThat(actualInstChPr.getEndpoint()) .isEqualTo(FakeStubSettings.DEFAULT_SERVICE_ENDPOINT); // TODO(michaelbausor): create JSON with credentials and define GOOGLE_APPLICATION_CREDENTIALS // environment variable to allow travis build to access application default credentials Truth.assertThat(settings.getCredentialsProvider().getCredentials()).isSameAs(credentials); }
.withCallCredentials( MoreCallCredentials.from( this.finalCredentialsProvider.getCredentials())) .withExecutor(executorProvider.getExecutor());
Credentials credentials = settings.getCredentialsProvider().getCredentials();
Credentials credentials = settings.getCredentialsProvider().getCredentials();
CoreSpannerAutoConfiguration(GcpSpannerProperties gcpSpannerProperties, GcpProjectIdProvider projectIdProvider, CredentialsProvider credentialsProvider) throws IOException { this.credentials = (gcpSpannerProperties.getCredentials().hasKey() ? new DefaultCredentialsProvider(gcpSpannerProperties) : credentialsProvider).getCredentials(); this.projectId = (gcpSpannerProperties.getProjectId() != null) ? gcpSpannerProperties.getProjectId() : projectIdProvider.getProjectId(); this.instanceId = gcpSpannerProperties.getInstanceId(); this.databaseName = gcpSpannerProperties.getDatabase(); this.numRpcChannels = gcpSpannerProperties.getNumRpcChannels(); this.prefetchChunks = gcpSpannerProperties.getPrefetchChunks(); this.minSessions = gcpSpannerProperties.getMinSessions(); this.maxSessions = gcpSpannerProperties.getMaxSessions(); this.maxIdleSessions = gcpSpannerProperties.getMaxIdleSessions(); this.writeSessionsFraction = gcpSpannerProperties.getWriteSessionsFraction(); this.keepAliveIntervalMinutes = gcpSpannerProperties .getKeepAliveIntervalMinutes(); this.createInterleavedTableDdlOnDeleteCascade = gcpSpannerProperties .isCreateInterleavedTableDdlOnDeleteCascade(); }