Search in sources :

Example 1 with JwtCredentialsWithAudience

use of com.google.cloud.bigtable.data.v2.internal.JwtCredentialsWithAudience in project java-bigtable by googleapis.

the class EnhancedBigtableStub method patchCredentials.

private static void patchCredentials(EnhancedBigtableStubSettings.Builder settings) throws IOException {
    int i = settings.getEndpoint().lastIndexOf(":");
    String host = settings.getEndpoint().substring(0, i);
    String audience = settings.getJwtAudienceMapping().get(host);
    if (audience == null) {
        return;
    }
    URI audienceUri = null;
    try {
        audienceUri = new URI(audience);
    } catch (URISyntaxException e) {
        throw new IllegalStateException("invalid JWT audience override", e);
    }
    CredentialsProvider credentialsProvider = settings.getCredentialsProvider();
    if (credentialsProvider == null) {
        return;
    }
    Credentials credentials = credentialsProvider.getCredentials();
    if (credentials == null) {
        return;
    }
    if (!(credentials instanceof ServiceAccountJwtAccessCredentials)) {
        return;
    }
    ServiceAccountJwtAccessCredentials jwtCreds = (ServiceAccountJwtAccessCredentials) credentials;
    JwtCredentialsWithAudience patchedCreds = new JwtCredentialsWithAudience(jwtCreds, audienceUri);
    settings.setCredentialsProvider(FixedCredentialsProvider.create(patchedCreds));
}
Also used : JwtCredentialsWithAudience(com.google.cloud.bigtable.data.v2.internal.JwtCredentialsWithAudience) ByteString(com.google.protobuf.ByteString) URISyntaxException(java.net.URISyntaxException) FixedCredentialsProvider(com.google.api.gax.core.FixedCredentialsProvider) CredentialsProvider(com.google.api.gax.core.CredentialsProvider) URI(java.net.URI) ServiceAccountJwtAccessCredentials(com.google.auth.oauth2.ServiceAccountJwtAccessCredentials) ServiceAccountJwtAccessCredentials(com.google.auth.oauth2.ServiceAccountJwtAccessCredentials) Credentials(com.google.auth.Credentials)

Aggregations

CredentialsProvider (com.google.api.gax.core.CredentialsProvider)1 FixedCredentialsProvider (com.google.api.gax.core.FixedCredentialsProvider)1 Credentials (com.google.auth.Credentials)1 ServiceAccountJwtAccessCredentials (com.google.auth.oauth2.ServiceAccountJwtAccessCredentials)1 JwtCredentialsWithAudience (com.google.cloud.bigtable.data.v2.internal.JwtCredentialsWithAudience)1 ByteString (com.google.protobuf.ByteString)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1