Skip to content

Commit

Permalink
Migrate Data Loss Prevention system tests according to AIP-47 (#26060)
Browse files Browse the repository at this point in the history
  • Loading branch information
bhirsz authored Sep 21, 2022
1 parent ba9a762 commit a60e3b9
Show file tree
Hide file tree
Showing 13 changed files with 713 additions and 313 deletions.
215 changes: 0 additions & 215 deletions airflow/providers/google/cloud/example_dags/example_dlp.py

This file was deleted.

10 changes: 5 additions & 5 deletions airflow/providers/google/cloud/operators/dlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ class CloudDLPDeleteDLPJobOperator(BaseOperator):
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:CloudDLPDeleteDLPJobOperator`
:param dlp_job_id: The ID of the DLP job resource to be cancelled.
:param dlp_job_id: The ID of the DLP job resource to be deleted.
:param project_id: (Optional) Google Cloud project ID where the
DLP Instance exists. If set to None or missing, the default
project_id from the Google Cloud connection is used.
Expand Down Expand Up @@ -1648,7 +1648,7 @@ def execute(self, context: Context):
gcp_conn_id=self.gcp_conn_id,
impersonation_chain=self.impersonation_chain,
)
template = hook.list_deidentify_templates(
templates = hook.list_deidentify_templates(
organization_id=self.organization_id,
project_id=self.project_id,
page_size=self.page_size,
Expand All @@ -1658,7 +1658,7 @@ def execute(self, context: Context):
metadata=self.metadata,
)
# the MessageToDict does not have the right type defined as possible to pass in constructor
return MessageToDict(template) # type: ignore[arg-type]
return [MessageToDict(template) for template in templates] # type: ignore[arg-type]


class CloudDLPListDLPJobsOperator(BaseOperator):
Expand Down Expand Up @@ -1735,7 +1735,7 @@ def execute(self, context: Context):
gcp_conn_id=self.gcp_conn_id,
impersonation_chain=self.impersonation_chain,
)
job = hook.list_dlp_jobs(
jobs = hook.list_dlp_jobs(
project_id=self.project_id,
results_filter=self.results_filter,
page_size=self.page_size,
Expand All @@ -1746,7 +1746,7 @@ def execute(self, context: Context):
metadata=self.metadata,
)
# the MessageToDict does not have the right type defined as possible to pass in constructor
return MessageToDict(job) # type: ignore[arg-type]
return [MessageToDict(job) for job in jobs] # type: ignore[arg-type]


class CloudDLPListInfoTypesOperator(BaseOperator):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Create Stored Info-Type
To create a custom info-type you can use
:class:`~airflow.providers.google.cloud.operators.cloud.dlp.CloudDLPCreateStoredInfoTypeOperator`.

.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_dlp.py
.. exampleinclude:: /../../tests/system/providers/google/cloud/data_loss_prevention/example_dlp_info_types.py
:language: python
:dedent: 4
:start-after: [START howto_operator_dlp_create_info_type]
Expand Down Expand Up @@ -70,7 +70,7 @@ Update Stored Info-Type
To update a info-type you can use
:class:`~airflow.providers.google.cloud.operators.cloud.dlp.CloudDLPUpdateStoredInfoTypeOperator`.

.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_dlp.py
.. exampleinclude:: /../../tests/system/providers/google/cloud/data_loss_prevention/example_dlp_info_types.py
:language: python
:dedent: 4
:start-after: [START howto_operator_dlp_update_info_type]
Expand All @@ -85,7 +85,7 @@ Deleting Stored Info-Type
To delete a info-type you can use
:class:`~airflow.providers.google.cloud.operators.cloud.dlp.CloudDLPDeleteStoredInfoTypeOperator`.

.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_dlp.py
.. exampleinclude:: /../../tests/system/providers/google/cloud/data_loss_prevention/example_dlp_info_types.py
:language: python
:dedent: 4
:start-after: [START howto_operator_dlp_delete_info_type]
Expand All @@ -112,7 +112,7 @@ Creating Template
To create a inspection template you can use
:class:`~airflow.providers.google.cloud.operators.cloud.dlp.CloudDLPCreateInspectTemplateOperator`.

.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_dlp.py
.. exampleinclude:: /../../tests/system/providers/google/cloud/data_loss_prevention/example_dlp_inspect_template.py
:language: python
:dedent: 4
:start-after: [START howto_operator_dlp_create_inspect_template]
Expand All @@ -139,7 +139,7 @@ Using Template
To find potentially sensitive info using the inspection template we just created, we can use
:class:`~airflow.providers.google.cloud.operators.cloud.dlp.CloudDLPInspectContentOperator`

.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_dlp.py
.. exampleinclude:: /../../tests/system/providers/google/cloud/data_loss_prevention/example_dlp_inspect_template.py
:language: python
:dedent: 4
:start-after: [START howto_operator_dlp_use_inspect_template]
Expand All @@ -161,7 +161,7 @@ Deleting Template
To delete the template you can use
:class:`~airflow.providers.google.cloud.operators.cloud.dlp.CloudDLPDeleteInspectTemplateOperator`.

.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_dlp.py
.. exampleinclude:: /../../tests/system/providers/google/cloud/data_loss_prevention/example_dlp_inspect_template.py
:language: python
:dedent: 4
:start-after: [START howto_operator_dlp_delete_inspect_template]
Expand Down Expand Up @@ -236,7 +236,7 @@ Creating Job Trigger
To create a job trigger you can use
:class:`~airflow.providers.google.cloud.operators.cloud.dlp.CloudDLPCreateJobTriggerOperator`.

.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_dlp.py
.. exampleinclude:: /../../tests/system/providers/google/cloud/data_loss_prevention/example_dlp_job_trigger.py
:language: python
:dedent: 4
:start-after: [START howto_operator_dlp_create_job_trigger]
Expand All @@ -261,7 +261,7 @@ Updating Job Trigger
To update a job trigger you can use
:class:`~airflow.providers.google.cloud.operators.cloud.dlp.CloudDLPUpdateJobTriggerOperator`.

.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_dlp.py
.. exampleinclude:: /../../tests/system/providers/google/cloud/data_loss_prevention/example_dlp_job_trigger.py
:language: python
:dedent: 4
:start-after: [START howto_operator_dlp_update_job_trigger]
Expand All @@ -275,7 +275,7 @@ Deleting Job Trigger
To delete a job trigger you can use
:class:`~airflow.providers.google.cloud.operators.cloud.dlp.CloudDLPDeleteJobTriggerOperator`.

.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_dlp.py
.. exampleinclude:: /../../tests/system/providers/google/cloud/data_loss_prevention/example_dlp_job_trigger.py
:language: python
:dedent: 4
:start-after: [START howto_operator_dlp_delete_job_trigger]
Expand All @@ -297,15 +297,15 @@ Configuration information defines how you want the sensitive data de-identified.

This config can either be saved and persisted in de-identification templates or defined in a :class:`~google.cloud.dlp_v2.types.DeidentifyConfig` object:

.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_dlp.py
.. exampleinclude:: /../../tests/system/providers/google/cloud/data_loss_prevention/example_dlp_deidentify_content.py
:language: python
:start-after: [START dlp_deidentify_config_example]
:end-before: [END dlp_deidentify_config_example]

To de-identify potentially sensitive information from a content item, you can use
:class:`~airflow.providers.google.cloud.operators.cloud.dlp.CloudDLPDeidentifyContentOperator`.

.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_dlp.py
.. exampleinclude:: /../../tests/system/providers/google/cloud/data_loss_prevention/example_dlp_deidentify_content.py
:language: python
:dedent: 4
:start-after: [START _howto_operator_dlp_deidentify_content]
Expand Down
19 changes: 0 additions & 19 deletions tests/always/test_project_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,25 +279,6 @@ class TestGoogleProviderProjectStructure(ExampleCoverageTest, AssetsCoverageTest

MISSING_EXAMPLES_FOR_CLASSES = {
'airflow.providers.google.cloud.operators.mlengine.MLEngineTrainingCancelJobOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPGetStoredInfoTypeOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPReidentifyContentOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPCreateDeidentifyTemplateOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPCreateDLPJobOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPUpdateDeidentifyTemplateOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPGetDLPJobTriggerOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPListDeidentifyTemplatesOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPGetDeidentifyTemplateOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPListInspectTemplatesOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPListStoredInfoTypesOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPUpdateInspectTemplateOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPDeleteDLPJobOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPListJobTriggersOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPCancelDLPJobOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPGetDLPJobOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPGetInspectTemplateOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPListInfoTypesOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPDeleteDeidentifyTemplateOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPListDLPJobsOperator',
'airflow.providers.google.cloud.operators.dlp.CloudDLPRedactImageOperator',
'airflow.providers.google.cloud.transfers.cassandra_to_gcs.CassandraToGCSOperator',
'airflow.providers.google.cloud.transfers.adls_to_gcs.ADLSToGCSOperator',
Expand Down
Loading

0 comments on commit a60e3b9

Please sign in to comment.