autoendpoint/routers/apns/settings.rs
1use std::collections::HashMap;
2
3/// Settings for `ApnsRouter`
4#[derive(Clone, Debug, serde::Deserialize)]
5#[serde(default)]
6//#[serde(deny_unknown_fields)] // Allow unknown fields so we can add comments to the secrets.
7pub struct ApnsSettings {
8 /// A JSON dict of `ApnsChannel`s. This must be a `String` because
9 /// environment variables cannot encode a `HashMap<String, ApnsChannel>`
10 pub channels: String,
11 /// The max size of notification data in bytes
12 pub max_data: usize,
13 // These values correspond to the a2 library ClientConfig struct.
14 // https://github.com/WalletConnect/a2/blob/master/src/client.rs#L65-L71.
15 // Utilized by apns router config in creating the client.
16 pub request_timeout_secs: Option<u64>,
17 pub pool_idle_timeout_secs: Option<u64>,
18}
19
20/// Settings for a specific APNS release channel
21#[derive(Clone, Debug, Default, serde::Deserialize)]
22#[serde(default)]
23//#[serde(deny_unknown_fields)] // Allow unknown fields so we can add comments to the secrets.
24pub struct ApnsChannel {
25 /// the cert and key are either paths
26 /// or an inline value that starts with "-"
27 /// e.g. `-----BEGIN PRIVATE KEY-----\n`
28 pub cert: String,
29 pub key: String,
30 pub topic: Option<String>,
31 pub sandbox: bool,
32}
33
34impl Default for ApnsSettings {
35 fn default() -> ApnsSettings {
36 ApnsSettings {
37 channels: "{}".to_string(),
38 max_data: 4096,
39 request_timeout_secs: Some(20),
40 pool_idle_timeout_secs: Some(600),
41 }
42 }
43}
44
45impl ApnsSettings {
46 /// Read the channels from the JSON string
47 pub fn channels(&self) -> serde_json::Result<HashMap<String, ApnsChannel>> {
48 serde_json::from_str(&self.channels)
49 }
50}