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
//! Settings models: every setting of a merchant, a project or a shop, each a
//! key with a JSON value, listed with its default, whether a value is stored,
//! its revision and who changed it last.
use serde::Deserialize;
use serde_json::Value;
/// Every setting at one scope.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct SettingsResponse {
/// `platform`, `merchant`, `project` or `shop`.
pub scope: String,
/// `platform`, the merchant id, the project id or the shop's profile id.
pub scope_id: String,
/// The settings at this scope.
#[serde(default)]
pub settings: Vec<SettingEntry>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One setting at the requested scope.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct SettingEntry {
/// The setting's key, e.g. `replay_retention`.
pub key: String,
/// The connector, for settings kept per connector at the platform scope.
#[serde(default)]
pub qualifier: Option<String>,
/// Who owns the stored value: `operator` or `merchant`. A value the
/// platform operator set is listed beside the merchant's and is
/// read-only to the merchant.
pub authority: String,
/// The value in force at this scope: the stored value, or the default.
/// A secret is never returned: it is `null`, and
/// [`is_set`](Self::is_set) says whether one is held.
#[serde(default)]
pub value: Value,
/// The value that applies when nothing is stored at this scope.
#[serde(default)]
pub default_value: Value,
/// Whether a value is stored at this scope.
pub is_set: bool,
/// Changes on every change and is never reused; `0` when nothing is
/// stored. Send it back as `expected_revision`.
pub revision: i64,
/// When the stored value last changed (ISO 8601).
#[serde(default)]
pub updated_at: Option<String>,
/// Who last changed the stored value.
#[serde(default)]
pub updated_by: Option<SettingActor>,
/// Whether the setting holds a secret.
pub secret: bool,
/// The value that actually applies at this scope after the setting's own
/// rules combine it with the scopes around it. `null` when it could not
/// be resolved.
#[serde(default)]
pub effective_value: Value,
/// Where `effective_value` comes from: one stored value
/// (`scope`, `scope_id`, `authority`, `qualifier`) or `{"default": true}`.
/// `None` when several scopes contribute or it could not be resolved.
#[serde(default)]
pub effective_source: Option<Value>,
/// Read-only facts specific to this setting; `null` when it has none.
#[serde(default)]
pub detail: Value,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// The person or credential that last changed a value.
///
/// `Debug` redacts [`name`](Self::name), a user's email address.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct SettingActor {
/// The user id, `admin_api_key` for the platform API key, or
/// `platform_operator` when a merchant is shown a value the operator
/// changed.
pub id: String,
/// The user's email address, when the actor is a user who still exists.
#[serde(default)]
pub name: Option<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
impl std::fmt::Debug for SettingActor {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SettingActor")
.field("id", &self.id)
.field("name", &self.name.as_ref().map(|_| "[redacted]"))
.field("extra", &self.extra)
.finish()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn an_actor_debug_redacts_the_email() {
let actor: SettingActor =
serde_json::from_str(r#"{"id":"usr_1","name":"ada@example.com"}"#).unwrap();
let rendered = format!("{actor:?}");
assert!(!rendered.contains("ada@example.com"), "{rendered}");
assert!(rendered.contains("usr_1"));
}
}