Skip to content

Commit fd2b039

Browse files
authored
chore: upgrade dlp samples to new surface (GoogleCloudPlatform#1898)
1 parent c3054b4 commit fd2b039

File tree

73 files changed

+772
-603
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+772
-603
lines changed

dlp/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "google/dlp-sample",
33
"type": "project",
44
"require": {
5-
"google/cloud-dlp": "^1.0.0",
6-
"google/cloud-pubsub": "^1.11.1"
5+
"google/cloud-dlp": "^1.12",
6+
"google/cloud-pubsub": "^1.49"
77
}
88
}

dlp/quickstart.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
require __DIR__ . '/vendor/autoload.php';
2020

2121
# [START dlp_quickstart]
22-
use Google\Cloud\Dlp\V2\DlpServiceClient;
22+
use Google\Cloud\Dlp\V2\Client\DlpServiceClient;
2323
use Google\Cloud\Dlp\V2\ContentItem;
2424
use Google\Cloud\Dlp\V2\InfoType;
2525
use Google\Cloud\Dlp\V2\InspectConfig;
26-
use Google\Cloud\Dlp\V2\Likelihood;
2726
use Google\Cloud\Dlp\V2\InspectConfig\FindingLimits;
27+
use Google\Cloud\Dlp\V2\InspectContentRequest;
28+
use Google\Cloud\Dlp\V2\Likelihood;
2829

2930
// Instantiate a client.
3031
$dlp = new DlpServiceClient();
@@ -66,11 +67,11 @@
6667
$parent = $dlp->projectName($projectId);
6768

6869
// Run request
69-
$response = $dlp->inspectContent([
70-
'parent' => $parent,
71-
'inspectConfig' => $inspectConfig,
72-
'item' => $content
73-
]);
70+
$inspectContentRequest = (new InspectContentRequest())
71+
->setParent($parent)
72+
->setInspectConfig($inspectConfig)
73+
->setItem($content);
74+
$response = $dlp->inspectContent($inspectContentRequest);
7475

7576
// Print the results
7677
$findings = $response->getResult()->getFindings();

dlp/src/categorical_stats.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@
2424
namespace Google\Cloud\Samples\Dlp;
2525

2626
# [START dlp_categorical_stats]
27-
use Google\Cloud\Dlp\V2\DlpServiceClient;
28-
use Google\Cloud\Dlp\V2\RiskAnalysisJobConfig;
29-
use Google\Cloud\Dlp\V2\BigQueryTable;
30-
use Google\Cloud\Dlp\V2\DlpJob\JobState;
3127
use Google\Cloud\Dlp\V2\Action;
3228
use Google\Cloud\Dlp\V2\Action\PublishToPubSub;
33-
use Google\Cloud\Dlp\V2\PrivacyMetric\CategoricalStatsConfig;
34-
use Google\Cloud\Dlp\V2\PrivacyMetric;
29+
use Google\Cloud\Dlp\V2\BigQueryTable;
30+
use Google\Cloud\Dlp\V2\Client\DlpServiceClient;
31+
use Google\Cloud\Dlp\V2\CreateDlpJobRequest;
32+
use Google\Cloud\Dlp\V2\DlpJob\JobState;
3533
use Google\Cloud\Dlp\V2\FieldId;
34+
use Google\Cloud\Dlp\V2\GetDlpJobRequest;
35+
use Google\Cloud\Dlp\V2\PrivacyMetric;
36+
use Google\Cloud\Dlp\V2\PrivacyMetric\CategoricalStatsConfig;
37+
use Google\Cloud\Dlp\V2\RiskAnalysisJobConfig;
3638
use Google\Cloud\PubSub\PubSubClient;
3739

