Skip to main content

winterbaume_cloudcontrol/
types.rs

1use chrono::{DateTime, Utc};
2
3/// Represents a resource managed by Cloud Control API.
4#[derive(Debug, Clone)]
5pub struct ManagedResource {
6    /// The CloudFormation type name, e.g. `AWS::S3::Bucket`.
7    pub type_name: String,
8    /// The primary identifier for the resource.
9    pub identifier: String,
10    /// JSON string representing the resource model (properties).
11    pub resource_model: String,
12}
13
14/// Represents a resource operation request.
15#[derive(Debug, Clone)]
16pub struct ResourceRequest {
17    /// Unique token identifying this request.
18    pub request_token: String,
19    /// The type name of the resource.
20    pub type_name: String,
21    /// The primary identifier for the resource (may be empty for CREATE before completion).
22    pub identifier: String,
23    /// The operation type.
24    pub operation: OperationType,
25    /// Current status of the operation.
26    pub operation_status: OperationStatus,
27    /// When the request was initiated.
28    pub event_time: DateTime<Utc>,
29    /// JSON string representing the resource model after the operation.
30    pub resource_model: Option<String>,
31    /// Status message for the operation.
32    pub status_message: Option<String>,
33    /// Error code if the operation failed.
34    pub error_code: Option<String>,
35}
36
37/// The type of resource operation.
38#[derive(Debug, Clone, PartialEq, Eq)]
39pub enum OperationType {
40    Create,
41    Delete,
42    Update,
43}
44
45impl OperationType {
46    pub fn as_str(&self) -> &'static str {
47        match self {
48            OperationType::Create => "CREATE",
49            OperationType::Delete => "DELETE",
50            OperationType::Update => "UPDATE",
51        }
52    }
53}
54
55/// Status of a resource operation.
56#[derive(Debug, Clone, PartialEq, Eq)]
57pub enum OperationStatus {
58    Pending,
59    InProgress,
60    Success,
61    Failed,
62    CancelInProgress,
63    CancelComplete,
64}
65
66impl OperationStatus {
67    pub fn as_str(&self) -> &'static str {
68        match self {
69            OperationStatus::Pending => "PENDING",
70            OperationStatus::InProgress => "IN_PROGRESS",
71            OperationStatus::Success => "SUCCESS",
72            OperationStatus::Failed => "FAILED",
73            OperationStatus::CancelInProgress => "CANCEL_IN_PROGRESS",
74            OperationStatus::CancelComplete => "CANCEL_COMPLETE",
75        }
76    }
77}