-
Notifications
You must be signed in to change notification settings - Fork 6
/
data_source_zia_dlp_web_rules.go
765 lines (743 loc) · 21.7 KB
/
data_source_zia_dlp_web_rules.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
package zia
import (
"fmt"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/dlp/dlp_web_rules"
)
func dataSourceDlpWebRules() *schema.Resource {
return &schema.Resource{
Read: dataSourceDlpWebRulesRead,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Optional: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
Description: "The DLP policy rule name.",
},
"order": {
Type: schema.TypeInt,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The description of the DLP policy rule.",
},
"access_control": {
Type: schema.TypeString,
Computed: true,
Description: "The access privilege for this DLP policy rule based on the admin's state.",
},
"protocols": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "The protocol criteria specified for the DLP policy rule.",
},
"rank": {
Type: schema.TypeInt,
Computed: true,
},
"locations": {
Type: schema.TypeList,
Computed: true,
Description: "The Name-ID pairs of locations to which the DLP policy rule must be applied.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"location_groups": {
Type: schema.TypeList,
Computed: true,
Description: "The Name-ID pairs of locations groups to which the DLP policy rule must be applied.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"groups": {
Type: schema.TypeList,
Computed: true,
Description: "The Name-ID pairs of groups to which the DLP policy rule must be applied.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"departments": {
Type: schema.TypeList,
Computed: true,
Description: "The Name-ID pairs of departments to which the DLP policy rule must be applied.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"users": {
Type: schema.TypeList,
Computed: true,
Description: "The Name-ID pairs of users to which the DLP policy rule must be applied.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"url_categories": {
Type: schema.TypeList,
Computed: true,
Description: "The list of URL categories to which the DLP policy rule must be applied.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"dlp_engines": {
Type: schema.TypeList,
Computed: true,
Description: "The list of DLP engines to which the DLP policy rule must be applied.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"file_types": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "The list of file types to which the DLP policy rule must be applied.",
},
"cloud_applications": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "The list of cloud applications to which the DLP policy rule must be applied.",
},
"min_size": {
Type: schema.TypeInt,
Computed: true,
Description: "The minimum file size (in KB) used for evaluation of the DLP policy rule.",
},
"action": {
Type: schema.TypeString,
Computed: true,
Description: "The action taken when traffic matches the DLP policy rule criteria.",
},
"state": {
Type: schema.TypeString,
Computed: true,
Description: "Enables or disables the DLP policy rule.",
},
"severity": {
Type: schema.TypeString,
Computed: true,
Description: "Indicates the severity selected for the DLP rule violation",
},
"parent_rule": {
Type: schema.TypeInt,
Computed: true,
Description: "The unique identifier of the parent rule under which an exception rule is added.",
},
"sub_rules": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "The list of exception rules added to a parent rule",
},
"time_windows": {
Type: schema.TypeList,
Computed: true,
Description: "The Name-ID pairs of time windows to which the DLP policy rule must be applied.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"auditor": {
Type: schema.TypeList,
Computed: true,
Description: "The auditor to which the DLP policy rule must be applied.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"external_auditor_email": {
Type: schema.TypeString,
Computed: true,
Description: "The email address of an external auditor to whom DLP email notifications are sent.",
},
"notification_template": {
Type: schema.TypeList,
Computed: true,
Description: "The template used for DLP notification emails.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"match_only": {
Type: schema.TypeBool,
Computed: true,
Description: "The match only criteria for DLP engines.",
},
"last_modified_time": {
Type: schema.TypeInt,
Computed: true,
Description: "Timestamp when the DLP policy rule was last modified.",
},
"last_modified_by": {
Type: schema.TypeList,
Computed: true,
Description: "The admin that modified the DLP policy rule last.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"icap_server": {
Type: schema.TypeList,
Computed: true,
Description: "The DLP server, using ICAP, to which the transaction content is forwarded.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"without_content_inspection": {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates a DLP policy rule without content inspection, when the value is set to true.",
},
"labels": {
Type: schema.TypeList,
Computed: true,
Description: "The Name-ID pairs of rule labels associated to the DLP policy rule.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"dlp_download_scan_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates a DLP policy rule without content inspection, when the value is set to true.",
},
"zcc_notifications_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates a DLP policy rule without content inspection, when the value is set to true.",
},
"ocr_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "Enables or disables image file scanning.",
},
"zscaler_incident_receiver": {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether a Zscaler Incident Receiver is associated to the DLP policy rule.",
},
"excluded_groups": {
Type: schema.TypeList,
Computed: true,
Description: "The name-ID pairs of the groups that are excluded from the DLP policy rule.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"excluded_departments": {
Type: schema.TypeList,
Computed: true,
Description: "The name-ID pairs of the departments that are excluded from the DLP policy rule.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"excluded_users": {
Type: schema.TypeList,
Computed: true,
Description: "The name-ID pairs of the users that are excluded from the DLP policy rule.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Identifier that uniquely identifies an entity",
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"workload_groups": {
Type: schema.TypeList,
Computed: true,
Description: "The list of preconfigured workload groups to which the policy must be applied",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "A unique identifier assigned to the workload group",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of the workload group",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The description of the workload group",
},
"expression_json": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"expression_containers": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"tag_type": {
Type: schema.TypeString,
Computed: true,
},
"operator": {
Type: schema.TypeString,
Computed: true,
},
"tag_container": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"tags": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Computed: true,
},
"value": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"operator": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
},
},
},
"expression": {
Type: schema.TypeString,
Computed: true,
Description: "The description of the workload group",
},
"last_modified_time": {
Type: schema.TypeInt,
Computed: true,
},
"last_modified_by": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"extensions": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
},
},
},
},
}
}
func dataSourceDlpWebRulesRead(d *schema.ResourceData, m interface{}) error {
zClient := m.(*Client)
var resp *dlp_web_rules.WebDLPRules
id, ok := getIntFromResourceData(d, "id")
if ok {
log.Printf("[INFO] Getting data for dlp web rule id: %d\n", id)
res, err := zClient.dlp_web_rules.Get(id)
if err != nil {
return err
}
resp = res
}
name, _ := d.Get("name").(string)
if resp == nil && name != "" {
log.Printf("[INFO] Getting data for dlp web rule: %s\n", name)
res, err := zClient.dlp_web_rules.GetByName(name)
if err != nil {
return err
}
resp = res
}
if resp != nil {
d.SetId(fmt.Sprintf("%d", resp.ID))
_ = d.Set("name", resp.Name)
_ = d.Set("order", resp.Order)
_ = d.Set("rank", resp.Rank)
_ = d.Set("access_control", resp.AccessControl)
_ = d.Set("protocols", resp.Protocols)
_ = d.Set("description", resp.Description)
_ = d.Set("file_types", resp.FileTypes)
_ = d.Set("cloud_applications", resp.CloudApplications)
_ = d.Set("state", resp.State)
_ = d.Set("min_size", resp.MinSize)
_ = d.Set("action", resp.Action)
_ = d.Set("severity", resp.Severity)
_ = d.Set("parent_rule", resp.ParentRule)
_ = d.Set("sub_rules", resp.SubRules)
_ = d.Set("match_only", resp.MatchOnly)
_ = d.Set("last_modified_time", resp.LastModifiedTime)
_ = d.Set("external_auditor_email", resp.ExternalAuditorEmail)
_ = d.Set("without_content_inspection", resp.WithoutContentInspection)
_ = d.Set("ocr_enabled", resp.OcrEnabled)
_ = d.Set("zscaler_incident_receiver", resp.ZscalerIncidentReceiver)
_ = d.Set("zcc_notifications_enabled", resp.ZCCNotificationsEnabled)
_ = d.Set("dlp_download_scan_enabled", resp.DLPDownloadScanEnabled)
if err := d.Set("locations", flattenIDExtensions(resp.Locations)); err != nil {
return err
}
if err := d.Set("location_groups", flattenIDExtensions(resp.LocationGroups)); err != nil {
return err
}
if err := d.Set("groups", flattenIDExtensions(resp.Groups)); err != nil {
return err
}
if err := d.Set("departments", flattenIDExtensions(resp.Departments)); err != nil {
return err
}
if err := d.Set("users", flattenIDExtensions(resp.Users)); err != nil {
return err
}
if err := d.Set("url_categories", flattenIDExtensions(resp.URLCategories)); err != nil {
return err
}
if err := d.Set("dlp_engines", flattenIDExtensions(resp.DLPEngines)); err != nil {
return err
}
if err := d.Set("time_windows", flattenIDExtensions(resp.TimeWindows)); err != nil {
return err
}
if err := d.Set("auditor", flattenIDExtensionsList(resp.Auditor)); err != nil {
return err
}
if err := d.Set("auditor", flattenIDExtensionsList(resp.Auditor)); err != nil {
return err
}
if err := d.Set("notification_template", flattenIDExtensionsList(resp.NotificationTemplate)); err != nil {
return err
}
if err := d.Set("last_modified_by", flattenIDExtensionsList(resp.LastModifiedBy)); err != nil {
return err
}
if err := d.Set("icap_server", flattenIDExtensionsList(resp.IcapServer)); err != nil {
return err
}
if err := d.Set("labels", flattenIDExtensions(resp.Labels)); err != nil {
return err
}
if err := d.Set("excluded_groups", flattenIDExtensions(resp.ExcludedGroups)); err != nil {
return err
}
if err := d.Set("excluded_departments", flattenIDExtensions(resp.ExcludedDepartments)); err != nil {
return err
}
if err := d.Set("excluded_users", flattenIDExtensions(resp.ExcludedUsers)); err != nil {
return err
}
if err := d.Set("workload_groups", flattenWorkloadGroups(resp.WorkloadGroups)); err != nil {
return fmt.Errorf("error setting workload_groups: %s", err)
}
} else {
return fmt.Errorf("couldn't find any web dlp rule with name '%s' or id '%d'", name, id)
}
return nil
}