Java Code Examples for com.google.api.gax.core.NoCredentialsProvider#create()

The following examples show how to use com.google.api.gax.core.NoCredentialsProvider#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GcpPubSubAutoConfiguration.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
public GcpPubSubAutoConfiguration(GcpPubSubProperties gcpPubSubProperties,
		GcpProjectIdProvider gcpProjectIdProvider,
		CredentialsProvider credentialsProvider) throws IOException {
	this.gcpPubSubProperties = gcpPubSubProperties;
	this.finalProjectIdProvider = (gcpPubSubProperties.getProjectId() != null)
			? gcpPubSubProperties::getProjectId
			: gcpProjectIdProvider;

	if (gcpPubSubProperties.getEmulatorHost() == null
			|| "false".equals(gcpPubSubProperties.getEmulatorHost())) {
		this.finalCredentialsProvider = gcpPubSubProperties.getCredentials().hasKey()
				? new DefaultCredentialsProvider(gcpPubSubProperties)
				: credentialsProvider;
	}
	else {
		// Since we cannot create a general NoCredentialsProvider if the emulator host is enabled
		// (because it would also be used for the other components), we have to create one here
		// for this particular case.
		this.finalCredentialsProvider = NoCredentialsProvider.create();
	}
}
 
Example 2
Source File: Connection.java    From heroic with Apache License 2.0 5 votes vote down vote up
void setEmulatorOptions(Optional<String> configuredEndpoint) {
    String endpoint = configuredEndpoint.orElse(System.getenv("PUBSUB_EMULATOR_HOST"));
    if (endpoint == null) {
        return;
    }

    log.info("PubSub emulator detected at {}", endpoint);
    ManagedChannel channel = ManagedChannelBuilder.forTarget(endpoint).usePlaintext().build();
    channelProvider = FixedTransportChannelProvider.create(
        GrpcTransportChannel.create(channel));
    credentialsProvider = NoCredentialsProvider.create();
}
 
Example 3
Source File: UsePubSubEmulatorSnippet.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
public static void main(String... args) throws IOException {
  // [START pubsub_use_emulator]
  String hostport = System.getenv("PUBSUB_EMULATOR_HOST");
  ManagedChannel channel = ManagedChannelBuilder.forTarget(hostport).usePlaintext().build();
  try {
    TransportChannelProvider channelProvider =
        FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel));
    CredentialsProvider credentialsProvider = NoCredentialsProvider.create();

    // Set the channel and credentials provider when creating a `TopicAdminClient`.
    // Similarly for SubscriptionAdminClient
    TopicAdminClient topicClient =
        TopicAdminClient.create(
            TopicAdminSettings.newBuilder()
                .setTransportChannelProvider(channelProvider)
                .setCredentialsProvider(credentialsProvider)
                .build());

    TopicName topicName = TopicName.of("my-project-id", "my-topic-id");
    // Set the channel and credentials provider when creating a `Publisher`.
    // Similarly for Subscriber
    Publisher publisher =
        Publisher.newBuilder(topicName)
            .setChannelProvider(channelProvider)
            .setCredentialsProvider(credentialsProvider)
            .build();
  } finally {
    channel.shutdown();
  }
  // [END pubsub_use_emulator]
}
 
Example 4
Source File: GcpStackdriverMetricsAutoConfigurationTest.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Bean
public CredentialsProvider credentialsProvider() {
	return NoCredentialsProvider.create();
}