manta_shared/types/api/group.rs
1//! HTTP request/response bodies and CLI-built parameter structs for
2//! the HSM group endpoints (`/api/v1/groups`,
3//! `/api/v1/groups/{name}/members`).
4
5use serde::{Deserialize, Serialize};
6use utoipa::ToSchema;
7
8/// Request body for `POST /api/v1/groups/{name}/members`.
9///
10/// Paired with [`AddNodesToGroupResponse`] on success.
11#[derive(Debug, Serialize, Deserialize, ToSchema)]
12pub struct AddNodesToGroupRequest {
13 /// Hostlist expression (xnames, NIDs, or hostlist notation)
14 /// identifying the new member set for the group.
15 pub hosts_expression: String,
16}
17
18/// Response body for `POST /api/v1/groups/{name}/members`.
19///
20/// The `removed` field name is retained for wire stability; its value
21/// is the final, sorted membership of the group after the update —
22/// **not** a list of removed nodes.
23///
24/// `added` and `final_members` are both sorted alphabetically by xname.
25///
26/// # Wire shape
27///
28/// ```json
29/// {
30/// "added": ["x3000c0s1b0n2", "x3000c0s1b0n3"],
31/// "final_members": ["x3000c0s1b0n0", "x3000c0s1b0n1", "x3000c0s1b0n2", "x3000c0s1b0n3"],
32/// "removed": ["x3000c0s1b0n0", "x3000c0s1b0n1", "x3000c0s1b0n2", "x3000c0s1b0n3"]
33/// }
34/// ```
35#[derive(Debug, Serialize, Deserialize, ToSchema)]
36pub struct AddNodesToGroupResponse {
37 /// Xnames that were added to the group as part of this request,
38 /// sorted alphabetically.
39 pub added: Vec<String>,
40 /// Final, sorted membership of the group after the update.
41 pub final_members: Vec<String>,
42 /// Deprecated alias for [`Self::final_members`]. Carries the same
43 /// value so existing clients reading `removed` keep working for one
44 /// release; new clients should read `final_members`. Scheduled for
45 /// removal in the next major bump — at which point the
46 /// `#[serde(alias = "removed")]` on `final_members` keeps inbound
47 /// compatibility for anyone POSTing back the old name.
48 #[serde(default)]
49 pub removed: Vec<String>,
50}
51
52/// Request body for `DELETE /api/v1/groups/{name}/members`.
53#[derive(Debug, Serialize, Deserialize, ToSchema)]
54pub struct DeleteGroupMembersRequest {
55 /// Hosts expression (xnames, NIDs, or hostlist notation)
56 /// identifying nodes to remove.
57 pub xnames_expression: String,
58 /// When true, validate the request without modifying group
59 /// membership.
60 #[serde(default)]
61 pub dry_run: bool,
62}
63
64/// Typed parameters for fetching HSM groups.
65#[derive(Debug)]
66pub struct GetGroupParams {
67 /// Exact group name to fetch; returns all groups when `None`.
68 pub group_name: Option<String>,
69 /// Operator default from `~/.config/manta/cli.toml`'s
70 /// `group_name`; used to scope results when `group_name` is
71 /// absent but a configured default exists.
72 pub settings_group_name: Option<String>,
73}
74
75impl GetGroupParams {
76 /// Returns the effective group name, preferring the explicit
77 /// `--group` flag and falling back to the operator default from
78 /// `cli.toml`.
79 pub fn effective_group(&self) -> Option<&str> {
80 self
81 .group_name
82 .as_deref()
83 .or(self.settings_group_name.as_deref())
84 }
85}