Skip to main content

xnode_manager_sdk/info/
handlers.rs

1use crate::{
2    info::{
3        Group, User,
4        models::{Flake, FlakeQuery},
5    },
6    utils::{Empty, SessionGetInput, SessionGetOutput, session_get},
7};
8
9pub fn scope() -> String {
10    "/info".to_string()
11}
12
13pub type FlakeInput<'a> = SessionGetInput<'a, Empty, FlakeQuery>;
14pub type FlakeOutput = Flake;
15pub async fn flake(input: FlakeInput<'_>) -> SessionGetOutput<FlakeOutput> {
16    session_get(input, scope(), |_path| "/flake").await
17}
18
19#[derive(Debug, Clone, PartialEq)]
20pub struct UsersPath {
21    pub scope: String,
22}
23pub type UsersInput<'a> = SessionGetInput<'a, UsersPath, Empty>;
24pub type UsersOutput = Vec<User>;
25pub async fn users(input: UsersInput<'_>) -> SessionGetOutput<UsersOutput> {
26    session_get(input, scope(), |path| {
27        format!("/users/{scope}/users", scope = path.scope)
28    })
29    .await
30}
31
32#[derive(Debug, Clone, PartialEq)]
33pub struct GroupsPath {
34    pub scope: String,
35}
36pub type GroupsInput<'a> = SessionGetInput<'a, GroupsPath, Empty>;
37pub type GroupsOutput = Vec<Group>;
38pub async fn groups(input: GroupsInput<'_>) -> SessionGetOutput<GroupsOutput> {
39    session_get(input, scope(), |path| {
40        format!("/users/{scope}/groups", scope = path.scope)
41    })
42    .await
43}