From c0ba4eb27304c4e216864f6707693b27dc22c214 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Fri, 8 Oct 2021 14:34:15 +0000 Subject: [PATCH] feat: add context manager support in client (#272) - [ ] 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 --- .../services/dlp_service/async_client.py | 6 + .../dlp_v2/services/dlp_service/client.py | 18 ++- .../services/dlp_service/transports/base.py | 9 ++ .../services/dlp_service/transports/grpc.py | 3 + .../dlp_service/transports/grpc_asyncio.py | 3 + google/cloud/dlp_v2/types/dlp.py | 121 ++++++++++++++++-- google/cloud/dlp_v2/types/storage.py | 18 ++- tests/unit/gapic/dlp_v2/test_dlp_service.py | 50 ++++++++ 8 files changed, 213 insertions(+), 15 deletions(-) diff --git a/google/cloud/dlp_v2/services/dlp_service/async_client.py b/google/cloud/dlp_v2/services/dlp_service/async_client.py index e5ae1cee..c299f82c 100644 --- a/google/cloud/dlp_v2/services/dlp_service/async_client.py +++ b/google/cloud/dlp_v2/services/dlp_service/async_client.py @@ -3146,6 +3146,12 @@ async def finish_dlp_job( 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/dlp_v2/services/dlp_service/client.py b/google/cloud/dlp_v2/services/dlp_service/client.py index e8ef4cc1..62f63ef8 100644 --- a/google/cloud/dlp_v2/services/dlp_service/client.py +++ b/google/cloud/dlp_v2/services/dlp_service/client.py @@ -440,10 +440,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 inspect_content( @@ -3225,6 +3222,19 @@ def finish_dlp_job( 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/dlp_v2/services/dlp_service/transports/base.py b/google/cloud/dlp_v2/services/dlp_service/transports/base.py index b6fe5214..50ec0cc1 100644 --- a/google/cloud/dlp_v2/services/dlp_service/transports/base.py +++ b/google/cloud/dlp_v2/services/dlp_service/transports/base.py @@ -515,6 +515,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 inspect_content( self, diff --git a/google/cloud/dlp_v2/services/dlp_service/transports/grpc.py b/google/cloud/dlp_v2/services/dlp_service/transports/grpc.py index 365bb856..c2b99361 100644 --- a/google/cloud/dlp_v2/services/dlp_service/transports/grpc.py +++ b/google/cloud/dlp_v2/services/dlp_service/transports/grpc.py @@ -1233,5 +1233,8 @@ def finish_dlp_job(self) -> Callable[[dlp.FinishDlpJobRequest], empty_pb2.Empty] ) return self._stubs["finish_dlp_job"] + def close(self): + self.grpc_channel.close() + __all__ = ("DlpServiceGrpcTransport",) diff --git a/google/cloud/dlp_v2/services/dlp_service/transports/grpc_asyncio.py b/google/cloud/dlp_v2/services/dlp_service/transports/grpc_asyncio.py index b5fc0b8a..8594da4f 100644 --- a/google/cloud/dlp_v2/services/dlp_service/transports/grpc_asyncio.py +++ b/google/cloud/dlp_v2/services/dlp_service/transports/grpc_asyncio.py @@ -1265,5 +1265,8 @@ def finish_dlp_job( ) return self._stubs["finish_dlp_job"] + def close(self): + return self.grpc_channel.close() + __all__ = ("DlpServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/dlp_v2/types/dlp.py b/google/cloud/dlp_v2/types/dlp.py index f4f6f873..f050b132 100644 --- a/google/cloud/dlp_v2/types/dlp.py +++ b/google/cloud/dlp_v2/types/dlp.py @@ -227,6 +227,7 @@ class StoredInfoTypeState(proto.Enum): class ExcludeInfoTypes(proto.Message): r"""List of exclude infoTypes. + Attributes: info_types (Sequence[google.cloud.dlp_v2.types.InfoType]): InfoType list in ExclusionRule rule drops a finding when it @@ -368,6 +369,7 @@ class InspectConfig(proto.Message): class FindingLimits(proto.Message): r"""Configuration to control the number of findings returned. + Attributes: max_findings_per_item (int): Max number of findings that will be returned for each item @@ -425,6 +427,7 @@ class InfoTypeLimit(proto.Message): class ByteContentItem(proto.Message): r"""Container for bytes to inspect or redact. + Attributes: type_ (google.cloud.dlp_v2.types.ByteContentItem.BytesType): The type of data stored in the bytes string. Default will be @@ -454,6 +457,7 @@ class BytesType(proto.Enum): class ContentItem(proto.Message): r"""Container structure for the content to inspect. + Attributes: value (str): String data to inspect or redact. @@ -488,6 +492,7 @@ class Table(proto.Message): class Row(proto.Message): r"""Values of the row. + Attributes: values (Sequence[google.cloud.dlp_v2.types.Value]): Individual cells. @@ -501,6 +506,7 @@ class Row(proto.Message): class InspectResult(proto.Message): r"""All the findings for a single scanned item. + Attributes: findings (Sequence[google.cloud.dlp_v2.types.Finding]): List of findings for an item. @@ -522,6 +528,7 @@ class InspectResult(proto.Message): class Finding(proto.Message): r"""Represents a piece of potentially sensitive content. + Attributes: name (str): Resource name in format @@ -596,6 +603,7 @@ class Finding(proto.Message): class Location(proto.Message): r"""Specifies the location of the finding. + Attributes: byte_range (google.cloud.dlp_v2.types.Range): Zero-based byte offsets delimiting the @@ -684,6 +692,7 @@ class ContentLocation(proto.Message): class MetadataLocation(proto.Message): r"""Metadata Location + Attributes: type_ (google.cloud.dlp_v2.types.MetadataType): Type of metadata containing the finding. @@ -711,6 +720,7 @@ class StorageMetadataLabel(proto.Message): class DocumentLocation(proto.Message): r"""Location of a finding within a document. + Attributes: file_offset (int): Offset of the line, from the beginning of the @@ -722,6 +732,7 @@ class DocumentLocation(proto.Message): class RecordLocation(proto.Message): r"""Location of a finding within a row or record. + Attributes: record_key (google.cloud.dlp_v2.types.RecordKey): Key of the finding. @@ -738,6 +749,7 @@ class RecordLocation(proto.Message): class TableLocation(proto.Message): r"""Location of a finding within a table. + Attributes: row_index (int): The zero-based index of the row where the finding is @@ -808,6 +820,7 @@ class Container(proto.Message): class Range(proto.Message): r"""Generic half-open interval [start, end) + Attributes: start (int): Index of the first character of the range @@ -823,6 +836,7 @@ class Range(proto.Message): class ImageLocation(proto.Message): r"""Location of the finding within an image. + Attributes: bounding_boxes (Sequence[google.cloud.dlp_v2.types.BoundingBox]): Bounding boxes locating the pixels within the @@ -836,6 +850,7 @@ class ImageLocation(proto.Message): class BoundingBox(proto.Message): r"""Bounding box encompassing detected text within an image. + Attributes: top (int): Top coordinate of the bounding box. (0,0) is @@ -932,6 +947,7 @@ class ImageRedactionConfig(proto.Message): class Color(proto.Message): r"""Represents a color in the RGB color space. + Attributes: red (float): The amount of red in the color as a value in the interval @@ -951,6 +967,7 @@ class Color(proto.Message): class RedactImageResponse(proto.Message): r"""Results of redacting an image. + Attributes: redacted_image (bytes): The redacted image. The type will be the same @@ -971,6 +988,7 @@ class RedactImageResponse(proto.Message): class DeidentifyContentRequest(proto.Message): r"""Request to de-identify a list of items. + Attributes: parent (str): Parent resource name. @@ -1033,6 +1051,7 @@ class DeidentifyContentRequest(proto.Message): class DeidentifyContentResponse(proto.Message): r"""Results of de-identifying a ContentItem. + Attributes: item (google.cloud.dlp_v2.types.ContentItem): The de-identified item. @@ -1046,6 +1065,7 @@ class DeidentifyContentResponse(proto.Message): class ReidentifyContentRequest(proto.Message): r"""Request to re-identify an item. + Attributes: parent (str): Required. Parent resource name. @@ -1118,6 +1138,7 @@ class ReidentifyContentRequest(proto.Message): class ReidentifyContentResponse(proto.Message): r"""Results of re-identifying a item. + Attributes: item (google.cloud.dlp_v2.types.ContentItem): The re-identified item. @@ -1179,6 +1200,7 @@ class InspectContentRequest(proto.Message): class InspectContentResponse(proto.Message): r"""Results of inspecting an item. + Attributes: result (google.cloud.dlp_v2.types.InspectResult): The findings. @@ -1189,6 +1211,7 @@ class InspectContentResponse(proto.Message): class OutputStorageConfig(proto.Message): r"""Cloud repository for storing output. + Attributes: table (google.cloud.dlp_v2.types.BigQueryTable): Store findings in an existing table or a new table in an @@ -1240,6 +1263,7 @@ class OutputSchema(proto.Enum): class InfoTypeStats(proto.Message): r"""Statistics regarding a specific InfoType. + Attributes: info_type (google.cloud.dlp_v2.types.InfoType): The type of finding this stat is for. @@ -1253,6 +1277,7 @@ class InfoTypeStats(proto.Message): class InspectDataSourceDetails(proto.Message): r"""The results of an inspect DataSource job. + Attributes: requested_options (google.cloud.dlp_v2.types.InspectDataSourceDetails.RequestedOptions): The configuration used for this job. @@ -1262,6 +1287,7 @@ class InspectDataSourceDetails(proto.Message): class RequestedOptions(proto.Message): r"""Snapshot of the inspection configuration. + Attributes: snapshot_inspect_template (google.cloud.dlp_v2.types.InspectTemplate): If run with an InspectTemplate, a snapshot of @@ -1311,6 +1337,7 @@ class Result(proto.Message): class HybridInspectStatistics(proto.Message): r"""Statistics related to processing hybrid inspect requests. + Attributes: processed_count (int): The number of hybrid inspection requests @@ -1335,6 +1362,7 @@ class HybridInspectStatistics(proto.Message): class InfoTypeDescription(proto.Message): r"""InfoType description. + Attributes: name (str): Internal name of the infoType. @@ -1358,6 +1386,7 @@ class InfoTypeDescription(proto.Message): class ListInfoTypesRequest(proto.Message): r"""Request for the list of infoTypes. + Attributes: parent (str): The parent resource name. @@ -1387,6 +1416,7 @@ class ListInfoTypesRequest(proto.Message): class ListInfoTypesResponse(proto.Message): r"""Response to the ListInfoTypes request. + Attributes: info_types (Sequence[google.cloud.dlp_v2.types.InfoTypeDescription]): Set of sensitive infoTypes. @@ -1419,6 +1449,7 @@ class RiskAnalysisJobConfig(proto.Message): class QuasiId(proto.Message): r"""A column with a semantic tag attached. + Attributes: field (google.cloud.dlp_v2.types.FieldId): Required. Identifies the column. @@ -1497,6 +1528,7 @@ class QuasiIdentifierField(proto.Message): class PrivacyMetric(proto.Message): r"""Privacy metric to compute for reidentification risk analysis. + Attributes: numerical_stats_config (google.cloud.dlp_v2.types.PrivacyMetric.NumericalStatsConfig): Numerical stats @@ -1621,6 +1653,7 @@ class KMapEstimationConfig(proto.Message): class TaggedField(proto.Message): r"""A column with a semantic tag attached. + Attributes: field (google.cloud.dlp_v2.types.FieldId): Required. Identifies the column. @@ -1757,6 +1790,7 @@ class DeltaPresenceEstimationConfig(proto.Message): class AnalyzeDataSourceRiskDetails(proto.Message): r"""Result of a risk analysis operation request. + Attributes: requested_privacy_metric (google.cloud.dlp_v2.types.PrivacyMetric): Privacy metric to compute. @@ -1780,6 +1814,7 @@ class AnalyzeDataSourceRiskDetails(proto.Message): class NumericalStatsResult(proto.Message): r"""Result of the numerical stats computation. + Attributes: min_value (google.cloud.dlp_v2.types.Value): Minimum value appearing in the column. @@ -1796,6 +1831,7 @@ class NumericalStatsResult(proto.Message): class CategoricalStatsResult(proto.Message): r"""Result of the categorical stats computation. + Attributes: value_frequency_histogram_buckets (Sequence[google.cloud.dlp_v2.types.AnalyzeDataSourceRiskDetails.CategoricalStatsResult.CategoricalStatsHistogramBucket]): Histogram of value frequencies in the column. @@ -1803,6 +1839,7 @@ class CategoricalStatsResult(proto.Message): class CategoricalStatsHistogramBucket(proto.Message): r"""Histogram of value frequencies in the column. + Attributes: value_frequency_lower_bound (int): Lower bound on the value frequency of the @@ -1837,6 +1874,7 @@ class CategoricalStatsHistogramBucket(proto.Message): class KAnonymityResult(proto.Message): r"""Result of the k-anonymity computation. + Attributes: equivalence_class_histogram_buckets (Sequence[google.cloud.dlp_v2.types.AnalyzeDataSourceRiskDetails.KAnonymityResult.KAnonymityHistogramBucket]): Histogram of k-anonymity equivalence classes. @@ -1864,6 +1902,7 @@ class KAnonymityEquivalenceClass(proto.Message): class KAnonymityHistogramBucket(proto.Message): r"""Histogram of k-anonymity equivalence classes. + Attributes: equivalence_class_size_lower_bound (int): Lower bound on the size of the equivalence @@ -1901,6 +1940,7 @@ class KAnonymityHistogramBucket(proto.Message): class LDiversityResult(proto.Message): r"""Result of the l-diversity computation. + Attributes: sensitive_value_frequency_histogram_buckets (Sequence[google.cloud.dlp_v2.types.AnalyzeDataSourceRiskDetails.LDiversityResult.LDiversityHistogramBucket]): Histogram of l-diversity equivalence class @@ -1994,6 +2034,7 @@ class KMapEstimationResult(proto.Message): class KMapEstimationQuasiIdValues(proto.Message): r"""A tuple of values for the quasi-identifier columns. + Attributes: quasi_ids_values (Sequence[google.cloud.dlp_v2.types.Value]): The quasi-identifier values. @@ -2067,6 +2108,7 @@ class DeltaPresenceEstimationResult(proto.Message): class DeltaPresenceEstimationQuasiIdValues(proto.Message): r"""A tuple of values for the quasi-identifier columns. + Attributes: quasi_ids_values (Sequence[google.cloud.dlp_v2.types.Value]): The quasi-identifier values. @@ -2131,6 +2173,7 @@ class DeltaPresenceEstimationHistogramBucket(proto.Message): class RequestedRiskAnalysisOptions(proto.Message): r"""Risk analysis options. + Attributes: job_config (google.cloud.dlp_v2.types.RiskAnalysisJobConfig): The job config for the risk job. @@ -2171,6 +2214,7 @@ class RequestedRiskAnalysisOptions(proto.Message): class ValueFrequency(proto.Message): r"""A value of a field, including its frequency. + Attributes: value (google.cloud.dlp_v2.types.Value): A value contained in the field in question. @@ -2230,6 +2274,7 @@ class Value(proto.Message): class QuoteInfo(proto.Message): r"""Message for infoType-dependent details parsed from quote. + Attributes: date_time (google.cloud.dlp_v2.types.DateTime): The date time indicated by the quote. @@ -2258,6 +2303,7 @@ class DateTime(proto.Message): class TimeZone(proto.Message): r"""Time zone of the date time object. + Attributes: offset_minutes (int): Set only if the offset can be determined. @@ -2275,6 +2321,7 @@ class TimeZone(proto.Message): class DeidentifyConfig(proto.Message): r"""The configuration that controls how the data will change. + Attributes: info_type_transformations (google.cloud.dlp_v2.types.InfoTypeTransformations): Treat the dataset as free-form text and apply @@ -2327,14 +2374,16 @@ class TransformationErrorHandling(proto.Message): class ThrowError(proto.Message): r"""Throw an error and fail the request when a transformation error occurs. - """ + + """ class LeaveUntransformed(proto.Message): r"""Skips the data without modifying it if the requested transformation would cause an error. For example, if a ``DateShift`` transformation were applied an an IP address, this mode would leave the IP address unchanged in the response. - """ + + """ throw_error = proto.Field( proto.MESSAGE, number=1, oneof="mode", message=ThrowError, @@ -2346,6 +2395,7 @@ class LeaveUntransformed(proto.Message): class PrimitiveTransformation(proto.Message): r"""A rule for transforming a value. + Attributes: replace_config (google.cloud.dlp_v2.types.ReplaceValueConfig): Replace @@ -2538,6 +2588,7 @@ class CryptoDeterministicConfig(proto.Message): class ReplaceValueConfig(proto.Message): r"""Replace each input value with a given ``Value``. + Attributes: new_value (google.cloud.dlp_v2.types.Value): Value to replace it with. @@ -2547,7 +2598,8 @@ class ReplaceValueConfig(proto.Message): class ReplaceWithInfoTypeConfig(proto.Message): - r"""Replace each matching finding with the name of the info_type. """ + r"""Replace each matching finding with the name of the info_type. + """ class RedactConfig(proto.Message): @@ -2555,7 +2607,8 @@ class RedactConfig(proto.Message): ``InfoTypeTransformation`` transforming PHONE_NUMBER, and input 'My phone number is 206-555-0123', the output would be 'My phone number is '. - """ + + """ class CharsToIgnore(proto.Message): @@ -2986,6 +3039,7 @@ class InfoTypeTransformation(proto.Message): class FieldTransformation(proto.Message): r"""The transformation to apply to the field. + Attributes: fields (Sequence[google.cloud.dlp_v2.types.FieldId]): Required. Input field(s) to apply the @@ -3110,6 +3164,7 @@ class Condition(proto.Message): class Conditions(proto.Message): r"""A collection of conditions. + Attributes: conditions (Sequence[google.cloud.dlp_v2.types.RecordCondition.Condition]): A collection of conditions. @@ -3121,6 +3176,7 @@ class Conditions(proto.Message): class Expressions(proto.Message): r"""An expression, consisting or an operator and conditions. + Attributes: logical_operator (google.cloud.dlp_v2.types.RecordCondition.Expressions.LogicalOperator): The operator to apply to the result of conditions. Default @@ -3146,6 +3202,7 @@ class LogicalOperator(proto.Enum): class TransformationOverview(proto.Message): r"""Overview of the modifications that occurred. + Attributes: transformed_bytes (int): Total size in bytes that were transformed in @@ -3232,6 +3289,7 @@ class SummaryResult(proto.Message): class Schedule(proto.Message): r"""Schedule for triggeredJobs. + Attributes: recurrence_period_duration (google.protobuf.duration_pb2.Duration): With this option a job is started a regular @@ -3253,7 +3311,8 @@ class Schedule(proto.Message): class Manual(proto.Message): r"""Job trigger option for hybrid jobs. Jobs must be manually created and finished. - """ + + """ class InspectTemplate(proto.Message): @@ -3405,6 +3464,7 @@ class Status(proto.Enum): class Trigger(proto.Message): r"""What event needs to occur for a new job to be started. + Attributes: schedule (google.cloud.dlp_v2.types.Schedule): Create a job on a repeating basis based on @@ -3511,7 +3571,8 @@ class PublishSummaryToCscc(proto.Message): https://cloud.google.com/terms/service-terms Only a single instance of this action can be specified. Compatible with: Inspect - """ + + """ class PublishFindingsToCloudDataCatalog(proto.Message): r"""Publish findings of a DlpJob to Cloud Data Catalog. Labels @@ -3525,19 +3586,22 @@ class PublishFindingsToCloudDataCatalog(proto.Message): Only a single instance of this action can be specified and only allowed if all resources being scanned are BigQuery tables. Compatible with: Inspect - """ + + """ class JobNotificationEmails(proto.Message): r"""Enable email notification to project owners and editors on jobs's completion/failure. - """ + + """ class PublishToStackdriver(proto.Message): r"""Enable Stackdriver metric dlp.googleapis.com/finding_count. This will publish a metric to stack driver on each infotype requested and how many findings were found for it. CustomDetectors will be bucketed as 'Custom' under the Stackdriver label 'info_type'. - """ + + """ save_findings = proto.Field( proto.MESSAGE, number=1, oneof="action", message=SaveFindings, @@ -3564,6 +3628,7 @@ class PublishToStackdriver(proto.Message): class CreateInspectTemplateRequest(proto.Message): r"""Request message for CreateInspectTemplate. + Attributes: parent (str): Required. Parent resource name. @@ -3609,6 +3674,7 @@ class CreateInspectTemplateRequest(proto.Message): class UpdateInspectTemplateRequest(proto.Message): r"""Request message for UpdateInspectTemplate. + Attributes: name (str): Required. Resource name of organization and inspectTemplate @@ -3630,6 +3696,7 @@ class UpdateInspectTemplateRequest(proto.Message): class GetInspectTemplateRequest(proto.Message): r"""Request message for GetInspectTemplate. + Attributes: name (str): Required. Resource name of the organization and @@ -3643,6 +3710,7 @@ class GetInspectTemplateRequest(proto.Message): class ListInspectTemplatesRequest(proto.Message): r"""Request message for ListInspectTemplates. + Attributes: parent (str): Required. Parent resource name. @@ -3703,6 +3771,7 @@ class ListInspectTemplatesRequest(proto.Message): class ListInspectTemplatesResponse(proto.Message): r"""Response message for ListInspectTemplates. + Attributes: inspect_templates (Sequence[google.cloud.dlp_v2.types.InspectTemplate]): List of inspectTemplates, up to page_size in @@ -3725,6 +3794,7 @@ def raw_page(self): class DeleteInspectTemplateRequest(proto.Message): r"""Request message for DeleteInspectTemplate. + Attributes: name (str): Required. Resource name of the organization and @@ -3738,6 +3808,7 @@ class DeleteInspectTemplateRequest(proto.Message): class CreateJobTriggerRequest(proto.Message): r"""Request message for CreateJobTrigger. + Attributes: parent (str): Required. Parent resource name. @@ -3778,6 +3849,7 @@ class CreateJobTriggerRequest(proto.Message): class ActivateJobTriggerRequest(proto.Message): r"""Request message for ActivateJobTrigger. + Attributes: name (str): Required. Resource name of the trigger to activate, for @@ -3789,6 +3861,7 @@ class ActivateJobTriggerRequest(proto.Message): class UpdateJobTriggerRequest(proto.Message): r"""Request message for UpdateJobTrigger. + Attributes: name (str): Required. Resource name of the project and the triggeredJob, @@ -3809,6 +3882,7 @@ class UpdateJobTriggerRequest(proto.Message): class GetJobTriggerRequest(proto.Message): r"""Request message for GetJobTrigger. + Attributes: name (str): Required. Resource name of the project and the triggeredJob, @@ -3871,6 +3945,7 @@ class CreateDlpJobRequest(proto.Message): class ListJobTriggersRequest(proto.Message): r"""Request message for ListJobTriggers. + Attributes: parent (str): Required. Parent resource name. @@ -3968,6 +4043,7 @@ class ListJobTriggersRequest(proto.Message): class ListJobTriggersResponse(proto.Message): r"""Response message for ListJobTriggers. + Attributes: job_triggers (Sequence[google.cloud.dlp_v2.types.JobTrigger]): List of triggeredJobs, up to page_size in @@ -3988,6 +4064,7 @@ def raw_page(self): class DeleteJobTriggerRequest(proto.Message): r"""Request message for DeleteJobTrigger. + Attributes: name (str): Required. Resource name of the project and the triggeredJob, @@ -4000,6 +4077,7 @@ class DeleteJobTriggerRequest(proto.Message): class InspectJobConfig(proto.Message): r"""Controls what and how to inspect for findings. + Attributes: storage_config (google.cloud.dlp_v2.types.StorageConfig): The data to scan. @@ -4024,6 +4102,7 @@ class InspectJobConfig(proto.Message): class DlpJob(proto.Message): r"""Combines all of the information about a DLP job. + Attributes: name (str): The server-assigned name. @@ -4080,6 +4159,7 @@ class JobState(proto.Enum): class GetDlpJobRequest(proto.Message): r"""The request message for [DlpJobs.GetDlpJob][]. + Attributes: name (str): Required. The name of the DlpJob resource. @@ -4090,6 +4170,7 @@ class GetDlpJobRequest(proto.Message): class ListDlpJobsRequest(proto.Message): r"""The request message for listing DLP jobs. + Attributes: parent (str): Required. Parent resource name. @@ -4186,6 +4267,7 @@ class ListDlpJobsRequest(proto.Message): class ListDlpJobsResponse(proto.Message): r"""The response message for listing DLP jobs. + Attributes: jobs (Sequence[google.cloud.dlp_v2.types.DlpJob]): A list of DlpJobs that matches the specified @@ -4204,6 +4286,7 @@ def raw_page(self): class CancelDlpJobRequest(proto.Message): r"""The request message for canceling a DLP job. + Attributes: name (str): Required. The name of the DlpJob resource to @@ -4215,6 +4298,7 @@ class CancelDlpJobRequest(proto.Message): class FinishDlpJobRequest(proto.Message): r"""The request message for finishing a DLP hybrid job. + Attributes: name (str): Required. The name of the DlpJob resource to @@ -4226,6 +4310,7 @@ class FinishDlpJobRequest(proto.Message): class DeleteDlpJobRequest(proto.Message): r"""The request message for deleting a DLP job. + Attributes: name (str): Required. The name of the DlpJob resource to @@ -4237,6 +4322,7 @@ class DeleteDlpJobRequest(proto.Message): class CreateDeidentifyTemplateRequest(proto.Message): r"""Request message for CreateDeidentifyTemplate. + Attributes: parent (str): Required. Parent resource name. @@ -4284,6 +4370,7 @@ class CreateDeidentifyTemplateRequest(proto.Message): class UpdateDeidentifyTemplateRequest(proto.Message): r"""Request message for UpdateDeidentifyTemplate. + Attributes: name (str): Required. Resource name of organization and deidentify @@ -4307,6 +4394,7 @@ class UpdateDeidentifyTemplateRequest(proto.Message): class GetDeidentifyTemplateRequest(proto.Message): r"""Request message for GetDeidentifyTemplate. + Attributes: name (str): Required. Resource name of the organization and deidentify @@ -4320,6 +4408,7 @@ class GetDeidentifyTemplateRequest(proto.Message): class ListDeidentifyTemplatesRequest(proto.Message): r"""Request message for ListDeidentifyTemplates. + Attributes: parent (str): Required. Parent resource name. @@ -4380,6 +4469,7 @@ class ListDeidentifyTemplatesRequest(proto.Message): class ListDeidentifyTemplatesResponse(proto.Message): r"""Response message for ListDeidentifyTemplates. + Attributes: deidentify_templates (Sequence[google.cloud.dlp_v2.types.DeidentifyTemplate]): List of deidentify templates, up to page_size in @@ -4402,6 +4492,7 @@ def raw_page(self): class DeleteDeidentifyTemplateRequest(proto.Message): r"""Request message for DeleteDeidentifyTemplate. + Attributes: name (str): Required. Resource name of the organization and deidentify @@ -4450,6 +4541,7 @@ class LargeCustomDictionaryConfig(proto.Message): class LargeCustomDictionaryStats(proto.Message): r"""Summary statistics of a custom dictionary. + Attributes: approx_num_phrases (int): Approximate number of distinct phrases in the @@ -4499,6 +4591,7 @@ class StoredInfoTypeConfig(proto.Message): class StoredInfoTypeStats(proto.Message): r"""Statistics for a StoredInfoType. + Attributes: large_custom_dictionary (google.cloud.dlp_v2.types.LargeCustomDictionaryStats): StoredInfoType where findings are defined by @@ -4578,6 +4671,7 @@ class StoredInfoType(proto.Message): class CreateStoredInfoTypeRequest(proto.Message): r"""Request message for CreateStoredInfoType. + Attributes: parent (str): Required. Parent resource name. @@ -4624,6 +4718,7 @@ class CreateStoredInfoTypeRequest(proto.Message): class UpdateStoredInfoTypeRequest(proto.Message): r"""Request message for UpdateStoredInfoType. + Attributes: name (str): Required. Resource name of organization and storedInfoType @@ -4648,6 +4743,7 @@ class UpdateStoredInfoTypeRequest(proto.Message): class GetStoredInfoTypeRequest(proto.Message): r"""Request message for GetStoredInfoType. + Attributes: name (str): Required. Resource name of the organization and @@ -4661,6 +4757,7 @@ class GetStoredInfoTypeRequest(proto.Message): class ListStoredInfoTypesRequest(proto.Message): r"""Request message for ListStoredInfoTypes. + Attributes: parent (str): Required. Parent resource name. @@ -4721,6 +4818,7 @@ class ListStoredInfoTypesRequest(proto.Message): class ListStoredInfoTypesResponse(proto.Message): r"""Response message for ListStoredInfoTypes. + Attributes: stored_info_types (Sequence[google.cloud.dlp_v2.types.StoredInfoType]): List of storedInfoTypes, up to page_size in @@ -4743,6 +4841,7 @@ def raw_page(self): class DeleteStoredInfoTypeRequest(proto.Message): r"""Request message for DeleteStoredInfoType. + Attributes: name (str): Required. Resource name of the organization and @@ -4808,6 +4907,7 @@ class HybridContentItem(proto.Message): class HybridFindingDetails(proto.Message): r"""Populate to associate additional data with each finding. + Attributes: container_details (google.cloud.dlp_v2.types.Container): Details about the container where the content @@ -4862,7 +4962,8 @@ class HybridFindingDetails(proto.Message): class HybridInspectResponse(proto.Message): - r"""Quota exceeded errors will be thrown once quota has been met. """ + r"""Quota exceeded errors will be thrown once quota has been met. + """ __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/dlp_v2/types/storage.py b/google/cloud/dlp_v2/types/storage.py index 9bd2fd62..8b8d724d 100644 --- a/google/cloud/dlp_v2/types/storage.py +++ b/google/cloud/dlp_v2/types/storage.py @@ -79,6 +79,7 @@ class FileType(proto.Enum): class InfoType(proto.Message): r"""Type of information detected by the API. + Attributes: name (str): Name of the information type. Either a name of your choosing @@ -94,6 +95,7 @@ class InfoType(proto.Message): class StoredType(proto.Message): r"""A reference to a StoredInfoType to use with scanning. + Attributes: name (str): Resource name of the requested ``StoredInfoType``, for @@ -217,6 +219,7 @@ class WordList(proto.Message): class Regex(proto.Message): r"""Message defining a custom regular expression. + Attributes: pattern (str): Pattern defining the regular expression. Its @@ -242,7 +245,8 @@ class SurrogateType(proto.Message): should be used in conjunction with a field on the transformation such as ``surrogate_info_type``. This CustomInfoType does not support the use of ``detection_rules``. - """ + + """ class DetectionRule(proto.Message): r"""Deprecated; use ``InspectionRuleSet`` instead. Rule for modifying a @@ -363,6 +367,7 @@ class HotwordRule(proto.Message): class FieldId(proto.Message): r"""General identifier of a data field in a storage service. + Attributes: name (str): Name describing the field. @@ -394,6 +399,7 @@ class PartitionId(proto.Message): class KindExpression(proto.Message): r"""A representation of a Datastore kind. + Attributes: name (str): The name of the kind. @@ -404,6 +410,7 @@ class KindExpression(proto.Message): class DatastoreOptions(proto.Message): r"""Options defining a data set within Google Cloud Datastore. + Attributes: partition_id (google.cloud.dlp_v2.types.PartitionId): A partition ID identifies a grouping of @@ -533,6 +540,7 @@ class SampleMethod(proto.Enum): class FileSet(proto.Message): r"""Set of files to scan. + Attributes: url (str): The Cloud Storage url of the file(s) to scan, in the format @@ -567,6 +575,7 @@ class FileSet(proto.Message): class CloudStorageFileSet(proto.Message): r"""Message representing a set of files in Cloud Storage. + Attributes: url (str): The url, in the format ``gs:///``. Trailing @@ -578,6 +587,7 @@ class CloudStorageFileSet(proto.Message): class CloudStoragePath(proto.Message): r"""Message representing a single file or path in Cloud Storage. + Attributes: path (str): A url representing a file or path (no wildcards) in Cloud @@ -589,6 +599,7 @@ class CloudStoragePath(proto.Message): class BigQueryOptions(proto.Message): r"""Options defining BigQuery table and row identifiers. + Attributes: table_reference (google.cloud.dlp_v2.types.BigQueryTable): Complete BigQuery table reference. @@ -641,6 +652,7 @@ class SampleMethod(proto.Enum): class StorageConfig(proto.Message): r"""Shared message indicating Cloud storage type. + Attributes: datastore_options (google.cloud.dlp_v2.types.DatastoreOptions): Google Cloud Datastore options. @@ -777,6 +789,7 @@ class HybridOptions(proto.Message): class BigQueryKey(proto.Message): r"""Row key for identifying a record in BigQuery table. + Attributes: table_reference (google.cloud.dlp_v2.types.BigQueryTable): Complete BigQuery table reference. @@ -795,6 +808,7 @@ class BigQueryKey(proto.Message): class DatastoreKey(proto.Message): r"""Record key for a finding in Cloud Datastore. + Attributes: entity_key (google.cloud.dlp_v2.types.Key): Datastore entity key. @@ -908,6 +922,7 @@ class BigQueryTable(proto.Message): class BigQueryField(proto.Message): r"""Message defining a field of a BigQuery table. + Attributes: table (google.cloud.dlp_v2.types.BigQueryTable): Source table of the field. @@ -938,6 +953,7 @@ class EntityId(proto.Message): class TableOptions(proto.Message): r"""Instructions regarding the table content being inspected. + Attributes: identifying_fields (Sequence[google.cloud.dlp_v2.types.FieldId]): The columns that are the primary keys for diff --git a/tests/unit/gapic/dlp_v2/test_dlp_service.py b/tests/unit/gapic/dlp_v2/test_dlp_service.py index 43407a72..c3508def 100644 --- a/tests/unit/gapic/dlp_v2/test_dlp_service.py +++ b/tests/unit/gapic/dlp_v2/test_dlp_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.dlp_v2.services.dlp_service import DlpServiceAsyncClient @@ -8126,6 +8127,9 @@ def test_dlp_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_dlp_service_base_transport_with_credentials_file(): @@ -8719,3 +8723,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 = DlpServiceAsyncClient( + 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 = DlpServiceClient( + 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 = DlpServiceClient( + 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()