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
// @generated by tools/gen_management.py from management-registry.json and
// openapi.json. DO NOT EDIT -- your changes will be overwritten. Regenerate
// with `tools/gen_management.py`; CI verifies the committed output is current.
//! The `directory` management namespace (CONTRACT §27.1).
//!
//! A tenant's LDAP / Active Directory identity source (CONTRACT §30): the one
//! configuration, the explicit act that links an existing local account to
//! its directory entry, and a read-only view of the sync job. Signing in
//! needs nothing new -- a directory account calls the same §1 `login`.
#![allow(clippy::too_many_arguments)]
use uuid::Uuid;
use crate::AxiamError;
use crate::client::AxiamClient;
use crate::management::models;
use crate::management::request::{Call, Verb};
use crate::management::scope::Scope;
/// The `directory` namespace handle.
///
/// A tenant's LDAP / Active Directory identity source (CONTRACT §30): the one
/// configuration, the explicit act that links an existing local account to
/// its directory entry, and a read-only view of the sync job. Signing in
/// needs nothing new -- a directory account calls the same §1 `login`.
///
/// Acquiring one performs no I/O and allocates nothing meaningful (§27.2 rule
/// 1); it borrows the client and cannot outlive it.
#[derive(Clone, Copy)]
pub struct Directory<'c> {
pub(crate) client: &'c AxiamClient,
pub(crate) scope: Scope,
}
impl std::fmt::Debug for Directory<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Directory")
.field("scope", &self.scope)
.finish()
}
}
impl<'c> Directory<'c> {
pub(crate) fn new(client: &'c AxiamClient) -> Self {
Self {
client,
scope: Scope::default(),
}
}
/// Address a different tenant than the client's own.
///
/// §27.4 rule 3: the client's `tenant_id` is the default.
#[must_use]
pub fn for_tenant(mut self, tenant_id: Uuid) -> Self {
self.scope.tenant_id = Some(tenant_id);
self
}
/// `GET /api/v1/tenants/{tenant_id}/directory`
pub async fn get(&self) -> Result<models::DirectoryConfig, AxiamError> {
let tenant_id = self.scope.tenant(self.client, "directory.get")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "directory.get",
verb: Verb::Get,
path_template: "/api/v1/tenants/{tenant_id}/directory",
path: format!("/api/v1/tenants/{tenant_id}/directory"),
query: &query,
};
self.client
.management_send::<_, models::DirectoryConfig>(call, None::<&()>)
.await
}
/// `PUT /api/v1/tenants/{tenant_id}/directory`
/// **This is a replacement, not a patch** (§27.4 rule 5). Its required fields
/// must all be given, and what you do not carry over from a prior read is not
/// preserved: an optional member left `None` is omitted, and the server
/// applies that member's default rather than keeping the stored value --
/// unless a note below says otherwise. Read first, change the field you mean,
/// send the whole thing back.
///
/// **Moving the connection requires the secret again** (§30.3 rule 2): a
/// `set` that changes `url`, `start_tls`, `bind_dn` or `trust_anchors_pem`
/// without `bind_secret` is refused `400` and changes nothing. The SDK holds
/// no copy of the secret and cannot re-send one for you. `bind_secret` is
/// required while the tenant has no configuration; otherwise absent keeps the
/// stored secret. Every other optional member left out is **reset to its
/// default**. An enabled directory and an effective `opaque_mode = required`
/// never coexist (`409`); without the deployment's directory key a write
/// carrying a secret is `503`.
/// Not retried on failure (§27.4 rule 8): every write on this surface is
/// issued exactly once, including the ones that look idempotent.
pub async fn set(
&self,
body: &models::SetDirectoryConfig,
) -> Result<models::DirectoryConfig, AxiamError> {
let tenant_id = self.scope.tenant(self.client, "directory.set")?;
let body = models::SetDirectoryConfigWire::from(body);
let body = &body;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "directory.set",
verb: Verb::Put,
path_template: "/api/v1/tenants/{tenant_id}/directory",
path: format!("/api/v1/tenants/{tenant_id}/directory"),
query: &query,
};
self.client
.management_send::<_, models::DirectoryConfig>(call, Some(body))
.await
}
/// `PATCH /api/v1/tenants/{tenant_id}/directory`
///
/// **Moving the connection requires the secret again** (§30.3 rule 2): an
/// `update` that changes `url`, `start_tls`, `bind_dn` or `trust_anchors_pem`
/// without `bind_secret` is refused `400` and changes nothing; the SDK holds
/// no copy of the secret to re-send. A member left `None` is not sent and
/// stays as stored; `group_base_dn` / `group_filter` set to `Some(None)` are
/// sent as `null` and clear the value. An enabled directory and an effective
/// `opaque_mode = required` never coexist (`409`).
/// Not retried on failure (§27.4 rule 8): every write on this surface is
/// issued exactly once, including the ones that look idempotent.
pub async fn update(
&self,
body: &models::UpdateDirectoryConfig,
) -> Result<models::DirectoryConfig, AxiamError> {
let tenant_id = self.scope.tenant(self.client, "directory.update")?;
let body = models::UpdateDirectoryConfigWire::from(body);
let body = &body;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "directory.update",
verb: Verb::Patch,
path_template: "/api/v1/tenants/{tenant_id}/directory",
path: format!("/api/v1/tenants/{tenant_id}/directory"),
query: &query,
};
self.client
.management_send::<_, models::DirectoryConfig>(call, Some(body))
.await
}
/// `DELETE /api/v1/tenants/{tenant_id}/directory`
///
/// **Deleting stops the directory, and only that** (§30.3 rule 5): directory
/// accounts can no longer sign in with a password -- there is no fallback to
/// a local hash -- and the sync stops. Sessions, refresh tokens and passkeys
/// those accounts already hold keep working until they expire or the accounts
/// are deactivated. There is no unlink: a linked account stays a directory
/// account.
/// Not retried on failure (§27.4 rule 8): every write on this surface is
/// issued exactly once, including the ones that look idempotent.
pub async fn delete(&self) -> Result<(), AxiamError> {
let tenant_id = self.scope.tenant(self.client, "directory.delete")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "directory.delete",
verb: Verb::Delete,
path_template: "/api/v1/tenants/{tenant_id}/directory",
path: format!("/api/v1/tenants/{tenant_id}/directory"),
query: &query,
};
self.client
.management_send_no_content(call, None::<&()>)
.await
}
/// `POST /api/v1/tenants/{tenant_id}/directory/links`
///
/// **Signs the account's owner out everywhere** (§30.3 rule 6): linking
/// deletes the account's WebAuthn credentials and federation links, revokes
/// its `User` certificates, all its sessions and its OAuth2 refresh tokens
/// (TOTP is kept). The entry is found by the account's own username; a repeat
/// on an already-linked account answers `was_already_linked` and repeats the
/// revocations.
/// Not retried on failure (§27.4 rule 8): every write on this surface is
/// issued exactly once, including the ones that look idempotent.
pub async fn link_account(
&self,
body: &models::LinkDirectoryAccount,
) -> Result<models::DirectoryLinkResult, AxiamError> {
let tenant_id = self.scope.tenant(self.client, "directory.link_account")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "directory.link_account",
verb: Verb::Post,
path_template: "/api/v1/tenants/{tenant_id}/directory/links",
path: format!("/api/v1/tenants/{tenant_id}/directory/links"),
query: &query,
};
self.client
.management_send::<_, models::DirectoryLinkResult>(call, Some(body))
.await
}
/// `GET /api/v1/tenants/{tenant_id}/directory/sync-status`
pub async fn get_sync_status(&self) -> Result<models::DirectorySyncStatus, AxiamError> {
let tenant_id = self
.scope
.tenant(self.client, "directory.get_sync_status")?;
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "directory.get_sync_status",
verb: Verb::Get,
path_template: "/api/v1/tenants/{tenant_id}/directory/sync-status",
path: format!("/api/v1/tenants/{tenant_id}/directory/sync-status"),
query: &query,
};
self.client
.management_send::<_, models::DirectorySyncStatus>(call, None::<&()>)
.await
}
}