Skip to content

Commit

Permalink
[compute] Add a flag to force API key parameter in v2 Discovery APIs (#…
Browse files Browse the repository at this point in the history
…127)

Added an additional flag to include API key when invoking staging
networkservices and networksecurity endpoints.

ref b/360284595
  • Loading branch information
sreenithi authored Aug 26, 2024
1 parent 8616923 commit 6ef4a97
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions framework/infrastructure/gcp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
default=discovery.V2_DISCOVERY_URI,
help="Override v2 Discovery URI",
)
V2_DISCOVERY_FORCE_API_KEY = flags.DEFINE_boolean(
"v2_discovery_force_api_key",
default=False,
help=(
"Set flag to add API key when accessing staging networksecurity, "
"networkservices endpoints"
),
)
COMPUTE_V1_DISCOVERY_FILE = flags.DEFINE_string(
"compute_v1_discovery_file",
default=None,
Expand Down Expand Up @@ -91,6 +99,7 @@ def __init__(
private_api_key_secret_name=None,
gcp_ui_url=None,
verbose_gcp_api: bool = False,
v2_discovery_force_api_key: bool = False,
):
# Log GCP API requests and responses.
# Note: this modifies a global variable on googleapiclient.model.
Expand All @@ -110,6 +119,10 @@ def __init__(
# TODO(sergiitk): add options to pass google Credentials
self._exit_stack = contextlib.ExitStack()

self.v2_discovery_force_api_key = (
v2_discovery_force_api_key or V2_DISCOVERY_FORCE_API_KEY.value
)

def close(self):
self._exit_stack.close()
# Reset value of global googleapiclient.model.dump_request_response,
Expand Down Expand Up @@ -256,6 +269,9 @@ def _build_from_discovery_v2(
params = {}
if api_key:
params["key"] = api_key
elif self.v2_discovery_force_api_key:
params["key"] = self.private_api_key

if visibility_labels:
# Dash-separated list of labels.
params["labels"] = "_".join(visibility_labels)
Expand Down

0 comments on commit 6ef4a97

Please sign in to comment.