Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions dlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ This simple command-line application demonstrates how to invoke

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

## Troubleshooting

### bcmath extension missing

If you see an error like this:

```
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
```

You may need to install the bcmath PHP extension.
e.g. (may depend on your php version)
```
$ sudo apt-get install php7.3-bcmath
```


## Contributing changes

* See [CONTRIBUTING.md](../CONTRIBUTING.md)
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/categorical_stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
->setActions([$action]);

// Submit request
$parent = $dlp->projectName($callingProjectId);
$parent = "projects/$callingProjectId/locations/global";;
$job = $dlp->createDlpJob($parent, [
'riskJob' => $riskJob
]);
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/create_inspect_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
->setDescription($description);

// Run request
$parent = $dlp->projectName($callingProjectId);
$parent = "projects/$callingProjectId/locations/global";
$template = $dlp->createInspectTemplate($parent, [
'inspectTemplate' => $inspectTemplate,
'templateId' => $templateId
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/create_trigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
->setDescription($description);

// Run trigger creation request
$parent = $dlp->projectName($callingProjectId);
$parent = "projects/$callingProjectId/locations/global";
$trigger = $dlp->createJobTrigger($parent, [
'jobTrigger' => $jobTriggerObject,
'triggerId' => $triggerId
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/deidentify_dates.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
$deidentifyConfig = (new DeidentifyConfig())
->setRecordTransformations($recordTransformations);

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

// Run request
$response = $dlp->deidentifyContent($parent, [
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/deidentify_fpe.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
$content = (new ContentItem())
->setValue($string);

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

// Run request
$response = $dlp->deidentifyContent($parent, [
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/deidentify_mask.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
$item = (new ContentItem())
->setValue($string);

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

// Run request
$response = $dlp->deidentifyContent($parent, [
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/inspect_bigquery.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
$subscription = $topic->subscription($subscriptionId);

// Submit request
$parent = $dlp->projectName($callingProjectId);
$parent = "projects/$callingProjectId/locations/global";
$job = $dlp->createDlpJob($parent, [
'inspectJob' => $inspectJob
]);
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/inspect_datastore.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
$subscription = $topic->subscription($subscriptionId);

// Submit request
$parent = $dlp->projectName($callingProjectId);
$parent = "projects/$callingProjectId/locations/global";
$job = $dlp->createDlpJob($parent, [
'inspectJob' => $inspectJob
]);
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/inspect_gcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
$subscription = $topic->subscription($subscriptionId);

// Submit request
$parent = $dlp->projectName($callingProjectId);
$parent = "projects/$callingProjectId/locations/global";
$job = $dlp->createDlpJob($parent, [
'inspectJob' => $inspectJob
]);
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/inspect_image_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
->setData(file_get_contents($filepath));

// Construct request
$parent = $dlp->projectName($projectId);
$parent = "projects/$projectId/locations/global";
$item = (new ContentItem())
->setByteItem($fileBytes);
$inspectConfig = (new InspectConfig())
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/inspect_string.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
$dlp = new DlpServiceClient();

// Construct request
$parent = $dlp->projectName($projectId);
$parent = "projects/$projectId/locations/global";
$item = (new ContentItem())
->setValue($textToInspect);
$inspectConfig = (new InspectConfig())
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/inspect_text_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
->setData(file_get_contents($filepath));

// Construct request
$parent = $dlp->projectName($projectId);
$parent = "projects/$projectId/locations/global";
$item = (new ContentItem())
->setByteItem($fileBytes);
$inspectConfig = (new InspectConfig())
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/k_anonymity.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function ($id) {
$subscription = $topic->subscription($subscriptionId);

// Submit request
$parent = $dlp->projectName($callingProjectId);
$parent = "projects/$callingProjectId/locations/global";
$job = $dlp->createDlpJob($parent, [
'riskJob' => $riskJob
]);
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/k_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
$subscription = $topic->subscription($subscriptionId);

// Submit request
$parent = $dlp->projectName($callingProjectId);
$parent = "projects/$callingProjectId/locations/global";
$job = $dlp->createDlpJob($parent, [
'riskJob' => $riskJob
]);
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/l_diversity.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function ($id) {
$subscription = $topic->subscription($subscriptionId);

// Submit request
$parent = $dlp->projectName($callingProjectId);
$parent = "projects/$callingProjectId/locations/global";
$job = $dlp->createDlpJob($parent, [
'riskJob' => $riskJob
]);
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/list_inspect_templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
// Instantiate a client.
$dlp = new DlpServiceClient();

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

// Run request
$response = $dlp->listInspectTemplates($parent);
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/list_jobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// Run job-listing request
// For more information and filter syntax,
// @see https://cloud.google.com/dlp/docs/reference/rest/v2/projects.dlpJobs/list
$parent = $dlp->projectName($callingProjectId);
$parent = "projects/$callingProjectId/locations/global";
$response = $dlp->listDlpJobs($parent, [
'filter' => $filter,
'type' => $jobType
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/list_triggers.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
// Instantiate a client.
$dlp = new DlpServiceClient();

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

// Run request
$response = $dlp->listJobTriggers($parent);
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/numerical_stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
$subscription = $topic->subscription($subscriptionId);

// Submit request
$parent = $dlp->projectName($callingProjectId);
$parent = "projects/$callingProjectId/locations/global";
$job = $dlp->createDlpJob($parent, [
'riskJob' => $riskJob
]);
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/redact_image.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
$imageRedactionConfigs[] = $config;
}

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

// Run request
$response = $dlp->redactImage($parent, [
Expand Down
2 changes: 1 addition & 1 deletion dlp/src/reidentify_fpe.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
$item = (new ContentItem())
->setValue($string);

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

// Run request
$response = $dlp->reidentifyContent($parent, [
Expand Down
2 changes: 2 additions & 0 deletions dlp/test/data/harmful.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Name,Description
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this added? This is in GCS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in the project used by kokoro, but wasn't in my project so I had to add it before I could properly run tests locally. I can remove it from the PR, it's not needed. (Although it's separately a good idea to either add all the instructions you need to replicate the test env in your own project, or to have the tests themselves push any data into the project that's needed, other langs do it both ways).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha. I don't mind keeping it, just wanted to make sure it was intentional.

John Doe,Name of a person
4 changes: 2 additions & 2 deletions dlp/test/dlpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function testTriggers()
$scanPeriod,
$autoPopulateTimespan,
]);
$fullTriggerId = sprintf('projects/%s/jobTriggers/%s', self::$projectId, $triggerId);
$fullTriggerId = sprintf('projects/%s/locations/global/jobTriggers/%s', self::$projectId, $triggerId);
$this->assertContains('Successfully created trigger ' . $fullTriggerId, $output);

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

$output = $this->runSnippet('create_inspect_template', [
self::$projectId,
Expand Down