From 304810da11e9bb6cddc32008613b2168e3a3d162 Mon Sep 17 00:00:00 2001 From: Bo Maryniuk Date: Tue, 10 Dec 2024 21:28:52 +0100 Subject: [PATCH] Drop "model://" targeting as there will be always only one scheme. --- docs/genusage/targeting.rst | 13 +++++++++---- docs/modeldescr/overview.rst | 9 +++++++-- docs/modeldescr/states.rst | 2 +- libsysinspect/src/proto/mod.rs | 2 +- libsysinspect/src/proto/query.rs | 18 ++++-------------- src/clidef.rs | 4 ++-- src/main.rs | 2 +- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/docs/genusage/targeting.rst b/docs/genusage/targeting.rst index 9236f72e..781b963a 100644 --- a/docs/genusage/targeting.rst +++ b/docs/genusage/targeting.rst @@ -47,12 +47,12 @@ in the following format: .. code-block:: text :caption: Precise model query synopsis - "model:///[entity]/[state] [traits query]" + "//[entity]/[state] [traits query]" .. code-block:: text :caption: Checkbook model query synopsis - "model:///[entity]:[checkbook labels]" + "//[entity]:[checkbook labels]" Since there can be many models, it is essential to select one, therefore a model Id is always required. If ``entity`` and/or ``state`` are not specified, they are defaulted to @@ -61,7 +61,7 @@ always required. If ``entity`` and/or ``state`` are not specified, they are defa .. code-block:: bash :caption: Example of Model targeting by precise query - sysinspect "model://router/network,devices/online" + sysinspect "/router/network,devices/online" In the example above, a network is verified in a router only when it supposed to be online. Under the hood, omitted parts are translated to "all" (``$``). E.g. ``router/network`` is @@ -74,11 +74,16 @@ values and logical operations. See :ref:`query_targeting` for more details. .. code-block:: bash :caption: Example of Model targeting by checkbook labels - sysinspect "model://router:network,devices" + sysinspect "/router:network,devices" The example above is the same as the previous one, except it is using Checkbook. Entities in the Checkbook are basically the top-high groups of other entities. +.. hint:: + + Trailing slash in model specification path can be omitted: ``router/network/online`` would also working + the same way. + Using Traits ------------ diff --git a/docs/modeldescr/overview.rst b/docs/modeldescr/overview.rst index 6b630176..4668ba8f 100644 --- a/docs/modeldescr/overview.rst +++ b/docs/modeldescr/overview.rst @@ -6,8 +6,13 @@ Model Description .. _model_description: -The Model is essentially a configuration of a system. It is written in YAML format, -and it is following a specific expression schema and logic. +The Model is essentially a configuration of a system. It serves two purposes: + +- An assertion verification about system integrity (information only) +- A state enforcement as a configuration management system does + + +The Aodel is written in YAML format, and it is following a specific expression schema and logic. This document explains each part of the Model Description. diff --git a/docs/modeldescr/states.rst b/docs/modeldescr/states.rst index 0a9f22c4..068122d0 100644 --- a/docs/modeldescr/states.rst +++ b/docs/modeldescr/states.rst @@ -54,4 +54,4 @@ is passed, then default state is selected: .. code-block:: text - syspect --model ./my_model --states=online,active + sysinspect --model ./my_model --states=online,active diff --git a/libsysinspect/src/proto/mod.rs b/libsysinspect/src/proto/mod.rs index de9d9fc1..c50682a4 100644 --- a/libsysinspect/src/proto/mod.rs +++ b/libsysinspect/src/proto/mod.rs @@ -140,7 +140,7 @@ pub struct MinionTarget { /// Session Id sid: String, // XXX: Should be gone - /// Scheme to call (model:// or state://) + /// Which scheme must be called (model://) #[serde(rename = "s")] scheme: String, diff --git a/libsysinspect/src/proto/query.rs b/libsysinspect/src/proto/query.rs index e10dd450..bccf776c 100644 --- a/libsysinspect/src/proto/query.rs +++ b/libsysinspect/src/proto/query.rs @@ -4,7 +4,6 @@ use crate::SysinspectError; /// Targeting schemes pub static SCHEME_MODEL: &str = "model://"; -pub static SCHEME_STATE: &str = "state://"; /// /// Query parser (scheme). @@ -25,21 +24,12 @@ pub struct MinionQuery { impl MinionQuery { pub fn new(q: &str) -> Result>, SysinspectError> { - let q = q.trim(); - if !q.starts_with(SCHEME_STATE) && !q.starts_with(SCHEME_MODEL) { - return Err(SysinspectError::ProtoError("Query has unknown scheme".to_string())); - } - - let sq: Vec<&str> = q.split("://").collect(); - if sq.len() != 2 { - return Err(SysinspectError::ProtoError("Unable to parse scheme".to_string())); - } - + let q = q.trim().trim_matches('/'); let mut instance = Self { ..Default::default() }; - instance.scheme = sq[0].to_owned(); + instance.scheme = SCHEME_MODEL.to_string(); // XXX: Drop "model://" scheme entirely - let precise = sq[1].contains('/'); - let sq: Vec<&str> = sq[1].split(if precise { '/' } else { ':' }).filter(|s| !s.is_empty()).collect(); + let precise = q.contains('/'); + let sq: Vec<&str> = q.split(if precise { '/' } else { ':' }).filter(|s| !s.is_empty()).collect(); match sq.len() { 0 => { return Err(SysinspectError::ProtoError("No model has been targeted".to_string())); diff --git a/src/clidef.rs b/src/clidef.rs index 56bf0c80..52da86a4 100644 --- a/src/clidef.rs +++ b/src/clidef.rs @@ -20,8 +20,8 @@ pub fn cli(version: &'static str) -> Command { // Sysinspect .next_help_heading("Main") .arg( - Arg::new("scheme") - .help("Specify scheme that needs to be requested (model:// or state://)") + Arg::new("path") + .help("Specify model path that needs to be requested") .required(false) .index(1) ) diff --git a/src/main.rs b/src/main.rs index 67e1bf6d..14c04dcc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -97,7 +97,7 @@ fn main() { } }; - if let Some(model) = params.get_one::("scheme") { + if let Some(model) = params.get_one::("path") { let query = params.get_one::("query"); let traits = params.get_one::("traits"); if let Err(err) = call_master_fifo(model, query.unwrap_or(&"".to_string()), traits, &cfg.socket()) {