elasticctl_api/compose/
mod.rs1use elasticctl_core::{Error, ErrorKind, Result};
2mod alert_activity;
3pub mod alert_context;
4pub mod coverage;
5mod exception_coverage;
6pub mod readiness;
7pub mod rule_health;
8mod rule_snapshot;
9pub use alert_activity::*;
10pub use alert_context::*;
11pub use coverage::*;
12pub use exception_coverage::*;
13pub use rule_health::*;
14pub use rule_snapshot::*;
15pub const MAX_EXCEPTION_LISTS: usize = 5;
16pub const MAX_RELATED_CASES: usize = 5;
17pub const RECENT_ALERTS: usize = 5;
18pub const MAX_PATTERNS: usize = 16;
19pub const MAX_PACKAGES: usize = 8;
20pub const MESSAGE_BYTES: usize = 2_048;
21#[derive(Debug)]
22pub enum Part<T> {
23 Ok(T),
24 Unavailable(Error),
25 Skipped(SkipReason),
26}
27#[derive(Clone, Copy, Debug, PartialEq, Eq)]
28pub enum SkipReason {
29 NotApplicable,
30 DependencyUnavailable,
31 NotConfigured,
32}
33pub fn is_fatal(kind: ErrorKind) -> bool {
34 matches!(
35 kind,
36 ErrorKind::Auth | ErrorKind::Connection | ErrorKind::Timeout
37 )
38}
39pub fn degrade<T>(result: Result<T>) -> Result<Part<T>> {
40 match result {
41 Ok(v) => Ok(Part::Ok(v)),
42 Err(e) if is_fatal(e.kind) => Err(e),
43 Err(e) => Ok(Part::Unavailable(e)),
44 }
45}
46pub fn is_path_segment(value: &str) -> bool {
47 !matches!(value, "" | "." | "..")
48}
49pub fn require_path_segment(value: &str) -> Result<&str> {
50 if is_path_segment(value) {
51 Ok(value)
52 } else {
53 Err(Error::new(
54 ErrorKind::Http,
55 "id is not a single URL path segment",
56 ))
57 }
58}