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 #[serde(default, skip_serializing_if = "Option::is_none")]
66 pub remote_bindings_access: Option<RemoteBindingsAccessOutputs>,
67}
68
69#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
71#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
72#[serde(rename_all = "camelCase", deny_unknown_fields)]
73pub struct RemoteBindingsAccessOutputs {
74 pub resource_id: String,
77
78 pub access_configuration: String,
80}
81
82impl ResourceDefinition for RemoteStackManagement {
84 fn get_resource_type(&self) -> ResourceType {
85 Self::RESOURCE_TYPE
86 }
87
88 fn id(&self) -> &str {
89 &self.id
90 }
91
92 fn get_dependencies(&self) -> Vec<ResourceRef> {
93 Vec::new()
96 }
97
98 fn validate_update(&self, new_config: &dyn ResourceDefinition) -> crate::error::Result<()> {
99 if let Some(new_remote_mgmt) = new_config.as_any().downcast_ref::<RemoteStackManagement>() {
101 if self.id != new_remote_mgmt.id {
103 return Err(AlienError::new(
104 crate::error::ErrorData::InvalidResourceUpdate {
105 resource_id: self.id.clone(),
106 reason: "the 'id' field is immutable".to_string(),
107 },
108 ));
109 }
110
111 Ok(())
113 } else {
114 Err(AlienError::new(
115 crate::error::ErrorData::UnexpectedResourceType {
116 resource_id: self.id.clone(),
117 expected: Self::RESOURCE_TYPE,
118 actual: new_config.get_resource_type(),
119 },
120 ))
121 }
122 }
123
124 fn as_any(&self) -> &dyn Any {
125 self
126 }
127
128 fn as_any_mut(&mut self) -> &mut dyn Any {
129 self
130 }
131
132 fn box_clone(&self) -> Box<dyn ResourceDefinition> {
133 Box::new(self.clone())
134 }
135
136 fn resource_eq(&self, other: &dyn ResourceDefinition) -> bool {
137 other
138 .as_any()
139 .downcast_ref::<RemoteStackManagement>()
140 .map(|other_remote_mgmt| self == other_remote_mgmt)
141 .unwrap_or(false)
142 }
143
144 fn to_json_value(&self) -> serde_json::Result<serde_json::Value> {
145 serde_json::to_value(self)
146 }
147}
148
149impl ResourceOutputsDefinition for RemoteStackManagementOutputs {
150 fn get_resource_type(&self) -> ResourceType {
151 RemoteStackManagement::RESOURCE_TYPE.clone()
152 }
153
154 fn as_any(&self) -> &dyn Any {
155 self
156 }
157
158 fn box_clone(&self) -> Box<dyn ResourceOutputsDefinition> {
159 Box::new(self.clone())
160 }
161
162 fn outputs_eq(&self, other: &dyn ResourceOutputsDefinition) -> bool {
163 other
164 .as_any()
165 .downcast_ref::<RemoteStackManagementOutputs>()
166 == Some(self)
167 }
168
169 fn to_json_value(&self) -> serde_json::Result<serde_json::Value> {
170 serde_json::to_value(self)
171 }
172}