@@ -81,7 +81,11 @@ public class DeIdentification {
81
81
* @param projectId ID of Google Cloud project to run the API under.
82
82
*/
83
83
private static void deIdentifyWithMask (
84
- String string , Character maskingCharacter , int numberToMask , String projectId ) {
84
+ String string ,
85
+ List <InfoType > infoTypes ,
86
+ Character maskingCharacter ,
87
+ int numberToMask ,
88
+ String projectId ) {
85
89
86
90
// instantiate a client
87
91
try (DlpServiceClient dlpServiceClient = DlpServiceClient .create ()) {
@@ -108,6 +112,11 @@ private static void deIdentifyWithMask(
108
112
.addTransformations (infoTypeTransformationObject )
109
113
.build ();
110
114
115
+ InspectConfig inspectConfig =
116
+ InspectConfig .newBuilder ()
117
+ .addAllInfoTypes (infoTypes )
118
+ .build ();
119
+
111
120
DeidentifyConfig deidentifyConfig =
112
121
DeidentifyConfig .newBuilder ()
113
122
.setInfoTypeTransformations (infoTypeTransformationArray )
@@ -117,6 +126,7 @@ private static void deIdentifyWithMask(
117
126
DeidentifyContentRequest request =
118
127
DeidentifyContentRequest .newBuilder ()
119
128
.setParent (ProjectName .of (projectId ).toString ())
129
+ .setInspectConfig (inspectConfig )
120
130
.setDeidentifyConfig (deidentifyConfig )
121
131
.setItem (contentItem )
122
132
.build ();
@@ -513,6 +523,10 @@ public static void main(String[] args) throws Exception {
513
523
Options commandLineOptions = new Options ();
514
524
commandLineOptions .addOptionGroup (optionsGroup );
515
525
526
+ Option infoTypesOption = Option .builder ("infoTypes" ).hasArg (true ).required (false ).build ();
527
+ infoTypesOption .setArgs (Option .UNLIMITED_VALUES );
528
+ commandLineOptions .addOption (infoTypesOption );
529
+
516
530
Option maskingCharacterOption =
517
531
Option .builder ("maskingCharacter" ).hasArg (true ).required (false ).build ();
518
532
commandLineOptions .addOption (maskingCharacterOption );
@@ -575,12 +589,21 @@ public static void main(String[] args) throws Exception {
575
589
String projectId =
576
590
cmd .getOptionValue (projectIdOption .getOpt (), ServiceOptions .getDefaultProjectId ());
577
591
592
+ List <InfoType > infoTypesList = Collections .emptyList ();
593
+ if (cmd .hasOption (infoTypesOption .getOpt ())) {
594
+ infoTypesList = new ArrayList <>();
595
+ String [] infoTypes = cmd .getOptionValues (infoTypesOption .getOpt ());
596
+ for (String infoType : infoTypes ) {
597
+ infoTypesList .add (InfoType .newBuilder ().setName (infoType ).build ());
598
+ }
599
+ }
600
+
578
601
if (cmd .hasOption ("m" )) {
579
602
// deidentification with character masking
580
603
int numberToMask = Integer .parseInt (cmd .getOptionValue (numberToMaskOption .getOpt (), "0" ));
581
604
char maskingCharacter = cmd .getOptionValue (maskingCharacterOption .getOpt (), "*" ).charAt (0 );
582
605
String val = cmd .getOptionValue (deidentifyMaskingOption .getOpt ());
583
- deIdentifyWithMask (val , maskingCharacter , numberToMask , projectId );
606
+ deIdentifyWithMask (val , infoTypes , maskingCharacter , numberToMask , projectId );
584
607
} else if (cmd .hasOption ("f" )) {
585
608
// deidentification with FPE
586
609
String wrappedKey = cmd .getOptionValue (wrappedKeyOption .getOpt ());
0 commit comments