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

feat: add support for hybrid jobs (via synth) #10

Merged
merged 3 commits into from Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
234 changes: 234 additions & 0 deletions google/cloud/dlp_v2/gapic/dlp_service_client.py
Expand Up @@ -2175,6 +2175,157 @@ def cancel_dlp_job(
request, retry=retry, timeout=timeout, metadata=metadata
)

def finish_dlp_job(
self,
name,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Finish a running hybrid DlpJob. Triggers the finalization steps and running
of any enabled actions that have not yet run.
Early access feature is in a pre-release state and might change or have
limited support. For more information, see
https://cloud.google.com/products#product-launch-stages.

Example:
>>> from google.cloud import dlp_v2
>>>
>>> client = dlp_v2.DlpServiceClient()
>>>
>>> name = client.dlp_job_path('[PROJECT]', '[DLP_JOB]')
>>>
>>> client.finish_dlp_job(name)

Args:
name (str): Required. The name of the DlpJob resource to be cancelled.
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will
be retried using a default configuration.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.

Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "finish_dlp_job" not in self._inner_api_calls:
self._inner_api_calls[
"finish_dlp_job"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.finish_dlp_job,
default_retry=self._method_configs["FinishDlpJob"].retry,
default_timeout=self._method_configs["FinishDlpJob"].timeout,
client_info=self._client_info,
)

request = dlp_pb2.FinishDlpJobRequest(name=name)
if metadata is None:
metadata = []
metadata = list(metadata)
try:
routing_header = [("name", name)]
except AttributeError:
pass
else:
routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
routing_header
)
metadata.append(routing_metadata)

self._inner_api_calls["finish_dlp_job"](
request, retry=retry, timeout=timeout, metadata=metadata
)

def hybrid_inspect_dlp_job(
self,
name,
hybrid_item=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Inspect hybrid content and store findings to a job.
To review the findings inspect the job. Inspection will occur
asynchronously.
Early access feature is in a pre-release state and might change or have
limited support. For more information, see
https://cloud.google.com/products#product-launch-stages.

Example:
>>> from google.cloud import dlp_v2
>>>
>>> client = dlp_v2.DlpServiceClient()
>>>
>>> # TODO: Initialize `name`:
>>> name = ''
>>>
>>> response = client.hybrid_inspect_dlp_job(name)

Args:
name (str): Required. Resource name of the job to execute a hybrid inspect on, for
example ``projects/dlp-test-project/dlpJob/53234423``.
hybrid_item (Union[dict, ~google.cloud.dlp_v2.types.HybridContentItem]): The item to inspect.

If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.dlp_v2.types.HybridContentItem`
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will
be retried using a default configuration.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.

Returns:
A :class:`~google.cloud.dlp_v2.types.HybridInspectResponse` instance.

Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "hybrid_inspect_dlp_job" not in self._inner_api_calls:
self._inner_api_calls[
"hybrid_inspect_dlp_job"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.hybrid_inspect_dlp_job,
default_retry=self._method_configs["HybridInspectDlpJob"].retry,
default_timeout=self._method_configs["HybridInspectDlpJob"].timeout,
client_info=self._client_info,
)

request = dlp_pb2.HybridInspectDlpJobRequest(name=name, hybrid_item=hybrid_item)
if metadata is None:
metadata = []
metadata = list(metadata)
try:
routing_header = [("name", name)]
except AttributeError:
pass
else:
routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
routing_header
)
metadata.append(routing_metadata)

return self._inner_api_calls["hybrid_inspect_dlp_job"](
request, retry=retry, timeout=timeout, metadata=metadata
)

def list_job_triggers(
self,
parent,
Expand Down Expand Up @@ -2473,6 +2624,89 @@ def delete_job_trigger(
request, retry=retry, timeout=timeout, metadata=metadata
)

def hybrid_inspect_job_trigger(
self,
name,
hybrid_item=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Inspect hybrid content and store findings to a trigger. The inspection
will be processed asynchronously. To review the findings monitor the
jobs within the trigger.
Early access feature is in a pre-release state and might change or have
limited support. For more information, see
https://cloud.google.com/products#product-launch-stages.

Example:
>>> from google.cloud import dlp_v2
>>>
>>> client = dlp_v2.DlpServiceClient()
>>>
>>> # TODO: Initialize `name`:
>>> name = ''
>>>
>>> response = client.hybrid_inspect_job_trigger(name)

Args:
name (str): Required. Resource name of the trigger to execute a hybrid inspect on,
for example ``projects/dlp-test-project/jobTriggers/53234423``.
hybrid_item (Union[dict, ~google.cloud.dlp_v2.types.HybridContentItem]): The item to inspect.

If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.dlp_v2.types.HybridContentItem`
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will
be retried using a default configuration.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.

Returns:
A :class:`~google.cloud.dlp_v2.types.HybridInspectResponse` instance.

Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "hybrid_inspect_job_trigger" not in self._inner_api_calls:
self._inner_api_calls[
"hybrid_inspect_job_trigger"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.hybrid_inspect_job_trigger,
default_retry=self._method_configs["HybridInspectJobTrigger"].retry,
default_timeout=self._method_configs["HybridInspectJobTrigger"].timeout,
client_info=self._client_info,
)

request = dlp_pb2.HybridInspectJobTriggerRequest(
name=name, hybrid_item=hybrid_item
)
if metadata is None:
metadata = []
metadata = list(metadata)
try:
routing_header = [("name", name)]
except AttributeError:
pass
else:
routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
routing_header
)
metadata.append(routing_metadata)

