Skip to content

Commit

Permalink
feat: add common resource helpers, expose client transport, remove cl…
Browse files Browse the repository at this point in the history
…ient side recv limit (#41)

This PR was generated using Autosynth. 🌈

Synth log will be available here:
https://source.cloud.google.com/results/invocations/0ea0e0e1-c693-4704-a662-fcd1812ef49e/targets

- [ ] To automatically regenerate this PR, check this box.

PiperOrigin-RevId: 347055288
Source-Link: googleapis/googleapis@dd372aa
PiperOrigin-RevId: 339292950
Source-Link: googleapis/googleapis@07d41a7
PiperOrigin-RevId: 338646463
Source-Link: googleapis/googleapis@20b11df
  • Loading branch information
yoshi-automation authored Dec 23, 2020
1 parent cb7991d commit 121eb43
Show file tree
Hide file tree
Showing 13 changed files with 419 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Types for Google Cloud Oslogin Common API

.. automodule:: google.cloud.oslogin_v1.common
:members:
:show-inheritance:
1 change: 1 addition & 0 deletions packages/google-cloud-os-login/docs/oslogin_v1/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Types for Google Cloud Oslogin v1 API

.. automodule:: google.cloud.oslogin_v1.types
:members:
:show-inheritance:
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
from .common import (
PosixAccount,
SshPublicKey,
OperatingSystemType,
)


__all__ = (
"PosixAccount",
"SshPublicKey",
"OperatingSystemType",
)
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,56 @@ class OsLoginServiceAsyncClient:
DEFAULT_ENDPOINT = OsLoginServiceClient.DEFAULT_ENDPOINT
DEFAULT_MTLS_ENDPOINT = OsLoginServiceClient.DEFAULT_MTLS_ENDPOINT

posix_account_path = staticmethod(OsLoginServiceClient.posix_account_path)
parse_posix_account_path = staticmethod(
OsLoginServiceClient.parse_posix_account_path
)
ssh_public_key_path = staticmethod(OsLoginServiceClient.ssh_public_key_path)
parse_ssh_public_key_path = staticmethod(
OsLoginServiceClient.parse_ssh_public_key_path
)

common_billing_account_path = staticmethod(
OsLoginServiceClient.common_billing_account_path
)
parse_common_billing_account_path = staticmethod(
OsLoginServiceClient.parse_common_billing_account_path
)

common_folder_path = staticmethod(OsLoginServiceClient.common_folder_path)
parse_common_folder_path = staticmethod(
OsLoginServiceClient.parse_common_folder_path
)

common_organization_path = staticmethod(
OsLoginServiceClient.common_organization_path
)
parse_common_organization_path = staticmethod(
OsLoginServiceClient.parse_common_organization_path
)

common_project_path = staticmethod(OsLoginServiceClient.common_project_path)
parse_common_project_path = staticmethod(
OsLoginServiceClient.parse_common_project_path
)

common_location_path = staticmethod(OsLoginServiceClient.common_location_path)
parse_common_location_path = staticmethod(
OsLoginServiceClient.parse_common_location_path
)

from_service_account_file = OsLoginServiceClient.from_service_account_file
from_service_account_json = from_service_account_file

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

get_transport_class = functools.partial(
type(OsLoginServiceClient).get_transport_class, type(OsLoginServiceClient)
)
Expand Down Expand Up @@ -142,7 +184,8 @@ async def delete_posix_account(
# 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 @@ -216,7 +259,8 @@ async def delete_ssh_public_key(
# 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 @@ -296,7 +340,8 @@ async def get_login_profile(
# 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 @@ -377,7 +422,8 @@ async def get_ssh_public_key(
# 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 @@ -473,7 +519,8 @@ async def import_ssh_public_key(
# 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, ssh_public_key, project_id]):
has_flattened_params = any([parent, ssh_public_key, project_id])
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 @@ -573,7 +620,8 @@ async def update_ssh_public_key(
# 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, ssh_public_key, update_mask]):
has_flattened_params = any([name, ssh_public_key, 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
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,26 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):

from_service_account_json = from_service_account_file

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

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

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

@staticmethod
def ssh_public_key_path(user: str, fingerprint: str,) -> str:
"""Return a fully-qualified ssh_public_key string."""
Expand All @@ -148,6 +168,65 @@ def parse_ssh_public_key_path(path: str) -> Dict[str, str]:
m = re.match(r"^users/(?P<user>.+?)/sshPublicKeys/(?P<fingerprint>.+?)$", 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,
*,
Expand Down Expand Up @@ -183,10 +262,10 @@ 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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
_transport_registry["grpc"] = OsLoginServiceGrpcTransport
_transport_registry["grpc_asyncio"] = OsLoginServiceGrpcAsyncIOTransport


__all__ = (
"OsLoginServiceTransport",
"OsLoginServiceGrpcTransport",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ def __init__(
for grpc channel. It is ignored if ``channel`` is provided.
quota_project_id (Optional[str]): An optional project to use for billing
and quota.
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:
Expand All @@ -106,13 +106,16 @@ def __init__(
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
and ``credentials_file`` are passed.
"""
self._ssl_channel_credentials = ssl_channel_credentials

if channel:
# Sanity check: Ensure that channel and credentials are not both
# provided.
credentials = False

# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
elif api_mtls_endpoint:
warnings.warn(
"api_mtls_endpoint and client_cert_source are deprecated",
Expand Down Expand Up @@ -148,7 +151,12 @@ def __init__(
ssl_credentials=ssl_credentials,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)
self._ssl_channel_credentials = ssl_credentials
else:
host = host if ":" in host else host + ":443"

Expand All @@ -165,6 +173,10 @@ def __init__(
ssl_credentials=ssl_channel_credentials,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)

self._stubs = {} # type: Dict[str, Callable]
Expand All @@ -191,7 +203,7 @@ def create_channel(
) -> grpc.Channel:
"""Create and return a gRPC channel object.
Args:
address (Optionsl[str]): The host for the channel to use.
address (Optional[str]): The host for the channel to use.
credentials (Optional[~.Credentials]): The
authorization credentials to attach to requests. These
credentials identify this application to the service. If
Expand Down Expand Up @@ -226,12 +238,8 @@ def create_channel(

@property
def grpc_channel(self) -> grpc.Channel:
"""Create the channel designed to connect to this service.
This property caches on the instance; repeated calls return
the same channel.
"""Return the channel designed to connect to this service.
"""
# Return the channel from cache.
return self._grpc_channel

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,16 @@ def __init__(
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
and ``credentials_file`` are passed.
"""
self._ssl_channel_credentials = ssl_channel_credentials

if channel:
# Sanity check: Ensure that channel and credentials are not both
# provided.
credentials = False

# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
elif api_mtls_endpoint:
warnings.warn(
"api_mtls_endpoint and client_cert_source are deprecated",
Expand Down Expand Up @@ -193,7 +196,12 @@ def __init__(
ssl_credentials=ssl_credentials,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)
self._ssl_channel_credentials = ssl_credentials
else:
host = host if ":" in host else host + ":443"

Expand All @@ -210,6 +218,10 @@ def __init__(
ssl_credentials=ssl_channel_credentials,
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)

# Run the base constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
UpdateSshPublicKeyRequest,
)


__all__ = (
"LoginProfile",
"DeletePosixAccountRequest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class ImportSshPublicKeyResponse(proto.Message):
The login profile information for the user.
"""

login_profile = proto.Field(proto.MESSAGE, number=1, message=LoginProfile,)
login_profile = proto.Field(proto.MESSAGE, number=1, message="LoginProfile",)


class UpdateSshPublicKeyRequest(proto.Message):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright 2020 Google LLC
Expand Down
Loading

0 comments on commit 121eb43

Please sign in to comment.