Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
feat: update to the latest version of the code generator (#147)
Browse files Browse the repository at this point in the history
The compute protos are now [available in googleapis/googleapis](https://github.com/googleapis/googleapis/tree/master/google/cloud/compute/v1), and the generated code is also available in googleapis/googleapis-gen [here](https://github.com/googleapis/googleapis-gen/tree/master/google/cloud/compute/v1/compute-small-v1-py). This PR pulls in the latest version of the generated client from googleapis-gen, which may have significant differences. I've added the `do not merge` label while we discuss whether any differences could break user code.

This PR also deletes `synth.py` and adds configuration files for owl bot. owl bot will save time for maintainers as it will automatically open PRs when there are updates in googleapis-gen without requiring maintainers to run synthtool to build the client from protos. Additionally, similar to autosynth, PRs will be automatically opened when there are updates to templated files.

fix(deps): require google-api-core >=2.2.0
fix(deps): require proto-plus >=1.19.7
docs: list oneofs in docstring
fix: add 'dict' annotation type to 'request'
feat: support self-signed JWT flow for service accounts
chore(samples): Merging usage bucket tests into one, to avoid race conditions
  • Loading branch information
parthea committed Nov 16, 2021
1 parent 2483691 commit de739a1
Show file tree
Hide file tree
Showing 410 changed files with 88,267 additions and 41,238 deletions.
17 changes: 17 additions & 0 deletions .github/.OwlBot.lock.yaml
@@ -0,0 +1,17 @@
# Copyright 2021 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.

docker:
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest
digest: sha256:ec49167c606648a063d1222220b48119c912562849a0528f35bfb592a9f72737
25 changes: 25 additions & 0 deletions .github/.OwlBot.yaml
@@ -0,0 +1,25 @@
# Copyright 2021 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.

docker:
image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest

deep-remove-regex:
- /owl-bot-staging

deep-copy-regex:
- source: /google/cloud/compute/(v.*)/compute-v.*-py/(.*)
dest: /owl-bot-staging/$1/$2

begin-after-commit-hash: 70f7f0525414fe4dfeb2fc2e81546b073f83a621
7 changes: 5 additions & 2 deletions docs/index.rst
@@ -1,5 +1,8 @@
.. include:: README.rst

.. include:: multiprocessing.rst


API Reference
-------------
.. toctree::
Expand All @@ -15,6 +18,6 @@ Changelog
For a list of all ``google-cloud-compute`` releases:

.. toctree::
:maxdepth: 2
:maxdepth: 2

changelog
changelog
59 changes: 42 additions & 17 deletions google/cloud/compute_v1/services/accelerator_types/client.py
Expand Up @@ -14,22 +14,26 @@
# limitations under the License.
#
from collections import OrderedDict
from distutils import util
import os
import re
from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union
from typing import Dict, Optional, Sequence, Tuple, Type, Union
import pkg_resources

from google.api_core import client_options as client_options_lib # type: ignore
from google.api_core import exceptions as core_exceptions # type: ignore
from google.api_core import gapic_v1 # type: ignore
from google.api_core import retry as retries # type: ignore
from google.api_core import client_options as client_options_lib
from google.api_core import exceptions as core_exceptions
from google.api_core import gapic_v1
from google.api_core import retry as retries
from google.auth import credentials as ga_credentials # type: ignore
from google.auth.transport import mtls # type: ignore
from google.auth.transport.grpc import SslCredentials # type: ignore
from google.auth.exceptions import MutualTLSChannelError # type: ignore
from google.oauth2 import service_account # type: ignore

try:
OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault]
except AttributeError: # pragma: NO COVER
OptionalRetry = Union[retries.Retry, object] # type: ignore

from google.cloud.compute_v1.services.accelerator_types import pagers
from google.cloud.compute_v1.types import compute
from .transports.base import AcceleratorTypesTransport, DEFAULT_CLIENT_INFO
Expand Down Expand Up @@ -265,8 +269,15 @@ def __init__(
client_options = client_options_lib.ClientOptions()

# Create SSL credentials for mutual TLS if needed.
use_client_cert = bool(
util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))
if os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") not in (
"true",
"false",
):
raise ValueError(
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
)
use_client_cert = (
os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true"
)

client_cert_source_func = None
Expand Down Expand Up @@ -328,21 +339,22 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=True,
)

