1
//! A stored script as the script-edit form holds it, with the revision
2
//! digesting its editable fields.
3

            
4
use crate::artifact_mgmt::user::ScriptDetail;
5
use crate::logical::hex_digest;
6

            
7
/// The error text of a script edit whose expected revision no longer matches.
8
pub const STALE_SCRIPT: &str = "the script changed since it was loaded; reload it";
9

            
10
/// Whether an `enabled` tag value leaves the script on: only `false` turns it off.
11
#[must_use]
12
24489
pub fn is_enabled(tag: Option<&str>) -> bool {
13
24489
    tag != Some("false")
14
24489
}
15

            
16
/// Digest of the script's name, source and enabled state.
17
#[must_use]
18
11709
pub fn script_revision(name: Option<&str>, source: Option<&str>, enabled: bool) -> String {
19
11709
    hex_digest(vec![format!("script {:?}", (name, source, enabled))])
20
11709
}
21

            
22
impl ScriptDetail {
23
    /// The revision an edit of this script must carry.
24
    #[must_use]
25
8284
    pub fn revision(&self) -> String {
26
8284
        script_revision(
27
8284
            self.name.as_deref(),
28
8284
            self.source.as_deref(),
29
8284
            is_enabled(self.enabled.as_deref()),
30
8284
        )
31
8284
    }
32
}