fakecloud-redshift 0.40.1

Amazon Redshift control-plane implementation for FakeCloud
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
//! In-memory, per-account state for Amazon Redshift.

use std::collections::BTreeMap;
use std::sync::Arc;

use chrono::{DateTime, Utc};
use parking_lot::RwLock;
use serde::{Deserialize, Serialize};

pub type SharedRedshiftState = Arc<RwLock<RedshiftAccounts>>;

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct RedshiftAccounts {
    pub accounts: BTreeMap<String, RedshiftState>,
}

impl RedshiftAccounts {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn account(&mut self, account_id: &str) -> &mut RedshiftState {
        self.accounts
            .entry(account_id.to_string())
            .or_insert_with(|| RedshiftState::new_for_account(account_id))
    }
}

/// On-disk snapshot envelope for Redshift state. Versioned so format changes
/// fail loudly on upgrade rather than silently mis-parsing.
#[derive(Clone, Serialize, Deserialize)]
pub struct RedshiftSnapshot {
    pub schema_version: u32,
    #[serde(default)]
    pub accounts: Option<RedshiftAccounts>,
}

pub const REDSHIFT_SNAPSHOT_SCHEMA_VERSION: u32 = 1;

/// All Redshift control-plane resources for a single AWS account.
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct RedshiftState {
    #[serde(default)]
    pub account_id: String,
    #[serde(default)]
    pub clusters: BTreeMap<String, Cluster>,
    #[serde(default)]
    pub parameter_groups: BTreeMap<String, ClusterParameterGroup>,
    #[serde(default)]
    pub security_groups: BTreeMap<String, ClusterSecurityGroup>,
    #[serde(default)]
    pub subnet_groups: BTreeMap<String, ClusterSubnetGroup>,
    #[serde(default)]
    pub snapshots: BTreeMap<String, Snapshot>,
    #[serde(default)]
    pub event_subscriptions: BTreeMap<String, EventSubscription>,
    #[serde(default)]
    pub hsm_client_certificates: BTreeMap<String, HsmClientCertificate>,
    #[serde(default)]
    pub hsm_configurations: BTreeMap<String, HsmConfiguration>,
    #[serde(default)]
    pub snapshot_copy_grants: BTreeMap<String, SnapshotCopyGrant>,
    #[serde(default)]
    pub snapshot_schedules: BTreeMap<String, SnapshotSchedule>,
    #[serde(default)]
    pub scheduled_actions: BTreeMap<String, ScheduledAction>,
    #[serde(default)]
    pub usage_limits: BTreeMap<String, UsageLimit>,
    #[serde(default)]
    pub endpoint_access: BTreeMap<String, EndpointAccess>,
    #[serde(default)]
    pub endpoint_authorizations: BTreeMap<String, EndpointAuthorization>,
    #[serde(default)]
    pub authentication_profiles: BTreeMap<String, AuthenticationProfile>,
    #[serde(default)]
    pub datashares: BTreeMap<String, DataShare>,
    #[serde(default)]
    pub partners: BTreeMap<String, Partner>,
    #[serde(default)]
    pub reserved_nodes: BTreeMap<String, ReservedNode>,
    #[serde(default)]
    pub integrations: BTreeMap<String, Integration>,
    #[serde(default)]
    pub idc_applications: BTreeMap<String, RedshiftIdcApplication>,
    #[serde(default)]
    pub custom_domains: BTreeMap<String, CustomDomainAssociation>,
    #[serde(default)]
    pub table_restore_status: BTreeMap<String, TableRestoreStatus>,
    /// Cluster-logging status keyed by cluster identifier.
    #[serde(default)]
    pub logging: BTreeMap<String, LoggingStatus>,
    /// IAM resource policies keyed by resource ARN.
    #[serde(default)]
    pub resource_policies: BTreeMap<String, String>,
    /// Cross-region snapshot copy config keyed by cluster identifier.
    #[serde(default)]
    pub registered_namespaces: BTreeMap<String, String>,
}

