Skip to main content

fakecloud_cloudfront/
functions.rs

1//! Data types for CloudFront Batch 3 resources: Functions, Public Keys,
2//! Key Groups, Key Value Stores, Origin Access Identities (legacy),
3//! Monitoring Subscriptions.
4
5use chrono::{DateTime, Utc};
6use serde::{Deserialize, Serialize};
7
8fn skip_if_none<T>(x: &Option<T>) -> bool {
9    x.is_none()
10}
11
12// ─── CloudFront Function ──────────────────────────────────────────────
13
14#[derive(Debug, Clone, Serialize, Deserialize, Default)]
15#[serde(rename_all = "PascalCase")]
16pub struct FunctionConfig {
17    #[serde(default, skip_serializing_if = "skip_if_none")]
18    pub comment: Option<String>,
19    pub runtime: String,
20    #[serde(default, skip_serializing_if = "skip_if_none")]
21    pub key_value_store_associations: Option<KeyValueStoreAssociations>,
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize, Default)]
25#[serde(rename_all = "PascalCase")]
26pub struct KeyValueStoreAssociations {
27    pub quantity: i32,
28    #[serde(default, skip_serializing_if = "skip_if_none")]
29    pub items: Option<KeyValueStoreAssociationItems>,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize, Default)]
33#[serde(rename_all = "PascalCase")]
34pub struct KeyValueStoreAssociationItems {
35    #[serde(default, rename = "KeyValueStoreAssociation")]
36    pub key_value_store_association: Vec<KeyValueStoreAssociation>,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize, Default)]
40#[serde(rename_all = "PascalCase")]
41pub struct KeyValueStoreAssociation {
42    // AWS spells the member `KeyValueStoreARN` (upper-case ARN), which the
43    // default PascalCase rule would render as `KeyValueStoreArn`. Pin the
44    // exact wire name so real SDK requests parse and responses round-trip.
45    #[serde(rename = "KeyValueStoreARN")]
46    pub key_value_store_arn: String,
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct StoredFunction {
51    pub name: String,
52    pub etag: String,
53    pub status: String,
54    /// "DEVELOPMENT" or "LIVE"
55    pub stage: String,
56    pub function_arn: String,
57    pub created_time: DateTime<Utc>,
58    pub last_modified_time: DateTime<Utc>,
59    pub config: FunctionConfig,
60    /// Function source code (base64-encoded as the API receives it).
61    /// This is the DEVELOPMENT-stage code: it tracks the latest
62    /// CreateFunction / UpdateFunction body and is the version that
63    /// `TestFunction(Stage=DEVELOPMENT)` runs against.
64    pub function_code: String,
65    /// Snapshot of `function_code` taken when the function is published.
66    /// `TestFunction(Stage=LIVE)` (and the corresponding distribution
67    /// data plane, once wired) reads from here so the published
68    /// behaviour stays stable while DEVELOPMENT keeps mutating.
69    #[serde(default, skip_serializing_if = "skip_if_none")]
70    pub live_function_code: Option<String>,
71}
72
73// ─── Public Key ───────────────────────────────────────────────────────
74
75#[derive(Debug, Clone, Serialize, Deserialize, Default)]
76#[serde(rename_all = "PascalCase")]
77pub struct PublicKeyConfig {
78    pub caller_reference: String,
79    pub name: String,
80    pub encoded_key: String,
81    #[serde(default, skip_serializing_if = "skip_if_none")]
82    pub comment: Option<String>,
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
86pub struct StoredPublicKey {
87    pub id: String,
88    pub etag: String,
89    pub created_time: DateTime<Utc>,
90    pub config: PublicKeyConfig,
91}
92
93// ─── Key Group ────────────────────────────────────────────────────────
94
95#[derive(Debug, Clone, Serialize, Deserialize, Default)]
96#[serde(rename_all = "PascalCase")]
97pub struct KeyGroupConfig {
98    pub name: String,
99    pub items: KeyGroupItems,
100    #[serde(default, skip_serializing_if = "skip_if_none")]
101    pub comment: Option<String>,
102}
103
104#[derive(Debug, Clone, Serialize, Deserialize, Default)]
105#[serde(rename_all = "PascalCase")]
106pub struct KeyGroupItems {
107    #[serde(default, rename = "PublicKey")]
108    pub public_key: Vec<String>,
109}
110
111#[derive(Debug, Clone, Serialize, Deserialize)]
112pub struct StoredKeyGroup {
113    pub id: String,
114    pub etag: String,
115    pub last_modified_time: DateTime<Utc>,
116    pub config: KeyGroupConfig,
117}
118
119// ─── Key Value Store ──────────────────────────────────────────────────
120
121#[derive(Debug, Clone, Serialize, Deserialize, Default)]
122#[serde(rename_all = "PascalCase")]
123pub struct ImportSource {
124    #[serde(default)]
125    pub source_type: String,
126    #[serde(default)]
127    pub source_arn: String,
128}
129
130#[derive(Debug, Clone, Serialize, Deserialize)]
131pub struct StoredKeyValueStore {
132    pub name: String,
133    pub id: String,
134    pub etag: String,
135    pub arn: String,
136    pub status: String,
137    pub created_time: DateTime<Utc>,
138    pub last_modified_time: DateTime<Utc>,
139    pub comment: Option<String>,
140    pub import_source: Option<ImportSource>,
141}
142
143// ─── Origin Access Identity (legacy) ──────────────────────────────────
144
145#[derive(Debug, Clone, Serialize, Deserialize, Default)]
146#[serde(rename_all = "PascalCase")]
147pub struct CloudFrontOriginAccessIdentityConfig {
148    pub caller_reference: String,
149    pub comment: String,
150}
151
152#[derive(Debug, Clone, Serialize, Deserialize)]
153pub struct StoredOriginAccessIdentity {
154    pub id: String,
155    pub etag: String,
156    pub s3_canonical_user_id: String,
157    pub config: CloudFrontOriginAccessIdentityConfig,
158}
159
160// ─── Monitoring Subscription ──────────────────────────────────────────
161
162#[derive(Debug, Clone, Serialize, Deserialize, Default)]
163#[serde(rename_all = "PascalCase")]
164pub struct MonitoringSubscriptionBody {
165    pub realtime_metrics_subscription_config: RealtimeMetricsSubscriptionConfig,
166}
167
168#[derive(Debug, Clone, Serialize, Deserialize, Default)]
169#[serde(rename_all = "PascalCase")]
170pub struct RealtimeMetricsSubscriptionConfig {
171    pub realtime_metrics_subscription_status: String,
172}
173
174#[derive(Debug, Clone, Serialize, Deserialize)]
175pub struct StoredMonitoringSubscription {
176    pub distribution_id: String,
177    pub config: RealtimeMetricsSubscriptionConfig,
178}