File tree Expand file tree Collapse file tree 3 files changed +24
-4
lines changed
Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -48,10 +48,13 @@ class DefaultDataClient : public DataClient {
4848 Options options = {})
4949 : project_(std::move(project)),
5050 instance_ (std::move(instance)),
51+ authority_(options.has<AuthorityOption>()
52+ ? absl::make_optional(options.get<AuthorityOption>())
53+ : absl::nullopt),
5154 user_project_(
5255 options.has<UserProjectOption>()
53- ? absl::nullopt
54- : absl::make_optional(options.get<UserProjectOption>()) ),
56+ ? absl::make_optional(options.get<UserProjectOption>())
57+ : absl::nullopt ),
5558 impl_(std::move(options)) {}
5659
5760 std::string const & project_id () const override { return project_; };
@@ -189,12 +192,17 @@ class DefaultDataClient : public DataClient {
189192 }
190193
191194 void ApplyOptions (grpc::ClientContext* context) {
192- if (!user_project_) return ;
193- context->AddMetadata (" x-goog-user-project" , *user_project_);
195+ if (authority_) {
196+ context->set_authority (*authority_);
197+ }
198+ if (user_project_) {
199+ context->AddMetadata (" x-goog-user-project" , *user_project_);
200+ }
194201 }
195202
196203 std::string project_;
197204 std::string instance_;
205+ absl::optional<std::string> authority_;
198206 absl::optional<std::string> user_project_;
199207 internal::CommonClient<btproto::Bigtable> impl_;
200208};
Original file line number Diff line number Diff line change @@ -164,6 +164,9 @@ Options DefaultDataOptions(Options opts) {
164164 if (user_project && !user_project->empty ()) {
165165 opts.set <UserProjectOption>(*std::move (user_project));
166166 }
167+ if (!opts.has <AuthorityOption>()) {
168+ opts.set <AuthorityOption>(" bigtable.googleapis.com" );
169+ }
167170 opts = DefaultOptions (std::move (opts));
168171 return opts.set <EndpointOption>(opts.get <DataEndpointOption>());
169172}
Original file line number Diff line number Diff line change @@ -167,6 +167,15 @@ TEST(OptionsTest, DataUserProjectOption) {
167167 EXPECT_EQ (options.get <UserProjectOption>(), " env-project" );
168168}
169169
170+ TEST (OptionsTest, DataAuthorityOption) {
171+ auto options = DefaultDataOptions (Options{});
172+ EXPECT_EQ (options.get <AuthorityOption>(), " bigtable.googleapis.com" );
173+
174+ options = DefaultDataOptions (
175+ Options{}.set <AuthorityOption>(" custom-endpoint.googleapis.com" ));
176+ EXPECT_EQ (options.get <AuthorityOption>(), " custom-endpoint.googleapis.com" );
177+ }
178+
170179TEST (EndpointEnvTest, EmulatorEnvOnly) {
171180 ScopedEnvironment emulator (" BIGTABLE_EMULATOR_HOST" , " emulator-host:8000" );
172181
You can’t perform that action at this time.
0 commit comments