Skip to main content

alien_core/deployment/
setup_drift.rs

1//! Setup drift: what a setup run would still change on an installed deployment.
2//!
3//! Drift is **recommended**, never required: it never pauses a release. It is a notice that the
4//! installer can run a setup update to bring grants, alarms and flow logs up to date.
5
6use serde::{Deserialize, Serialize};
7
8/// Why an installed deployment's setup is behind. Codes are stable: clients render and match
9/// them, so a new reason gets a new code.
10#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
11#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
12#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
13pub enum SetupDriftCode {
14    /// A permission set the management identity holds has a body this version would change,
15    /// compared by content, not by name. `resource` is the permission set id when known.
16    ManagementPermissionsChanged,
17    /// No record of the management permissions that were installed (an older install): setup
18    /// runs once to record them.
19    ManagementPermissionsUnrecorded,
20    /// The Alien-created VPC has no complete flow log. `resource` is the network id.
21    FlowLogMissing,
22    /// The management identity has no recorded permissions boundary (an install from before
23    /// the boundary existed). Setup installs it. `resource` is the management resource id.
24    PermissionsBoundaryMissing,
25    /// The installed permissions boundary differs from the one this version would install.
26    /// Setup rewrites it. `resource` is the management resource id.
27    PermissionsBoundaryChanged,
28    /// A grant was denied while creating something setup's grant covers (CloudWatch alarms,
29    /// point-in-time recovery). `resource` is the resource id; `detail` names what was denied.
30    GrantDenied,
31}
32
33/// One reason an installed deployment's setup is behind.
34#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
35#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
36#[serde(rename_all = "camelCase")]
37pub struct SetupDriftReason {
38    /// What kind of reason this is.
39    pub code: SetupDriftCode,
40    /// The resource or permission set the reason is about, when one is.
41    #[serde(default, skip_serializing_if = "Option::is_none")]
42    pub resource: Option<String>,
43    /// Plain-language detail for a person.
44    pub detail: String,
45}
46
47impl SetupDriftReason {
48    /// One line for a terminal.
49    pub fn summary(&self) -> String {
50        match &self.resource {
51            Some(resource) => format!("{} ({resource})", self.detail),
52            None => self.detail.clone(),
53        }
54    }
55}