fakecloud_codepipeline/state.rs
1//! Account-partitioned, serializable state for AWS CodePipeline.
2//!
3//! Resources are stored as assembled response-shaped JSON values so a read
4//! returns exactly what was written (round-trip fidelity). A pipeline execution
5//! settles purely from its own stored `status`: a read after
6//! `StartPipelineExecution` advances a non-terminal execution one step toward a
7//! terminal state (`InProgress` -> `Succeeded`, `Stopping` -> `Stopped`), and a
8//! terminal execution is never re-settled. No separate counter is kept.
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 CODEPIPELINE_SNAPSHOT_SCHEMA_VERSION: u32 = 1;
20
21/// The account-scoped CodePipeline state for one AWS account.
22#[derive(Debug, Clone, Default, Serialize, Deserialize)]
23pub struct CodePipelineState {
24 /// Current pipeline declaration keyed by pipeline name; value is a
25 /// `PipelineDeclaration` JSON carrying the current `version`.
26 #[serde(default)]
27 pub pipelines: BTreeMap<String, Value>,
28 /// Insertion order of pipeline names (most-recent last).
29 #[serde(default)]
30 pub pipeline_order: Vec<String>,
31 /// Per-pipeline metadata keyed by pipeline name; value is a
32 /// `PipelineMetadata` JSON (`pipelineArn`, `created`, `updated`).
33 #[serde(default)]
34 pub pipeline_meta: BTreeMap<String, Value>,
35 /// Historical pipeline declarations keyed by pipeline name; the element at
36 /// index `version - 1` is the declaration as of that version.
37 #[serde(default)]
38 pub pipeline_versions: BTreeMap<String, Vec<Value>>,
39 /// Pipeline executions keyed by execution id (a UUID); value is a stored
40 /// `PipelineExecution`-shaped JSON.
41 #[serde(default)]
42 pub executions: BTreeMap<String, Value>,
43 /// Per-pipeline execution id order (most-recent last).
44 #[serde(default)]
45 pub execution_order: BTreeMap<String, Vec<String>>,
46 /// Disabled stage transitions keyed by pipeline name, then by
47 /// `<stageName>/<transitionType>`; value is a `TransitionState`-shaped JSON
48 /// (`enabled: false`, `disabledReason`, `lastChangedBy`, `lastChangedAt`).
49 /// A `(pipeline, stage, transitionType)` absent here is enabled.
50 #[serde(default)]
51 pub transitions_disabled: BTreeMap<String, BTreeMap<String, Value>>,
52 /// User-created custom action types keyed by `category:provider:version`;
53 /// value is an `ActionType` JSON.
54 #[serde(default)]
55 pub custom_actions: BTreeMap<String, Value>,
56 /// Insertion order of custom action-type keys.
57 #[serde(default)]
58 pub custom_action_order: Vec<String>,
59 /// Webhooks keyed by webhook name; value is a `ListWebhookItem` JSON.
60 #[serde(default)]
61 pub webhooks: BTreeMap<String, Value>,
62 /// Insertion order of webhook names.
63 #[serde(default)]
64 pub webhook_order: Vec<String>,
65 /// Resource tags keyed by resource ARN; value is a `TagList` (list of
66 /// `{key,value}` objects).
67 #[serde(default)]
68 pub tags: BTreeMap<String, Vec<Value>>,
69}
70
71impl AccountState for CodePipelineState {
72 fn new_for_account(_account_id: &str, _region: &str, _endpoint: &str) -> Self {
73 Self::default()
74 }
75}
76
77pub type SharedCodePipelineState = Arc<RwLock<MultiAccountState<CodePipelineState>>>;
78
79#[derive(Debug, Serialize, Deserialize)]
80pub struct CodePipelineSnapshot {
81 pub schema_version: u32,
82 pub accounts: MultiAccountState<CodePipelineState>,
83}