-
Notifications
You must be signed in to change notification settings - Fork 250
/
tcnotify.go
234 lines (220 loc) · 7.16 KB
/
tcnotify.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
// The following code is AUTO-GENERATED. Please DO NOT edit.
// To update this generated code, run the following command:
// in the /codegenerator/model subdirectory of this project,
// making sure that `${GOPATH}/bin` is in your `PATH`:
//
// go install && go generate
//
// This package was generated from the schema defined at
// /references/notify/v1/api.json
// The notification service listens for tasks with associated notifications
// and handles requests to send emails and post pulse messages.
//
// See:
//
// How to use this package
//
// First create a Notify object:
//
// notify := tcnotify.New(nil)
//
// and then call one or more of notify's methods, e.g.:
//
// err := notify.Ping(.....)
//
// handling any errors...
//
// if err != nil {
// // handle error...
// }
//
// Taskcluster Schema
//
// The source code of this go package was auto-generated from the API definition at
// <rootUrl>/references/notify/v1/api.json together with the input and output schemas it references,
package tcnotify
import (
"net/url"
"time"
tcclient "github.com/taskcluster/taskcluster/clients/client-go/v17"
)
type Notify tcclient.Client
// New returns a Notify client, configured to run against production. Pass in
// nil credentials to create a client without authentication. The
// returned client is mutable, so returned settings can be altered.
//
// notify := tcnotify.New(
// nil, // client without authentication
// "http://localhost:1234/my/taskcluster", // taskcluster hosted at this root URL on local machine
// )
// err := notify.Ping(.....) // for example, call the Ping(.....) API endpoint (described further down)...
// if err != nil {
// // handle errors...
// }
func New(credentials *tcclient.Credentials, rootURL string) *Notify {
return &Notify{
Credentials: credentials,
BaseURL: tcclient.BaseURL(rootURL, "notify", "v1"),
Authenticate: credentials != nil,
}
}
// NewFromEnv returns a *Notify configured from environment variables.
//
// The root URL is taken from TASKCLUSTER_PROXY_URL if set to a non-empty
// string, otherwise from TASKCLUSTER_ROOT_URL if set, otherwise the empty
// string.
//
// The credentials are taken from environment variables:
//
// TASKCLUSTER_CLIENT_ID
// TASKCLUSTER_ACCESS_TOKEN
// TASKCLUSTER_CERTIFICATE
//
// If TASKCLUSTER_CLIENT_ID is empty/unset, authentication will be
// disabled.
func NewFromEnv() *Notify {
c := tcclient.CredentialsFromEnvVars()
return &Notify{
Credentials: c,
BaseURL: tcclient.BaseURL(tcclient.RootURLFromEnvVars(), "notify", "v1"),
Authenticate: c.ClientID != "",
}
}
// Respond without doing anything.
// This endpoint is used to check that the service is up.
//
// See #ping
func (notify *Notify) Ping() error {
cd := tcclient.Client(*notify)
_, _, err := (&cd).APICall(nil, "GET", "/ping", nil, nil)
return err
}
// Stability: *** EXPERIMENTAL ***
//
// Send an email to `address`. The content is markdown and will be rendered
// to HTML, but both the HTML and raw markdown text will be sent in the
// email. If a link is included, it will be rendered to a nice button in the
// HTML version of the email
//
// Required scopes:
// notify:email:<address>
//
// See #email
func (notify *Notify) Email(payload *SendEmailRequest) error {
cd := tcclient.Client(*notify)
_, _, err := (&cd).APICall(payload, "POST", "/email", nil, nil)
return err
}
// Stability: *** EXPERIMENTAL ***
//
// Publish a message on pulse with the given `routingKey`.
//
// Required scopes:
// notify:pulse:<routingKey>
//
// See #pulse
func (notify *Notify) Pulse(payload *PostPulseMessageRequest) error {
cd := tcclient.Client(*notify)
_, _, err := (&cd).APICall(payload, "POST", "/pulse", nil, nil)
return err
}
// Stability: *** EXPERIMENTAL ***
//
// Post a message on IRC to a specific channel or user, or a specific user
// on a specific channel.
//
// Success of this API method does not imply the message was successfully
// posted. This API method merely inserts the IRC message into a queue
// that will be processed by a background process.
// This allows us to re-send the message in face of connection issues.
//
// However, if the user isn't online the message will be dropped without
// error. We maybe improve this behavior in the future. For now just keep
// in mind that IRC is a best-effort service.
//
// Required scopes:
// If channelRequest:
// notify:irc-channel:<channel>
//
// See #irc
func (notify *Notify) Irc(payload *PostIRCMessageRequest) error {
cd := tcclient.Client(*notify)
_, _, err := (&cd).APICall(payload, "POST", "/irc", nil, nil)
return err
}
// Stability: *** EXPERIMENTAL ***
//
// Add the given address to the notification denylist. The address
// can be of either of the three supported address type namely pulse, email
// or IRC(user or channel). Addresses in the denylist will be ignored
// by the notification service.
//
// Required scopes:
// notify:manage-denylist
//
// See #addDenylistAddress
func (notify *Notify) AddDenylistAddress(payload *NotificationTypeAndAddress) error {
cd := tcclient.Client(*notify)
_, _, err := (&cd).APICall(payload, "POST", "/denylist/add", nil, nil)
return err
}
// Stability: *** EXPERIMENTAL ***
//
// Delete the specified address from the notification denylist.
//
// Required scopes:
// notify:manage-denylist
//
// See #deleteDenylistAddress
func (notify *Notify) DeleteDenylistAddress(payload *NotificationTypeAndAddress) error {
cd := tcclient.Client(*notify)
_, _, err := (&cd).APICall(payload, "DELETE", "/denylist/delete", nil, nil)
return err
}
// Stability: *** EXPERIMENTAL ***
//
// Lists all the denylisted addresses.
//
// By default this end-point will try to return up to 1000 addresses in one
// request. But it **may return less**, even if more tasks are available.
// It may also return a `continuationToken` even though there are no more
// results. However, you can only be sure to have seen all results if you
// keep calling `list` with the last `continuationToken` until you
// get a result without a `continuationToken`.
//
// If you are not interested in listing all the members at once, you may
// use the query-string option `limit` to return fewer.
//
// Required scopes:
// notify:manage-denylist
//
// See #listDenylist
func (notify *Notify) ListDenylist(continuationToken, limit string) (*ListOfNotificationAdresses, error) {
v := url.Values{}
if continuationToken != "" {
v.Add("continuationToken", continuationToken)
}
if limit != "" {
v.Add("limit", limit)
}
cd := tcclient.Client(*notify)
responseObject, _, err := (&cd).APICall(nil, "GET", "/denylist/list", new(ListOfNotificationAdresses), v)
return responseObject.(*ListOfNotificationAdresses), err
}
// Returns a signed URL for ListDenylist, valid for the specified duration.
//
// Required scopes:
// notify:manage-denylist
//
// See ListDenylist for more details.
func (notify *Notify) ListDenylist_SignedURL(continuationToken, limit string, duration time.Duration) (*url.URL, error) {
v := url.Values{}
if continuationToken != "" {
v.Add("continuationToken", continuationToken)
}
if limit != "" {
v.Add("limit", limit)
}
cd := tcclient.Client(*notify)
return (&cd).SignedURL("/denylist/list", v, duration)
}