D: D3 peer wording, peers://status and peer-aware prompts
Server instructions and the eight tool descriptions mention peers and the untrusted-data rule only while a registry is configured. peers://status returns the list_peers JSON and is advertised only then. diagnose_unit and container_health_report take an optional validated peer argument.
This commit is contained in:
1 parent
ae09f0530c
commit
5237e772d4
5 files changed
+466
-162
No files matched your search
+35
-12
@@ -10,12 +10,14 @@ use crate::state::AppState;
|
||||
|
||||
pub const FAILED_UNITS_URI: &str = "systemd://units/failed";
|
||||
pub const CONTAINERS_URI: &str = "docker://containers";
|
||||
pub const PEERS_STATUS_URI: &str = "peers://status";
|
||||
pub const UNIT_URI_PREFIX: &str = "systemd://unit/";
|
||||
pub const CONTAINER_URI_PREFIX: &str = "docker://container/";
|
||||
|
||||
/// Resources advertised by `resources/list`.
|
||||
pub fn list() -> Vec<Resource> {
|
||||
vec![
|
||||
/// Resources advertised by `resources/list`. `peers://status` only exists
|
||||
/// while peers are configured.
|
||||
pub fn list(peers: bool) -> Vec<Resource> {
|
||||
let mut v = vec![
|
||||
Resource::new(FAILED_UNITS_URI, "failed-units")
|
||||
.with_title("Failed systemd units")
|
||||
.with_description("Units currently in the failed active state.")
|
||||
@@ -24,7 +26,20 @@ pub fn list() -> Vec<Resource> {
|
||||
.with_title("Docker containers")
|
||||
.with_description("All containers (running and stopped) with state and health.")
|
||||
.with_mime_type("application/json"),
|
||||
]
|
||||
];
|
||||
if peers {
|
||||
v.push(
|
||||
Resource::new(PEERS_STATUS_URI, "peer-status")
|
||||
.with_title("Peer status")
|
||||
.with_description(
|
||||
"Health of each configured peer: server.up (TCP connect), api.up \
|
||||
(authenticated ping) with auth state, latency and last change. Same JSON \
|
||||
as the list_peers tool.",
|
||||
)
|
||||
.with_mime_type("application/json"),
|
||||
);
|
||||
}
|
||||
v
|
||||
}
|
||||
|
||||
/// Templates advertised by `resources/templates/list`. They return the same
|
||||
@@ -55,8 +70,23 @@ fn decode_name(raw: &str) -> Result<String, AppError> {
|
||||
.map_err(|_| AppError::BadRequest("resource name is not valid UTF-8".into()))
|
||||
}
|
||||
|
||||
fn json_resource(uri: &str, json: String) -> ReadResourceResult {
|
||||
ReadResourceResult::new(vec![ResourceContents::TextResourceContents {
|
||||
uri: uri.to_owned(),
|
||||
mime_type: Some("application/json".into()),
|
||||
text: json,
|
||||
meta: None,
|
||||
}])
|
||||
}
|
||||
|
||||
/// Read a resource by URI, querying the source on each call.
|
||||
pub async fn read(state: &AppState, uri: &str) -> Result<ReadResourceResult, AppError> {
|
||||
if uri == PEERS_STATUS_URI {
|
||||
let reg = super::peers::registry(state)?;
|
||||
let json = serde_json::to_string(&super::peers::statuses(reg))
|
||||
.map_err(|e| AppError::Internal(e.to_string()))?;
|
||||
return Ok(json_resource(uri, json));
|
||||
}
|
||||
let json = match uri {
|
||||
FAILED_UNITS_URI => {
|
||||
let units = state.systemd.list_units(Some("failed")).await?;
|
||||
@@ -80,12 +110,5 @@ pub async fn read(state: &AppState, uri: &str) -> Result<ReadResourceResult, App
|
||||
}
|
||||
}
|
||||
.map_err(|e| AppError::Internal(e.to_string()))?;
|
||||
Ok(ReadResourceResult::new(vec![
|
||||
ResourceContents::TextResourceContents {
|
||||
uri: uri.to_owned(),
|
||||
mime_type: Some("application/json".into()),
|
||||
text: json,
|
||||
meta: None,
|
||||
},
|
||||
]))
|
||||
Ok(json_resource(uri, json))
|
||||
}
|
||||
Reference in new issue
Block a user