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));
}
Aggregations