Skip to content

Commit

Permalink
馃 Updates from OwlBot post-processor
Browse files Browse the repository at this point in the history
  • Loading branch information
gcf-owl-bot[bot] committed Mar 25, 2024
1 parent 4ee9bbb commit 07fa8ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
8 changes: 5 additions & 3 deletions googleapiclient/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,9 @@ def build_from_document(
universe_domain = None
if HAS_UNIVERSE:
universe_domain_env = os.getenv(GOOGLE_CLOUD_UNIVERSE_DOMAIN, None)
universe_domain = universe.determine_domain(client_options.universe_domain, universe_domain_env)
universe_domain = universe.determine_domain(
client_options.universe_domain, universe_domain_env
)
base = base.replace(universe.DEFAULT_UNIVERSE, universe_domain)

audience_for_self_signed_jwt = base
Expand Down Expand Up @@ -683,7 +685,7 @@ def build_from_document(
if HAS_UNIVERSE and universe_domain != universe.DEFAULT_UNIVERSE:
raise MutualTLSChannelError(
f"mTLS is not supported in any universe other than {universe.DEFAULT_UNIVERSE}."
)
)
base = mtls_endpoint

if model is None:
Expand All @@ -699,7 +701,7 @@ def build_from_document(
resourceDesc=service,
rootDesc=service,
schema=schema,
universe_domain=universe_domain
universe_domain=universe_domain,
)


Expand Down
22 changes: 13 additions & 9 deletions tests/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2619,26 +2619,29 @@ def test_universe_env_var_configured_with_mtls(self):

with self.assertRaises(MutualTLSChannelError):
with mock.patch.dict(
"os.environ", {"GOOGLE_API_USE_MTLS_ENDPOINT": "always",
"GOOGLE_CLOUD_UNIVERSE_DOMAIN": fake_universe}
"os.environ",
{
"GOOGLE_API_USE_MTLS_ENDPOINT": "always",
"GOOGLE_CLOUD_UNIVERSE_DOMAIN": fake_universe,
},
):
tasks = build_from_document(discovery)

def test_universe_env_var_configured_with_api_override(self):
fake_universe = "foo.com"
fake_api_endpoint = "https://www.bar.com/"
credentials = mock.Mock(universe_domain=fake_universe)
discovery = read_datafile("tasks.json")

with mock.patch.dict(
"os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": fake_universe}
):
"os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": fake_universe}
):
tasks = build_from_document(
discovery,
credentials=credentials,
client_options=google.api_core.client_options.ClientOptions(
api_endpoint=fake_api_endpoint
),
api_endpoint=fake_api_endpoint
),
)

assert tasks._baseUrl == fake_api_endpoint
Expand All @@ -2650,8 +2653,8 @@ def test_universe_env_var_configured_with_client_options_universe(self):
discovery = read_datafile("tasks.json")

with mock.patch.dict(
"os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": another_fake_universe}
):
"os.environ", {"GOOGLE_CLOUD_UNIVERSE_DOMAIN": another_fake_universe}
):
tasks = build_from_document(
discovery,
credentials=credentials,
Expand All @@ -2662,5 +2665,6 @@ def test_universe_env_var_configured_with_client_options_universe(self):

assert tasks._universe_domain == fake_universe


if __name__ == "__main__":
unittest.main()

0 comments on commit 07fa8ba

Please sign in to comment.