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
#![allow(unused_imports)]
#![cfg_attr(rustfmt, rustfmt_skip)]
/* THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT */
use crate::{Client, ClientBuilder, Credentials, Retry};
use anyhow::Error;
use serde_json::Value;
use std::time::Duration;
use crate::util::urlencode;

/// Notification Service
///
/// The notification service listens for tasks with associated notifications
/// and handles requests to send emails and post pulse messages.
pub struct Notify (Client);

#[allow(non_snake_case)]
impl Notify {
    /// Create a new undefined instance, based on the given client.
    pub fn new<CB: Into<ClientBuilder>>(client_builder: CB) -> Result<Self, Error> {
        Ok(Self(client_builder
            .into()
            .path_prefix("api/notify/v1/")
            .build()?))
    }

    /// Ping Server
    /// 
    /// Respond without doing anything.
    /// This endpoint is used to check that the service is up.
    pub async fn ping(&self) -> Result<(), Error> {
        let method = "GET";
        let (path, query) = Self::ping_details();
        let body = None;
        let resp = self.0.request(method, path, query, body).await?;
        resp.bytes().await?;
        Ok(())
    }

    /// Generate an unsigned URL for the ping endpoint
    pub fn ping_url(&self) -> Result<String, Error> {
        let (path, query) = Self::ping_details();
        self.0.make_url(path, query)
    }

    /// Generate a signed URL for the ping endpoint
    pub fn ping_signed_url(&self, ttl: Duration) -> Result<String, Error> {
        let (path, query) = Self::ping_details();
        self.0.make_signed_url(path, query, ttl)
    }

    /// Determine the HTTP request details for ping
    fn ping_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
        let path = "ping";
        let query = None;

        (path, query)
    }

    /// Send an Email
    /// 
    /// 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
    pub async fn email(&self, payload: &Value) -> Result<(), Error> {
        let method = "POST";
        let (path, query) = Self::email_details();
        let body = Some(payload);
        let resp = self.0.request(method, path, query, body).await?;
        resp.bytes().await?;
        Ok(())
    }

    /// Determine the HTTP request details for email
    fn email_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
        let path = "email";
        let query = None;

        (path, query)
    }

    /// Publish a Pulse Message
    /// 
    /// Publish a message on pulse with the given `routingKey`.
    pub async fn pulse(&self, payload: &Value) -> Result<(), Error> {
        let method = "POST";
        let (path, query) = Self::pulse_details();
        let body = Some(payload);
        let resp = self.0.request(method, path, query, body).await?;
        resp.bytes().await?;
        Ok(())
    }

    /// Determine the HTTP request details for pulse
    fn pulse_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
        let path = "pulse";
        let query = None;

        (path, query)
    }

    /// Post Matrix Message
    /// 
    /// Post a message to a room in Matrix. Optionally includes formatted message.
    /// 
    /// The `roomId` in the scopes is a fully formed `roomId` with leading `!` such
    /// as `!foo:bar.com`.
    /// 
    /// Note that the matrix client used by taskcluster must be invited to a room before
    /// it can post there!
    pub async fn matrix(&self, payload: &Value) -> Result<(), Error> {
        let method = "POST";
        let (path, query) = Self::matrix_details();
        let body = Some(payload);
        let resp = self.0.request(method, path, query, body).await?;
        resp.bytes().await?;
        Ok(())
    }

    /// Determine the HTTP request details for matrix
    fn matrix_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
        let path = "matrix";
        let query = None;

        (path, query)
    }

    /// Post Slack Message
    /// 
    /// Post a message to a Slack channel.
    /// 
    /// The `channelId` in the scopes is a Slack channel ID, starting with a capital C.
    /// 
    /// The Slack app can post into public channels by default but will need to be added
    /// to private channels before it can post messages there.
    pub async fn slack(&self, payload: &Value) -> Result<(), Error> {
        let method = "POST";
        let (path, query) = Self::slack_details();
        let body = Some(payload);
        let resp = self.0.request(method, path, query, body).await?;
        resp.bytes().await?;
        Ok(())
    }

    /// Determine the HTTP request details for slack
    fn slack_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
        let path = "slack";
        let query = None;

        (path, query)
    }

    /// Denylist Given Address
    /// 
    /// Add the given address to the notification denylist. Addresses in the denylist will be ignored
    /// by the notification service.
    pub async fn addDenylistAddress(&self, payload: &Value) -> Result<(), Error> {
        let method = "POST";
        let (path, query) = Self::addDenylistAddress_details();
        let body = Some(payload);
        let resp = self.0.request(method, path, query, body).await?;
        resp.bytes().await?;
        Ok(())
    }

    /// Determine the HTTP request details for addDenylistAddress
    fn addDenylistAddress_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
        let path = "denylist/add";
        let query = None;

        (path, query)
    }

    /// Delete Denylisted Address
    /// 
    /// Delete the specified address from the notification denylist.
    pub async fn deleteDenylistAddress(&self, payload: &Value) -> Result<(), Error> {
        let method = "DELETE";
        let (path, query) = Self::deleteDenylistAddress_details();
        let body = Some(payload);
        let resp = self.0.request(method, path, query, body).await?;
        resp.bytes().await?;
        Ok(())
    }

    /// Determine the HTTP request details for deleteDenylistAddress
    fn deleteDenylistAddress_details<'a>() -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
        let path = "denylist/delete";
        let query = None;

        (path, query)
    }

    /// List Denylisted Notifications
    /// 
    /// 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.
    pub async fn listDenylist(&self, continuationToken: Option<&str>, limit: Option<&str>) -> Result<Value, Error> {
        let method = "GET";
        let (path, query) = Self::listDenylist_details(continuationToken, limit);
        let body = None;
        let resp = self.0.request(method, path, query, body).await?;
        Ok(resp.json().await?)
    }

    /// Generate an unsigned URL for the listDenylist endpoint
    pub fn listDenylist_url(&self, continuationToken: Option<&str>, limit: Option<&str>) -> Result<String, Error> {
        let (path, query) = Self::listDenylist_details(continuationToken, limit);
        self.0.make_url(path, query)
    }

    /// Generate a signed URL for the listDenylist endpoint
    pub fn listDenylist_signed_url(&self, continuationToken: Option<&str>, limit: Option<&str>, ttl: Duration) -> Result<String, Error> {
        let (path, query) = Self::listDenylist_details(continuationToken, limit);
        self.0.make_signed_url(path, query, ttl)
    }

    /// Determine the HTTP request details for listDenylist
    fn listDenylist_details<'a>(continuationToken: Option<&'a str>, limit: Option<&'a str>) -> (&'static str, Option<Vec<(&'static str, &'a str)>>) {
        let path = "denylist/list";
        let mut query = None;
        if let Some(q) = continuationToken {
            query.get_or_insert_with(Vec::new).push(("continuationToken", q));
        }
        if let Some(q) = limit {
            query.get_or_insert_with(Vec::new).push(("limit", q));
        }

        (path, query)
    }
}