def aggregated_list(
self,
request: compute.AggregatedListAcceleratorTypesRequest = None,
request: Union[compute.AggregatedListAcceleratorTypesRequest, dict] = None,
*,
project: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.AggregatedListPager:
r"""Retrieves an aggregated list of accelerator types.
Args:
request (google.cloud.compute_v1.types.AggregatedListAcceleratorTypesRequest):
request (Union[google.cloud.compute_v1.types.AggregatedListAcceleratorTypesRequest, dict]):
The request object. A request message for
AcceleratorTypes.AggregatedList. See the method
description for details.
Expand Down Expand Up @@ -403,19 +415,19 @@ def aggregated_list(

def get(
self,
request: compute.GetAcceleratorTypeRequest = None,
request: Union[compute.GetAcceleratorTypeRequest, dict] = None,
*,
project: str = None,
zone: str = None,
accelerator_type: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> compute.AcceleratorType:
r"""Returns the specified accelerator type.
Args:
request (google.cloud.compute_v1.types.GetAcceleratorTypeRequest):
request (Union[google.cloud.compute_v1.types.GetAcceleratorTypeRequest, dict]):
The request object. A request message for
AcceleratorTypes.Get. See the method description for
details.
Expand Down Expand Up @@ -493,19 +505,19 @@ def get(

def list(
self,
request: compute.ListAcceleratorTypesRequest = None,
request: Union[compute.ListAcceleratorTypesRequest, dict] = None,
*,
project: str = None,
zone: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.ListPager:
r"""Retrieves a list of accelerator types that are
available to the specified project.
Args:
request (google.cloud.compute_v1.types.ListAcceleratorTypesRequest):
request (Union[google.cloud.compute_v1.types.ListAcceleratorTypesRequest, dict]):
The request object. A request message for
AcceleratorTypes.List. See the method description for
details.
Expand Down Expand Up @@ -574,6 +586,19 @@ def list(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
12 changes: 6 additions & 6 deletions google/cloud/compute_v1/services/accelerator_types/pagers.py
Expand Up @@ -15,13 +15,13 @@
#
from typing import (
Any,
AsyncIterable,
AsyncIterator,
Awaitable,
Callable,
Iterable,
Sequence,
Tuple,
Optional,
Iterator,
)

from google.cloud.compute_v1.types import compute
Expand Down Expand Up @@ -74,14 +74,14 @@ def __getattr__(self, name: str) -> Any:
return getattr(self._response, name)

@property
def pages(self) -> Iterable[compute.AcceleratorTypeAggregatedList]:
def pages(self) -> Iterator[compute.AcceleratorTypeAggregatedList]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = self._method(self._request, metadata=self._metadata)
yield self._response

def __iter__(self) -> Iterable[Tuple[str, compute.AcceleratorTypesScopedList]]:
def __iter__(self) -> Iterator[Tuple[str, compute.AcceleratorTypesScopedList]]:
for page in self.pages:
yield from page.items.items()

Expand Down Expand Up @@ -139,14 +139,14 @@ def __getattr__(self, name: str) -> Any:
return getattr(self._response, name)

@property
def pages(self) -> Iterable[compute.AcceleratorTypeList]:
def pages(self) -> Iterator[compute.AcceleratorTypeList]:
yield self._response
while self._response.next_page_token:
self._request.page_token = self._response.next_page_token
self._response = self._method(self._request, metadata=self._metadata)
yield self._response

def __iter__(self) -> Iterable[compute.AcceleratorType]:
def __iter__(self) -> Iterator[compute.AcceleratorType]:
for page in self.pages:
yield from page.items

Expand Down
Expand Up @@ -15,15 +15,13 @@
#
import abc
from typing import Awaitable, Callable, Dict, Optional, Sequence, Union
import packaging.version
import pkg_resources
from requests import __version__ as requests_version

import google.auth # type: ignore
import google.api_core # type: ignore
from google.api_core import exceptions as core_exceptions # type: ignore
from google.api_core import gapic_v1 # type: ignore
from google.api_core import retry as retries # type: ignore
import google.api_core
from google.api_core import exceptions as core_exceptions
from google.api_core import gapic_v1
from google.api_core import retry as retries
from google.auth import credentials as ga_credentials # type: ignore
from google.oauth2 import service_account # type: ignore

Expand All @@ -32,21 +30,10 @@
try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
gapic_version=pkg_resources.get_distribution("google-cloud-compute",).version,
grpc_version=None,
rest_version=requests_version,
)
except pkg_resources.DistributionNotFound:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()

try:
# google.auth.__version__ was added in 1.26.0
_GOOGLE_AUTH_VERSION = google.auth.__version__
except AttributeError:
try: # try pkg_resources if it is available
_GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version
except pkg_resources.DistributionNotFound: # pragma: NO COVER
_GOOGLE_AUTH_VERSION = None


class AcceleratorTypesTransport(abc.ABC):
"""Abstract transport class for AcceleratorTypes."""
Expand Down Expand Up @@ -100,7 +87,7 @@ def __init__(
host += ":443"
self._host = host

scopes_kwargs = self._get_scopes_kwargs(self._host, scopes)
scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES}

# Save the scopes.
self._scopes = scopes
Expand All @@ -122,7 +109,7 @@ def __init__(
**scopes_kwargs, quota_project_id=quota_project_id
)

# If the credentials is service account credentials, then always try to use self signed JWT.
# If the credentials are service account credentials, then always try to use self signed JWT.
if (
always_use_jwt_access
and isinstance(credentials, service_account.Credentials)
Expand All @@ -133,29 +120,6 @@ def __init__(
# Save the credentials.
self._credentials = credentials

# TODO(busunkim): This method is in the base transport
# to avoid duplicating code across the transport classes. These functions
# should be deleted once the minimum required versions of google-auth is increased.

# TODO: Remove this function once google-auth >= 1.25.0 is required
@classmethod
def _get_scopes_kwargs(
cls, host: str, scopes: Optional[Sequence[str]]
) -> Dict[str, Optional[Sequence[str]]]:
"""Returns scopes kwargs to pass to google-auth methods depending on the google-auth version"""

scopes_kwargs = {}

if _GOOGLE_AUTH_VERSION and (
packaging.version.parse(_GOOGLE_AUTH_VERSION)
>= packaging.version.parse("1.25.0")
):
scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES}
else:
scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES}

return scopes_kwargs

def _prep_wrapped_messages(self, client_info):
# Precompute the wrapped methods.
self._wrapped_methods = {
Expand All @@ -170,6 +134,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def aggregated_list(
self,
Expand Down

0 comments on commit de739a1

Please sign in to comment.