Skip to content

Commit 678fd0b

Browse files
committed
Make Checkstyle Happy Again.
1 parent 3dc8bad commit 678fd0b

File tree

14 files changed

+163
-84
lines changed

14 files changed

+163
-84
lines changed

dlp/src/main/java/com/example/dlp/DeIdentification.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ private static void deidentifyWithDateShift(
280280
// (Optional) The name of the Cloud KMS key used to encrypt ('wrap') the AES-256 key
281281
// If this is specified, then 'wrappedKey' and 'contextFieldId' must also be set
282282
// String keyName =
283-
// 'projects/YOUR_GCLOUD_PROJECT/locations/YOUR_LOCATION/keyRings/YOUR_KEYRING_NAME/cryptoKeys/YOUR_KEY_NAME';
283+
// 'projects/PROJECT/locations/LOCATION/keyRings/YOUR_KEYRING_NAME/cryptoKeys/YOUR_KEY_NAME';
284284

285285
// (Optional) The encrypted ('wrapped') AES-256 key to use when shifting dates
286286
// This key should be encrypted using the Cloud KMS key specified above
@@ -303,8 +303,6 @@ private static void deidentifyWithDateShift(
303303
"You must set either ALL or NONE of {contextFieldId, keyName, wrappedKey}!");
304304
}
305305

