/
data_source_security_dos_dos_protection_profilelist.go
81 lines (66 loc) · 1.66 KB
/
data_source_security_dos_dos_protection_profilelist.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
// Copyright 2022 Fortinet, Inc. All rights reserved.
// Author: Shih-Hsin Huang
// Description: Configure SecurityDosDosProtectionProfile.
package fortiadc
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceSecurityDosDosProtectionProfileList() *schema.Resource {
return &schema.Resource{
Read: dataSourceSecurityDosDosProtectionProfileListRead,
Schema: map[string]*schema.Schema{
"mkey_list": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"filter": {
Type: schema.TypeString,
Optional: true,
},
"vdom": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
},
}
}
func dataSourceSecurityDosDosProtectionProfileListRead(d *schema.ResourceData, m interface{}) error {
c := m.(*FortiClient).Client
c.Retries = 1
vdom := ""
if v, ok := d.GetOk("vdom"); ok {
if s, ok := v.(string); ok {
vdom = s
}
}
filter := d.Get("filter").(string)
if filter != "" {
filter = escapeFilter(filter)
}
filters := parse_filter(filter)
o, err := c.GenericGroupRead("/api/security_dos_dos_protection_profile", filter, vdom)
if err != nil {
return fmt.Errorf("Error describing SecurityDosDosProtectionProfile: %v", err)
}
var tmps []string
if o != nil {
if len(o) == 0 || o[0] == nil {
return nil
}
for _, r := range o {
i := r.(map[string]interface{})
if !run_filter(filters, i) {
continue
}
if _, ok := i["mkey"]; ok {
tmps = append(tmps, i["mkey"].(string))
}
}
}
d.Set("mkey_list", tmps)
d.SetId("DataSourceSecurityDosDosProtectionProfileList" + filter)
return nil
}