Skip to main content

fakecloud_acm/
state.rs

1//! In-memory state for ACM certificates.
2
3use std::collections::HashMap;
4use std::sync::Arc;
5
6use chrono::{DateTime, Utc};
7use parking_lot::RwLock;
8use serde::{Deserialize, Serialize};
9
10pub type SharedAcmState = Arc<RwLock<AcmAccounts>>;
11
12#[derive(Debug, Default, Serialize, Deserialize)]
13pub struct AcmAccounts {
14    pub accounts: HashMap<String, AccountState>,
15}
16
17impl AcmAccounts {
18    pub fn new() -> Self {
19        Self::default()
20    }
21}
22
23#[derive(Debug, Default, Serialize, Deserialize)]
24pub struct AccountState {
25    /// Keyed by full certificate ARN.
26    pub certificates: HashMap<String, StoredCertificate>,
27    pub account_config: AccountConfig,
28}
29
30#[derive(Debug, Clone, Default, Serialize, Deserialize)]
31pub struct AccountConfig {
32    pub expiry_events_days_before_expiry: Option<i32>,
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
36pub struct StoredCertificate {
37    pub arn: String,
38    pub domain_name: String,
39    pub subject_alternative_names: Vec<String>,
40    pub status: String,
41    pub cert_type: String,
42    /// Stored when present so we can round-trip it on `GetCertificate`.
43    pub certificate_pem: Option<String>,
44    pub certificate_chain_pem: Option<String>,
45    /// Imported certs only — held in memory but never returned
46    /// (matches real ACM, which never returns the private key).
47    pub private_key_pem: Option<String>,
48    pub idempotency_token: Option<String>,
49    pub serial: String,
50    pub subject: String,
51    pub issuer: String,
52    pub key_algorithm: String,
53    pub signature_algorithm: String,
54    pub created_at: DateTime<Utc>,
55    pub issued_at: Option<DateTime<Utc>>,
56    pub imported_at: Option<DateTime<Utc>>,
57    pub revoked_at: Option<DateTime<Utc>>,
58    pub revocation_reason: Option<String>,
59    pub not_before: DateTime<Utc>,
60    pub not_after: DateTime<Utc>,
61    pub validation_method: Option<String>,
62    pub domain_validation: Vec<DomainValidation>,
63    pub options: CertificateOptions,
64    pub renewal_eligibility: String,
65    pub managed_by: Option<String>,
66    pub certificate_authority_arn: Option<String>,
67    pub tags: HashMap<String, String>,
68    pub in_use_by: Vec<String>,
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct DomainValidation {
73    pub domain_name: String,
74    pub validation_status: String,
75    pub validation_method: String,
76    pub resource_record_name: Option<String>,
77    pub resource_record_type: Option<String>,
78    pub resource_record_value: Option<String>,
79}
80
81#[derive(Debug, Clone, Default, Serialize, Deserialize)]
82pub struct CertificateOptions {
83    pub certificate_transparency_logging_preference: String,
84    pub export: String,
85}