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    pub key_value_store_arn: String,
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct StoredFunction {
47    pub name: String,
48    pub etag: String,
49    pub status: String,
50    /// "DEVELOPMENT" or "LIVE"
51    pub stage: String,
52    pub function_arn: String,
53    pub created_time: DateTime<Utc>,
54    pub last_modified_time: DateTime<Utc>,
55    pub config: FunctionConfig,
56    /// Function source code (base64-encoded as the API receives it).
57    /// This is the DEVELOPMENT-stage code: it tracks the latest
58    /// CreateFunction / UpdateFunction body and is the version that
59    /// `TestFunction(Stage=DEVELOPMENT)` runs against.
60    pub function_code: String,
61    /// Snapshot of `function_code` taken when the function is published.
62    /// `TestFunction(Stage=LIVE)` (and the corresponding distribution
63    /// data plane, once wired) reads from here so the published
64    /// behaviour stays stable while DEVELOPMENT keeps mutating.
65    #[serde(default, skip_serializing_if = "skip_if_none")]
66    pub live_function_code: Option<String>,
67}
68
69// ─── Public Key ───────────────────────────────────────────────────────
70
71#[derive(Debug, Clone, Serialize, Deserialize, Default)]
72#[serde(rename_all = "PascalCase")]
73pub struct PublicKeyConfig {
74    pub caller_reference: String,
75    pub name: String,
76    pub encoded_key: String,
77    #[serde(default, skip_serializing_if = "skip_if_none")]
78    pub comment: Option<String>,
79}
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
82pub struct StoredPublicKey {
83    pub id: String,
84    pub etag: String,
85    pub created_time: DateTime<Utc>,
86    pub config: PublicKeyConfig,
87}
88
89// ─── Key Group ────────────────────────────────────────────────────────
90
91#[derive(Debug, Clone, Serialize, Deserialize, Default)]
92#[serde(rename_all = "PascalCase")]
93pub struct KeyGroupConfig {
94    pub name: String,
95    pub items: KeyGroupItems,
96    #[serde(default, skip_serializing_if = "skip_if_none")]
97    pub comment: Option<String>,
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize, Default)]
101#[serde(rename_all = "PascalCase")]
102pub struct KeyGroupItems {
103    #[serde(default, rename = "PublicKey")]
104    pub public_key: Vec<String>,
105}
106
107#[derive(Debug, Clone, Serialize, Deserialize)]
108pub struct StoredKeyGroup {
109    pub id: String,
110    pub etag: String,
111    pub last_modified_time: DateTime<Utc>,
112    pub config: KeyGroupConfig,
113}
114
115// ─── Key Value Store ──────────────────────────────────────────────────
116
117#[derive(Debug, Clone, Serialize, Deserialize, Default)]
118#[serde(rename_all = "PascalCase")]
119pub struct ImportSource {
120    #[serde(default)]
121    pub source_type: String,
122    #[serde(default)]
123    pub source_arn: String,
124}
125
126#[derive(Debug, Clone, Serialize, Deserialize)]
127pub struct StoredKeyValueStore {
128    pub name: String,
129    pub id: String,
130    pub etag: String,
131    pub arn: String,
132    pub status: String,
133    pub created_time: DateTime<Utc>,
134    pub last_modified_time: DateTime<Utc>,
135    pub comment: Option<String>,
136    pub import_source: Option<ImportSource>,
137}
138
139// ─── Origin Access Identity (legacy) ──────────────────────────────────
140
141#[derive(Debug, Clone, Serialize, Deserialize, Default)]
142#[serde(rename_all = "PascalCase")]
143pub struct CloudFrontOriginAccessIdentityConfig {
144    pub caller_reference: String,
145    pub comment: String,
146}
147
148#[derive(Debug, Clone, Serialize, Deserialize)]
149pub struct StoredOriginAccessIdentity {
150    pub id: String,
151    pub etag: String,
152    pub s3_canonical_user_id: String,
153    pub config: CloudFrontOriginAccessIdentityConfig,
154}
155
156// ─── Monitoring Subscription ──────────────────────────────────────────
157
158#[derive(Debug, Clone, Serialize, Deserialize, Default)]
159#[serde(rename_all = "PascalCase")]
160pub struct MonitoringSubscriptionBody {
161    pub realtime_metrics_subscription_config: RealtimeMetricsSubscriptionConfig,
162}
163
164#[derive(Debug, Clone, Serialize, Deserialize, Default)]
165#[serde(rename_all = "PascalCase")]
166pub struct RealtimeMetricsSubscriptionConfig {
167    pub realtime_metrics_subscription_status: String,
168}
169
170#[derive(Debug, Clone, Serialize, Deserialize)]
171pub struct StoredMonitoringSubscription {
172    pub distribution_id: String,
173    pub config: RealtimeMetricsSubscriptionConfig,
174}