[control] Overview for the UI: who is looking (viewer) and the underlying pause reason, so the UI offers the right action
This commit is contained in:
@@ -128,7 +128,11 @@ fn replay(st: &AppState, s: Stored) -> Response {
|
|||||||
#[utoipa::path(get, path = "/api/v1/overview", tag = "overview",
|
#[utoipa::path(get, path = "/api/v1/overview", tag = "overview",
|
||||||
responses((status = 200, body = Overview), (status = 304, description = "Unchanged since the ETag"), (status = 401, body = ErrorEnvelope)),
|
responses((status = 200, body = Overview), (status = 304, description = "Unchanged since the ETag"), (status = 401, body = ErrorEnvelope)),
|
||||||
security(("bearer" = [])))]
|
security(("bearer" = [])))]
|
||||||
pub async fn overview(State(st): Shared, headers: HeaderMap) -> Result<Response, ApiError> {
|
pub async fn overview(
|
||||||
|
State(st): Shared,
|
||||||
|
Extension(actor): Extension<Actor>,
|
||||||
|
headers: HeaderMap,
|
||||||
|
) -> Result<Response, ApiError> {
|
||||||
let c = &st.ctl;
|
let c = &st.ctl;
|
||||||
let (status, error, since) = {
|
let (status, error, since) = {
|
||||||
let h = c
|
let h = c
|
||||||
@@ -227,6 +231,7 @@ pub async fn overview(State(st): Shared, headers: HeaderMap) -> Result<Response,
|
|||||||
repo: Some(repo_view(c, &head)),
|
repo: Some(repo_view(c, &head)),
|
||||||
intermediate: super::pki::intermediate_view(c),
|
intermediate: super::pki::intermediate_view(c),
|
||||||
site,
|
site,
|
||||||
|
paused_reason: c.effective_pause().map(|p| p.code),
|
||||||
paused: c.effective_pause().map(|p| {
|
paused: c.effective_pause().map(|p| {
|
||||||
if p.code == "engine.caddy" {
|
if p.code == "engine.caddy" {
|
||||||
Blocked {
|
Blocked {
|
||||||
@@ -251,6 +256,14 @@ pub async fn overview(State(st): Shared, headers: HeaderMap) -> Result<Response,
|
|||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
rev: Some(head),
|
rev: Some(head),
|
||||||
|
viewer: Some(Viewer {
|
||||||
|
via: if actor.token_id.starts_with("user:") {
|
||||||
|
"authelia".into()
|
||||||
|
} else {
|
||||||
|
"token".into()
|
||||||
|
},
|
||||||
|
name: actor.name.clone(),
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
let body = serde_json::to_vec(&ov).map_err(|e| ApiError::internal(e.to_string()))?;
|
let body = serde_json::to_vec(&ov).map_err(|e| ApiError::internal(e.to_string()))?;
|
||||||
let etag = format!("\"{}\"", &sha256_hex(&body)[..32]);
|
let etag = format!("\"{}\"", &sha256_hex(&body)[..32]);
|
||||||
|
|||||||
@@ -528,9 +528,21 @@ pub struct Overview {
|
|||||||
pub intermediate: Option<super::pki::IntermediateView>,
|
pub intermediate: Option<super::pki::IntermediateView>,
|
||||||
pub site: Option<SiteView>,
|
pub site: Option<SiteView>,
|
||||||
pub paused: Option<Blocked>,
|
pub paused: Option<Blocked>,
|
||||||
|
/// Why changes are paused: the underlying code (`apply.needs_attention`, `control.files_unwritten`,
|
||||||
|
/// `repo.unreadable`, `engine.caddy`, …), so the UI can offer the right action.
|
||||||
|
pub paused_reason: Option<String>,
|
||||||
/// Set when control cannot read health from edge (`health.unavailable`).
|
/// Set when control cannot read health from edge (`health.unavailable`).
|
||||||
pub health_error: Option<Blocked>,
|
pub health_error: Option<Blocked>,
|
||||||
pub rev: Option<String>,
|
pub rev: Option<String>,
|
||||||
|
/// Who is looking: the Authelia user (through edge) or the API token's name.
|
||||||
|
pub viewer: Option<Viewer>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, ToSchema)]
|
||||||
|
pub struct Viewer {
|
||||||
|
pub name: String,
|
||||||
|
/// `authelia` or `token`.
|
||||||
|
pub via: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn added_at(c: &Control, hostname: &str) -> Option<String> {
|
pub fn added_at(c: &Control, hostname: &str) -> Option<String> {
|
||||||
|
|||||||
@@ -22,11 +22,12 @@ use ianitor_control::util::{hex, random, write_atomic};
|
|||||||
/// on the offline machine), and the PKI password credential. Control then works like
|
/// on the offline machine), and the PKI password credential. Control then works like
|
||||||
/// production: it issues server certificates for every `tls = "domi"` host.
|
/// production: it issues server certificates for every `tls = "domi"` host.
|
||||||
fn dev_pki(dir: &Path) -> Result<(String, ianitor_core::pki::KeyPair), String> {
|
fn dev_pki(dir: &Path) -> Result<(String, ianitor_core::pki::KeyPair), String> {
|
||||||
let (root, key) =
|
let (root, key) = ianitor_core::pki::create_root(ianitor_control::util::now() as i64)
|
||||||
ianitor_core::pki::create_root(ianitor_control::util::now() as i64).map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
std::fs::write(dir.join("offline-root/domi-root.crt"), &root).map_err(|e| e.to_string())?;
|
std::fs::write(dir.join("offline-root/domi-root.crt"), &root).map_err(|e| e.to_string())?;
|
||||||
let pass = hex(&random::<24>().map_err(|e| e.to_string())?);
|
let pass = hex(&random::<24>().map_err(|e| e.to_string())?);
|
||||||
write_atomic(&dir.join("creds/pki-password"), pass.as_bytes(), 0o600).map_err(|e| e.to_string())?;
|
write_atomic(&dir.join("creds/pki-password"), pass.as_bytes(), 0o600)
|
||||||
|
.map_err(|e| e.to_string())?;
|
||||||
Ok((root, key))
|
Ok((root, key))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user