xnode_manager_sdk/config/
handlers.rs

1use crate::{
2    config::models::{ContainerChange, ContainerConfiguration},
3    request::RequestIdResponse,
4    utils::{
5        Empty, SessionGetInput, SessionGetOutput, SessionPostInput, SessionPostOutput, session_get,
6        session_post,
7    },
8};
9
10pub fn scope() -> String {
11    "/config".to_string()
12}
13
14pub type ContainersInput<'a> = SessionGetInput<'a, Empty, Empty>;
15pub type ContainersOutput = Vec<String>;
16pub async fn containers(input: ContainersInput<'_>) -> SessionGetOutput<ContainersOutput> {
17    session_get(input, scope(), |_path| "/containers").await
18}
19
20#[derive(Debug)]
21pub struct GetPath {
22    pub container: String,
23}
24pub type GetInput<'a> = SessionGetInput<'a, GetPath, Empty>;
25pub type GetOutput = ContainerConfiguration;
26pub async fn get(input: GetInput<'_>) -> SessionGetOutput<GetOutput> {
27    session_get(input, scope(), |path| {
28        format!("/container/{container}/get", container = path.container)
29    })
30    .await
31}
32
33#[derive(Debug)]
34pub struct SetPath {
35    pub container: String,
36}
37pub type SetInput<'a> = SessionPostInput<'a, SetPath, ContainerChange>;
38pub type SetOutput = RequestIdResponse;
39pub async fn set(input: SetInput<'_>) -> SessionPostOutput<SetOutput> {
40    session_post(input, scope(), |path| {
41        format!("/container/{container}/set", container = path.container)
42    })
43    .await
44}
45
46#[derive(Debug)]
47pub struct RemovePath {
48    pub container: String,
49}
50pub type RemoveInput<'a> = SessionPostInput<'a, RemovePath, Empty>;
51pub type RemoveOutput = RequestIdResponse;
52pub async fn remove(input: RemoveInput<'_>) -> SessionPostOutput<RemoveOutput> {
53    session_post(input, scope(), |path| {
54        format!("/container/{container}/remove", container = path.container)
55    })
56    .await
57}