-
Notifications
You must be signed in to change notification settings - Fork 134
/
data_source_tc_ses_black_email_address.go
143 lines (116 loc) · 3.81 KB
/
data_source_tc_ses_black_email_address.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
package ses
import (
"context"
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
ses "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses/v20201002"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)
func DataSourceTencentCloudSesBlackEmailAddress() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudSesBlackEmailAddressRead,
Schema: map[string]*schema.Schema{
"start_date": {
Required: true,
Type: schema.TypeString,
Description: "Start date in the format of `YYYY-MM-DD`.",
},
"end_date": {
Required: true,
Type: schema.TypeString,
Description: "End date in the format of `YYYY-MM-DD`.",
},
"email_address": {
Optional: true,
Type: schema.TypeString,
Description: "You can specify an email address to query.",
},
"task_id": {
Optional: true,
Type: schema.TypeString,
Description: "You can specify a task ID to query.",
},
"black_list": {
Computed: true,
Type: schema.TypeList,
Description: "List of blocklisted addresses.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"bounce_time": {
Type: schema.TypeString,
Computed: true,
Description: "Time when the email address is blocklisted.",
},
"email_address": {
Type: schema.TypeString,
Computed: true,
Description: "Blocklisted email address.",
},
},
},
},
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}
func dataSourceTencentCloudSesBlackEmailAddressRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("data_source.tencentcloud_ses_black_email_address.read")()
defer tccommon.InconsistentCheck(d, meta)()
logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
paramMap := make(map[string]interface{})
if v, ok := d.GetOk("start_date"); ok {
paramMap["StartDate"] = helper.String(v.(string))
}
if v, ok := d.GetOk("end_date"); ok {
paramMap["EndDate"] = helper.String(v.(string))
}
if v, ok := d.GetOk("email_address"); ok {
paramMap["EmailAddress"] = helper.String(v.(string))
}
if v, ok := d.GetOk("task_id"); ok {
paramMap["TaskID"] = helper.String(v.(string))
}
service := SesService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
var blackList []*ses.BlackEmailAddress
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeSesBlackEmailAddressByFilter(ctx, paramMap)
if e != nil {
return tccommon.RetryError(e)
}
blackList = result
return nil
})
if err != nil {
return err
}
ids := make([]string, 0, len(blackList))
tmpList := make([]map[string]interface{}, 0, len(blackList))
if blackList != nil {
for _, blackEmailAddress := range blackList {
blackEmailAddressMap := map[string]interface{}{}
if blackEmailAddress.BounceTime != nil {
blackEmailAddressMap["bounce_time"] = blackEmailAddress.BounceTime
}
if blackEmailAddress.EmailAddress != nil {
blackEmailAddressMap["email_address"] = blackEmailAddress.EmailAddress
}
ids = append(ids, *blackEmailAddress.EmailAddress)
tmpList = append(tmpList, blackEmailAddressMap)
}
_ = d.Set("black_list", tmpList)
}
d.SetId(helper.DataResourceIdsHash(ids))
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := tccommon.WriteToFile(output.(string), tmpList); e != nil {
return e
}
}
return nil
}