return self._inner_api_calls["hybrid_inspect_job_trigger"](
request, retry=retry, timeout=timeout, metadata=metadata
)

def update_job_trigger(
self,
name,
Expand Down
15 changes: 15 additions & 0 deletions google/cloud/dlp_v2/gapic/dlp_service_client_config.py
Expand Up @@ -117,6 +117,16 @@
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
"FinishDlpJob": {
"timeout_millis": 300000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
"HybridInspectDlpJob": {
"timeout_millis": 300000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
"ListJobTriggers": {
"timeout_millis": 300000,
"retry_codes_name": "idempotent",
Expand All @@ -132,6 +142,11 @@
"retry_codes_name": "idempotent",
"retry_params_name": "default",
},
"HybridInspectJobTrigger": {
"timeout_millis": 300000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
"UpdateJobTrigger": {
"timeout_millis": 300000,
"retry_codes_name": "non_idempotent",
Expand Down
11 changes: 9 additions & 2 deletions google/cloud/dlp_v2/gapic/enums.py
Expand Up @@ -338,15 +338,20 @@ class ExclusionType(enum.IntEnum):
class DlpJob(object):
class JobState(enum.IntEnum):
"""
Possible states of a job.
Possible states of a job. New items may be added.

Attributes:
JOB_STATE_UNSPECIFIED (int): Unused.
PENDING (int): The job has not yet started.
RUNNING (int): The job is currently running.
RUNNING (int): The job is currently running. Once a job has finished it will transition
to FAILED or DONE.
DONE (int): The job is no longer running.
CANCELED (int): The job was canceled before it could complete.
FAILED (int): The job had an error and did not complete.
ACTIVE (int): The job is currently accepting findings via hybridInspect.
A hybrid job in ACTIVE state may continue to have findings added to it
through calling of hybridInspect. After the job has finished no more
calls to hybridInspect may be made. ACTIVE jobs can transition to DONE.
"""

JOB_STATE_UNSPECIFIED = 0
Expand All @@ -355,6 +360,7 @@ class JobState(enum.IntEnum):
DONE = 3
CANCELED = 4
FAILED = 5
ACTIVE = 6


class JobTrigger(object):
Expand Down Expand Up @@ -382,6 +388,7 @@ class OutputStorageConfig(object):
class OutputSchema(enum.IntEnum):
"""
Predefined schemas for storing findings.
Only for use with external storage.

Attributes:
OUTPUT_SCHEMA_UNSPECIFIED (int): Unused.
Expand Down
53 changes: 53 additions & 0 deletions google/cloud/dlp_v2/gapic/transports/dlp_service_grpc_transport.py
Expand Up @@ -426,6 +426,41 @@ def cancel_dlp_job(self):
"""
return self._stubs["dlp_service_stub"].CancelDlpJob

@property
def finish_dlp_job(self):
"""Return the gRPC stub for :meth:`DlpServiceClient.finish_dlp_job`.

Finish a running hybrid DlpJob. Triggers the finalization steps and running
of any enabled actions that have not yet run.
Early access feature is in a pre-release state and might change or have
limited support. For more information, see
https://cloud.google.com/products#product-launch-stages.

Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["dlp_service_stub"].FinishDlpJob

@property
def hybrid_inspect_dlp_job(self):
"""Return the gRPC stub for :meth:`DlpServiceClient.hybrid_inspect_dlp_job`.

Inspect hybrid content and store findings to a job.
To review the findings inspect the job. Inspection will occur
asynchronously.
Early access feature is in a pre-release state and might change or have
limited support. For more information, see
https://cloud.google.com/products#product-launch-stages.

Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["dlp_service_stub"].HybridInspectDlpJob

@property
def list_job_triggers(self):
"""Return the gRPC stub for :meth:`DlpServiceClient.list_job_triggers`.
Expand Down Expand Up @@ -468,6 +503,24 @@ def delete_job_trigger(self):
"""
return self._stubs["dlp_service_stub"].DeleteJobTrigger

@property
def hybrid_inspect_job_trigger(self):
"""Return the gRPC stub for :meth:`DlpServiceClient.hybrid_inspect_job_trigger`.

Inspect hybrid content and store findings to a trigger. The inspection
will be processed asynchronously. To review the findings monitor the
jobs within the trigger.
Early access feature is in a pre-release state and might change or have
limited support. For more information, see
https://cloud.google.com/products#product-launch-stages.

Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["dlp_service_stub"].HybridInspectJobTrigger

@property
def update_job_trigger(self):
"""Return the gRPC stub for :meth:`DlpServiceClient.update_job_trigger`.
Expand Down