use of com.google.api.gax.core.GoogleCredentialsProvider in project gax-java by googleapis.
the class SettingsTest method channelCustomCredentialScopes.
@Test
public void channelCustomCredentialScopes() throws IOException {
ImmutableList<String> inputScopes = ImmutableList.<String>builder().add("https://www.googleapis.com/auth/fakeservice").build();
CredentialsProvider credentialsProvider = FakeStubSettings.defaultCredentialsProviderBuilder().setScopesToApply(inputScopes).build();
FakeStubSettings settings = FakeStubSettings.newBuilder().setCredentialsProvider(credentialsProvider).build();
TransportChannelProvider actualChannelProvider = settings.getTransportChannelProvider();
Truth.assertThat(actualChannelProvider).isInstanceOf(InstantiatingGrpcChannelProvider.class);
InstantiatingGrpcChannelProvider actualInstChPr = (InstantiatingGrpcChannelProvider) actualChannelProvider;
Truth.assertThat(actualInstChPr.getEndpoint()).isEqualTo(FakeStubSettings.DEFAULT_SERVICE_ENDPOINT);
CredentialsProvider actualCredentialsProvider = settings.getCredentialsProvider();
Truth.assertThat(actualCredentialsProvider).isInstanceOf(GoogleCredentialsProvider.class);
GoogleCredentialsProvider googCredProv = (GoogleCredentialsProvider) actualCredentialsProvider;
Truth.assertThat(googCredProv.getScopesToApply()).isEqualTo(inputScopes);
// TODO(michaelbausor): create JSON with credentials and define GOOGLE_APPLICATION_CREDENTIALS
// environment variable to allow travis build to access application default credentials
// Truth.assertThat(connSettings.getCredentials()).isNotNull();
}
use of com.google.api.gax.core.GoogleCredentialsProvider in project stairway by DataBiosphere.
the class QueueCreate method makeTopic.
public static void makeTopic(String projectId, String topicId) throws IOException {
TopicName topicName = TopicName.ofProjectTopicName(projectId, topicId);
logger.debug("Construct credentials");
GoogleCredentialsProvider credentialsProvider = GoogleCredentialsProvider.newBuilder().setScopesToApply(Collections.singletonList("https://www.googleapis.com/auth/pubsub")).build();
TopicAdminSettings topicAdminSettings = TopicAdminSettings.newBuilder().setCredentialsProvider(credentialsProvider).build();
logger.debug("Try to create the topic");
try (TopicAdminClient topicAdminClient = TopicAdminClient.create(topicAdminSettings)) {
topicAdminClient.createTopic(topicName);
logger.debug("Created topic: " + topicId);
} catch (AlreadyExistsException ex) {
logger.debug("Topic already exists: " + topicId);
}
}
use of com.google.api.gax.core.GoogleCredentialsProvider in project stairway by DataBiosphere.
the class QueueCreate method makeSubscription.
public static void makeSubscription(String projectId, String topicId, String subscriptionId) throws IOException {
logger.debug("Construct names");
TopicName topicName = TopicName.ofProjectTopicName(projectId, topicId);
ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(projectId, subscriptionId);
logger.debug("Construct credentials");
GoogleCredentialsProvider credentialsProvider = GoogleCredentialsProvider.newBuilder().setScopesToApply(Collections.singletonList("https://www.googleapis.com/auth/pubsub")).build();
SubscriptionAdminSettings subscriptionAdminSettings = SubscriptionAdminSettings.newBuilder().setCredentialsProvider(credentialsProvider).build();
logger.debug("Try to create the subscription");
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create(subscriptionAdminSettings)) {
Subscription request = Subscription.newBuilder().setName(subscriptionName.toString()).setTopic(topicName.toString()).setAckDeadlineSeconds(ACK_DEADLINE_SECONDS).setMessageRetentionDuration(Duration.newBuilder().setSeconds(MESSAGE_RETENTION_SECONDS)).build();
subscriptionAdminClient.createSubscription(request);
logger.debug("Created subscription: " + subscriptionId);
} catch (AlreadyExistsException ex) {
logger.debug("Subscription already exists: " + subscriptionId);
}
}
Aggregations