Skip to main content

elasticctl_api/compose/
mod.rs

1//! Bounded shared reads for cross-vertical reports.
2use elasticctl_core::{Error, ErrorKind, Result};
3mod alert_activity;
4pub mod alert_context;
5pub mod coverage;
6mod exception_coverage;
7pub mod readiness;
8pub mod rule_health;
9mod rule_snapshot;
10pub use alert_activity::*;
11pub use alert_context::*;
12pub use coverage::*;
13pub use exception_coverage::*;
14pub use rule_health::*;
15pub use rule_snapshot::*;
16pub const MAX_EXCEPTION_LISTS: usize = 5;
17pub const MAX_RELATED_CASES: usize = 5;
18pub const RECENT_ALERTS: usize = 5;
19pub const MAX_PATTERNS: usize = 16;
20pub const MAX_PACKAGES: usize = 8;
21pub const MESSAGE_BYTES: usize = 2_048;
22#[derive(Debug)]
23pub enum Part<T> {
24    Ok(T),
25    Unavailable(Error),
26    Skipped(SkipReason),
27}
28#[derive(Clone, Copy, Debug, PartialEq, Eq)]
29pub enum SkipReason {
30    NotApplicable,
31    DependencyUnavailable,
32    NotConfigured,
33}
34pub fn is_fatal(kind: ErrorKind) -> bool {
35    matches!(
36        kind,
37        ErrorKind::Auth | ErrorKind::Connection | ErrorKind::Timeout
38    )
39}
40pub fn degrade<T>(result: Result<T>) -> Result<Part<T>> {
41    match result {
42        Ok(v) => Ok(Part::Ok(v)),
43        Err(e) if is_fatal(e.kind) => Err(e),
44        Err(e) => Ok(Part::Unavailable(e)),
45    }
46}
47pub fn is_path_segment(value: &str) -> bool {
48    !matches!(value, "" | "." | "..")
49}
50/// Refuse an id read from a response or a local file before it becomes one
51/// URL path segment. URL parsing removes `.` and `..` segments, so either
52/// would move the request to a parent route.
53pub fn require_path_segment(value: &str) -> Result<&str> {
54    if is_path_segment(value) {
55        Ok(value)
56    } else {
57        Err(Error::new(
58            ErrorKind::Http,
59            "id is not a single URL path segment",
60        ))
61    }
62}