From b207115ed97544585c5f0dc7512d71fd94b5aae2 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 7 Oct 2021 00:40:45 +0000 Subject: [PATCH] feat: add context manager support in client (#129) - [ ] Regenerate this pull request now. chore: fix docstring for first attribute of protos committer: @busunkim96 PiperOrigin-RevId: 401271153 Source-Link: https://github.com/googleapis/googleapis/commit/787f8c9a731f44e74a90b9847d48659ca9462d10 Source-Link: https://github.com/googleapis/googleapis-gen/commit/81decffe9fc72396a8153e756d1d67a6eecfd620 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9 --- .../os_config_service/async_client.py | 6 +++ .../services/os_config_service/client.py | 18 +++++-- .../os_config_service/transports/base.py | 9 ++++ .../os_config_service/transports/grpc.py | 3 ++ .../transports/grpc_asyncio.py | 3 ++ .../os_config_zonal_service/async_client.py | 6 +++ .../os_config_zonal_service/client.py | 18 +++++-- .../transports/base.py | 9 ++++ .../transports/grpc.py | 3 ++ .../transports/grpc_asyncio.py | 3 ++ google/cloud/osconfig_v1/types/inventory.py | 5 ++ .../osconfig_v1/types/patch_deployments.py | 7 +++ google/cloud/osconfig_v1/types/patch_jobs.py | 14 +++++- .../cloud/osconfig_v1/types/vulnerability.py | 2 + .../os_config_zonal_service/async_client.py | 6 +++ .../os_config_zonal_service/client.py | 18 +++++-- .../transports/base.py | 9 ++++ .../transports/grpc.py | 3 ++ .../transports/grpc_asyncio.py | 3 ++ .../osconfig_v1alpha/types/config_common.py | 2 + .../types/instance_os_policies_compliance.py | 1 + .../cloud/osconfig_v1alpha/types/inventory.py | 5 ++ .../cloud/osconfig_v1alpha/types/os_policy.py | 8 +++ .../types/os_policy_assignments.py | 4 ++ .../osconfig_v1alpha/types/vulnerability.py | 2 + .../osconfig_v1/test_os_config_service.py | 50 +++++++++++++++++++ .../test_os_config_zonal_service.py | 50 +++++++++++++++++++ .../test_os_config_zonal_service.py | 50 +++++++++++++++++++ 28 files changed, 303 insertions(+), 14 deletions(-) diff --git a/google/cloud/osconfig_v1/services/os_config_service/async_client.py b/google/cloud/osconfig_v1/services/os_config_service/async_client.py index 91c5bad..297cc66 100644 --- a/google/cloud/osconfig_v1/services/os_config_service/async_client.py +++ b/google/cloud/osconfig_v1/services/os_config_service/async_client.py @@ -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( diff --git a/google/cloud/osconfig_v1/services/os_config_service/client.py b/google/cloud/osconfig_v1/services/os_config_service/client.py index f4a18f7..2a86b37 100644 --- a/google/cloud/osconfig_v1/services/os_config_service/client.py +++ b/google/cloud/osconfig_v1/services/os_config_service/client.py @@ -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( @@ -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( diff --git a/google/cloud/osconfig_v1/services/os_config_service/transports/base.py b/google/cloud/osconfig_v1/services/os_config_service/transports/base.py index 6a58b0e..9699f5a 100644 --- a/google/cloud/osconfig_v1/services/os_config_service/transports/base.py +++ b/google/cloud/osconfig_v1/services/os_config_service/transports/base.py @@ -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, diff --git a/google/cloud/osconfig_v1/services/os_config_service/transports/grpc.py b/google/cloud/osconfig_v1/services/os_config_service/transports/grpc.py index a0816c4..2b9fe7c 100644 --- a/google/cloud/osconfig_v1/services/os_config_service/transports/grpc.py +++ b/google/cloud/osconfig_v1/services/os_config_service/transports/grpc.py @@ -482,5 +482,8 @@ def delete_patch_deployment( ) return self._stubs["delete_patch_deployment"] + def close(self): + self.grpc_channel.close() + __all__ = ("OsConfigServiceGrpcTransport",) diff --git a/google/cloud/osconfig_v1/services/os_config_service/transports/grpc_asyncio.py b/google/cloud/osconfig_v1/services/os_config_service/transports/grpc_asyncio.py index b43967f..9820ac6 100644 --- a/google/cloud/osconfig_v1/services/os_config_service/transports/grpc_asyncio.py +++ b/google/cloud/osconfig_v1/services/os_config_service/transports/grpc_asyncio.py @@ -490,5 +490,8 @@ def delete_patch_deployment( ) return self._stubs["delete_patch_deployment"] + def close(self): + return self.grpc_channel.close() + __all__ = ("OsConfigServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/osconfig_v1/services/os_config_zonal_service/async_client.py b/google/cloud/osconfig_v1/services/os_config_zonal_service/async_client.py index 67bc12a..6817eb9 100644 --- a/google/cloud/osconfig_v1/services/os_config_zonal_service/async_client.py +++ b/google/cloud/osconfig_v1/services/os_config_zonal_service/async_client.py @@ -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( diff --git a/google/cloud/osconfig_v1/services/os_config_zonal_service/client.py b/google/cloud/osconfig_v1/services/os_config_zonal_service/client.py index 8d637fd..0ec4a5b 100644 --- a/google/cloud/osconfig_v1/services/os_config_zonal_service/client.py +++ b/google/cloud/osconfig_v1/services/os_config_zonal_service/client.py @@ -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( @@ -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( diff --git a/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/base.py b/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/base.py index d9e0096..a070518 100644 --- a/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/base.py +++ b/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/base.py @@ -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, diff --git a/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/grpc.py b/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/grpc.py index 524faa8..b273bd3 100644 --- a/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/grpc.py +++ b/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/grpc.py @@ -345,5 +345,8 @@ def list_vulnerability_reports( ) return self._stubs["list_vulnerability_reports"] + def close(self): + self.grpc_channel.close() + __all__ = ("OsConfigZonalServiceGrpcTransport",) diff --git a/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/grpc_asyncio.py b/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/grpc_asyncio.py index 961a407..42038e4 100644 --- a/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/grpc_asyncio.py +++ b/google/cloud/osconfig_v1/services/os_config_zonal_service/transports/grpc_asyncio.py @@ -349,5 +349,8 @@ def list_vulnerability_reports( ) return self._stubs["list_vulnerability_reports"] + def close(self): + return self.grpc_channel.close() + __all__ = ("OsConfigZonalServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/osconfig_v1/types/inventory.py b/google/cloud/osconfig_v1/types/inventory.py index 513e95c..1714807 100644 --- a/google/cloud/osconfig_v1/types/inventory.py +++ b/google/cloud/osconfig_v1/types/inventory.py @@ -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. @@ -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 @@ -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, @@ -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. @@ -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 diff --git a/google/cloud/osconfig_v1/types/patch_deployments.py b/google/cloud/osconfig_v1/types/patch_deployments.py index d246804..8d60ec1 100644 --- a/google/cloud/osconfig_v1/types/patch_deployments.py +++ b/google/cloud/osconfig_v1/types/patch_deployments.py @@ -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 @@ -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. @@ -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 @@ -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 @@ -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 @@ -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. @@ -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 diff --git a/google/cloud/osconfig_v1/types/patch_jobs.py b/google/cloud/osconfig_v1/types/patch_jobs.py index 9f63376..ee075d5 100644 --- a/google/cloud/osconfig_v1/types/patch_jobs.py +++ b/google/cloud/osconfig_v1/types/patch_jobs.py @@ -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 @@ -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/*`` @@ -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. @@ -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.""" @@ -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 @@ -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): @@ -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 @@ -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 @@ -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. @@ -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. diff --git a/google/cloud/osconfig_v1/types/vulnerability.py b/google/cloud/osconfig_v1/types/vulnerability.py index ac4120e..b5f53a8 100644 --- a/google/cloud/osconfig_v1/types/vulnerability.py +++ b/google/cloud/osconfig_v1/types/vulnerability.py @@ -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 @@ -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. diff --git a/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/async_client.py b/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/async_client.py index 89431d0..a516966 100644 --- a/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/async_client.py +++ b/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/async_client.py @@ -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( diff --git a/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/client.py b/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/client.py index 272f917..b4fecc7 100644 --- a/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/client.py +++ b/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/client.py @@ -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( @@ -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( diff --git a/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/base.py b/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/base.py index a6a563a..616108e 100644 --- a/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/base.py +++ b/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/base.py @@ -215,6 +215,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 operations_client(self) -> operations_v1.OperationsClient: """Return the client designed to process long-running operations.""" diff --git a/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc.py b/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc.py index 1454fa0..7222ac2 100644 --- a/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc.py +++ b/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc.py @@ -646,5 +646,8 @@ def list_vulnerability_reports( ) return self._stubs["list_vulnerability_reports"] + def close(self): + self.grpc_channel.close() + __all__ = ("OsConfigZonalServiceGrpcTransport",) diff --git a/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc_asyncio.py b/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc_asyncio.py index 502e728..ccbcfda 100644 --- a/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc_asyncio.py +++ b/google/cloud/osconfig_v1alpha/services/os_config_zonal_service/transports/grpc_asyncio.py @@ -654,5 +654,8 @@ def list_vulnerability_reports( ) return self._stubs["list_vulnerability_reports"] + def close(self): + return self.grpc_channel.close() + __all__ = ("OsConfigZonalServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/osconfig_v1alpha/types/config_common.py b/google/cloud/osconfig_v1alpha/types/config_common.py index 7d6e04c..db66cff 100644 --- a/google/cloud/osconfig_v1alpha/types/config_common.py +++ b/google/cloud/osconfig_v1alpha/types/config_common.py @@ -71,6 +71,7 @@ class Outcome(proto.Enum): class OSPolicyResourceCompliance(proto.Message): r"""Compliance data for an OS policy resource. + Attributes: os_policy_resource_id (str): The id of the OS policy resource. @@ -85,6 +86,7 @@ class OSPolicyResourceCompliance(proto.Message): class ExecResourceOutput(proto.Message): r"""ExecResource specific output. + Attributes: enforcement_output (bytes): Output from Enforcement phase output file (if diff --git a/google/cloud/osconfig_v1alpha/types/instance_os_policies_compliance.py b/google/cloud/osconfig_v1alpha/types/instance_os_policies_compliance.py index 7414995..8702cd3 100644 --- a/google/cloud/osconfig_v1alpha/types/instance_os_policies_compliance.py +++ b/google/cloud/osconfig_v1alpha/types/instance_os_policies_compliance.py @@ -94,6 +94,7 @@ class InstanceOSPoliciesCompliance(proto.Message): class OSPolicyCompliance(proto.Message): r"""Compliance data for an OS policy + Attributes: os_policy_id (str): The OS policy id diff --git a/google/cloud/osconfig_v1alpha/types/inventory.py b/google/cloud/osconfig_v1alpha/types/inventory.py index 52972ef..6b30364 100644 --- a/google/cloud/osconfig_v1alpha/types/inventory.py +++ b/google/cloud/osconfig_v1alpha/types/inventory.py @@ -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. @@ -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 @@ -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_v1alpha.types.Inventory.VersionedPackage): Yum package info. For details about the yum package manager, @@ -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. @@ -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 diff --git a/google/cloud/osconfig_v1alpha/types/os_policy.py b/google/cloud/osconfig_v1alpha/types/os_policy.py index 0a11b5a..02f86c8 100644 --- a/google/cloud/osconfig_v1alpha/types/os_policy.py +++ b/google/cloud/osconfig_v1alpha/types/os_policy.py @@ -118,6 +118,7 @@ class Resource(proto.Message): class File(proto.Message): r"""A remote or local file. + Attributes: remote (google.cloud.osconfig_v1alpha.types.OSPolicy.Resource.File.Remote): A generic remote file. @@ -135,6 +136,7 @@ class File(proto.Message): class Remote(proto.Message): r"""Specifies a file available via some URI. + Attributes: uri (str): Required. URI from which to fetch the object. It should @@ -149,6 +151,7 @@ class Remote(proto.Message): class Gcs(proto.Message): r"""Specifies a file available as a Cloud Storage Object. + Attributes: bucket (str): Required. Bucket of the Cloud Storage object. @@ -180,6 +183,7 @@ class Gcs(proto.Message): class PackageResource(proto.Message): r"""A resource that manages a system package. + Attributes: desired_state (google.cloud.osconfig_v1alpha.types.OSPolicy.Resource.PackageResource.DesiredState): Required. The desired state the agent should @@ -303,6 +307,7 @@ class GooGet(proto.Message): class MSI(proto.Message): r"""An MSI package. MSI packages only support INSTALLED state. + Attributes: source (google.cloud.osconfig_v1alpha.types.OSPolicy.Resource.File): Required. The MSI package. @@ -367,6 +372,7 @@ class MSI(proto.Message): class RepositoryResource(proto.Message): r"""A resource that manages a package repository. + Attributes: apt (google.cloud.osconfig_v1alpha.types.OSPolicy.Resource.RepositoryResource.AptRepository): An Apt Repository. @@ -554,6 +560,7 @@ class ExecResource(proto.Message): class Exec(proto.Message): r"""A file or script to execute. + Attributes: file (google.cloud.osconfig_v1alpha.types.OSPolicy.Resource.File): A remote or local file. @@ -607,6 +614,7 @@ class Interpreter(proto.Enum): class FileResource(proto.Message): r"""A resource that manages the state of a file. + Attributes: file (google.cloud.osconfig_v1alpha.types.OSPolicy.Resource.File): A remote or local source. diff --git a/google/cloud/osconfig_v1alpha/types/os_policy_assignments.py b/google/cloud/osconfig_v1alpha/types/os_policy_assignments.py index cde4f84..67a4349 100644 --- a/google/cloud/osconfig_v1alpha/types/os_policy_assignments.py +++ b/google/cloud/osconfig_v1alpha/types/os_policy_assignments.py @@ -270,6 +270,7 @@ class RolloutState(proto.Enum): class CreateOSPolicyAssignmentRequest(proto.Message): r"""A request message to create an OS policy assignment + Attributes: parent (str): Required. The parent resource name in the @@ -298,6 +299,7 @@ class CreateOSPolicyAssignmentRequest(proto.Message): class UpdateOSPolicyAssignmentRequest(proto.Message): r"""A request message to update an OS policy assignment + Attributes: os_policy_assignment (google.cloud.osconfig_v1alpha.types.OSPolicyAssignment): Required. The updated OS policy assignment. @@ -316,6 +318,7 @@ class UpdateOSPolicyAssignmentRequest(proto.Message): class GetOSPolicyAssignmentRequest(proto.Message): r"""A request message to get an OS policy assignment + Attributes: name (str): Required. The resource name of OS policy assignment. @@ -414,6 +417,7 @@ def raw_page(self): class DeleteOSPolicyAssignmentRequest(proto.Message): r"""A request message for deleting a OS policy assignment. + Attributes: name (str): Required. The name of the OS policy diff --git a/google/cloud/osconfig_v1alpha/types/vulnerability.py b/google/cloud/osconfig_v1alpha/types/vulnerability.py index 06977d8..59b0387 100644 --- a/google/cloud/osconfig_v1alpha/types/vulnerability.py +++ b/google/cloud/osconfig_v1alpha/types/vulnerability.py @@ -54,6 +54,7 @@ class VulnerabilityReport(proto.Message): class Vulnerability(proto.Message): r"""A vulnerability affecting the VM instance. + Attributes: details (google.cloud.osconfig_v1alpha.types.VulnerabilityReport.Vulnerability.Details): Contains metadata as per the upstream feed of @@ -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. diff --git a/tests/unit/gapic/osconfig_v1/test_os_config_service.py b/tests/unit/gapic/osconfig_v1/test_os_config_service.py index 72d5dbf..8e370a3 100644 --- a/tests/unit/gapic/osconfig_v1/test_os_config_service.py +++ b/tests/unit/gapic/osconfig_v1/test_os_config_service.py @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.osconfig_v1.services.os_config_service import ( @@ -3015,6 +3016,9 @@ def test_os_config_service_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + @requires_google_auth_gte_1_25_0 def test_os_config_service_base_transport_with_credentials_file(): @@ -3541,3 +3545,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = OsConfigServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = OsConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = OsConfigServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/osconfig_v1/test_os_config_zonal_service.py b/tests/unit/gapic/osconfig_v1/test_os_config_zonal_service.py index 3da984b..0ec8bbe 100644 --- a/tests/unit/gapic/osconfig_v1/test_os_config_zonal_service.py +++ b/tests/unit/gapic/osconfig_v1/test_os_config_zonal_service.py @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.osconfig_v1.services.os_config_zonal_service import ( @@ -1819,6 +1820,9 @@ def test_os_config_zonal_service_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + @requires_google_auth_gte_1_25_0 def test_os_config_zonal_service_base_transport_with_credentials_file(): @@ -2355,3 +2359,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = OsConfigZonalServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = OsConfigZonalServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = OsConfigZonalServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() diff --git a/tests/unit/gapic/osconfig_v1alpha/test_os_config_zonal_service.py b/tests/unit/gapic/osconfig_v1alpha/test_os_config_zonal_service.py index bd5ff53..b1070e7 100644 --- a/tests/unit/gapic/osconfig_v1alpha/test_os_config_zonal_service.py +++ b/tests/unit/gapic/osconfig_v1alpha/test_os_config_zonal_service.py @@ -32,6 +32,7 @@ from google.api_core import grpc_helpers_async from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.osconfig_v1alpha.services.os_config_zonal_service import ( @@ -4368,6 +4369,9 @@ def test_os_config_zonal_service_base_transport(): with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): @@ -4987,3 +4991,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = OsConfigZonalServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = OsConfigZonalServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = OsConfigZonalServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called()