Skip to main content

fakecloud_codedeploy/
state.rs

1//! Account-partitioned, serializable state for AWS CodeDeploy.
2//!
3//! Resources are stored as assembled response-shaped JSON values so a read
4//! returns exactly what was written (round-trip fidelity). Deployments carry a
5//! separate `deployment_settle` step counter so the first reads after
6//! `CreateDeployment` can advance them from `Created` through `InProgress` to a
7//! terminal `Succeeded` state deterministically, without leaking an internal
8//! counter into the response shape.
9
10use std::collections::BTreeMap;
11use std::sync::Arc;
12
13use parking_lot::RwLock;
14use serde::{Deserialize, Serialize};
15use serde_json::Value;
16
17use fakecloud_core::multi_account::{AccountState, MultiAccountState};
18
19pub const CODEDEPLOY_SNAPSHOT_SCHEMA_VERSION: u32 = 1;
20
21/// The account-scoped CodeDeploy state for one AWS account.
22#[derive(Debug, Clone, Default, Serialize, Deserialize)]
23pub struct CodeDeployState {
24    /// Applications keyed by application name; value is an `ApplicationInfo` JSON.
25    #[serde(default)]
26    pub applications: BTreeMap<String, Value>,
27    /// Insertion order of application names (most-recent last).
28    #[serde(default)]
29    pub application_order: Vec<String>,
30    /// Registered application revisions keyed by application name; value is an
31    /// ordered list of `RevisionInfo` JSON objects.
32    #[serde(default)]
33    pub app_revisions: BTreeMap<String, Vec<Value>>,
34    /// Deployment groups keyed by application name then group name; value is a
35    /// `DeploymentGroupInfo` JSON.
36    #[serde(default)]
37    pub deployment_groups: BTreeMap<String, BTreeMap<String, Value>>,
38    /// User-created deployment configurations keyed by name; value is a
39    /// `DeploymentConfigInfo` JSON. The predefined `CodeDeployDefault.*`
40    /// configs are synthesized on read and never stored here.
41    #[serde(default)]
42    pub deployment_configs: BTreeMap<String, Value>,
43    /// Insertion order of user deployment-config names.
44    #[serde(default)]
45    pub deployment_config_order: Vec<String>,
46    /// Deployments keyed by deployment id (`d-XXXXXXXXX`); value is a
47    /// `DeploymentInfo` JSON.
48    #[serde(default)]
49    pub deployments: BTreeMap<String, Value>,
50    /// Insertion order of deployment ids (most-recent last).
51    #[serde(default)]
52    pub deployment_order: Vec<String>,
53    /// Per-deployment settle step, used to advance a deployment from
54    /// `Created` -> `InProgress` -> `Succeeded` across successive reads.
55    #[serde(default)]
56    pub deployment_settle: BTreeMap<String, u8>,
57    /// On-premises instances keyed by instance name; value is an `InstanceInfo` JSON.
58    #[serde(default)]
59    pub on_premises_instances: BTreeMap<String, Value>,
60    /// Insertion order of on-premises instance names.
61    #[serde(default)]
62    pub on_premises_order: Vec<String>,
63    /// Resource tags keyed by resource ARN; value is a `TagList` (list of
64    /// `{Key,Value}` objects).
65    #[serde(default)]
66    pub tags: BTreeMap<String, Vec<Value>>,
67}
68
69impl AccountState for CodeDeployState {
70    fn new_for_account(_account_id: &str, _region: &str, _endpoint: &str) -> Self {
71        Self::default()
72    }
73}
74
75pub type SharedCodeDeployState = Arc<RwLock<MultiAccountState<CodeDeployState>>>;
76
77#[derive(Debug, Serialize, Deserialize)]
78pub struct CodeDeploySnapshot {
79    pub schema_version: u32,
80    pub accounts: MultiAccountState<CodeDeployState>,
81}