-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement async rest transport constructor (#2123)
- Loading branch information
Showing
17 changed files
with
380 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 79 additions & 4 deletions
83
.../templates/%namespace/%name_%version/%sub/services/%service/transports/rest_asyncio.py.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,80 @@ | ||
{# TODO: Remove the following condition for async rest transport once support for it is GA: | ||
# {% if rest_async_io_enabled %} | ||
# See related issue: https://github.com/googleapis/gapic-generator-python/issues/2121. | ||
#} | ||
{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121): Remove the following variable (and the condition later in this file) for async rest transport once support for it is GA. #} | ||
{% set rest_async_io_enabled = api.all_library_settings[api.naming.proto_package].python_settings.experimental_features.rest_async_io_enabled %} | ||
{% extends '_base.py.j2' %} | ||
|
||
{% block content %} | ||
|
||
from google.api_core import gapic_v1 | ||
|
||
from typing import Any, Optional | ||
|
||
from .rest_base import _Base{{ service.name }}RestTransport | ||
|
||
from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO | ||
|
||
{# TODO (https://github.com/googleapis/gapic-generator-python/issues/2128): Update `rest_version` to include the transport dependency version. #} | ||
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( | ||
gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version, | ||
grpc_version=None, | ||
rest_version=None, | ||
) | ||
|
||
class Async{{service.name}}RestTransport(_Base{{ service.name }}RestTransport): | ||
"""Asynchronous REST backend transport for {{ service.name }}. | ||
|
||
{{ service.meta.doc|rst(width=72, indent=4) }} | ||
|
||
This class defines the same methods as the primary client, so the | ||
primary client can load the underlying transport implementation | ||
and call it. | ||
|
||
It sends JSON representations of protocol buffers over HTTP/1.1 | ||
""" | ||
def __init__(self, *, | ||
host: str{% if service.host %} = '{{ service.host }}'{% endif %}, | ||
{# TODO (https://github.com/googleapis/gapic-generator-python/issues/2129): Update the default type for credentials. #} | ||
credentials: Optional[Any] = None, | ||
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, | ||
url_scheme: str = 'https', | ||
) -> None: | ||
"""Instantiate the transport. | ||
|
||
{% if not opts.rest_numeric_enums %} | ||
NOTE: This async REST transport functionality is currently in a beta | ||
state (preview). We welcome your feedback via a GitHub issue in | ||
this library's repository. Thank you! | ||
{% endif %} | ||
|
||
Args: | ||
host ({% if service.host %}Optional[str]{% else %}str{% endif %}): | ||
{{ ' ' }}The hostname to connect to {% if service.host %}(default: '{{ service.host }}'){% endif %}. | ||
{# TODO (https://github.com/googleapis/gapic-generator-python/issues/2129): Update the default type for credentials. #} | ||
credentials (Optional[Any]): The | ||
authorization credentials to attach to requests. These | ||
credentials identify the application to the service; if none | ||
are specified, the client will attempt to ascertain the | ||
credentials from the environment. | ||
client_info (google.api_core.gapic_v1.client_info.ClientInfo): | ||
The client info used to send a user-agent string along with | ||
API requests. If ``None``, then default info will be used. | ||
Generally, you only need to set this if you are developing | ||
your own client library. | ||
url_scheme (str): the protocol scheme for the API endpoint. Normally | ||
"https", but for testing or local servers, | ||
"http" can be specified. | ||
""" | ||
# Run the base constructor | ||
super().__init__( | ||
host=host, | ||
credentials=credentials, | ||
client_info=client_info, | ||
always_use_jwt_access=False, | ||
url_scheme=url_scheme, | ||
api_audience=None | ||
) | ||
|
||
@property | ||
def kind(self) -> str: | ||
return "rest_asyncio" | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.