Search in sources :

Example 1 with GoogleCredentialsProvider

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();
}
Also used : FixedCredentialsProvider(com.google.api.gax.core.FixedCredentialsProvider) CredentialsProvider(com.google.api.gax.core.CredentialsProvider) GoogleCredentialsProvider(com.google.api.gax.core.GoogleCredentialsProvider) TransportChannelProvider(com.google.api.gax.rpc.TransportChannelProvider) GoogleCredentialsProvider(com.google.api.gax.core.GoogleCredentialsProvider) Test(org.junit.Test)

Example 2 with GoogleCredentialsProvider

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);
    }
}
Also used : TopicAdminSettings(com.google.cloud.pubsub.v1.TopicAdminSettings) AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) TopicAdminClient(com.google.cloud.pubsub.v1.TopicAdminClient) GoogleCredentialsProvider(com.google.api.gax.core.GoogleCredentialsProvider) TopicName(com.google.pubsub.v1.TopicName)

Example 3 with GoogleCredentialsProvider

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);
    }
}
Also used : ProjectSubscriptionName(com.google.pubsub.v1.ProjectSubscriptionName) SubscriptionAdminSettings(com.google.cloud.pubsub.v1.SubscriptionAdminSettings) AlreadyExistsException(com.google.api.gax.rpc.AlreadyExistsException) SubscriptionAdminClient(com.google.cloud.pubsub.v1.SubscriptionAdminClient) Subscription(com.google.pubsub.v1.Subscription) GoogleCredentialsProvider(com.google.api.gax.core.GoogleCredentialsProvider) TopicName(com.google.pubsub.v1.TopicName)

Aggregations

GoogleCredentialsProvider (com.google.api.gax.core.GoogleCredentialsProvider)3 AlreadyExistsException (com.google.api.gax.rpc.AlreadyExistsException)2 TopicName (com.google.pubsub.v1.TopicName)2 CredentialsProvider (com.google.api.gax.core.CredentialsProvider)1 FixedCredentialsProvider (com.google.api.gax.core.FixedCredentialsProvider)1 TransportChannelProvider (com.google.api.gax.rpc.TransportChannelProvider)1 SubscriptionAdminClient (com.google.cloud.pubsub.v1.SubscriptionAdminClient)1 SubscriptionAdminSettings (com.google.cloud.pubsub.v1.SubscriptionAdminSettings)1 TopicAdminClient (com.google.cloud.pubsub.v1.TopicAdminClient)1 TopicAdminSettings (com.google.cloud.pubsub.v1.TopicAdminSettings)1 ProjectSubscriptionName (com.google.pubsub.v1.ProjectSubscriptionName)1 Subscription (com.google.pubsub.v1.Subscription)1 Test (org.junit.Test)1