Skip to main content

pubhubs/api/
admin.rs

1//! `.ph/admin/...` endpoints
2use crate::api::*;
3use actix_web::http;
4use serde::{Deserialize, Serialize};
5
6/// Changes the [crate::servers::Config] **in memory**, and restarts the server service.
7/// The configuration file remains unchanged, so when the binary restarts, the changes
8/// are lost.  This endpoint is used for testing, and can also be useful for debugging.
9///
10/// The request is verified using the [crate::servers::config::ServerConfig::admin_key].
11pub struct UpdateConfigEP {}
12impl EndpointDetails for UpdateConfigEP {
13    type RequestType = Signed<UpdateConfigReq>;
14    type ResponseType = Result<UpdateConfigResp>;
15
16    const METHOD: http::Method = http::Method::POST;
17    const PATH: &'static str = ".ph/admin/update-config";
18}
19
20#[derive(Serialize, Deserialize, Debug, Clone)]
21#[serde(deny_unknown_fields)]
22pub struct UpdateConfigReq {
23    /// JSON Pointer (see RFC6901) to the part of the configuration that is to be changed
24    ///
25    /// Example: "/transcryptor/enc_key"
26    pub pointer: String,
27
28    pub new_value: serde_json::Value,
29}
30
31/// Response type for [`UpdateConfigEP`]
32#[derive(Serialize, Deserialize, Debug, Clone)]
33#[serde(deny_unknown_fields)]
34#[must_use]
35pub enum UpdateConfigResp {
36    /// Signature on request was expired; retry with a fresh one
37    ResignRequest,
38
39    /// Admin key is invalid
40    InvalidAdminKey,
41
42    /// Updating configuration succeeded
43    Success,
44}
45
46having_message_code!(UpdateConfigReq, AdminUpdateConfigReq);
47
48/// Retrieves sensitive details (like the [crate::servers::Config]) from this server.
49///
50/// The request is verified using the [crate::servers::config::ServerConfig::admin_key].
51///
52/// NB Cannot be a GET request because the request needs to be signed.
53pub struct InfoEP {}
54impl EndpointDetails for InfoEP {
55    type RequestType = Signed<InfoReq>;
56    type ResponseType = Result<InfoResp>;
57
58    const METHOD: http::Method = http::Method::POST;
59    const PATH: &'static str = ".ph/admin/info";
60}
61
62/// Request type for [`InfoEP`]
63#[derive(Serialize, Deserialize, Debug, Clone)]
64#[serde(deny_unknown_fields)]
65pub struct InfoReq {}
66
67having_message_code!(InfoReq, AdminInfoReq);
68
69/// Response type for [`InfoEP`]
70#[derive(Serialize, Deserialize, Debug, Clone)]
71#[serde(deny_unknown_fields)]
72#[must_use]
73pub enum InfoResp {
74    /// Signature on request was expired; retry with a fresh one
75    ResignRequest,
76
77    /// Admin key is invalid
78    InvalidAdminKey,
79
80    /// Request succeeded
81    Success {
82        /// Current server configuration
83        config: Box<crate::servers::Config>,
84    },
85}