306-
DateShiftConfig dateShiftConfig = dateShiftConfigBuilder.build();
307-
308306
// Read and parse the CSV file
309307
// The first row of the file must specify column names, and all other rows
310308
// Path inputCsvFile = Paths.get("/path/to/file.csv");
@@ -334,6 +332,8 @@ private static void deidentifyWithDateShift(
334332
.map(field -> FieldId.newBuilder().setName(field).build())
335333
.collect(Collectors.toList());
336334

335+
DateShiftConfig dateShiftConfig = dateShiftConfigBuilder.build();
336+
337337
FieldTransformation fieldTransformation =
338338
FieldTransformation.newBuilder()
339339
.addAllFields(dateFieldIds)

dlp/src/main/java/com/example/dlp/Inspect.java

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import com.google.cloud.ServiceOptions;
2121
import com.google.cloud.dlp.v2.DlpServiceClient;
2222
import com.google.cloud.pubsub.v1.Subscriber;
23-
import com.google.privacy.dlp.v2.ProjectName;
24-
import com.google.pubsub.v1.ProjectSubscriptionName;
2523
import com.google.privacy.dlp.v2.Action;
2624
import com.google.privacy.dlp.v2.BigQueryOptions;
2725
import com.google.privacy.dlp.v2.BigQueryTable;
@@ -44,10 +42,11 @@
4442
import com.google.privacy.dlp.v2.KindExpression;
4543
import com.google.privacy.dlp.v2.Likelihood;
4644
import com.google.privacy.dlp.v2.PartitionId;
45+
import com.google.privacy.dlp.v2.ProjectName;
4746
import com.google.privacy.dlp.v2.StorageConfig;
4847
import com.google.protobuf.ByteString;
48+
import com.google.pubsub.v1.ProjectSubscriptionName;
4949
import com.google.pubsub.v1.ProjectTopicName;
50-
import com.google.pubsub.v1.TopicName;
5150
import java.net.URLConnection;
5251
import java.nio.file.Files;
5352
import java.nio.file.Paths;
@@ -157,19 +156,14 @@ private static void inspectFile(
157156

158157
ByteContentItem.BytesType bytesType = ByteContentItem.BytesType.TEXT_UTF8;
159158

160-
switch (mimeType) {
161-
case "image/jpeg":
162-
bytesType = ByteContentItem.BytesType.IMAGE_JPEG;
163-
break;
164-
case "image/bmp":
165-
bytesType = ByteContentItem.BytesType.IMAGE_BMP;
166-
break;
167-
case "image/png":
168-
bytesType = ByteContentItem.BytesType.IMAGE_PNG;
169-
break;
170-
case "image/svg":
171-
bytesType = ByteContentItem.BytesType.IMAGE_SVG;
172-
break;
159+
if (mimeType.equals("image/jpeg")) {
160+
bytesType = ByteContentItem.BytesType.IMAGE_JPEG;
161+
} else if (mimeType.equals("image/bmp")) {
162+
bytesType = ByteContentItem.BytesType.IMAGE_BMP;
163+
} else if (mimeType.equals("image/png")) {
164+
bytesType = ByteContentItem.BytesType.IMAGE_PNG;
165+
} else if (mimeType.equals("image/svg")) {
166+
bytesType = ByteContentItem.BytesType.IMAGE_SVG;
173167
}
174168

175169
byte[] data = Files.readAllBytes(Paths.get(filePath));
@@ -325,18 +319,18 @@ private static void waitOnJobCompletion(
325319
// setup a Pub/Sub subscriber to listen on the job completion status
326320
Subscriber subscriber =
327321
Subscriber.newBuilder(
328-
ProjectSubscriptionName.newBuilder()
329-
.setProject(projectId)
330-
.setSubscription(subscriptionId)
331-
.build(),
332-
(pubsubMessage, ackReplyConsumer) -> {
333-
ackReplyConsumer.ack();
334-
if (pubsubMessage.getAttributesCount() > 0
335-
&& pubsubMessage.getAttributesMap().get("DlpJobName").equals(dlpJobName)) {
336-
// notify job completion
337-
done.set(true);
338-
}
339-
})
322+
ProjectSubscriptionName.newBuilder()
323+
.setProject(projectId)
324+
.setSubscription(subscriptionId)
325+
.build(),
326+
(pubsubMessage, ackReplyConsumer) -> {
327+
ackReplyConsumer.ack();
328+
if (pubsubMessage.getAttributesCount() > 0
329+
&& pubsubMessage.getAttributesMap().get("DlpJobName").equals(dlpJobName)) {
330+
// notify job completion
331+
done.set(true);
332+
}
333+
})
340334
.build();
341335

342336
// wait for job completion
@@ -356,8 +350,7 @@ private static void waitOnJobCompletion(
356350
* @param maxFindings max number of findings
357351
* @param topicId Google Cloud Pub/Sub topic to notify job status updates
358352
* @param subscriptionId Google Cloud Pub/Sub subscription to above topic to receive status
359-
* updates
360-
* @throws Exception
353+
* updates
361354
*/
362355
private static void inspectDatastore(
363356
String projectId,
@@ -367,8 +360,7 @@ private static void inspectDatastore(
367360
List<InfoType> infoTypes,
368361
int maxFindings,
369362
String topicId,
370-
String subscriptionId)
371-
throws Exception {
363+
String subscriptionId) {
372364
// Instantiates a client
373365
try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
374366

@@ -437,6 +429,8 @@ private static void inspectDatastore(
437429
} else {
438430
System.out.println("No findings.");
439431
}
432+
} catch (Exception e) {
433+
System.out.println("inspectDatastore Problems: " + e.getMessage());
440434
}
441435
}
442436
// [END dlp_inspect_datastore]
@@ -449,10 +443,9 @@ private static void inspectDatastore(
449443
* @param tableId The ID of the table to inspect, e.g. 'my_table'
450444
* @param minLikelihood The minimum likelihood required before returning a match
451445
* @param infoTypes The infoTypes of information to match
452-
* @param maxFindings
453-
* @param topicId
454-
* @param subscriptionId
455-
* @throws Exception
446+
* @param maxFindings The maximum number of findings to report (0 = server maximum)
447+
* @param topicId Topic ID for pubsub.
448+
* @param subscriptionId Subscription ID for pubsub.
456449
*/
457450
private static void inspectBigquery(
458451
String projectId,
@@ -462,8 +455,7 @@ private static void inspectBigquery(
462455
List<InfoType> infoTypes,
463456
int maxFindings,
464457
String topicId,
465-
String subscriptionId)
466-
throws Exception {
458+
String subscriptionId) {
467459
// Instantiates a client
468460
try (DlpServiceClient dlpServiceClient = DlpServiceClient.create()) {
469461
// Reference to the BigQuery table
@@ -535,6 +527,8 @@ private static void inspectBigquery(
535527
} else {
536528
System.out.println("No findings.");
537529
}
530+
} catch (Exception e) {
531+
System.out.println("inspectBigquery Problems: " + e.getMessage());
538532
}
539533
}
540534
// [END dlp_inspect_bigquery]

dlp/src/main/java/com/example/dlp/Jobs.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package com.example.dlp;
1718

1819
import com.google.cloud.ServiceOptions;

dlp/src/main/java/com/example/dlp/Redact.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,16 @@ private static void redactImage(
6262
}
6363
ByteContentItem.BytesType bytesType = ByteContentItem.BytesType.BYTES_TYPE_UNSPECIFIED;
6464

65-
switch (mimeType) {
66-
case "image/jpeg":
67-
bytesType = ByteContentItem.BytesType.IMAGE_JPEG;
68-
break;
69-
case "image/bmp":
70-
bytesType = ByteContentItem.BytesType.IMAGE_BMP;
71-
break;
72-
case "image/png":
73-
bytesType = ByteContentItem.BytesType.IMAGE_PNG;
74-
break;
75-
case "image/svg":
76-
bytesType = ByteContentItem.BytesType.IMAGE_SVG;
77-
break;
65+
if (mimeType.equals("image/jpeg")) {
66+
bytesType = ByteContentItem.BytesType.IMAGE_JPEG;
67+
} else if (mimeType.equals("image/bmp")) {
68+
bytesType = ByteContentItem.BytesType.IMAGE_BMP;
69+
} else if (mimeType.equals("image/png")) {
70+
bytesType = ByteContentItem.BytesType.IMAGE_PNG;
71+
} else if (mimeType.equals("image/svg")) {
72+
bytesType = ByteContentItem.BytesType.IMAGE_SVG;
7873
}
74+
7975
byte[] data = Files.readAllBytes(Paths.get(filePath));
8076

8177
// The minimum likelihood required before redacting a match

dlp/src/main/java/com/example/dlp/RiskAnalysis.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,9 @@ private static void calculateKAnonymity(
352352
System.out.println("Job status: " + completedJob.getState());
353353
AnalyzeDataSourceRiskDetails riskDetails = completedJob.getRiskDetails();
354354

355-
KAnonymityResult kAnonymityResult = riskDetails.getKAnonymityResult();
355+
KAnonymityResult kanonymityResult = riskDetails.getKAnonymityResult();
356356
for (KAnonymityHistogramBucket result :
357-
kAnonymityResult.getEquivalenceClassHistogramBucketsList()) {
357+
kanonymityResult.getEquivalenceClassHistogramBucketsList()) {
358358
System.out.println(
359359
"Bucket size range: ["
360360
+ result.getEquivalenceClassSizeLowerBound()
@@ -461,9 +461,9 @@ private static void calculateLDiversity(
461461
System.out.println("Job status: " + completedJob.getState());
462462
AnalyzeDataSourceRiskDetails riskDetails = completedJob.getRiskDetails();
463463

464-
LDiversityResult lDiversityResult = riskDetails.getLDiversityResult();
464+
LDiversityResult ldiversityResult = riskDetails.getLDiversityResult();
465465
for (LDiversityHistogramBucket result :
466-
lDiversityResult.getSensitiveValueFrequencyHistogramBucketsList()) {
466+
ldiversityResult.getSensitiveValueFrequencyHistogramBucketsList()) {
467467
for (LDiversityEquivalenceClass bucket : result.getBucketValuesList()) {
468468
List<String> quasiIdValues =
469469
bucket

dlp/src/main/java/com/example/dlp/Templates.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
/**
2-
* Copyright 2018, Google, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you
3-
* may not use this file except in compliance with the License. You may obtain a copy of the License
4-
* at
1+
/*
2+
* Copyright 2018 Google Inc.
53
*
6-
* <p>http://www.apache.org/licenses/LICENSE-2.0
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
77
*
8-
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
9-
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10-
* express or implied. See the License for the specific language governing permissions and
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
1114
* limitations under the License.
1215
*/
16+
1317
package com.example.dlp;
1418

1519
import com.google.cloud.ServiceOptions;
@@ -162,9 +166,6 @@ private static void deleteInspectTemplate(String projectId, String templateId) {
162166
/** Command line application to create, list and delete DLP inspect templates. */
163167
public static void main(String[] args) throws Exception {
164168

165-
Options commandLineOptions = new Options();
166-
167-
Option projectIdOption = Option.builder("projectId").hasArg(true).required(false).build();
168169

169170
OptionGroup optionsGroup = new OptionGroup();
170171
optionsGroup.setRequired(true);
@@ -178,11 +179,14 @@ public static void main(String[] args) throws Exception {
178179
Option deleteOption = new Option("d", "delete", false, "Delete inspect template");
179180
optionsGroup.addOption(deleteOption);
180181

182+
Options commandLineOptions = new Options();
181183
commandLineOptions.addOptionGroup(optionsGroup);
182184

185+
Option projectIdOption = Option.builder("projectId").hasArg(true).required(false).build();
186+
commandLineOptions.addOption(projectIdOption);
187+
183188
Option minLikelihoodOption =
184189
Option.builder("minLikelihood").hasArg(true).required(false).build();
185-
186190
commandLineOptions.addOption(minLikelihoodOption);
187191

188192
Option infoTypesOption = Option.builder("infoTypes").hasArg(true).required(false).build();

dlp/src/test/java/com/example/dlp/DeIdentificationIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void testDeidentifyWithDateShift() throws Exception {
8989
"-d",
9090
"-inputCsvPath", "src/test/resources/dates.csv",
9191
"-outputCsvPath", "src/test/resources/results.temp.csv",
92-
"-dateFields", "birth_date,register_date",
92+
"-dateFields", "birth_date,register_date",
9393
"-lowerBoundDays", "5",
9494
"-upperBoundDays", "5",
9595
"-contextField", "name",

dlp/src/test/java/com/example/dlp/InspectIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static org.junit.Assert.assertTrue;
2121

2222
import java.io.ByteArrayOutputStream;
23-
import java.io.File;
2423
import java.io.PrintStream;
2524
import org.junit.After;
2625
import org.junit.Before;
@@ -32,8 +31,8 @@
3231
@RunWith(JUnit4.class)
3332
// CHECKSTYLE OFF: AbbreviationAsWordInName
3433
public class InspectIT {
35-
3634
// CHECKSTYLE ON: AbbreviationAsWordInName
35+
3736
private ByteArrayOutputStream bout;
3837
private PrintStream out;
3938

@@ -50,7 +49,8 @@ public class InspectIT {
5049
public void setUp() {
5150
bout = new ByteArrayOutputStream();
5251
out = new PrintStream(bout);
53-
System.setOut(out); // TODO(b/64541432) DLP currently doesn't support GOOGLE DEFAULT AUTH
52+
System.setOut(out);
53+
// TODO(b/64541432) DLP currently doesn't support GOOGLE DEFAULT AUTH
5454
assertNotNull(System.getenv("GOOGLE_APPLICATION_CREDENTIALS"));
5555
}
5656

0 commit comments

Comments
 (0)