Skip to content

Commit 2776614

Browse files
authored
fix: migrate DLP samples to use regional syntax in parent field (GoogleCloudPlatform#1122)
1 parent 091b3c2 commit 2776614

24 files changed

+42
-23
lines changed

dlp/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ This simple command-line application demonstrates how to invoke
4545

4646
See the [DLP Documentation](https://cloud.google.com/dlp/docs/inspecting-text) for more information.
4747

48+
## Troubleshooting
49+
50+
### bcmath extension missing
51+
52+
If you see an error like this:
53+
54+
```
55+
PHP Fatal error: Uncaught Error: Call to undefined function Google\Protobuf\Internal\bccomp() in /usr/local/google/home/crwilson/github/GoogleCloudPlatform/php-docs-samples/dlp/vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php:986
56+
```
57+
58+
You may need to install the bcmath PHP extension.
59+
e.g. (may depend on your php version)
60+
```
61+
$ sudo apt-get install php7.3-bcmath
62+
```
63+
64+
4865
## Contributing changes
4966
5067
* See [CONTRIBUTING.md](../CONTRIBUTING.md)

dlp/src/categorical_stats.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
->setActions([$action]);
9595

9696
// Submit request
97-
$parent = $dlp->projectName($callingProjectId);
97+
$parent = "projects/$callingProjectId/locations/global";;
9898
$job = $dlp->createDlpJob($parent, [
9999
'riskJob' => $riskJob
100100
]);

dlp/src/create_inspect_template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
->setDescription($description);
8787

8888
// Run request
89-
$parent = $dlp->projectName($callingProjectId);
89+
$parent = "projects/$callingProjectId/locations/global";
9090
$template = $dlp->createInspectTemplate($parent, [
9191
'inspectTemplate' => $inspectTemplate,
9292
'templateId' => $templateId

dlp/src/create_trigger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
->setDescription($description);
130130

131131
// Run trigger creation request
132-
$parent = $dlp->projectName($callingProjectId);
132+
$parent = "projects/$callingProjectId/locations/global";
133133
$trigger = $dlp->createJobTrigger($parent, [
134134
'jobTrigger' => $jobTriggerObject,
135135
'triggerId' => $triggerId

dlp/src/deidentify_dates.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
$deidentifyConfig = (new DeidentifyConfig())
152152
->setRecordTransformations($recordTransformations);
153153

154-
$parent = $dlp->projectName($callingProjectId);
154+
$parent = "projects/$callingProjectId/locations/global";
155155

156156
// Run request
157157
$response = $dlp->deidentifyContent($parent, [

dlp/src/deidentify_fpe.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
$content = (new ContentItem())
105105
->setValue($string);
106106

107-
$parent = $dlp->projectName($callingProjectId);
107+
$parent = "projects/$callingProjectId/locations/global";
108108

109109
// Run request
110110
$response = $dlp->deidentifyContent($parent, [

dlp/src/deidentify_mask.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
$item = (new ContentItem())
8383
->setValue($string);
8484

85-
$parent = $dlp->projectName($callingProjectId);
85+
$parent = "projects/$callingProjectId/locations/global";
8686

8787
// Run request
8888
$response = $dlp->deidentifyContent($parent, [

dlp/src/inspect_bigquery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
$subscription = $topic->subscription($subscriptionId);
115115

116116
// Submit request
117-
$parent = $dlp->projectName($callingProjectId);
117+
$parent = "projects/$callingProjectId/locations/global";
118118
$job = $dlp->createDlpJob($parent, [
119119
'inspectJob' => $inspectJob
120120
]);

dlp/src/inspect_datastore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
$subscription = $topic->subscription($subscriptionId);
119119

120120
// Submit request
121-
$parent = $dlp->projectName($callingProjectId);
121+
$parent = "projects/$callingProjectId/locations/global";
122122
$job = $dlp->createDlpJob($parent, [
123123
'inspectJob' => $inspectJob
124124
]);

dlp/src/inspect_gcs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
$subscription = $topic->subscription($subscriptionId);
115115

116116
// Submit request
117-
$parent = $dlp->projectName($callingProjectId);
117+
$parent = "projects/$callingProjectId/locations/global";
118118
$job = $dlp->createDlpJob($parent, [
119119
'inspectJob' => $inspectJob
120120
]);

dlp/src/inspect_image_file.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
->setData(file_get_contents($filepath));
5252

5353
// Construct request
54-
$parent = $dlp->projectName($projectId);
54+
$parent = "projects/$projectId/locations/global";
5555
$item = (new ContentItem())
5656
->setByteItem($fileBytes);
5757
$inspectConfig = (new InspectConfig())

dlp/src/inspect_string.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
$dlp = new DlpServiceClient();
4545

4646
// Construct request
47-
$parent = $dlp->projectName($projectId);
47+
$parent = "projects/$projectId/locations/global";
4848
$item = (new ContentItem())
4949
->setValue($textToInspect);
5050
$inspectConfig = (new InspectConfig())

dlp/src/inspect_text_file.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
->setData(file_get_contents($filepath));
5252

5353
// Construct request
54-
$parent = $dlp->projectName($projectId);
54+
$parent = "projects/$projectId/locations/global";
5555
$item = (new ContentItem())
5656
->setByteItem($fileBytes);
5757
$inspectConfig = (new InspectConfig())

dlp/src/k_anonymity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function ($id) {
101101
$subscription = $topic->subscription($subscriptionId);
102102

103103
// Submit request
104-
$parent = $dlp->projectName($callingProjectId);
104+
$parent = "projects/$callingProjectId/locations/global";
105105
$job = $dlp->createDlpJob($parent, [
106106
'riskJob' => $riskJob
107107
]);

dlp/src/k_map.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
$subscription = $topic->subscription($subscriptionId);
123123

124124
// Submit request
125-
$parent = $dlp->projectName($callingProjectId);
125+
$parent = "projects/$callingProjectId/locations/global";
126126
$job = $dlp->createDlpJob($parent, [
127127
'riskJob' => $riskJob
128128
]);

dlp/src/l_diversity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function ($id) {
108108
$subscription = $topic->subscription($subscriptionId);
109109

110110
// Submit request
111-
$parent = $dlp->projectName($callingProjectId);
111+
$parent = "projects/$callingProjectId/locations/global";
112112
$job = $dlp->createDlpJob($parent, [
113113
'riskJob' => $riskJob
114114
]);

dlp/src/list_inspect_templates.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
// Instantiate a client.
4343
$dlp = new DlpServiceClient();
4444

45-
$parent = $dlp->projectName($callingProjectId);
45+
$parent = "projects/$callingProjectId/locations/global";
4646

4747
// Run request
4848
$response = $dlp->listInspectTemplates($parent);

dlp/src/list_jobs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
// Run job-listing request
5252
// For more information and filter syntax,
5353
// @see https://cloud.google.com/dlp/docs/reference/rest/v2/projects.dlpJobs/list
54-
$parent = $dlp->projectName($callingProjectId);
54+
$parent = "projects/$callingProjectId/locations/global";
5555
$response = $dlp->listDlpJobs($parent, [
5656
'filter' => $filter,
5757
'type' => $jobType

dlp/src/list_triggers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
// Instantiate a client.
4343
$dlp = new DlpServiceClient();
4444

45-
$parent = $dlp->projectName($callingProjectId);
45+
$parent = "projects/$callingProjectId/locations/global";
4646

4747
// Run request
4848
$response = $dlp->listJobTriggers($parent);

dlp/src/numerical_stats.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
$subscription = $topic->subscription($subscriptionId);
100100

101101
// Submit request
102-
$parent = $dlp->projectName($callingProjectId);
102+
$parent = "projects/$callingProjectId/locations/global";
103103
$job = $dlp->createDlpJob($parent, [
104104
'riskJob' => $riskJob
105105
]);

dlp/src/redact_image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
$imageRedactionConfigs[] = $config;
9090
}
9191

92-
$parent = $dlp->projectName($callingProjectId);
92+
$parent = "projects/$callingProjectId/locations/global";
9393

9494
// Run request
9595
$response = $dlp->redactImage($parent, [

dlp/src/reidentify_fpe.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
$item = (new ContentItem())
114114
->setValue($string);
115115

116-
$parent = $dlp->projectName($callingProjectId);
116+
$parent = "projects/$callingProjectId/locations/global";
117117

118118
// Run request
119119
$response = $dlp->reidentifyContent($parent, [

dlp/test/data/harmful.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Name,Description
2+
John Doe,Name of a person

dlp/test/dlpTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public function testTriggers()
242242
$scanPeriod,
243243
$autoPopulateTimespan,
244244
]);
245-
$fullTriggerId = sprintf('projects/%s/jobTriggers/%s', self::$projectId, $triggerId);
245+
$fullTriggerId = sprintf('projects/%s/locations/global/jobTriggers/%s', self::$projectId, $triggerId);
246246
$this->assertContains('Successfully created trigger ' . $fullTriggerId, $output);
247247

248248
$output = $this->runSnippet('list_triggers', [self::$projectId]);
@@ -263,7 +263,7 @@ public function testInspectTemplates()
263263
$displayName = uniqid("My inspect template display name ");
264264
$description = uniqid("My inspect template description ");
265265
$templateId = uniqid('my-php-test-inspect-template-');
266-
$fullTemplateId = sprintf('projects/%s/inspectTemplates/%s', self::$projectId, $templateId);
266+
$fullTemplateId = sprintf('projects/%s/locations/global/inspectTemplates/%s', self::$projectId, $templateId);
267267

268268
$output = $this->runSnippet('create_inspect_template', [
269269
self::$projectId,

0 commit comments

Comments
 (0)