-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_source_gmailfilter_filter.go
113 lines (107 loc) · 3.81 KB
/
data_source_gmailfilter_filter.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
package gmailfilter
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceGmailfilterFilter() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceGmailfilterFilterRead,
Schema: map[string]*schema.Schema{
"filter_id": {
Type: schema.TypeString,
Required: true,
Description: "The filter",
},
"action": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"add_label_ids": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
Description: `List of labels to add to the message`,
},
"forward": {
Type: schema.TypeString,
Computed: true,
Description: `Email address that the message should be forwarded to`,
},
"remove_label_ids": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
Description: `List of labels to remove from the message`,
},
},
},
},
"criteria": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"exclude_chats": {
Type: schema.TypeBool,
Computed: true,
Description: `Whether the response should exclude chats`,
},
"from": {
Type: schema.TypeString,
Computed: true,
Description: `The sender's display name or email address`,
},
"has_attachment": {
Type: schema.TypeBool,
Computed: true,
Description: `Whether the message has any attachment`,
},
"negated_query": {
Type: schema.TypeString,
Computed: true,
Description: `Only return messages not matching the specified query. Supports the same query format as the Gmail search box. For example, "from:someuser@example.com rfc822msgid: is:unread"`,
},
"query": {
Type: schema.TypeString,
Computed: true,
Description: `Only return messages matching the specified query. Supports the same query format as the Gmail search box. For example, "from:someuser@example.com rfc822msgid: is:unread"`,
},
"size": {
Type: schema.TypeInt,
Computed: true,
Description: `The size of the entire RFC822 message in bytes, including all headers and attachments`,
},
"size_comparison": {
Type: schema.TypeString,
Computed: true,
Description: `How the message size in bytes should be in relation to the size field`,
},
"subject": {
Type: schema.TypeString,
Computed: true,
Description: `Case-insensitive phrase found in the message's subject. Trailing and leading whitespace are be trimmed and adjacent spaces are collapsed`,
},
"to": {
Type: schema.TypeString,
Computed: true,
Description: `The recipient's display name or email address. Includes recipients in the "to", "cc", and "bcc" header fields. You can use simply the local part of the email address. For example, "example" and "example@" both match "example@gmail.com". This field is case-insensitive`,
},
},
},
},
},
}
}
func dataSourceGmailfilterFilterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
config := meta.(*Config)
id := d.Get("filter_id").(string)
filter, err := config.gmailService.Users.Settings.Filters.Get(gmailUser, id).Do()
if err != nil {
return diag.FromErr(handleNotFoundError(err, d, "Filter"))
}
d.SetId(id)
d.Set("filter_id", id)
return diag.FromErr(setFilterValuesToState(d, filter))
}