16
16
package com .google .cloud .bigtable .data .v2 .stub ;
17
17
18
18
import com .google .api .core .BetaApi ;
19
+ import com .google .api .core .InternalApi ;
19
20
import com .google .api .gax .batching .BatchingCallSettings ;
20
21
import com .google .api .gax .batching .BatchingSettings ;
21
22
import com .google .api .gax .batching .FlowControlSettings ;
@@ -151,12 +152,20 @@ public class EnhancedBigtableStubSettings extends StubSettings<EnhancedBigtableS
151
152
.add ("https://www.googleapis.com/auth/cloud-platform" )
152
153
.build ();
153
154
155
+ /**
156
+ * In most cases, jwt audience == service name. However in some cases, this is not the case. The
157
+ * following mapping is used to patch the audience in a JWT token.
158
+ */
159
+ private static final Map <String , String > DEFAULT_JWT_AUDIENCE_MAPPING =
160
+ ImmutableMap .of ("batch-bigtable.googleapis.com" , "https://bigtable.googleapis.com/" );
161
+
154
162
private final String projectId ;
155
163
private final String instanceId ;
156
164
private final String appProfileId ;
157
165
private final boolean isRefreshingChannel ;
158
166
private ImmutableList <String > primedTableIds ;
159
167
private HeaderTracer headerTracer ;
168
+ private final Map <String , String > jwtAudienceMapping ;
160
169
161
170
private final ServerStreamingCallSettings <Query , Row > readRowsSettings ;
162
171
private final UnaryCallSettings <Query , Row > readRowSettings ;
@@ -191,6 +200,7 @@ private EnhancedBigtableStubSettings(Builder builder) {
191
200
isRefreshingChannel = builder .isRefreshingChannel ;
192
201
primedTableIds = builder .primedTableIds ;
193
202
headerTracer = builder .headerTracer ;
203
+ jwtAudienceMapping = builder .jwtAudienceMapping ;
194
204
195
205
// Per method settings.
196
206
readRowsSettings = builder .readRowsSettings .build ();
@@ -240,6 +250,11 @@ HeaderTracer getHeaderTracer() {
240
250
return headerTracer ;
241
251
}
242
252
253
+ @ InternalApi ("Used for internal testing" )
254
+ public Map <String , String > getJwtAudienceMapping () {
255
+ return jwtAudienceMapping ;
256
+ }
257
+
243
258
/** Returns a builder for the default ChannelProvider for this service. */
244
259
public static InstantiatingGrpcChannelProvider .Builder defaultGrpcTransportProviderBuilder () {
245
260
return BigtableStubSettings .defaultGrpcTransportProviderBuilder ()
@@ -498,6 +513,7 @@ public static class Builder extends StubSettings.Builder<EnhancedBigtableStubSet
498
513
private boolean isRefreshingChannel ;
499
514
private ImmutableList <String > primedTableIds ;
500
515
private HeaderTracer headerTracer ;
516
+ private Map <String , String > jwtAudienceMapping ;
501
517
502
518
private final ServerStreamingCallSettings .Builder <Query , Row > readRowsSettings ;
503
519
private final UnaryCallSettings .Builder <Query , Row > readRowSettings ;
@@ -522,6 +538,7 @@ private Builder() {
522
538
this .isRefreshingChannel = false ;
523
539
primedTableIds = ImmutableList .of ();
524
540
headerTracer = HeaderTracer .newBuilder ().build ();
541
+ jwtAudienceMapping = DEFAULT_JWT_AUDIENCE_MAPPING ;
525
542
setCredentialsProvider (defaultCredentialsProviderBuilder ().build ());
526
543
527
544
// Defaults provider
@@ -629,6 +646,7 @@ private Builder(EnhancedBigtableStubSettings settings) {
629
646
isRefreshingChannel = settings .isRefreshingChannel ;
630
647
primedTableIds = settings .primedTableIds ;
631
648
headerTracer = settings .headerTracer ;
649
+ jwtAudienceMapping = settings .jwtAudienceMapping ;
632
650
633
651
// Per method settings.
634
652
readRowsSettings = settings .readRowsSettings .toBuilder ();
@@ -762,6 +780,17 @@ HeaderTracer getHeaderTracer() {
762
780
return headerTracer ;
763
781
}
764
782
783
+ @ InternalApi ("Used for internal testing" )
784
+ public Builder setJwtAudienceMapping (Map <String , String > jwtAudienceMapping ) {
785
+ this .jwtAudienceMapping = Preconditions .checkNotNull (jwtAudienceMapping );
786
+ return this ;
787
+ }
788
+
789
+ @ InternalApi ("Used for internal testing" )
790
+ public Map <String , String > getJwtAudienceMapping () {
791
+ return jwtAudienceMapping ;
792
+ }
793
+
765
794
/** Returns the builder for the settings used for calls to readRows. */
766
795
public ServerStreamingCallSettings .Builder <Query , Row > readRowsSettings () {
767
796
return readRowsSettings ;
@@ -842,6 +871,7 @@ public String toString() {
842
871
.add ("isRefreshingChannel" , isRefreshingChannel )
843
872
.add ("primedTableIds" , primedTableIds )
844
873
.add ("headerTracer" , headerTracer )
874
+ .add ("jwtAudienceMapping" , jwtAudienceMapping )
845
875
.add ("readRowsSettings" , readRowsSettings )
846
876
.add ("readRowSettings" , readRowSettings )
847
877
.add ("sampleRowKeysSettings" , sampleRowKeysSettings )
0 commit comments