Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 22550a9

Browse filesBrowse files
authored
fix DLP region tags, and add @flaky to pub/sub sample tests (GoogleCloudPlatform#1418)
1 parent d343967 commit 22550a9
Copy full SHA for 22550a9

File tree

Expand file treeCollapse file tree

7 files changed

+41
-4
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+41
-4
lines changed

‎dlp/deid.py

Copy file name to clipboardExpand all lines: dlp/deid.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import argparse
2020

2121

22+
# [START dlp_deidentify_masking]
2223
def deidentify_with_mask(project, string, masking_character=None,
2324
number_to_mask=0):
2425
"""Uses the Data Loss Prevention API to deidentify sensitive data in a
@@ -68,8 +69,10 @@ def deidentify_with_mask(project, string, masking_character=None,
6869

6970
# Print out the results.
7071
print(response.item.value)
72+
# [END dlp_deidentify_masking]
7173

7274

75+
# [START dlp_deidentify_fpe]
7376
def deidentify_with_fpe(project, string, alphabet=None,
7477
surrogate_type=None, key_name=None, wrapped_key=None):
7578
"""Uses the Data Loss Prevention API to deidentify sensitive data in a
@@ -147,8 +150,10 @@ def deidentify_with_fpe(project, string, alphabet=None,
147150

148151
# Print results
149152
print(response.item.value)
153+
# [END dlp_deidentify_fpe]
150154

151155

156+
# [START dlp_reidentify_fpe]
152157
def reidentify_with_fpe(project, string, alphabet=None,
153158
surrogate_type=None, key_name=None, wrapped_key=None):
154159
"""Uses the Data Loss Prevention API to reidentify sensitive data in a
@@ -232,8 +237,10 @@ def reidentify_with_fpe(project, string, alphabet=None,
232237

233238
# Print results
234239
print(response.item.value)
240+
# [END dlp_reidentify_fpe]
235241

236242

243+
# [START dlp_deidentify_date_shift]
237244
def deidentify_with_date_shift(project, input_csv_file=None,
238245
output_csv_file=None, date_fields=None,
239246
lower_bound_days=None, upper_bound_days=None,
@@ -384,6 +391,7 @@ def write_data(data):
384391
# Print status
385392
print('Successfully saved date-shift output to {}'.format(
386393
output_csv_file))
394+
# [END dlp_deidentify_date_shift]
387395

388396

389397
if __name__ == '__main__':

‎dlp/inspect_content_test.py

Copy file name to clipboardExpand all lines: dlp/inspect_content_test.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ def test_inspect_image_file(capsys):
222222
assert 'Info type: PHONE_NUMBER' in out
223223

224224

225+
@flaky
225226
def test_inspect_gcs_file(bucket, topic_id, subscription_id, capsys):
226227
inspect_content.inspect_gcs_file(
227228
GCLOUD_PROJECT,
@@ -235,6 +236,7 @@ def test_inspect_gcs_file(bucket, topic_id, subscription_id, capsys):
235236
assert 'Info type: EMAIL_ADDRESS' in out
236237

237238

239+
@flaky
238240
def test_inspect_gcs_file_no_results(
239241
bucket, topic_id, subscription_id, capsys):
240242
inspect_content.inspect_gcs_file(
@@ -263,6 +265,7 @@ def test_inspect_gcs_image_file(bucket, topic_id, subscription_id, capsys):
263265
assert 'Info type: EMAIL_ADDRESS' in out
264266

265267

268+
@flaky
266269
def test_inspect_gcs_multiple_files(bucket, topic_id, subscription_id, capsys):
267270
inspect_content.inspect_gcs_file(
268271
GCLOUD_PROJECT,
@@ -294,6 +297,7 @@ def _():
294297
assert 'Info type: EMAIL_ADDRESS' in out
295298

296299

300+
@flaky
297301
def test_inspect_datastore_no_results(
298302
datastore_project, topic_id, subscription_id, capsys):
299303
inspect_content.inspect_datastore(

‎dlp/jobs.py

Copy file name to clipboardExpand all lines: dlp/jobs.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import argparse
2020

2121

22+
# [START dlp_list_jobs]
2223
def list_dlp_jobs(project, filter_string=None, job_type=None):
2324
"""Uses the Data Loss Prevention API to lists DLP jobs that match the
2425
specified filter in the request.
@@ -83,8 +84,10 @@ def list_dlp_jobs(project, filter_string=None, job_type=None):
8384
# Iterate over results.
8485
for job in response:
8586
print('Job: %s; status: %s' % (job.name, job.JobState.Name(job.state)))
87+
# [END dlp_list_jobs]
8688

8789

90+
# [START dlp_delete_job]
8891
def delete_dlp_job(project, job_name):
8992
"""Uses the Data Loss Prevention API to delete a long-running DLP job.
9093
Args:
@@ -108,6 +111,7 @@ def delete_dlp_job(project, job_name):
108111
dlp.delete_dlp_job(name)
109112

110113
print('Successfully deleted %s' % job_name)
114+
# [END dlp_delete_job]
111115

112116

113117
if __name__ == '__main__':

‎dlp/metadata.py

Copy file name to clipboardExpand all lines: dlp/metadata.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import argparse
2121

2222

23-
# [START list_info_types]
23+
# [START dlp_list_info_types]
2424
def list_info_types(language_code=None, result_filter=None):
2525
"""List types of sensitive information within a category.
2626
Args:
@@ -44,7 +44,7 @@ def list_info_types(language_code=None, result_filter=None):
4444
for info_type in response.info_types:
4545
print('{name}: {display_name}'.format(
4646
name=info_type.name, display_name=info_type.display_name))
47-
# [END list_info_types]
47+
# [END dlp_list_info_types]
4848

4949

5050
if __name__ == '__main__':

‎dlp/quickstart.py

Copy file name to clipboardExpand all lines: dlp/quickstart.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
def quickstart():
2222
"""Demonstrates use of the Data Loss Prevention API client library."""
2323

24-
# [START quickstart]
24+
# [START dlp_quickstart]
2525
# Import the client library
2626
import google.cloud.dlp
2727

@@ -80,7 +80,7 @@ def quickstart():
8080
print('Likelihood: {}'.format(likelihood))
8181
else:
8282
print('No findings.')
83-
# [END quickstart]
83+
# [END dlp_quickstart]
8484

8585

8686
if __name__ == '__main__':

‎dlp/risk.py

Copy file name to clipboardExpand all lines: dlp/risk.py
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import argparse
2020

2121

22+
# [START dlp_numerical_stats]
2223
def numerical_risk_analysis(project, table_project_id, dataset_id, table_id,
2324
column_name, topic_id, subscription_id,
2425
timeout=300):
@@ -133,8 +134,10 @@ def callback(message):
133134
if not finished:
134135
print('No event received before the timeout. Please verify that the '
135136
'subscription provided is subscribed to the topic provided.')
137+
# [END dlp_numerical_stats]
136138

137139

140+
# [START dlp_categorical_stats]
138141
def categorical_risk_analysis(project, table_project_id, dataset_id, table_id,
139142
column_name, topic_id, subscription_id,
140143
timeout=300):
@@ -253,8 +256,10 @@ def callback(message):
253256
if not finished:
254257
print('No event received before the timeout. Please verify that the '
255258
'subscription provided is subscribed to the topic provided.')
259+
# [END dlp_categorical_stats]
256260

257261

262+
# [START dlp_k_anonymity]
258263
def k_anonymity_analysis(project, table_project_id, dataset_id, table_id,
259264
topic_id, subscription_id, quasi_ids, timeout=300):
260265
"""Uses the Data Loss Prevention API to compute the k-anonymity of a
@@ -380,8 +385,10 @@ def callback(message):
380385
if not finished:
381386
print('No event received before the timeout. Please verify that the '
382387
'subscription provided is subscribed to the topic provided.')
388+
# [END dlp_k_anonymity]
383389

384390

391+
# [START dlp_l_diversity]
385392
def l_diversity_analysis(project, table_project_id, dataset_id, table_id,
386393
topic_id, subscription_id, sensitive_attribute,
387394
quasi_ids, timeout=300):
@@ -515,8 +522,10 @@ def callback(message):
515522
if not finished:
516523
print('No event received before the timeout. Please verify that the '
517524
'subscription provided is subscribed to the topic provided.')
525+
# [END dlp_l_diversity]
518526

519527

528+
# [START dlp_k_map]
520529
def k_map_estimate_analysis(project, table_project_id, dataset_id, table_id,
521530
topic_id, subscription_id, quasi_ids, info_types,
522531
region_code='US', timeout=300):
@@ -655,6 +664,7 @@ def callback(message):
655664
if not finished:
656665
print('No event received before the timeout. Please verify that the '
657666
'subscription provided is subscribed to the topic provided.')
667+
# [END dlp_k_map]
658668

659669

660670
if __name__ == '__main__':

‎dlp/risk_test.py

Copy file name to clipboardExpand all lines: dlp/risk_test.py
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from gcp_devrel.testing.flaky import flaky
1516
import google.cloud.pubsub
1617

1718
import pytest
@@ -62,6 +63,7 @@ def subscription_id(topic_id):
6263
subscriber.delete_subscription(subscription_path)
6364

6465

66+
@flaky
6567
def test_numerical_risk_analysis(topic_id, subscription_id, capsys):
6668
risk.numerical_risk_analysis(
6769
GCLOUD_PROJECT,
@@ -76,6 +78,7 @@ def test_numerical_risk_analysis(topic_id, subscription_id, capsys):
7678
assert 'Value Range:' in out
7779

7880

81+
@flaky
7982
def test_categorical_risk_analysis_on_string_field(
8083
topic_id, subscription_id, capsys):
8184
risk.categorical_risk_analysis(
@@ -91,6 +94,7 @@ def test_categorical_risk_analysis_on_string_field(
9194
assert 'Most common value occurs' in out
9295

9396

97+
@flaky
9498
def test_categorical_risk_analysis_on_number_field(
9599
topic_id, subscription_id, capsys):
96100
risk.categorical_risk_analysis(
@@ -106,6 +110,7 @@ def test_categorical_risk_analysis_on_number_field(
106110
assert 'Most common value occurs' in out
107111

108112

113+
@flaky
109114
def test_k_anonymity_analysis_single_field(topic_id, subscription_id, capsys):
110115
risk.k_anonymity_analysis(
111116
GCLOUD_PROJECT,
@@ -121,6 +126,7 @@ def test_k_anonymity_analysis_single_field(topic_id, subscription_id, capsys):
121126
assert 'Class size:' in out
122127

123128

129+
@flaky
124130
def test_k_anonymity_analysis_multiple_fields(topic_id, subscription_id,
125131
capsys):
126132
risk.k_anonymity_analysis(
@@ -137,6 +143,7 @@ def test_k_anonymity_analysis_multiple_fields(topic_id, subscription_id,
137143
assert 'Class size:' in out
138144

139145

146+
@flaky
140147
def test_l_diversity_analysis_single_field(topic_id, subscription_id, capsys):
141148
risk.l_diversity_analysis(
142149
GCLOUD_PROJECT,
@@ -154,6 +161,7 @@ def test_l_diversity_analysis_single_field(topic_id, subscription_id, capsys):
154161
assert 'Sensitive value' in out
155162

156163

164+
@flaky
157165
def test_l_diversity_analysis_multiple_field(
158166
topic_id, subscription_id, capsys):
159167
risk.l_diversity_analysis(
@@ -172,6 +180,7 @@ def test_l_diversity_analysis_multiple_field(
172180
assert 'Sensitive value' in out
173181

174182

183+
@flaky
175184
def test_k_map_estimate_analysis_single_field(
176185
topic_id, subscription_id, capsys):
177186
risk.k_map_estimate_analysis(
@@ -190,6 +199,7 @@ def test_k_map_estimate_analysis_single_field(
190199
assert 'Values' in out
191200

192201

202+
@flaky
193203
def test_k_map_estimate_analysis_multiple_field(
194204
topic_id, subscription_id, capsys):
195205
risk.k_map_estimate_analysis(
@@ -208,6 +218,7 @@ def test_k_map_estimate_analysis_multiple_field(
208218
assert 'Values' in out
209219

210220

221+
@flaky
211222
def test_k_map_estimate_analysis_quasi_ids_info_types_equal(
212223
topic_id, subscription_id):
213224
with pytest.raises(ValueError):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.