Skip to content

Commit 1f41f5c

Browse files
authored
upgrades DLP and tries to fix tests (GoogleCloudPlatform#819)
1 parent c34ac1c commit 1f41f5c

19 files changed

+96
-98
lines changed

dlp/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "google/dlp-sample",
33
"type": "project",
44
"require": {
5-
"google/cloud-dlp": "~0.12",
6-
"google/cloud-pubsub": "^1.0",
5+
"google/cloud-dlp": "^0.15.2",
6+
"google/cloud-pubsub": "^1.8",
77
"symfony/console": "^3.3"
88
},
99
"autoload": {

dlp/quickstart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use Google\Cloud\Dlp\V2\InfoType;
2525
use Google\Cloud\Dlp\V2\InspectConfig;
2626
use Google\Cloud\Dlp\V2\Likelihood;
27-
use Google\Cloud\Dlp\V2\InspectConfig_FindingLimits;
27+
use Google\Cloud\Dlp\V2\InspectConfig\FindingLimits;
2828

2929
// Instantiate a client.
3030
$dlp = new DlpServiceClient();
@@ -49,7 +49,7 @@
4949
$includeQuote = true;
5050

5151
// Specify finding limits
52-
$limits = (new InspectConfig_FindingLimits())
52+
$limits = (new FindingLimits())
5353
->setMaxFindingsPerRequest($maxFindings);
5454

5555
// Create the configuration object

dlp/src/categorical_stats.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
use Google\Cloud\Dlp\V2\DlpServiceClient;
2222
use Google\Cloud\Dlp\V2\RiskAnalysisJobConfig;
2323
use Google\Cloud\Dlp\V2\BigQueryTable;
24-
use Google\Cloud\Dlp\V2\DlpJob_JobState;
24+
use Google\Cloud\Dlp\V2\DlpJob\JobState;
2525
use Google\Cloud\Dlp\V2\Action;
26-
use Google\Cloud\Dlp\V2\Action_PublishToPubSub;
27-
use Google\Cloud\Dlp\V2\PrivacyMetric_CategoricalStatsConfig;
26+
use Google\Cloud\Dlp\V2\Action\PublishToPubSub;
27+
use Google\Cloud\Dlp\V2\PrivacyMetric\CategoricalStatsConfig;
2828
use Google\Cloud\Dlp\V2\PrivacyMetric;
2929
use Google\Cloud\Dlp\V2\FieldId;
3030
use Google\Cloud\PubSub\PubSubClient;
@@ -62,7 +62,7 @@ function categorical_stats(
6262
$columnField = (new FieldId())
6363
->setName($columnName);
6464

65-
$statsConfig = (new PrivacyMetric_CategoricalStatsConfig())
65+
$statsConfig = (new CategoricalStatsConfig())
6666
->setField($columnField);
6767

6868
$privacyMetric = (new PrivacyMetric())
@@ -75,7 +75,7 @@ function categorical_stats(
7575
->setTableId($tableId);
7676

7777
// Construct the action to run when job completes
78-
$pubSubAction = (new Action_PublishToPubSub())
78+
$pubSubAction = (new PublishToPubSub())
7979
->setTopic($topic->name());
8080

8181
$action = (new Action())
@@ -122,7 +122,7 @@ function categorical_stats(
122122
// Print finding counts
123123
printf('Job %s status: %s' . PHP_EOL, $job->getName(), $job->getState());
124124
switch ($job->getState()) {
125-
case DlpJob_JobState::DONE:
125+
case JobState::DONE:
126126
$histBuckets = $job->getRiskDetails()->getCategoricalStatsResult()->getValueFrequencyHistogramBuckets();
127127

128128
foreach ($histBuckets as $bucketIndex => $histBucket) {
@@ -143,7 +143,7 @@ function categorical_stats(
143143
}
144144

145145
break;
146-
case DlpJob_JobState::FAILED:
146+
case JobState::FAILED:
147147
$errors = $job->getErrors();
148148
printf('Job %s had errors:' . PHP_EOL, $job->getName());
149149
foreach ($errors as $error) {

dlp/src/create_inspect_template.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Google\Cloud\Dlp\V2\InspectConfig;
2424
use Google\Cloud\Dlp\V2\InspectTemplate;
2525
use Google\Cloud\Dlp\V2\Likelihood;
26-
use Google\Cloud\Dlp\V2\InspectConfig_FindingLimits;
26+
use Google\Cloud\Dlp\V2\InspectConfig\FindingLimits;
2727

2828
/**
2929
* Create a new DLP inspection configuration template.
@@ -59,7 +59,7 @@ function create_inspect_template(
5959
$minLikelihood = likelihood::LIKELIHOOD_UNSPECIFIED;
6060

6161
// Specify finding limits
62-
$limits = (new InspectConfig_FindingLimits())
62+
$limits = (new FindingLimits())
6363
->setMaxFindingsPerRequest($maxFindings);
6464

6565
// Create the configuration object

dlp/src/create_trigger.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
// [START dlp_create_trigger]
2121
use Google\Cloud\Dlp\V2\DlpServiceClient;
2222
use Google\Cloud\Dlp\V2\JobTrigger;
23-
use Google\Cloud\Dlp\V2\JobTrigger_Trigger;
24-
use Google\Cloud\Dlp\V2\JobTrigger_Status;
23+
use Google\Cloud\Dlp\V2\JobTrigger\Trigger;
24+
use Google\Cloud\Dlp\V2\JobTrigger\Status;
2525
use Google\Cloud\Dlp\V2\InspectConfig;
2626
use Google\Cloud\Dlp\V2\InspectJobConfig;
2727
use Google\Cloud\Dlp\V2\Schedule;
@@ -31,7 +31,7 @@
3131
use Google\Cloud\Dlp\V2\StorageConfig_TimespanConfig;
3232
use Google\Cloud\Dlp\V2\InfoType;
3333
use Google\Cloud\Dlp\V2\Likelihood;
34-
use Google\Cloud\Dlp\V2\InspectConfig_FindingLimits;
34+
use Google\Cloud\Dlp\V2\InspectConfig\FindingLimits;
3535
use Google\Protobuf\Duration;
3636

3737
/**
@@ -72,7 +72,7 @@ function create_trigger(
7272
$minLikelihood = likelihood::LIKELIHOOD_UNSPECIFIED;
7373

7474
// Specify finding limits
75-
$limits = (new InspectConfig_FindingLimits())
75+
$limits = (new FindingLimits())
7676
->setMaxFindingsPerRequest($maxFindings);
7777

7878
// Create the inspectConfig object
@@ -88,7 +88,7 @@ function create_trigger(
8888
$schedule = (new Schedule())
8989
->setRecurrencePeriodDuration($duration);
9090

91-
$triggerObject = (new JobTrigger_Trigger())
91+
$triggerObject = (new Trigger())
9292
->setSchedule($schedule);
9393

9494
// Create the storageConfig object
@@ -115,7 +115,7 @@ function create_trigger(
115115
$jobTriggerObject = (new JobTrigger())
116116
->setTriggers([$triggerObject])
117117
->setInspectJob($jobConfig)
118-
->setStatus(JobTrigger_Status::HEALTHY)
118+
->setStatus(Status::HEALTHY)
119119
->setDisplayName($displayName)
120120
->setDescription($description);
121121

dlp/src/deidentify_dates.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
use Google\Cloud\Dlp\V2\PrimitiveTransformation;
3131
use Google\Cloud\Dlp\V2\RecordTransformations;
3232
use Google\Cloud\Dlp\V2\Table;
33-
use Google\Cloud\Dlp\V2\Table_Row;
33+
use Google\Cloud\Dlp\V2\Table\Row;
3434
use Google\Cloud\Dlp\V2\Value;
3535
use Google\Type\Date;
3636
use DateTime;
@@ -91,7 +91,7 @@ function deidentify_dates(
9191
}
9292
}, explode(',', $csvRow));
9393

94-
return (new Table_Row())
94+
return (new Row())
9595
->setValues($rowValues);
9696
}, $csvRows);
9797

dlp/src/deidentify_fpe.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
# [START dlp_deidentify_fpe]
2121
use Google\Cloud\Dlp\V2\CryptoReplaceFfxFpeConfig;
22-
use Google\Cloud\Dlp\V2\CryptoReplaceFfxFpeConfig_FfxCommonNativeAlphabet;
22+
use Google\Cloud\Dlp\V2\CryptoReplaceFfxFpeConfig\FfxCommonNativeAlphabet;
2323
use Google\Cloud\Dlp\V2\CryptoKey;
2424
use Google\Cloud\Dlp\V2\DlpServiceClient;
2525
use Google\Cloud\Dlp\V2\PrimitiveTransformation;
2626
use Google\Cloud\Dlp\V2\KmsWrappedCryptoKey;
2727
use Google\Cloud\Dlp\V2\InfoType;
2828
use Google\Cloud\Dlp\V2\DeidentifyConfig;
29-
use Google\Cloud\Dlp\V2\InfoTypeTransformations_InfoTypeTransformation;
29+
use Google\Cloud\Dlp\V2\InfoTypeTransformations\InfoTypeTransformation;
3030
use Google\Cloud\Dlp\V2\InfoTypeTransformations;
3131
use Google\Cloud\Dlp\V2\ContentItem;
3232

@@ -64,7 +64,7 @@ function deidentify_fpe(
6464

6565
// The set of characters to replace sensitive ones with
6666
// For more information, see https://cloud.google.com/dlp/docs/reference/rest/V2/organizations.deidentifyTemplates#ffxcommonnativealphabet
67-
$commonAlphabet = CryptoReplaceFfxFpeConfig_FfxCommonNativeAlphabet::NUMERIC;
67+
$commonAlphabet = FfxCommonNativeAlphabet::NUMERIC;
6868

6969
// Create the crypto key configuration object
7070
$cryptoKey = (new CryptoKey())
@@ -84,7 +84,7 @@ function deidentify_fpe(
8484
$primitiveTransformation = (new PrimitiveTransformation())
8585
->setCryptoReplaceFfxFpeConfig($cryptoReplaceFfxFpeConfig);
8686

87-
$infoTypeTransformation = (new InfoTypeTransformations_InfoTypeTransformation())
87+
$infoTypeTransformation = (new InfoTypeTransformation())
8888
->setPrimitiveTransformation($primitiveTransformation)
8989
->setInfoTypes($infoTypes);
9090

dlp/src/deidentify_mask.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Google\Cloud\Dlp\V2\InfoType;
2424
use Google\Cloud\Dlp\V2\PrimitiveTransformation;
2525
use Google\Cloud\Dlp\V2\DeidentifyConfig;
26-
use Google\Cloud\Dlp\V2\InfoTypeTransformations_InfoTypeTransformation;
26+
use Google\Cloud\Dlp\V2\InfoTypeTransformations\InfoTypeTransformation;
2727
use Google\Cloud\Dlp\V2\InfoTypeTransformations;
2828
use Google\Cloud\Dlp\V2\ContentItem;
2929

@@ -57,7 +57,7 @@ function deidentify_mask(
5757
$primitiveTransformation = (new PrimitiveTransformation())
5858
->setCharacterMaskConfig($maskConfig);
5959

60-
$infoTypeTransformation = (new InfoTypeTransformations_InfoTypeTransformation())
60+
$infoTypeTransformation = (new InfoTypeTransformation())
6161
->setPrimitiveTransformation($primitiveTransformation)
6262
->setInfoTypes($infoTypes);
6363

dlp/src/inspect_bigquery.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
use Google\Cloud\Dlp\V2\StorageConfig;
2626
use Google\Cloud\Dlp\V2\BigQueryTable;
2727
use Google\Cloud\Dlp\V2\Likelihood;
28-
use Google\Cloud\Dlp\V2\DlpJob_JobState;
29-
use Google\Cloud\Dlp\V2\InspectConfig_FindingLimits;
28+
use Google\Cloud\Dlp\V2\DlpJob\JobState;
29+
use Google\Cloud\Dlp\V2\InspectConfig\FindingLimits;
3030
use Google\Cloud\Dlp\V2\Action;
31-
use Google\Cloud\Dlp\V2\Action_PublishToPubSub;
31+
use Google\Cloud\Dlp\V2\Action\PublishToPubSub;
3232
use Google\Cloud\Dlp\V2\InspectJobConfig;
3333
use Google\Cloud\PubSub\PubSubClient;
3434

@@ -68,7 +68,7 @@ function inspect_bigquery(
6868
$minLikelihood = likelihood::LIKELIHOOD_UNSPECIFIED;
6969

7070
// Specify finding limits
71-
$limits = (new InspectConfig_FindingLimits())
71+
$limits = (new FindingLimits())
7272
->setMaxFindingsPerRequest($maxFindings);
7373

7474
// Construct items to be inspected
@@ -90,7 +90,7 @@ function inspect_bigquery(
9090
->setInfoTypes($infoTypes);
9191

9292
// Construct the action to run when job completes
93-
$pubSubAction = (new Action_PublishToPubSub())
93+
$pubSubAction = (new PublishToPubSub())
9494
->setTopic($topic->name());
9595

9696
$action = (new Action())
@@ -131,7 +131,7 @@ function inspect_bigquery(
131131
// Print finding counts
132132
printf('Job %s status: %s' . PHP_EOL, $job->getName(), $job->getState());
133133
switch ($job->getState()) {
134-
case DlpJob_JobState::DONE:
134+
case JobState::DONE:
135135
$infoTypeStats = $job->getInspectDetails()->getResult()->getInfoTypeStats();
136136
if (count($infoTypeStats) === 0) {
137137
print('No findings.' . PHP_EOL);
@@ -145,7 +145,7 @@ function inspect_bigquery(
145145
}
146146
}
147147
break;
148-
case DlpJob_JobState::FAILED:
148+
case JobState::FAILED:
149149
printf('Job %s had errors:' . PHP_EOL, $job->getName());
150150
$errors = $job->getErrors();
151151
foreach ($errors as $error) {

dlp/src/inspect_datastore.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
use Google\Cloud\Dlp\V2\DatastoreOptions;
2323
use Google\Cloud\Dlp\V2\InfoType;
2424
use Google\Cloud\Dlp\V2\Action;
25-
use Google\Cloud\Dlp\V2\Action_PublishToPubSub;
25+
use Google\Cloud\Dlp\V2\Action\PublishToPubSub;
2626
use Google\Cloud\Dlp\V2\InspectConfig;
2727
use Google\Cloud\Dlp\V2\InspectJobConfig;
2828
use Google\Cloud\Dlp\V2\KindExpression;
2929
use Google\Cloud\Dlp\V2\PartitionId;
3030
use Google\Cloud\Dlp\V2\StorageConfig;
3131
use Google\Cloud\Dlp\V2\Likelihood;
32-
use Google\Cloud\Dlp\V2\DlpJob_JobState;
33-
use Google\Cloud\Dlp\V2\InspectConfig_FindingLimits;
32+
use Google\Cloud\Dlp\V2\DlpJob\JobState;
33+
use Google\Cloud\Dlp\V2\InspectConfig\FindingLimits;
3434
use Google\Cloud\PubSub\PubSubClient;
3535

3636
/**
@@ -70,7 +70,7 @@ function inspect_datastore(
7070
$minLikelihood = likelihood::LIKELIHOOD_UNSPECIFIED;
7171

7272
// Specify finding limits
73-
$limits = (new InspectConfig_FindingLimits())
73+
$limits = (new FindingLimits())
7474
->setMaxFindingsPerRequest($maxFindings);
7575

7676
// Construct items to be inspected
@@ -96,7 +96,7 @@ function inspect_datastore(
9696
->setDatastoreOptions($datastoreOptions);
9797

9898
// Construct the action to run when job completes
99-
$pubSubAction = (new Action_PublishToPubSub())
99+
$pubSubAction = (new PublishToPubSub())
100100
->setTopic($topic->name());
101101

102102
$action = (new Action())
@@ -118,13 +118,12 @@ function inspect_datastore(
118118
]);
119119

120120
// Poll via Pub/Sub until job finishes
121-
$polling = true;
122-
while ($polling) {
121+
while (true) {
123122
foreach ($subscription->pull() as $message) {
124123
if (isset($message->attributes()['DlpJobName']) &&
125124
$message->attributes()['DlpJobName'] === $job->getName()) {
126125
$subscription->acknowledge($message);
127-
$polling = false;
126+
break 2;
128127
}
129128
}
130129
}
@@ -138,7 +137,7 @@ function inspect_datastore(
138137
// Print finding counts
139138
printf('Job %s status: %s' . PHP_EOL, $job->getName(), $job->getState());
140139
switch ($job->getState()) {
141-
case DlpJob_JobState::DONE:
140+
case JobState::DONE:
142141
$infoTypeStats = $job->getInspectDetails()->getResult()->getInfoTypeStats();
143142
if (count($infoTypeStats) === 0) {
144143
print('No findings.' . PHP_EOL);
@@ -148,7 +147,7 @@ function inspect_datastore(
148147
}
149148
}
150149
break;
151-
case DlpJob_JobState::FAILED:
150+
case JobState::FAILED:
152151
printf('Job %s had errors:' . PHP_EOL, $job->getName());
153152
$errors = $job->getErrors();
154153
foreach ($errors as $error) {

dlp/src/inspect_file.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Google\Cloud\Dlp\V2\InfoType;
2424
use Google\Cloud\Dlp\V2\InspectConfig;
2525
use Google\Cloud\Dlp\V2\Likelihood;
26-
use Google\Cloud\Dlp\V2\InspectConfig_FindingLimits;
26+
use Google\Cloud\Dlp\V2\InspectConfig\FindingLimits;
2727
use Google\Cloud\Dlp\V2\ByteContentItem;
2828

2929
/**
@@ -55,7 +55,7 @@ function inspect_file(
5555
$includeQuote = true;
5656

5757
// Specify finding limits
58-
$limits = (new InspectConfig_FindingLimits())
58+
$limits = (new FindingLimits())
5959
->setMaxFindingsPerRequest($maxFindings);
6060

6161
// Create the configuration object

0 commit comments

Comments
 (0)