impl RedshiftState {
    pub fn new_for_account(account_id: &str) -> Self {
        Self {
            account_id: account_id.to_string(),
            ..Default::default()
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Tag {
    pub key: String,
    pub value: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Cluster {
    pub cluster_identifier: String,
    pub node_type: String,
    pub cluster_status: String,
    pub cluster_availability_status: String,
    pub master_username: String,
    pub db_name: String,
    pub endpoint_address: String,
    pub endpoint_port: i32,
    pub cluster_create_time: DateTime<Utc>,
    pub automated_snapshot_retention_period: i32,
    pub manual_snapshot_retention_period: i32,
    pub cluster_security_groups: Vec<String>,
    pub vpc_security_group_ids: Vec<String>,
    pub cluster_parameter_group_name: String,
    pub cluster_subnet_group_name: Option<String>,
    pub vpc_id: Option<String>,
    pub availability_zone: String,
    pub preferred_maintenance_window: String,
    pub cluster_version: String,
    pub allow_version_upgrade: bool,
    pub number_of_nodes: i32,
    pub publicly_accessible: bool,
    pub encrypted: bool,
    pub multi_az: bool,
    pub cluster_type: String,
    pub kms_key_id: Option<String>,
    pub enhanced_vpc_routing: bool,
    pub maintenance_track_name: String,
    pub elastic_ip: Option<String>,
    pub availability_zone_relocation_status: String,
    pub aqua_configuration_status: String,
    pub default_iam_role_arn: Option<String>,
    pub iam_roles: Vec<String>,
    pub snapshot_schedule_identifier: Option<String>,
    pub total_storage_capacity_in_mega_bytes: i64,
    pub next_maintenance_window_start_time: Option<DateTime<Utc>>,
    pub snapshot_copy: Option<SnapshotCopyStatus>,
    pub tags: Vec<Tag>,
}

/// Cross-region snapshot-copy configuration set via `EnableSnapshotCopy`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SnapshotCopyStatus {
    pub destination_region: String,
    pub retention_period: i64,
    pub manual_snapshot_retention_period: i32,
    pub snapshot_copy_grant_name: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Parameter {
    pub parameter_name: String,
    pub parameter_value: String,
    pub description: String,
    pub source: String,
    pub data_type: String,
    pub allowed_values: String,
    pub apply_type: String,
    pub is_modifiable: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClusterParameterGroup {
    pub parameter_group_name: String,
    pub parameter_group_family: String,
    pub description: String,
    pub parameters: Vec<Parameter>,
    pub tags: Vec<Tag>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Ec2SecurityGroup {
    pub status: String,
    pub ec2_security_group_name: String,
    pub ec2_security_group_owner_id: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IpRange {
    pub status: String,
    pub cidrip: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClusterSecurityGroup {
    pub cluster_security_group_name: String,
    pub description: String,
    pub ec2_security_groups: Vec<Ec2SecurityGroup>,
    pub ip_ranges: Vec<IpRange>,
    pub tags: Vec<Tag>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Subnet {
    pub subnet_identifier: String,
    pub subnet_availability_zone: String,
    pub subnet_status: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClusterSubnetGroup {
    pub cluster_subnet_group_name: String,
    pub description: String,
    pub vpc_id: String,
    pub subnet_group_status: String,
    pub subnets: Vec<Subnet>,
    pub tags: Vec<Tag>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Snapshot {
    pub snapshot_identifier: String,
    pub snapshot_arn: String,
    pub cluster_identifier: String,
    pub snapshot_create_time: DateTime<Utc>,
    pub status: String,
    pub port: i32,
    pub availability_zone: String,
    pub cluster_create_time: DateTime<Utc>,
    pub master_username: String,
    pub cluster_version: String,
    pub snapshot_type: String,
    pub node_type: String,
    pub number_of_nodes: i32,
    pub db_name: String,
    pub vpc_id: Option<String>,
    pub encrypted: bool,
    pub kms_key_id: Option<String>,
    pub manual_snapshot_retention_period: i32,
    pub total_backup_size_in_mega_bytes: f64,
    pub actual_incremental_backup_size_in_mega_bytes: f64,
    pub accounts_with_restore_access: Vec<String>,
    pub owner_account: String,
    pub source_region: Option<String>,
    pub tags: Vec<Tag>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EventSubscription {
    pub subscription_name: String,
    pub customer_aws_id: String,
    pub sns_topic_arn: String,
    pub status: String,
    pub subscription_creation_time: DateTime<Utc>,
    pub source_type: Option<String>,
    pub source_ids: Vec<String>,
    pub event_categories: Vec<String>,
    pub severity: Option<String>,
    pub enabled: bool,
    pub tags: Vec<Tag>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HsmClientCertificate {
    pub hsm_client_certificate_identifier: String,
    pub hsm_client_certificate_public_key: String,
    pub tags: Vec<Tag>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HsmConfiguration {
    pub hsm_configuration_identifier: String,
    pub description: String,
    pub hsm_ip_address: String,
    pub hsm_partition_name: String,
    pub tags: Vec<Tag>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SnapshotCopyGrant {
    pub snapshot_copy_grant_name: String,
    pub kms_key_id: String,
    pub tags: Vec<Tag>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SnapshotSchedule {
    pub schedule_identifier: String,
    pub schedule_description: String,
    pub schedule_definitions: Vec<String>,
    pub tags: Vec<Tag>,
    pub associated_cluster_count: i32,
    pub associated_clusters: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScheduledAction {
    pub scheduled_action_name: String,
    pub target_action: Option<String>,
    pub schedule: String,
    pub iam_role: String,
    pub scheduled_action_description: String,
    pub state: String,
    pub start_time: Option<DateTime<Utc>>,
    pub end_time: Option<DateTime<Utc>>,
    pub enable: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UsageLimit {
    pub usage_limit_id: String,
    pub cluster_identifier: String,
    pub feature_type: String,
    pub limit_type: String,
    pub amount: i64,
    pub period: String,
    pub breach_action: String,
    pub tags: Vec<Tag>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EndpointAccess {
    pub endpoint_name: String,
    pub cluster_identifier: String,
    pub subnet_group_name: String,
    pub endpoint_status: String,
    pub endpoint_create_time: DateTime<Utc>,
    pub resource_owner: String,
    pub port: i32,
    pub address: String,
    pub vpc_security_group_ids: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EndpointAuthorization {
    pub grantor: String,
    pub grantee: String,
    pub cluster_identifier: String,
    pub authorize_time: DateTime<Utc>,
    pub cluster_status: String,
    pub status: String,
    pub allowed_all_vpcs: bool,
    pub allowed_vpcs: Vec<String>,
    pub endpoint_count: i32,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthenticationProfile {
    pub authentication_profile_name: String,
    pub authentication_profile_content: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DataShare {
    pub data_share_arn: String,
    pub producer_arn: String,
    pub allow_publicly_accessible_consumers: bool,
    pub managed_by: Option<String>,
    pub data_share_type: String,
    pub status: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Partner {
    pub database_name: String,
    pub partner_name: String,
    pub cluster_identifier: String,
    pub account_id: String,
    pub status: String,
    pub status_message: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReservedNode {
    pub reserved_node_id: String,
    pub reserved_node_offering_id: String,
    pub node_type: String,
    pub start_time: DateTime<Utc>,
    pub duration: i32,
    pub fixed_price: f64,
    pub usage_price: f64,
    pub currency_code: String,
    pub node_count: i32,
    pub state: String,
    pub offering_type: String,
    pub reserved_node_offering_type: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Integration {
    pub integration_arn: String,
    pub integration_name: String,
    pub source_arn: String,
    pub target_arn: String,
    pub status: String,
    pub create_time: DateTime<Utc>,
    pub description: Option<String>,
    pub kms_key_id: Option<String>,
    pub tags: Vec<Tag>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RedshiftIdcApplication {
    pub redshift_idc_application_name: String,
    pub redshift_idc_application_arn: String,
    pub identity_namespace: Option<String>,
    pub idc_instance_arn: String,
    pub idc_display_name: String,
    pub iam_role_arn: String,
    pub idc_managed_application_arn: String,
    pub authorized_token_issuer_list: Vec<String>,
    pub service_integrations: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CustomDomainAssociation {
    pub custom_domain_name: String,
    pub custom_domain_certificate_arn: String,
    pub cluster_identifier: String,
    pub custom_domain_certificate_expiry_date: DateTime<Utc>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TableRestoreStatus {
    pub table_restore_request_id: String,
    pub status: String,
    pub cluster_identifier: String,
    pub snapshot_identifier: String,
    pub source_database_name: String,
    pub source_table_name: String,
    pub new_table_name: String,
    pub target_database_name: String,
    pub request_time: DateTime<Utc>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LoggingStatus {
    pub logging_enabled: bool,
    pub bucket_name: Option<String>,
    pub s3_key_prefix: Option<String>,
    pub log_destination_type: Option<String>,
    pub log_exports: Vec<String>,
    pub last_successful_delivery_time: Option<DateTime<Utc>>,
}