25
25
import com .google .privacy .dlp .v2 .Likelihood ;
26
26
import com .google .privacy .dlp .v2 .ListInspectTemplatesRequest ;
27
27
import com .google .privacy .dlp .v2 .ListInspectTemplatesResponse ;
28
+ import com .google .privacy .dlp .v2 .ProjectName ;
28
29
import java .util .ArrayList ;
29
30
import java .util .List ;
30
31
import org .apache .commons .cli .CommandLine ;
@@ -41,20 +42,19 @@ public class Templates {
41
42
/**
42
43
* [START dlp_create_template]
43
44
*
45
+ * @param displayName (Optional) The human-readable name to give the template
44
46
* @param projectId Google Cloud Project ID to call the API under
45
47
* @param templateId (Optional) The name of the template to be created
46
- * @param displayName (Optional) The human-readable name to give the template
47
48
* @param infoTypeList The infoTypes of information to match
48
- * @param includeQuote Whether to include the matching string
49
49
* @param minLikelihood The minimum likelihood required before returning a match
50
50
* @param maxFindings The maximum number of findings to report per request (0 = server maximum)
51
51
*/
52
52
private static void createInspectTemplate (
53
- String projectId ,
54
- String templateId ,
55
53
String displayName ,
54
+ String templateId ,
55
+ String description ,
56
+ String projectId ,
56
57
List <InfoType > infoTypeList ,
57
- boolean includeQuote ,
58
58
Likelihood minLikelihood ,
59
59
int maxFindings ) {
60
60
try (DlpServiceClient dlpServiceClient = DlpServiceClient .create ()) {
@@ -67,19 +67,19 @@ private static void createInspectTemplate(
67
67
InspectConfig .newBuilder ()
68
68
.addAllInfoTypes (infoTypeList )
69
69
.setMinLikelihood (minLikelihood )
70
- .setIncludeQuote (includeQuote )
71
70
.setLimits (findingLimits )
72
71
.build ();
73
72
74
73
InspectTemplate inspectTemplate =
75
74
InspectTemplate .newBuilder ()
76
75
.setInspectConfig (inspectConfig )
77
76
.setDisplayName (displayName )
77
+ .setDescription (description )
78
78
.build ();
79
79
80
80
CreateInspectTemplateRequest createInspectTemplateRequest =
81
81
CreateInspectTemplateRequest .newBuilder ()
82
- .setParent (projectId )
82
+ .setParent (ProjectName . of ( projectId ). toString () )
83
83
.setInspectTemplate (inspectTemplate )
84
84
.setTemplateId (templateId )
85
85
.build ();
@@ -105,18 +105,20 @@ private static void listInspectTemplates(String projectId) {
105
105
try (DlpServiceClient dlpServiceClient = DlpServiceClient .create ()) {
106
106
107
107
ListInspectTemplatesRequest request =
108
- ListInspectTemplatesRequest .newBuilder ().setParent (projectId ).setPageSize (1 ).build ();
108
+ ListInspectTemplatesRequest .newBuilder ()
109
+ .setParent (ProjectName .of (projectId ).toString ())
110
+ .setPageSize (1 ).build ();
109
111
110
112
ListInspectTemplatesPagedResponse response = dlpServiceClient .listInspectTemplates (request );
111
113
ListInspectTemplatesPage page = response .getPage ();
112
114
ListInspectTemplatesResponse templatesResponse = page .getResponse ();
113
115
114
116
for (InspectTemplate template : templatesResponse .getInspectTemplatesList ()) {
115
- System .out .printf ("Template name: %s" , template .getName ());
117
+ System .out .printf ("Template name: %s\n " , template .getName ());
116
118
if (template .getDisplayName () != null ) {
117
- System .out .printf ("Template display name: %s" , template .getDisplayName ());
118
- System .out .printf ("Template create time: %s" , template .getCreateTime ());
119
- System .out .printf ("Template update time: %s" , template .getUpdateTime ());
119
+ System .out .printf ("Template display name: %s \n " , template .getDisplayName ());
120
+ System .out .printf ("Template create time: %s \n " , template .getCreateTime ());
121
+ System .out .printf ("Template update time: %s \n " , template .getUpdateTime ());
120
122
121
123
// print inspection config
122
124
InspectConfig inspectConfig = template .getInspectConfig ();
@@ -167,13 +169,13 @@ public static void main(String[] args) throws Exception {
167
169
OptionGroup optionsGroup = new OptionGroup ();
168
170
optionsGroup .setRequired (true );
169
171
170
- Option createOption = new Option ("c" , "create" , true , "Create inspect template" );
172
+ Option createOption = new Option ("c" , "create" , false , "Create inspect template" );
171
173
optionsGroup .addOption (createOption );
172
174
173
- Option listOption = new Option ("l" , "list" , true , "List inspect templates" );
175
+ Option listOption = new Option ("l" , "list" , false , "List inspect templates" );
174
176
optionsGroup .addOption (listOption );
175
177
176
- Option deleteOption = new Option ("d" , "delete" , true , "Delete inspect template" );
178
+ Option deleteOption = new Option ("d" , "delete" , false , "Delete inspect template" );
177
179
optionsGroup .addOption (deleteOption );
178
180
179
181
commandLineOptions .addOptionGroup (optionsGroup );
@@ -190,6 +192,9 @@ public static void main(String[] args) throws Exception {
190
192
Option templateIdOption = Option .builder ("templateId" ).hasArg (true ).required (false ).build ();
191
193
commandLineOptions .addOption (templateIdOption );
192
194
195
+ Option templateDescription = Option .builder ("description" ).hasArg (true ).required (false ).build ();
196
+ commandLineOptions .addOption (templateDescription );
197
+
193
198
Option templateDisplayNameOption =
194
199
Option .builder ("displayName" ).hasArg (true ).required (false ).build ();
195
200
commandLineOptions .addOption (templateDisplayNameOption );
@@ -219,6 +224,7 @@ public static void main(String[] args) throws Exception {
219
224
if (cmd .hasOption (createOption .getOpt ())) {
220
225
String templateId = cmd .getOptionValue (templateIdOption .getOpt ());
221
226
String displayName = cmd .getOptionValue (templateDisplayNameOption .getOpt ());
227
+ String description = cmd .getOptionValue (templateDescription .getOpt ());
222
228
223
229
Likelihood minLikelihood =
224
230
Likelihood .valueOf (
@@ -232,17 +238,10 @@ public static void main(String[] args) throws Exception {
232
238
infoTypesList .add (InfoType .newBuilder ().setName (infoType ).build ());
233
239
}
234
240
}
235
- Boolean includeQuote =
236
- Boolean .valueOf (cmd .getOptionValue (includeQuoteOption .getOpt (), "false" ));
237
- int maxFindings = Integer .valueOf (maxFindingsOption .getOpt (), 0 );
241
+ int maxFindings = Integer .valueOf (cmd .getOptionValue (maxFindingsOption .getOpt (), "0" ));
238
242
createInspectTemplate (
239
- projectId ,
240
- templateId ,
241
- displayName ,
242
- infoTypesList ,
243
- includeQuote ,
244
- minLikelihood ,
245
- maxFindings );
243
+ displayName , templateId , description , projectId ,
244
+ infoTypesList , minLikelihood , maxFindings );
246
245
247
246
} else if (cmd .hasOption (listOption .getOpt ())) {
248
247
listInspectTemplates (projectId );
0 commit comments