fakecloud_ce/state.rs
1//! Account-partitioned, serializable state for AWS Cost Explorer (`ce`).
2//!
3//! Every stored Cost Explorer resource is kept as an already-output-valid JSON
4//! object (`serde_json::Value`) keyed by its ARN, name, or id. Storing the wire
5//! shape directly keeps nested configuration (cost-category rules, monitor
6//! specifications, subscription expressions) round-tripping verbatim and
7//! guarantees the `Get`/`Describe` responses echo exactly what was persisted.
8
9use std::collections::BTreeMap;
10use std::sync::Arc;
11
12use parking_lot::RwLock;
13use serde::{Deserialize, Serialize};
14use serde_json::Value;
15
16use fakecloud_core::multi_account::{AccountState, MultiAccountState};
17
18pub const CE_SNAPSHOT_SCHEMA_VERSION: u32 = 1;
19
20/// Per-account Cost Explorer state.
21#[derive(Debug, Clone, Default, Serialize, Deserialize)]
22pub struct CeData {
23 /// Anomaly monitors keyed by `MonitorArn`, holding the `AnomalyMonitor`
24 /// object.
25 #[serde(default)]
26 pub anomaly_monitors: BTreeMap<String, Value>,
27 /// Anomaly subscriptions keyed by `SubscriptionArn`, holding the
28 /// `AnomalySubscription` object.
29 #[serde(default)]
30 pub anomaly_subscriptions: BTreeMap<String, Value>,
31 /// Detected anomalies keyed by `AnomalyId` (feedback target).
32 #[serde(default)]
33 pub anomalies: BTreeMap<String, Value>,
34 /// Cost category definitions keyed by `CostCategoryArn`, holding the
35 /// `CostCategory` object.
36 #[serde(default)]
37 pub cost_categories: BTreeMap<String, Value>,
38 /// Cost-category resource associations keyed by `CostCategoryArn`.
39 #[serde(default)]
40 pub cost_category_associations: BTreeMap<String, Vec<Value>>,
41 /// Cost allocation tags keyed by `TagKey`, holding the `CostAllocationTag`
42 /// object (status/type/timestamps).
43 #[serde(default)]
44 pub cost_allocation_tags: BTreeMap<String, Value>,
45 /// Cost-allocation-tag backfill requests, newest last.
46 #[serde(default)]
47 pub backfill_requests: Vec<Value>,
48 /// Commitment-purchase analyses keyed by `AnalysisId`.
49 #[serde(default)]
50 pub commitment_analyses: BTreeMap<String, Value>,
51 /// Savings-plans purchase recommendation generations keyed by
52 /// `RecommendationId`.
53 #[serde(default)]
54 pub sp_generations: BTreeMap<String, Value>,
55 /// Resource tags keyed by resource ARN -> (key -> value).
56 #[serde(default)]
57 pub tags: BTreeMap<String, BTreeMap<String, String>>,
58}
59
60impl AccountState for CeData {
61 fn new_for_account(_account_id: &str, _region: &str, _endpoint: &str) -> Self {
62 Self::default()
63 }
64}
65
66pub type SharedCeState = Arc<RwLock<MultiAccountState<CeData>>>;
67
68#[derive(Debug, Serialize, Deserialize)]
69pub struct CeSnapshot {
70 pub schema_version: u32,
71 pub accounts: MultiAccountState<CeData>,
72}