diff --git a/.librarian/generator-input/client-post-processing/docs-index-rst-for-unversioned-apis.yaml b/.librarian/generator-input/client-post-processing/docs-index-rst-for-unversioned-apis.yaml index 266307713a7d..1111835bf0f0 100644 --- a/.librarian/generator-input/client-post-processing/docs-index-rst-for-unversioned-apis.yaml +++ b/.librarian/generator-input/client-post-processing/docs-index-rst-for-unversioned-apis.yaml @@ -119,6 +119,8 @@ replacements: drive/types_ gmail/services_ gmail/types_ + meet/services_ + meet/types_ sheets/services_ sheets/types_ slides/services_ diff --git a/librarian.yaml b/librarian.yaml index 1e6967c90da2..2c0cade054ca 100644 --- a/librarian.yaml +++ b/librarian.yaml @@ -198,11 +198,13 @@ libraries: - path: google/apps/script/type/sheets - path: google/apps/script/type/calendar - path: google/apps/script/type/slides + - path: google/apps/script/type/meet keep: - tests/unit/gapic/calendar/test_calendar.py - tests/unit/gapic/docs/test_docs.py - tests/unit/gapic/drive/test_drive.py - tests/unit/gapic/gmail/test_gmail.py + - tests/unit/gapic/meet/test_meet.py - tests/unit/gapic/sheets/test_sheets.py - tests/unit/gapic/slides/test_slides.py - tests/unit/gapic/type/test_type.py @@ -227,6 +229,10 @@ libraries: - proto-plus-deps=google.apps.script.type - python-gapic-namespace=google.apps.script.type - python-gapic-name=gmail + google/apps/script/type/meet: + - proto-plus-deps=google.apps.script.type + - python-gapic-namespace=google.apps.script.type + - python-gapic-name=meet google/apps/script/type/sheets: - proto-plus-deps=google.apps.script.type - python-gapic-namespace=google.apps.script.type diff --git a/packages/google-apps-script-type/docs/index.rst b/packages/google-apps-script-type/docs/index.rst index cfd0e231537b..22d2f0871917 100644 --- a/packages/google-apps-script-type/docs/index.rst +++ b/packages/google-apps-script-type/docs/index.rst @@ -19,6 +19,8 @@ API Reference drive/types_ gmail/services_ gmail/types_ + meet/services_ + meet/types_ sheets/services_ sheets/types_ slides/services_ diff --git a/packages/google-apps-script-type/docs/meet/services_.rst b/packages/google-apps-script-type/docs/meet/services_.rst new file mode 100644 index 000000000000..e868040cb22f --- /dev/null +++ b/packages/google-apps-script-type/docs/meet/services_.rst @@ -0,0 +1,4 @@ +Services for Google Apps Script Type Meet API +============================================== +.. toctree:: + :maxdepth: 2 diff --git a/packages/google-apps-script-type/docs/meet/types_.rst b/packages/google-apps-script-type/docs/meet/types_.rst new file mode 100644 index 000000000000..4987e4e65b83 --- /dev/null +++ b/packages/google-apps-script-type/docs/meet/types_.rst @@ -0,0 +1,6 @@ +Types for Google Apps Script Type Meet API +=========================================== + +.. automodule:: google.apps.script.type.meet.types + :members: + :show-inheritance: diff --git a/packages/google-apps-script-type/google/apps/script/type/meet/__init__.py b/packages/google-apps-script-type/google/apps/script/type/meet/__init__.py new file mode 100644 index 000000000000..2bf8985356d7 --- /dev/null +++ b/packages/google-apps-script-type/google/apps/script/type/meet/__init__.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import google.api_core as api_core + +from google.apps.script.type.meet import gapic_version as package_version + +__version__ = package_version.__version__ + +# PEP 0810: Explicit Lazy Imports +# Python 3.15+ natively intercepts and defers these imports. +# Developers can disable this behavior and force eager imports. +# For more information, see: +# https://docs.python.org/3.15/library/sys.html#sys.set_lazy_imports_filter +# Older Python versions safely ignore this variable. +__lazy_modules__ = { + "google.apps.script.type.meet.types.meet_addon_manifest", +} + + +from .types.meet_addon_manifest import MeetAddOnManifest, Web + +__all__ = ( + "MeetAddOnManifest", + "Web", +) + +api_core.check_python_version("google.apps.script.type.meet") +api_core.check_dependency_versions("google.apps.script.type.meet") diff --git a/packages/google-apps-script-type/google/apps/script/type/meet/_compat.py b/packages/google-apps-script-type/google/apps/script/type/meet/_compat.py new file mode 100644 index 000000000000..3d3bdf9e2c91 --- /dev/null +++ b/packages/google-apps-script-type/google/apps/script/type/meet/_compat.py @@ -0,0 +1,262 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +"""A compatibility module for older versions of google-api-core.""" + +import json +import os +from typing import Any, Dict, List, Optional, Tuple +from urllib.parse import urlparse, urlunparse + +from google.api_core import path_template +from google.api_core.universe import EmptyUniverseError +from google.auth.exceptions import MutualTLSChannelError +from google.protobuf import json_format + +try: + # note: `#type: ignore` is added because the return type for `should_use_client_cert` + # is different than that of the fallback implementation below. This will be removed once + # we bump the minimum supported version of google-auth. + from google.auth.transport.mtls import should_use_client_cert # type: ignore +except ImportError: # pragma: NO COVER + + def should_use_client_cert(): + """Returns whether client certificate should be used for mTLS.""" + use_client_cert = os.getenv( + "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false" + ).lower() + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be" + " either `true` or `false`" + ) + return use_client_cert == "true" + + +def read_environment_variables(): + """Returns the environment variables used by the client. + + Returns: + Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE, + GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables. + + Raises: + ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not + any of ["true", "false"]. + google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT + is not any of ["auto", "never", "always"]. + """ + use_client_cert = should_use_client_cert() + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower() + universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN") + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`," + " `auto` or `always`" + ) + return use_client_cert, use_mtls_endpoint, universe_domain_env + + +DEFAULT_UNIVERSE = "googleapis.com" + +try: + from google.api_core.universe import get_default_mtls_endpoint +except ImportError: # pragma: NO COVER + + def get_default_mtls_endpoint(api_endpoint: Optional[str]) -> Optional[str]: + """Converts api endpoint to mTLS endpoint. + + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Other URLs (including those that do not match these domain suffixes or + already contain '.mtls.') are passed through as-is. + + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + + Returns: + Optional[str]: converted mTLS api endpoint. + """ + if not api_endpoint or ".mtls." in api_endpoint.lower(): + return api_endpoint + + has_scheme = "://" in api_endpoint + if not has_scheme: + parsed = urlparse("//" + api_endpoint) + else: + parsed = urlparse(api_endpoint) + + host = parsed.hostname + if not host: + return api_endpoint + + port = f":{parsed.port}" if parsed.port else "" + + lowered_host = host.lower() + suffix_sandbox = ".sandbox.googleapis.com" + suffix_google = ".googleapis.com" + if lowered_host.endswith(suffix_sandbox): + new_host = host[: -len(suffix_sandbox)] + ".mtls.sandbox.googleapis.com" + elif lowered_host.endswith(suffix_google): + new_host = host[: -len(suffix_google)] + ".mtls.googleapis.com" + else: + return api_endpoint + + netloc = new_host + port + new_parsed = parsed._replace(netloc=netloc) + + if not has_scheme: + return urlunparse(new_parsed)[2:] + else: + return urlunparse(new_parsed) + + +try: + from google.api_core.universe import get_api_endpoint +except ImportError: # pragma: NO COVER + + def get_api_endpoint( + api_override: Optional[str], + universe_domain: str, + default_universe: str, + default_mtls_endpoint: Optional[str], + default_endpoint_template: str, + use_mtls: bool, + ) -> str: + """Return the API endpoint used by the client. + + Args: + api_override (Optional[str]): The API endpoint override. If specified, + this is always returned. + universe_domain (str): The universe domain used by the client. + default_universe (str): The default universe domain. + default_mtls_endpoint (Optional[str]): The default mTLS endpoint. + default_endpoint_template (str): The default endpoint template containing + a placeholder `{UNIVERSE_DOMAIN}`. + use_mtls (bool): Whether to use the mTLS endpoint. + + Returns: + str: The API endpoint to be used by the client. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mTLS is requested but + not supported in the configured universe domain. + ValueError: If mTLS is requested but no mTLS endpoint is available. + """ + if api_override is not None: + return api_override + + if use_mtls: + if universe_domain.lower() != default_universe.lower(): + raise MutualTLSChannelError( + f"mTLS is not supported in any universe other than {default_universe}." + ) + if not default_mtls_endpoint: + raise ValueError("mTLS endpoint is not available.") + return default_mtls_endpoint + else: + return default_endpoint_template.format(UNIVERSE_DOMAIN=universe_domain) + + +try: + from google.api_core.universe import get_universe_domain +except ImportError: # pragma: NO COVER + + def get_universe_domain( + *potential_universes: Optional[str], + default_universe: str, + ) -> str: + """Return the universe domain used by the client. + + Args: + *potential_universes (Optional[str]): Potential universe domains in order of preference. + default_universe (str): The default universe domain. + + Returns: + str: The universe domain to be used by the client. + + Raises: + EmptyUniverseError: If the resolved universe domain is an empty string. + """ + resolved = next( + (x.strip() for x in potential_universes if x is not None), + default_universe, + ) + + if not resolved: + raise EmptyUniverseError() + return resolved + + +try: + from google.api_core.rest_helpers import transcode_request # type: ignore +except ImportError: # pragma: NO COVER + + def transcode_request( + http_options: List[Dict[str, str]], + request: Any, + required_fields_default_values: Optional[Dict[str, Any]] = None, + rest_numeric_enums: bool = False, + ) -> Tuple[Dict[str, Any], Optional[str], Dict[str, Any]]: + """Transcodes a request into HTTP method, URI, body, and query parameters. + + Args: + http_options (List[Dict[str, str]]): List of HTTP transcoding rules. + request (Any): The protobuf or proto-plus request message. + required_fields_default_values (Optional[Dict[str, Any]]): Dictionary + of required fields default values to merge into query parameters if missing. + rest_numeric_enums (bool): Whether to encode enums as integers. + + Returns: + Tuple[Dict[str, Any], Optional[str], Dict[str, Any]]: A tuple containing: + - The raw transcoded request dictionary (containing keys like 'uri', 'method'). + - The serialized request body JSON string, or None if no body. + - The query parameters dictionary. + """ + if request is None: + raise TypeError("request cannot be None") + + # Convert proto-plus message to its underlying protobuf message if needed + pb_request = getattr(request, "_pb", request) + + transcoded_request = path_template.transcode(http_options, pb_request) + + body_json = None + if transcoded_request.get("body") is not None: + body_json = json_format.MessageToJson( + transcoded_request["body"], + use_integers_for_enums=rest_numeric_enums, + ) + + query_params_json = {} + if transcoded_request.get("query_params") is not None: + query_params_json = json.loads( + json_format.MessageToJson( + transcoded_request["query_params"], + use_integers_for_enums=rest_numeric_enums, + ) + ) + + # If required_fields_default_values is provided, we merge default values for missing + # required fields into the query parameters. + if required_fields_default_values: + for k, v in required_fields_default_values.items(): + if k not in query_params_json: + query_params_json[k] = v + + if rest_numeric_enums: + query_params_json["$alt"] = "json;enum-encoding=int" + + return transcoded_request, body_json, query_params_json diff --git a/packages/google-apps-script-type/google/apps/script/type/meet/gapic_metadata.json b/packages/google-apps-script-type/google/apps/script/type/meet/gapic_metadata.json new file mode 100644 index 000000000000..f225fa5a3c4c --- /dev/null +++ b/packages/google-apps-script-type/google/apps/script/type/meet/gapic_metadata.json @@ -0,0 +1,7 @@ + { + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "python", + "libraryPackage": "google.apps.script.type.meet", + "protoPackage": "google.apps.script.type.meet", + "schema": "1.0" +} diff --git a/packages/google-apps-script-type/google/apps/script/type/meet/gapic_version.py b/packages/google-apps-script-type/google/apps/script/type/meet/gapic_version.py new file mode 100644 index 000000000000..af283a821985 --- /dev/null +++ b/packages/google-apps-script-type/google/apps/script/type/meet/gapic_version.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +__version__ = "0.8.1" # {x-release-please-version} diff --git a/packages/google-apps-script-type/google/apps/script/type/meet/py.typed b/packages/google-apps-script-type/google/apps/script/type/meet/py.typed new file mode 100644 index 000000000000..04b9596b161d --- /dev/null +++ b/packages/google-apps-script-type/google/apps/script/type/meet/py.typed @@ -0,0 +1,2 @@ +# Marker file for PEP 561. +# The google-apps-script-type package uses inline types. diff --git a/packages/google-apps-script-type/google/apps/script/type/meet/services/__init__.py b/packages/google-apps-script-type/google/apps/script/type/meet/services/__init__.py new file mode 100644 index 000000000000..32b36c5c4fe0 --- /dev/null +++ b/packages/google-apps-script-type/google/apps/script/type/meet/services/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/packages/google-apps-script-type/google/apps/script/type/meet/types/__init__.py b/packages/google-apps-script-type/google/apps/script/type/meet/types/__init__.py new file mode 100644 index 000000000000..66080a1cb194 --- /dev/null +++ b/packages/google-apps-script-type/google/apps/script/type/meet/types/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from .meet_addon_manifest import ( + MeetAddOnManifest, + Web, +) + +__all__ = ( + "MeetAddOnManifest", + "Web", +) diff --git a/packages/google-apps-script-type/google/apps/script/type/meet/types/meet_addon_manifest.py b/packages/google-apps-script-type/google/apps/script/type/meet/types/meet_addon_manifest.py new file mode 100644 index 000000000000..7823f8e594cf --- /dev/null +++ b/packages/google-apps-script-type/google/apps/script/type/meet/types/meet_addon_manifest.py @@ -0,0 +1,219 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from __future__ import annotations + +from typing import MutableMapping, MutableSequence + +import proto # type: ignore + +from google.apps.script.type.types import extension_point + +__protobuf__ = proto.module( + package="google.apps.script.type.meet", + manifest={ + "MeetAddOnManifest", + "Web", + }, +) + + +class MeetAddOnManifest(proto.Message): + r"""Meet add-on manifest. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + homepage_trigger (google.apps.script.type.types.HomepageExtensionPoint): + If present, this overrides the configuration from + ``addOns.common.homepageTrigger``. + web (google.apps.script.type.meet.types.Web): + Details for addons that enhance the Meet web + client. + terms_uri (str): + A link to the terms of service for the + add-on, if any should be shown. + + This field is a member of `oneof`_ ``_terms_uri``. + supports_collaboration (bool): + Whether the addon supports collaboration or + inviting others into the addon experience. + """ + + homepage_trigger: extension_point.HomepageExtensionPoint = proto.Field( + proto.MESSAGE, + number=2, + message=extension_point.HomepageExtensionPoint, + ) + web: "Web" = proto.Field( + proto.MESSAGE, + number=3, + message="Web", + ) + terms_uri: str = proto.Field( + proto.STRING, + number=6, + optional=True, + ) + supports_collaboration: bool = proto.Field( + proto.BOOL, + number=7, + ) + + +class Web(proto.Message): + r"""Details for addons that enhance the Meet web client. + + Attributes: + side_panel_uri (str): + The URI for the side panel iframe. + side_panel_url (str): + The URL for the side panel iframe. + main_stage_uri (str): + The URI for the "main stage" iframe. + supports_screen_sharing (bool): + Whether the addon supports screen sharing the + main stage. + supports_collaboration (bool): + Whether the addon supports collaboration or + inviting others into the addon experience. This + field is deprecated now, please use the top + level field in MeetAddOnManifest. + supports_pop_out (bool): + Whether the addon supports popping out to a + browser PiP experience. + host_origins (MutableSequence[str]): + Deprecated, legacy name. Origins that should be added to the + frame-src property of the iframe containing the third party + site. Use add_on_origins instead. + add_on_origins (MutableSequence[str]): + Origins that should be added to the frame-src + property of the iframe containing the third + party site. + open_state (google.apps.script.type.meet.types.Web.State): + The initial state when the addon is opened. + supports_collaboration_host_controls (bool): + Whether the collaboration add-on supports + host controls. + logo_url (str): + The URL of the logo to be displayed for the + addon. If not specified, the logo defaults to + the logo in the common section of the manifest. + dark_mode_logo_url (str): + A dark mode version of the logo_url. + display_flow (google.apps.script.type.meet.types.Web.DisplayFlow): + The display flow the add-on will follow when + launched. + """ + + class State(proto.Enum): + r"""Enum for specifying initial addon opening state. + + Values: + STATE_UNSPECIFIED (0): + Initial state has not been specified with the + addon. + SIDE_PANEL_ONLY (1): + The addon opens with only the side panel + active. + MAIN_STAGE_ONLY (2): + The addon opens with only the main stage + active. + SIDE_PANEL_AND_MAIN_STAGE (3): + The addon opens with both the side panel and + the main stage active. + """ + + STATE_UNSPECIFIED = 0 + SIDE_PANEL_ONLY = 1 + MAIN_STAGE_ONLY = 2 + SIDE_PANEL_AND_MAIN_STAGE = 3 + + class DisplayFlow(proto.Enum): + r"""Enum for specifying the display flow the add-on will follow + when launched + + Values: + DISPLAY_FLOW_UNSPECIFIED (0): + Display flow has not been specified. + FOCUS (1): + Add-on should launch in the "focus" display + flow. + AUGMENT (2): + Add-on should launch in the "augment" display + flow. + """ + + DISPLAY_FLOW_UNSPECIFIED = 0 + FOCUS = 1 + AUGMENT = 2 + + side_panel_uri: str = proto.Field( + proto.STRING, + number=1, + ) + side_panel_url: str = proto.Field( + proto.STRING, + number=12, + ) + main_stage_uri: str = proto.Field( + proto.STRING, + number=2, + ) + supports_screen_sharing: bool = proto.Field( + proto.BOOL, + number=3, + ) + supports_collaboration: bool = proto.Field( + proto.BOOL, + number=4, + ) + supports_pop_out: bool = proto.Field( + proto.BOOL, + number=5, + ) + host_origins: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=6, + ) + add_on_origins: MutableSequence[str] = proto.RepeatedField( + proto.STRING, + number=11, + ) + open_state: State = proto.Field( + proto.ENUM, + number=7, + enum=State, + ) + supports_collaboration_host_controls: bool = proto.Field( + proto.BOOL, + number=8, + ) + logo_url: str = proto.Field( + proto.STRING, + number=9, + ) + dark_mode_logo_url: str = proto.Field( + proto.STRING, + number=13, + ) + display_flow: DisplayFlow = proto.Field( + proto.ENUM, + number=10, + enum=DisplayFlow, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/packages/google-apps-script-type/tests/unit/gapic/meet/__init__.py b/packages/google-apps-script-type/tests/unit/gapic/meet/__init__.py new file mode 100644 index 000000000000..32b36c5c4fe0 --- /dev/null +++ b/packages/google-apps-script-type/tests/unit/gapic/meet/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# diff --git a/packages/google-apps-script-type/tests/unit/gapic/meet/test_compat.py b/packages/google-apps-script-type/tests/unit/gapic/meet/test_compat.py new file mode 100644 index 000000000000..545ac8ab9dc1 --- /dev/null +++ b/packages/google-apps-script-type/tests/unit/gapic/meet/test_compat.py @@ -0,0 +1,429 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +"""Tests for the compatibility module for older versions of google-api-core.""" + +import json +import os +from unittest import mock + +import google.auth.transport.mtls +import pytest +from google.api_core.universe import EmptyUniverseError +from google.auth.exceptions import MutualTLSChannelError +from google.protobuf import descriptor_pb2 + +from google.apps.script.type.meet._compat import ( + get_api_endpoint, + get_default_mtls_endpoint, + get_universe_domain, + read_environment_variables, + should_use_client_cert, + transcode_request, +) + + +def test_get_universe_domain(): + # When universe_domain is provided + assert get_universe_domain("foo.com", default_universe="default.com") == "foo.com" + assert ( + get_universe_domain(" foo.com ", default_universe="default.com") == "foo.com" + ) + + # When universe_domain is None, falls back to default_universe + assert get_universe_domain(None, default_universe="default.com") == "default.com" + + # When multiple potential universes are provided, resolves in order of preference + assert ( + get_universe_domain("foo.com", "bar.com", default_universe="default.com") + == "foo.com" + ) + assert ( + get_universe_domain(None, "bar.com", default_universe="default.com") + == "bar.com" + ) + assert ( + get_universe_domain(None, None, default_universe="default.com") == "default.com" + ) + + # EmptyUniverseError raised when resolved value is empty string + with pytest.raises(EmptyUniverseError) as excinfo: + get_universe_domain("", default_universe="default.com") + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + with pytest.raises(EmptyUniverseError) as excinfo: + get_universe_domain(" ", default_universe="default.com") + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + with pytest.raises(EmptyUniverseError) as excinfo: + get_universe_domain(None, "", default_universe="default.com") + assert str(excinfo.value) == "Universe Domain cannot be an empty string." + + +def test_get_default_mtls_endpoint(): + # Test valid API endpoints + assert get_default_mtls_endpoint("foo.googleapis.com") == "foo.mtls.googleapis.com" + assert ( + get_default_mtls_endpoint("foo.sandbox.googleapis.com") + == "foo.mtls.sandbox.googleapis.com" + ) + # Test case-insensitivity + assert get_default_mtls_endpoint("foo.GoogleAPIs.com") == "foo.mtls.googleapis.com" + assert ( + get_default_mtls_endpoint("foo.Sandbox.GoogleAPIs.com") + == "foo.mtls.sandbox.googleapis.com" + ) + + # Test valid API endpoints with schemes + assert ( + get_default_mtls_endpoint("https://foo.googleapis.com") + == "https://foo.mtls.googleapis.com" + ) + assert ( + get_default_mtls_endpoint("http://foo.googleapis.com:8080/v1") + == "http://foo.mtls.googleapis.com:8080/v1" + ) + + # Test valid API endpoints with ports + assert ( + get_default_mtls_endpoint("foo.googleapis.com:443") + == "foo.mtls.googleapis.com:443" + ) + assert ( + get_default_mtls_endpoint("foo.sandbox.googleapis.com:443") + == "foo.mtls.sandbox.googleapis.com:443" + ) + # Test case-insensitivity with ports + assert ( + get_default_mtls_endpoint("foo.GoogleAPIs.com:443") + == "foo.mtls.googleapis.com:443" + ) + assert ( + get_default_mtls_endpoint("foo.Sandbox.GoogleAPIs.com:443") + == "foo.mtls.sandbox.googleapis.com:443" + ) + + # Test endpoints that shouldn't be converted + assert ( + get_default_mtls_endpoint("foo.mtls.googleapis.com") + == "foo.mtls.googleapis.com" + ) + assert get_default_mtls_endpoint("foo.com") == "foo.com" + assert get_default_mtls_endpoint("foo.com:8080") == "foo.com:8080" + + # Test empty/None endpoints + assert get_default_mtls_endpoint("") == "" + assert get_default_mtls_endpoint(None) is None + + # Test endpoints without host + assert get_default_mtls_endpoint("http://") == "http://" + assert get_default_mtls_endpoint("https://") == "https://" + + +@pytest.mark.parametrize( + "api_override,universe_domain,default_universe,default_mtls_endpoint,default_endpoint_template,use_mtls,expected", + [ + ( + "foo.com", + "googleapis.com", + "googleapis.com", + "foo.mtls.googleapis.com", + "foo.{UNIVERSE_DOMAIN}", + True, + "foo.com", + ), + ( + None, + "googleapis.com", + "googleapis.com", + "foo.mtls.googleapis.com", + "foo.{UNIVERSE_DOMAIN}", + True, + "foo.mtls.googleapis.com", + ), + ( + None, + "googleapis.com", + "googleapis.com", + "foo.mtls.googleapis.com", + "foo.{UNIVERSE_DOMAIN}", + False, + "foo.googleapis.com", + ), + ( + None, + "bar.com", + "googleapis.com", + "foo.mtls.googleapis.com", + "foo.{UNIVERSE_DOMAIN}", + True, + MutualTLSChannelError, + ), + ( + None, + "googleapis.com", + "googleapis.com", + None, + "foo.{UNIVERSE_DOMAIN}", + True, + ValueError, + ), + ], +) +def test_get_api_endpoint( + api_override, + universe_domain, + default_universe, + default_mtls_endpoint, + default_endpoint_template, + use_mtls, + expected, +): + if isinstance(expected, type) and issubclass(expected, Exception): + with pytest.raises(expected): + get_api_endpoint( + api_override, + universe_domain, + default_universe, + default_mtls_endpoint, + default_endpoint_template, + use_mtls, + ) + else: + assert ( + get_api_endpoint( + api_override, + universe_domain, + default_universe, + default_mtls_endpoint, + default_endpoint_template, + use_mtls, + ) + == expected + ) + + +def test_should_use_client_cert_fallback_env(): + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}, clear=True + ): + assert should_use_client_cert() is True + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}, clear=True + ): + assert should_use_client_cert() is False + + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "invalid"}, clear=True + ): + if not hasattr(google.auth.transport.mtls, "should_use_client_cert"): + with pytest.raises( + ValueError, + match="Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`", + ): + should_use_client_cert() + + +def test_transcode_basic(): + # We use FieldDescriptorProto as it has standard primitive fields and nested messages. + http_options = [ + { + "method": "get", + "uri": "/v1/test/{name}", + } + ] + + request = descriptor_pb2.FieldDescriptorProto() + request.name = "my-field" + request.number = 123 + + transcoded, body, query_params = transcode_request(http_options, request) + + assert transcoded["method"] == "get" + assert transcoded["uri"] == "/v1/test/my-field" + assert body is None + # 'number' should be in query parameters + assert "number" in query_params + assert query_params["number"] == 123 + + +def test_transcode_with_nested_field(): + http_options = [ + { + "method": "get", + "uri": "/v1/test/{options.deprecated}/{name}", + } + ] + + request = descriptor_pb2.FieldDescriptorProto() + request.name = "my-field" + request.options.deprecated = True + request.number = 123 + + transcoded, body, query_params = transcode_request(http_options, request) + + assert transcoded["method"] == "get" + assert transcoded["uri"] == "/v1/test/True/my-field" + assert body is None + assert "number" in query_params + assert query_params["number"] == 123 + + +def test_transcode_with_body(): + http_options = [ + { + "method": "post", + "uri": "/v1/test/{name}", + "body": "options", + } + ] + + request = descriptor_pb2.FieldDescriptorProto() + request.name = "my-field" + request.options.deprecated = True + request.number = 123 + + transcoded, body, query_params = transcode_request(http_options, request) + + assert transcoded["method"] == "post" + assert transcoded["uri"] == "/v1/test/my-field" + assert body is not None + body_data = json.loads(body) + assert body_data["deprecated"] is True + # Query parameters should not contain 'options' (the body) + assert "number" in query_params + assert query_params["number"] == 123 + assert "options" not in query_params + + +def test_transcode_with_required_fields_default_values(): + http_options = [ + { + "method": "get", + "uri": "/v1/test/{name}", + } + ] + + request = descriptor_pb2.FieldDescriptorProto() + request.name = "my-field" + + required_defaults = {"requiredQueryParam": "default-val"} + + transcoded, body, query_params = transcode_request( + http_options, + request, + required_fields_default_values=required_defaults, + ) + + assert query_params["requiredQueryParam"] == "default-val" + + +def test_transcode_with_numeric_enums(): + http_options = [ + { + "method": "get", + "uri": "/v1/test/{name}", + } + ] + + request = descriptor_pb2.FieldDescriptorProto() + request.name = "my-field" + request.type = descriptor_pb2.FieldDescriptorProto.TYPE_STRING + + # Without numeric enums + _, _, query_params = transcode_request( + http_options, request, rest_numeric_enums=False + ) + assert query_params["type"] == "TYPE_STRING" + + # With numeric enums + _, _, query_params = transcode_request( + http_options, request, rest_numeric_enums=True + ) + # Type number for TYPE_STRING is 9 + assert query_params["type"] == 9 + assert query_params["$alt"] == "json;enum-encoding=int" + + +def test_transcode_no_query_params(): + http_options = [{"method": "get", "uri": "/v1/test"}] + request = descriptor_pb2.FieldDescriptorProto() + + with mock.patch( + "google.api_core.path_template.transcode", + return_value={"method": "get", "uri": "/v1/test"}, + ): + transcoded, body, query_params = transcode_request(http_options, request) + assert query_params == {} + + +def test_transcode_with_required_fields_existing_key(): + http_options = [ + { + "method": "get", + "uri": "/v1/test", + } + ] + + request = descriptor_pb2.FieldDescriptorProto() + request.name = "custom-name" + + required_defaults = {"name": "default-name"} + + transcoded, body, query_params = transcode_request( + http_options, + request, + required_fields_default_values=required_defaults, + ) + + assert query_params["name"] == "custom-name" + + +def test_transcode_request_invalid_request(): + http_options = [{"method": "get", "uri": "/v1/test"}] + with pytest.raises(TypeError, match="request cannot be None"): + transcode_request(http_options, None) + + +def test_transcode_request_proto_plus_wrapper(): + http_options = [{"method": "get", "uri": "/v1/test/{name}"}] + mock_pb = descriptor_pb2.FieldDescriptorProto() + mock_pb.name = "proto-plus-field" + + mock_proto_plus = mock.Mock() + mock_proto_plus._pb = mock_pb + + transcoded, _, _ = transcode_request(http_options, mock_proto_plus) + assert transcoded["uri"] == "/v1/test/proto-plus-field" + + +def test_read_environment_variables(): + with mock.patch.dict( + os.environ, + { + "GOOGLE_API_USE_CLIENT_CERTIFICATE": "true", + "GOOGLE_API_USE_MTLS_ENDPOINT": "always", + "GOOGLE_CLOUD_UNIVERSE_DOMAIN": "foo.com", + }, + ): + use_cert, mtls_endpoint, universe_domain = read_environment_variables() + assert use_cert is True + assert mtls_endpoint == "always" + assert universe_domain == "foo.com" + + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "invalid"}): + with pytest.raises(MutualTLSChannelError): + read_environment_variables() diff --git a/packages/google-apps-script-type/tests/unit/gapic/meet/test_meet.py b/packages/google-apps-script-type/tests/unit/gapic/meet/test_meet.py new file mode 100644 index 000000000000..80434742e5f2 --- /dev/null +++ b/packages/google-apps-script-type/tests/unit/gapic/meet/test_meet.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from google.apps.script.type import meet + +# NOTE: These are dummy tests to reach 100% coverage +# They simply check that the message can be created. + + +def test_meet(): + meet.MeetAddOnManifest() diff --git a/release-please-bulk-config.json b/release-please-bulk-config.json index da68c7e72d77..8cda1d3e27bb 100644 --- a/release-please-bulk-config.json +++ b/release-please-bulk-config.json @@ -177,6 +177,7 @@ "google/apps/script/type/drive/gapic_version.py", "google/apps/script/type/gapic_version.py", "google/apps/script/type/gmail/gapic_version.py", + "google/apps/script/type/meet/gapic_version.py", "google/apps/script/type/sheets/gapic_version.py", "google/apps/script/type/slides/gapic_version.py" ]