3840
/**
@@ -91,9 +93,10 @@ function categorical_stats(
9193

9294
// Submit request
9395
$parent = "projects/$callingProjectId/locations/global";
94-
$job = $dlp->createDlpJob($parent, [
95-
'riskJob' => $riskJob
96-
]);
96+
$createDlpJobRequest = (new CreateDlpJobRequest())
97+
->setParent($parent)
98+
->setRiskJob($riskJob);
99+
$job = $dlp->createDlpJob($createDlpJobRequest);
97100

98101
// Listen for job notifications via an existing topic/subscription.
99102
$subscription = $topic->subscription($subscriptionId);
@@ -111,7 +114,9 @@ function categorical_stats(
111114
$subscription->acknowledge($message);
112115
// Get the updated job. Loop to avoid race condition with DLP API.
113116
do {
114-
$job = $dlp->getDlpJob($job->getName());
117+
$getDlpJobRequest = (new GetDlpJobRequest())
118+
->setName($job->getName());
119+
$job = $dlp->getDlpJob($getDlpJobRequest);
115120
} while ($job->getState() == JobState::RUNNING);
116121
break 2; // break from parent do while
117122
}

dlp/src/create_inspect_template.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
namespace Google\Cloud\Samples\Dlp;
2626

2727
// [START dlp_create_inspect_template]
28-
use Google\Cloud\Dlp\V2\DlpServiceClient;
28+
use Google\Cloud\Dlp\V2\Client\DlpServiceClient;
29+
use Google\Cloud\Dlp\V2\CreateInspectTemplateRequest;
2930
use Google\Cloud\Dlp\V2\InfoType;
3031
use Google\Cloud\Dlp\V2\InspectConfig;
32+
use Google\Cloud\Dlp\V2\InspectConfig\FindingLimits;
3133
use Google\Cloud\Dlp\V2\InspectTemplate;
3234
use Google\Cloud\Dlp\V2\Likelihood;
33-
use Google\Cloud\Dlp\V2\InspectConfig\FindingLimits;
3435

3536
/**
3637
* Create a new DLP inspection configuration template.
@@ -84,9 +85,11 @@ function create_inspect_template(
8485

8586
// Run request
8687
$parent = "projects/$callingProjectId/locations/global";
87-
$template = $dlp->createInspectTemplate($parent, $inspectTemplate, [
88-
'templateId' => $templateId
89-
]);
88+
$createInspectTemplateRequest = (new CreateInspectTemplateRequest())
89+
->setParent($parent)
90+
->setInspectTemplate($inspectTemplate)
91+
->setTemplateId($templateId);
92+
$template = $dlp->createInspectTemplate($createInspectTemplateRequest);
9093

9194
// Print results
9295
printf('Successfully created template %s' . PHP_EOL, $template->getName());

dlp/src/create_job.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@
2525
namespace Google\Cloud\Samples\Dlp;
2626

2727
# [START dlp_create_job]
28+
use Google\Cloud\Dlp\V2\Action;
29+
use Google\Cloud\Dlp\V2\Action\PublishSummaryToCscc;
30+
use Google\Cloud\Dlp\V2\Client\DlpServiceClient;
2831
use Google\Cloud\Dlp\V2\CloudStorageOptions;
2932
use Google\Cloud\Dlp\V2\CloudStorageOptions\FileSet;
30-
use Google\Cloud\Dlp\V2\DlpServiceClient;
33+
use Google\Cloud\Dlp\V2\CreateDlpJobRequest;
3134
use Google\Cloud\Dlp\V2\InfoType;
3235
use Google\Cloud\Dlp\V2\InspectConfig;
3336
use Google\Cloud\Dlp\V2\InspectConfig\FindingLimits;
34-
use Google\Cloud\Dlp\V2\StorageConfig;
35-
use Google\Cloud\Dlp\V2\Likelihood;
36-
use Google\Cloud\Dlp\V2\Action;
37-
use Google\Cloud\Dlp\V2\Action\PublishSummaryToCscc;
3837
use Google\Cloud\Dlp\V2\InspectJobConfig;
38+
use Google\Cloud\Dlp\V2\Likelihood;
39+
use Google\Cloud\Dlp\V2\StorageConfig;
3940
use Google\Cloud\Dlp\V2\StorageConfig\TimespanConfig;
4041

4142
/**
@@ -102,9 +103,10 @@ function create_job(
102103

103104
// Send the job creation request and process the response.
104105
$parent = "projects/$callingProjectId/locations/global";
105-
$job = $dlp->createDlpJob($parent, [
106-
'inspectJob' => $inspectJobConfig
107-
]);
106+
$createDlpJobRequest = (new CreateDlpJobRequest())
107+
->setParent($parent)
108+
->setInspectJob($inspectJobConfig);
109+
$job = $dlp->createDlpJob($createDlpJobRequest);
108110

109111
// Print results.
110112
printf($job->getName());

dlp/src/create_trigger.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,20 @@
2424
namespace Google\Cloud\Samples\Dlp;
2525

2626
// [START dlp_create_trigger]
27-
use Google\Cloud\Dlp\V2\DlpServiceClient;
28-
use Google\Cloud\Dlp\V2\JobTrigger;
29-
use Google\Cloud\Dlp\V2\JobTrigger\Trigger;
30-
use Google\Cloud\Dlp\V2\JobTrigger\Status;
31-
use Google\Cloud\Dlp\V2\InspectConfig;
32-
use Google\Cloud\Dlp\V2\InspectJobConfig;
33-
use Google\Cloud\Dlp\V2\Schedule;
27+
use Google\Cloud\Dlp\V2\Client\DlpServiceClient;
3428
use Google\Cloud\Dlp\V2\CloudStorageOptions;
3529
use Google\Cloud\Dlp\V2\CloudStorageOptions\FileSet;
36-
use Google\Cloud\Dlp\V2\StorageConfig;
30+
use Google\Cloud\Dlp\V2\CreateJobTriggerRequest;
3731
use Google\Cloud\Dlp\V2\InfoType;
38-
use Google\Cloud\Dlp\V2\Likelihood;
32+
use Google\Cloud\Dlp\V2\InspectConfig;
3933
use Google\Cloud\Dlp\V2\InspectConfig\FindingLimits;
34+
use Google\Cloud\Dlp\V2\InspectJobConfig;
35+
use Google\Cloud\Dlp\V2\JobTrigger;
36+
use Google\Cloud\Dlp\V2\JobTrigger\Status;
37+
use Google\Cloud\Dlp\V2\JobTrigger\Trigger;
38+
use Google\Cloud\Dlp\V2\Likelihood;
39+
use Google\Cloud\Dlp\V2\Schedule;
40+
use Google\Cloud\Dlp\V2\StorageConfig;
4041
use Google\Cloud\Dlp\V2\StorageConfig\TimespanConfig;
4142
use Google\Protobuf\Duration;
4243

@@ -125,11 +126,12 @@ function create_trigger(
125126
->setDescription($description);
126127

127128
// Run trigger creation request
128-
// $parent = "projects/$callingProjectId/locations/global";
129129
$parent = $dlp->locationName($callingProjectId, 'global');
130-
$trigger = $dlp->createJobTrigger($parent, $jobTriggerObject, [
131-
'triggerId' => $triggerId
132-
]);
130+
$createJobTriggerRequest = (new CreateJobTriggerRequest())
131+
->setParent($parent)
132+
->setJobTrigger($jobTriggerObject)
133+
->setTriggerId($triggerId);
134+
$trigger = $dlp->createJobTrigger($createJobTriggerRequest);
133135

134136
// Print results
135137
printf('Successfully created trigger %s' . PHP_EOL, $trigger->getName());

dlp/src/deidentify_cloud_storage.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,22 @@
2424
namespace Google\Cloud\Samples\Dlp;
2525

2626
# [START dlp_deidentify_cloud_storage]
27-
use Google\Cloud\Dlp\V2\CloudStorageOptions;
28-
use Google\Cloud\Dlp\V2\CloudStorageOptions\FileSet;
29-
use Google\Cloud\Dlp\V2\DlpServiceClient;
30-
use Google\Cloud\Dlp\V2\InfoType;
31-
use Google\Cloud\Dlp\V2\InspectConfig;
32-
use Google\Cloud\Dlp\V2\StorageConfig;
3327
use Google\Cloud\Dlp\V2\Action;
3428
use Google\Cloud\Dlp\V2\Action\Deidentify;
3529
use Google\Cloud\Dlp\V2\BigQueryTable;
30+
use Google\Cloud\Dlp\V2\Client\DlpServiceClient;
31+
use Google\Cloud\Dlp\V2\CloudStorageOptions;
32+
use Google\Cloud\Dlp\V2\CloudStorageOptions\FileSet;
33+
use Google\Cloud\Dlp\V2\CreateDlpJobRequest;
34+
use Google\Cloud\Dlp\V2\DlpJob\JobState;
3635
use Google\Cloud\Dlp\V2\FileType;
36+
use Google\Cloud\Dlp\V2\GetDlpJobRequest;
37+
use Google\Cloud\Dlp\V2\InfoType;
38+
use Google\Cloud\Dlp\V2\InspectConfig;
3739
use Google\Cloud\Dlp\V2\InspectJobConfig;
40+
use Google\Cloud\Dlp\V2\StorageConfig;
3841
use Google\Cloud\Dlp\V2\TransformationConfig;
3942
use Google\Cloud\Dlp\V2\TransformationDetailsStorageConfig;
40-
use Google\Cloud\Dlp\V2\DlpJob\JobState;
4143

4244
/**
4345
* De-identify sensitive data stored in Cloud Storage using the API.
@@ -128,15 +130,18 @@ function deidentify_cloud_storage(
128130
->setActions([$action]);
129131

130132
// Send the job creation request and process the response.
131-
$job = $dlp->createDlpJob($parent, [
132-
'inspectJob' => $inspectJobConfig
133-
]);
133+
$createDlpJobRequest = (new CreateDlpJobRequest())
134+
->setParent($parent)
135+
->setInspectJob($inspectJobConfig);
136+
$job = $dlp->createDlpJob($createDlpJobRequest);
134137

135138
$numOfAttempts = 10;
136139
do {
137140
printf('Waiting for job to complete' . PHP_EOL);
138141
sleep(30);
139-
$job = $dlp->getDlpJob($job->getName());
142+
$getDlpJobRequest = (new GetDlpJobRequest())
143+
->setName($job->getName());
144+
$job = $dlp->getDlpJob($getDlpJobRequest);
140145
if ($job->getState() == JobState::DONE) {
141146
break;
142147
}

dlp/src/deidentify_dates.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
# [START dlp_deidentify_date_shift]
2828
use DateTime;
2929
use Exception;
30+
use Google\Cloud\Dlp\V2\Client\DlpServiceClient;
3031
use Google\Cloud\Dlp\V2\ContentItem;
3132
use Google\Cloud\Dlp\V2\CryptoKey;
3233
use Google\Cloud\Dlp\V2\DateShiftConfig;
3334
use Google\Cloud\Dlp\V2\DeidentifyConfig;
34-
use Google\Cloud\Dlp\V2\DlpServiceClient;
35+
use Google\Cloud\Dlp\V2\DeidentifyContentRequest;
3536
use Google\Cloud\Dlp\V2\FieldId;
3637
use Google\Cloud\Dlp\V2\FieldTransformation;
3738
use Google\Cloud\Dlp\V2\KmsWrappedCryptoKey;
@@ -155,11 +156,11 @@ function deidentify_dates(
155156
$parent = "projects/$callingProjectId/locations/global";
156157

157158
// Run request
158-
$response = $dlp->deidentifyContent([
159-
'parent' => $parent,
160-
'deidentifyConfig' => $deidentifyConfig,
161-
'item' => $item
162-
]);
159+
$deidentifyContentRequest = (new DeidentifyContentRequest())
160+
->setParent($parent)
161+
->setDeidentifyConfig($deidentifyConfig)
162+
->setItem($item);
163+
$response = $dlp->deidentifyContent($deidentifyContentRequest);
163164

164165
// Check for errors
165166
foreach ($response->getOverview()->getTransformationSummaries() as $summary) {

dlp/src/deidentify_deterministic.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@
2626

2727
# [START dlp_deidentify_deterministic]
2828

29-
use Google\Cloud\Dlp\V2\DlpServiceClient;
30-
use Google\Cloud\Dlp\V2\PrimitiveTransformation;
31-
use Google\Cloud\Dlp\V2\DeidentifyConfig;
29+
use Google\Cloud\Dlp\V2\Client\DlpServiceClient;
3230
use Google\Cloud\Dlp\V2\ContentItem;
3331
use Google\Cloud\Dlp\V2\CryptoDeterministicConfig;
32+
use Google\Cloud\Dlp\V2\CryptoKey;
33+
use Google\Cloud\Dlp\V2\DeidentifyConfig;
34+
use Google\Cloud\Dlp\V2\DeidentifyContentRequest;
3435
use Google\Cloud\Dlp\V2\InfoType;
35-
use Google\Cloud\Dlp\V2\InfoTypeTransformations\InfoTypeTransformation;
3636
use Google\Cloud\Dlp\V2\InfoTypeTransformations;
37+
use Google\Cloud\Dlp\V2\InfoTypeTransformations\InfoTypeTransformation;
3738
use Google\Cloud\Dlp\V2\InspectConfig;
3839
use Google\Cloud\Dlp\V2\KmsWrappedCryptoKey;
39-
use Google\Cloud\Dlp\V2\CryptoKey;
40+
use Google\Cloud\Dlp\V2\PrimitiveTransformation;
4041

4142
/**
4243
* De-identify content through deterministic encryption.
@@ -108,13 +109,12 @@ function deidentify_deterministic(
108109
->setInfoTypeTransformations($infoTypeTransformations);
109110

110111
// Send the request and receive response from the service.
111-
$response = $dlp->deidentifyContent([
112-
'parent' => $parent,
113-
'deidentifyConfig' => $deidentifyConfig,
114-
'item' => $content,
115-
'inspectConfig' => $inspectConfig
116-
117-
]);
112+
$deidentifyContentRequest = (new DeidentifyContentRequest())
113+
->setParent($parent)
114+
->setDeidentifyConfig($deidentifyConfig)
115+
->setItem($content)
116+
->setInspectConfig($inspectConfig);
117+
$response = $dlp->deidentifyContent($deidentifyContentRequest);
118118

119119
// Print the results.
120120
printf($response->getItem()->getValue());

dlp/src/deidentify_dictionary_replacement.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@
2424
namespace Google\Cloud\Samples\Dlp;
2525

2626
# [START dlp_deidentify_dictionary_replacement]
27+
use Google\Cloud\Dlp\V2\Client\DlpServiceClient;
2728
use Google\Cloud\Dlp\V2\ContentItem;
28-
use Google\Cloud\Dlp\V2\DlpServiceClient;
2929
use Google\Cloud\Dlp\V2\CustomInfoType\Dictionary\WordList;
30-
use Google\Cloud\Dlp\V2\InfoType;
3130
use Google\Cloud\Dlp\V2\DeidentifyConfig;
32-
use Google\Cloud\Dlp\V2\InspectConfig;
33-
use Google\Cloud\Dlp\V2\PrimitiveTransformation;
31+
use Google\Cloud\Dlp\V2\DeidentifyContentRequest;
32+
use Google\Cloud\Dlp\V2\InfoType;
3433
use Google\Cloud\Dlp\V2\InfoTypeTransformations;
3534
use Google\Cloud\Dlp\V2\InfoTypeTransformations\InfoTypeTransformation;
35+
use Google\Cloud\Dlp\V2\InspectConfig;
36+
use Google\Cloud\Dlp\V2\PrimitiveTransformation;
3637
use Google\Cloud\Dlp\V2\ReplaceDictionaryConfig;
3738

3839
/**
@@ -90,12 +91,12 @@ function deidentify_dictionary_replacement(
9091

9192
// Send the request and receive response from the service.
9293
$parent = "projects/$callingProjectId/locations/global";
93-
$response = $dlp->deidentifyContent([
94-
'parent' => $parent,
95-
'deidentifyConfig' => $deidentifyConfig,
96-
'inspectConfig' => $inspectConfig,
97-
'item' => $contentItem
98-
]);
94+
$deidentifyContentRequest = (new DeidentifyContentRequest())
95+
->setParent($parent)
96+
->setDeidentifyConfig($deidentifyConfig)
97+
->setInspectConfig($inspectConfig)
98+
->setItem($contentItem);
99+
$response = $dlp->deidentifyContent($deidentifyContentRequest);
99100

100101
// Print the results.
101102
printf('Text after replace with infotype config: %s', $response->getItem()->getValue());

0 commit comments

Comments
 (0)