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

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: add common resource helper methods; expose client transport; ad…
…d shebang to fixup scripts (#57)

This PR was generated using Autosynth. 🌈

Synth log will be available here:
https://source.cloud.google.com/results/invocations/6c49b023-73d4-4d21-9e9f-028a9067e602/targets

- [ ] To automatically regenerate this PR, check this box.
  • Loading branch information
yoshi-automation committed Dec 3, 2020
1 parent 8d02b18 commit b5c022b
Show file tree
Hide file tree
Showing 20 changed files with 1,294 additions and 459 deletions.
14 changes: 14 additions & 0 deletions .github/sync-repo-settings.yaml
@@ -0,0 +1,14 @@

# https://github.com/googleapis/repo-automation-bots/tree/master/packages/sync-repo-settings
# Rules for master branch protection
branchProtectionRules:
# Identifies the protection rule pattern. Name of the branch to be protected.
# Defaults to `master`
- pattern: master
requiredStatusCheckContexts:
- 'Kokoro'
- 'cla/google'
- 'Samples - Lint'
- 'Samples - Python 3.6'
- 'Samples - Python 3.7'
- 'Samples - Python 3.8'
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -5,7 +5,7 @@

### ⚠ BREAKING CHANGES

* migrate to use microgen (#44)
* migrate to use microgen. See [Migration Guide](https://googleapis.dev/python/secretmanager/latest/UPGRADING.html) (#44)

### Features

Expand Down
1 change: 1 addition & 0 deletions docs/secretmanager_v1/types.rst
Expand Up @@ -3,3 +3,4 @@ Types for Google Cloud Secretmanager v1 API

.. automodule:: google.cloud.secretmanager_v1.types
:members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/secretmanager_v1beta1/types.rst
Expand Up @@ -3,3 +3,4 @@ Types for Google Cloud Secretmanager v1beta1 API

.. automodule:: google.cloud.secretmanager_v1beta1.types
:members:
:show-inheritance:
Expand Up @@ -58,10 +58,52 @@ class SecretManagerServiceAsyncClient:

secret_path = staticmethod(SecretManagerServiceClient.secret_path)
parse_secret_path = staticmethod(SecretManagerServiceClient.parse_secret_path)
secret_version_path = staticmethod(SecretManagerServiceClient.secret_version_path)
parse_secret_version_path = staticmethod(
SecretManagerServiceClient.parse_secret_version_path
)

common_billing_account_path = staticmethod(
SecretManagerServiceClient.common_billing_account_path
)
parse_common_billing_account_path = staticmethod(
SecretManagerServiceClient.parse_common_billing_account_path
)

common_folder_path = staticmethod(SecretManagerServiceClient.common_folder_path)
parse_common_folder_path = staticmethod(
SecretManagerServiceClient.parse_common_folder_path
)

common_organization_path = staticmethod(
SecretManagerServiceClient.common_organization_path
)
parse_common_organization_path = staticmethod(
SecretManagerServiceClient.parse_common_organization_path
)

common_project_path = staticmethod(SecretManagerServiceClient.common_project_path)
parse_common_project_path = staticmethod(
SecretManagerServiceClient.parse_common_project_path
)

common_location_path = staticmethod(SecretManagerServiceClient.common_location_path)
parse_common_location_path = staticmethod(
SecretManagerServiceClient.parse_common_location_path
)

from_service_account_file = SecretManagerServiceClient.from_service_account_file
from_service_account_json = from_service_account_file

@property
def transport(self) -> SecretManagerServiceTransport:
"""Return the transport used by the client instance.
Returns:
SecretManagerServiceTransport: The transport used by the client instance.
"""
return self._client.transport

get_transport_class = functools.partial(
type(SecretManagerServiceClient).get_transport_class,
type(SecretManagerServiceClient),
Expand Down Expand Up @@ -157,7 +199,8 @@ async def list_secrets(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([parent]):
has_flattened_params = any([parent])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down Expand Up @@ -261,7 +304,8 @@ async def create_secret(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([parent, secret_id, secret]):
has_flattened_params = any([parent, secret_id, secret])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down Expand Up @@ -349,7 +393,8 @@ async def add_secret_version(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([parent, payload]):
has_flattened_params = any([parent, payload])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down Expand Up @@ -429,7 +474,8 @@ async def get_secret(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([name]):
has_flattened_params = any([name])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down Expand Up @@ -513,7 +559,8 @@ async def update_secret(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([secret, update_mask]):
has_flattened_params = any([secret, update_mask])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down Expand Up @@ -583,7 +630,8 @@ async def delete_secret(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([name]):
has_flattened_params = any([name])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down Expand Up @@ -661,7 +709,8 @@ async def list_secret_versions(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([parent]):
has_flattened_params = any([parent])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down Expand Up @@ -747,7 +796,8 @@ async def get_secret_version(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([name]):
has_flattened_params = any([name])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down Expand Up @@ -825,7 +875,8 @@ async def access_secret_version(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([name]):
has_flattened_params = any([name])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand All @@ -848,7 +899,7 @@ async def access_secret_version(
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(
exceptions.Unknown, exceptions.ServiceUnavailable,
exceptions.ServiceUnavailable, exceptions.Unknown,
),
),
default_timeout=60.0,
Expand Down Expand Up @@ -913,7 +964,8 @@ async def disable_secret_version(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([name]):
has_flattened_params = any([name])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down Expand Up @@ -993,7 +1045,8 @@ async def enable_secret_version(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([name]):
has_flattened_params = any([name])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down Expand Up @@ -1074,7 +1127,8 @@ async def destroy_secret_version(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([name]):
has_flattened_params = any([name])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down
Expand Up @@ -19,10 +19,10 @@
from distutils import util
import os
import re
from typing import Callable, Dict, Sequence, Tuple, Type, Union
from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union
import pkg_resources

import google.api_core.client_options as ClientOptions # type: ignore
from google.api_core import client_options as client_options_lib # type: ignore
from google.api_core import exceptions # type: ignore
from google.api_core import gapic_v1 # type: ignore
from google.api_core import retry as retries # type: ignore
Expand Down Expand Up @@ -144,6 +144,15 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):

from_service_account_json = from_service_account_file

@property
def transport(self) -> SecretManagerServiceTransport:
"""Return the transport used by the client instance.
Returns:
SecretManagerServiceTransport: The transport used by the client instance.
"""
return self._transport

@staticmethod
def secret_path(project: str, secret: str,) -> str:
"""Return a fully-qualified secret string."""
Expand All @@ -157,12 +166,87 @@ def parse_secret_path(path: str) -> Dict[str, str]:
m = re.match(r"^projects/(?P<project>.+?)/secrets/(?P<secret>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def secret_version_path(project: str, secret: str, secret_version: str,) -> str:
"""Return a fully-qualified secret_version string."""
return "projects/{project}/secrets/{secret}/versions/{secret_version}".format(
project=project, secret=secret, secret_version=secret_version,
)

@staticmethod
def parse_secret_version_path(path: str) -> Dict[str, str]:
"""Parse a secret_version path into its component segments."""
m = re.match(
r"^projects/(?P<project>.+?)/secrets/(?P<secret>.+?)/versions/(?P<secret_version>.+?)$",
path,
)
return m.groupdict() if m else {}

@staticmethod
def common_billing_account_path(billing_account: str,) -> str:
"""Return a fully-qualified billing_account string."""
return "billingAccounts/{billing_account}".format(
billing_account=billing_account,
)

@staticmethod
def parse_common_billing_account_path(path: str) -> Dict[str, str]:
"""Parse a billing_account path into its component segments."""
m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_folder_path(folder: str,) -> str:
"""Return a fully-qualified folder string."""
return "folders/{folder}".format(folder=folder,)

@staticmethod
def parse_common_folder_path(path: str) -> Dict[str, str]:
"""Parse a folder path into its component segments."""
m = re.match(r"^folders/(?P<folder>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_organization_path(organization: str,) -> str:
"""Return a fully-qualified organization string."""
return "organizations/{organization}".format(organization=organization,)

@staticmethod
def parse_common_organization_path(path: str) -> Dict[str, str]:
"""Parse a organization path into its component segments."""
m = re.match(r"^organizations/(?P<organization>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_project_path(project: str,) -> str:
"""Return a fully-qualified project string."""
return "projects/{project}".format(project=project,)

@staticmethod
def parse_common_project_path(path: str) -> Dict[str, str]:
"""Parse a project path into its component segments."""
m = re.match(r"^projects/(?P<project>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_location_path(project: str, location: str,) -> str:
"""Return a fully-qualified location string."""
return "projects/{project}/locations/{location}".format(
project=project, location=location,
)

@staticmethod
def parse_common_location_path(path: str) -> Dict[str, str]:
"""Parse a location path into its component segments."""
m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
return m.groupdict() if m else {}

def __init__(
self,
*,
credentials: credentials.Credentials = None,
transport: Union[str, SecretManagerServiceTransport] = None,
client_options: ClientOptions = None,
credentials: Optional[credentials.Credentials] = None,
transport: Union[str, SecretManagerServiceTransport, None] = None,
client_options: Optional[client_options_lib.ClientOptions] = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the secret manager service client.
Expand All @@ -176,8 +260,8 @@ def __init__(
transport (Union[str, ~.SecretManagerServiceTransport]): The
transport to use. If set to None, a transport is chosen
automatically.
client_options (ClientOptions): Custom options for the client. It
won't take effect if a ``transport`` instance is provided.
client_options (client_options_lib.ClientOptions): Custom options for the
client. It won't take effect if a ``transport`` instance is provided.
(1) The ``api_endpoint`` property can be used to override the
default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
environment variable can also be used to override the endpoint:
Expand All @@ -192,20 +276,20 @@ def __init__(
not provided, the default SSL client certificate will be used if
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
set, no client certificate will be used.
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're developing
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're developing
your own client library.
Raises:
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
creation failed for any reason.
"""
if isinstance(client_options, dict):
client_options = ClientOptions.from_dict(client_options)
client_options = client_options_lib.from_dict(client_options)
if client_options is None:
client_options = ClientOptions.ClientOptions()
client_options = client_options_lib.ClientOptions()

# Create SSL credentials for mutual TLS if needed.
use_client_cert = bool(
Expand Down
Expand Up @@ -143,7 +143,7 @@ def _prep_wrapped_messages(self, client_info):
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(
exceptions.Unknown, exceptions.ServiceUnavailable,
exceptions.ServiceUnavailable, exceptions.Unknown,
),
),
default_timeout=60.0,
Expand Down

0 comments on commit b5c022b

Please sign in to comment.