Skip to content

Commit

Permalink
feat: add context manager support in client (#129)
Browse files Browse the repository at this point in the history
- [ ] Regenerate this pull request now.

chore: fix docstring for first attribute of protos

committer: @busunkim96
PiperOrigin-RevId: 401271153

Source-Link: googleapis/googleapis@787f8c9

Source-Link: googleapis/googleapis-gen@81decff
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9
  • Loading branch information
gcf-owl-bot[bot] authored Oct 7, 2021
1 parent 5b9cf0a commit 8e744ff
Show file tree
Hide file tree
Showing 28 changed files with 303 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,12 @@ async def delete_patch_deployment(
request, retry=retry, timeout=timeout, metadata=metadata,
)

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,7 @@ 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=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def execute_patch_job(
Expand Down Expand Up @@ -1066,6 +1063,19 @@ def delete_patch_deployment(
request, retry=retry, timeout=timeout, metadata=metadata,
)

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
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,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 execute_patch_job(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,5 +482,8 @@ def delete_patch_deployment(
)
return self._stubs["delete_patch_deployment"]

def close(self):
self.grpc_channel.close()


__all__ = ("OsConfigServiceGrpcTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -490,5 +490,8 @@ def delete_patch_deployment(
)
return self._stubs["delete_patch_deployment"]

def close(self):
return self.grpc_channel.close()


__all__ = ("OsConfigServiceGrpcAsyncIOTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,12 @@ async def list_vulnerability_reports(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,7 @@ 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=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def get_inventory(
Expand Down Expand Up @@ -738,6 +735,19 @@ def list_vulnerability_reports(
# 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
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,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 get_inventory(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,8 @@ def list_vulnerability_reports(
)
return self._stubs["list_vulnerability_reports"]

def close(self):
self.grpc_channel.close()


__all__ = ("OsConfigZonalServiceGrpcTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,8 @@ def list_vulnerability_reports(
)
return self._stubs["list_vulnerability_reports"]

def close(self):
return self.grpc_channel.close()


__all__ = ("OsConfigZonalServiceGrpcAsyncIOTransport",)
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Inventory(proto.Message):

class OsInfo(proto.Message):
r"""Operating system information for the VM.
Attributes:
hostname (str):
The VM hostname.
Expand Down Expand Up @@ -106,6 +107,7 @@ class OsInfo(proto.Message):

class Item(proto.Message):
r"""A single piece of inventory on a VM.
Attributes:
id (str):
Identifier for this item, unique across items
Expand Down Expand Up @@ -163,6 +165,7 @@ class Type(proto.Enum):

class SoftwarePackage(proto.Message):
r"""Software package information of the operating system.
Attributes:
yum_package (google.cloud.osconfig_v1.types.Inventory.VersionedPackage):
Yum package info. For details about the yum package manager,
Expand Down Expand Up @@ -273,6 +276,7 @@ class VersionedPackage(proto.Message):

class ZypperPatch(proto.Message):
r"""Details related to a Zypper Patch.
Attributes:
patch_name (str):
The name of the patch.
Expand Down Expand Up @@ -328,6 +332,7 @@ class WindowsUpdatePackage(proto.Message):

class WindowsUpdateCategory(proto.Message):
r"""Categories specified by the Windows Update.
Attributes:
id (str):
The identifier of the windows update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class OneTimeSchedule(proto.Message):

class RecurringSchedule(proto.Message):
r"""Sets the time for recurring patch deployments.
Attributes:
time_zone (google.type.datetime_pb2.TimeZone):
Required. Defines the time zone that ``time_of_day`` is
Expand Down Expand Up @@ -185,6 +186,7 @@ class Frequency(proto.Enum):

class WeeklySchedule(proto.Message):
r"""Represents a weekly schedule.
Attributes:
day_of_week (google.type.dayofweek_pb2.DayOfWeek):
Required. Day of the week.
Expand Down Expand Up @@ -235,6 +237,7 @@ class WeekDayOfMonth(proto.Message):

class CreatePatchDeploymentRequest(proto.Message):
r"""A request message for creating a patch deployment.
Attributes:
parent (str):
Required. The project to apply this patch deployment to in
Expand All @@ -260,6 +263,7 @@ class CreatePatchDeploymentRequest(proto.Message):

class GetPatchDeploymentRequest(proto.Message):
r"""A request message for retrieving a patch deployment.
Attributes:
name (str):
Required. The resource name of the patch deployment in the
Expand All @@ -271,6 +275,7 @@ class GetPatchDeploymentRequest(proto.Message):

class ListPatchDeploymentsRequest(proto.Message):
r"""A request message for listing patch deployments.
Attributes:
parent (str):
Required. The resource name of the parent in the form
Expand All @@ -292,6 +297,7 @@ class ListPatchDeploymentsRequest(proto.Message):

class ListPatchDeploymentsResponse(proto.Message):
r"""A response message for listing patch deployments.
Attributes:
patch_deployments (Sequence[google.cloud.osconfig_v1.types.PatchDeployment]):
The list of patch deployments.
Expand All @@ -312,6 +318,7 @@ def raw_page(self):

class DeletePatchDeploymentRequest(proto.Message):
r"""A request message for deleting a patch deployment.
Attributes:
name (str):
Required. The resource name of the patch deployment in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class ExecutePatchJobRequest(proto.Message):

class GetPatchJobRequest(proto.Message):
r"""Request to get an active or completed patch job.
Attributes:
name (str):
Required. Name of the patch in the form
Expand Down Expand Up @@ -184,6 +185,7 @@ class PatchJobInstanceDetails(proto.Message):

class ListPatchJobsRequest(proto.Message):
r"""A request message for listing patch jobs.
Attributes:
parent (str):
Required. In the form of ``projects/*``
Expand All @@ -208,6 +210,7 @@ class ListPatchJobsRequest(proto.Message):

class ListPatchJobsResponse(proto.Message):
r"""A response message for listing patch jobs.
Attributes:
patch_jobs (Sequence[google.cloud.osconfig_v1.types.PatchJob]):
The list of patch jobs.
Expand Down Expand Up @@ -424,7 +427,8 @@ class RebootConfig(proto.Enum):


class Instance(proto.Message):
r"""Namespace for instance state enums. """
r"""Namespace for instance state enums.
"""

class PatchState(proto.Enum):
r"""Patch state of an instance."""
Expand All @@ -448,6 +452,7 @@ class PatchState(proto.Enum):

class CancelPatchJobRequest(proto.Message):
r"""Message for canceling a patch job.
Attributes:
name (str):
Required. Name of the patch in the form
Expand Down Expand Up @@ -520,7 +525,8 @@ class YumSettings(proto.Message):


class GooSettings(proto.Message):
r"""Googet patching is performed by running ``googet update``. """
r"""Googet patching is performed by running ``googet update``.
"""


class ZypperSettings(proto.Message):
Expand Down Expand Up @@ -559,6 +565,7 @@ class ZypperSettings(proto.Message):

class WindowsUpdateSettings(proto.Message):
r"""Windows patching is performed using the Windows Update Agent.
Attributes:
classifications (Sequence[google.cloud.osconfig_v1.types.WindowsUpdateSettings.Classification]):
Only apply updates of these windows update
Expand Down Expand Up @@ -595,6 +602,7 @@ class Classification(proto.Enum):

class ExecStep(proto.Message):
r"""A step that runs an executable for a PatchJob.
Attributes:
linux_exec_step_config (google.cloud.osconfig_v1.types.ExecStepConfig):
The ExecStepConfig for all Linux VMs targeted
Expand All @@ -614,6 +622,7 @@ class ExecStep(proto.Message):

class ExecStepConfig(proto.Message):
r"""Common configurations for an ExecStep.
Attributes:
local_path (str):
An absolute path to the executable on the VM.
Expand Down Expand Up @@ -647,6 +656,7 @@ class Interpreter(proto.Enum):

class GcsObject(proto.Message):
r"""Cloud Storage object representation.
Attributes:
bucket (str):
Required. Bucket of the Cloud Storage object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class VulnerabilityReport(proto.Message):

class Vulnerability(proto.Message):
r"""A vulnerability affecting the VM instance.
Attributes:
details (google.cloud.osconfig_v1.types.VulnerabilityReport.Vulnerability.Details):
Contains metadata as per the upstream feed of
Expand Down Expand Up @@ -113,6 +114,7 @@ class Details(proto.Message):

class Reference(proto.Message):
r"""A reference for this vulnerability.
Attributes:
url (str):
The url of the reference.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,12 @@ async def list_vulnerability_reports(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,7 @@ 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=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def create_os_policy_assignment(
Expand Down Expand Up @@ -1618,6 +1615,19 @@ def list_vulnerability_reports(
# 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
Loading

0 comments on commit 8e744ff

Please sign in to comment.