alien_core/resources/
remote_stack_management.rs1use crate::resource::{ResourceDefinition, ResourceOutputsDefinition, ResourceRef, ResourceType};
2use alien_error::AlienError;
3use bon::Builder;
4use serde::{Deserialize, Serialize};
5use std::any::Any;
6use std::fmt::Debug;
7
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Builder)]
21#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
22#[serde(rename_all = "camelCase", deny_unknown_fields)]
23#[builder(start_fn = new)]
24pub struct RemoteStackManagement {
25 #[builder(start_fn)]
28 pub id: String,
29}
30
31impl RemoteStackManagement {
32 pub const RESOURCE_TYPE: ResourceType = ResourceType::from_static("remote-stack-management");
34
35 pub fn id(&self) -> &str {
37 &self.id
38 }
39}
40
41#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
44#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
45#[serde(rename_all = "camelCase", deny_unknown_fields)]
46pub struct RemoteStackManagementOutputs {
47 pub management_resource_id: String,
52
53 pub access_configuration: String,
58}
59
60impl ResourceDefinition for RemoteStackManagement {
62 fn get_resource_type(&self) -> ResourceType {
63 Self::RESOURCE_TYPE
64 }
65
66 fn id(&self) -> &str {
67 &self.id
68 }
69
70 fn get_dependencies(&self) -> Vec<ResourceRef> {
71 Vec::new()
74 }
75
76 fn validate_update(&self, new_config: &dyn ResourceDefinition) -> crate::error::Result<()> {
77 if let Some(new_remote_mgmt) = new_config.as_any().downcast_ref::<RemoteStackManagement>() {
79 if self.id != new_remote_mgmt.id {
81 return Err(AlienError::new(
82 crate::error::ErrorData::InvalidResourceUpdate {
83 resource_id: self.id.clone(),
84 reason: "the 'id' field is immutable".to_string(),
85 },
86 ));
87 }
88
89 Ok(())
91 } else {
92 Err(AlienError::new(
93 crate::error::ErrorData::UnexpectedResourceType {
94 resource_id: self.id.clone(),
95 expected: Self::RESOURCE_TYPE,
96 actual: new_config.get_resource_type(),
97 },
98 ))
99 }
100 }
101
102 fn as_any(&self) -> &dyn Any {
103 self
104 }
105
106 fn as_any_mut(&mut self) -> &mut dyn Any {
107 self
108 }
109
110 fn box_clone(&self) -> Box<dyn ResourceDefinition> {
111 Box::new(self.clone())
112 }
113
114 fn resource_eq(&self, other: &dyn ResourceDefinition) -> bool {
115 other
116 .as_any()
117 .downcast_ref::<RemoteStackManagement>()
118 .map(|other_remote_mgmt| self == other_remote_mgmt)
119 .unwrap_or(false)
120 }
121
122 fn to_json_value(&self) -> serde_json::Result<serde_json::Value> {
123 serde_json::to_value(self)
124 }
125}
126
127impl ResourceOutputsDefinition for RemoteStackManagementOutputs {
128 fn get_resource_type(&self) -> ResourceType {
129 RemoteStackManagement::RESOURCE_TYPE.clone()
130 }
131
132 fn as_any(&self) -> &dyn Any {
133 self
134 }
135
136 fn box_clone(&self) -> Box<dyn ResourceOutputsDefinition> {
137 Box::new(self.clone())
138 }
139
140 fn outputs_eq(&self, other: &dyn ResourceOutputsDefinition) -> bool {
141 other
142 .as_any()
143 .downcast_ref::<RemoteStackManagementOutputs>()
144 == Some(self)
145 }
146
147 fn to_json_value(&self) -> serde_json::Result<serde_json::Value> {
148 serde_json::to_value(self)
149 }
150}