alien_core/resources/
signing_verifier.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 SigningVerifier {
25 #[builder(start_fn)]
27 pub id: String,
28}
29
30impl SigningVerifier {
31 pub const RESOURCE_TYPE: ResourceType = ResourceType::from_static("verifier");
33
34 pub const ID: &'static str = "verifier";
36
37 pub fn id(&self) -> &str {
39 &self.id
40 }
41}
42
43pub fn verifier_launches_machines(stack: &crate::Stack) -> bool {
46 let has = |resource_type: ResourceType| {
47 stack
48 .resources()
49 .any(|(_, entry)| entry.config.resource_type() == resource_type)
50 };
51 has(SigningVerifier::RESOURCE_TYPE) && has(crate::ComputeCluster::RESOURCE_TYPE)
52}
53
54#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
56#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
57#[serde(rename_all = "camelCase")]
58pub struct SigningVerifierOutputs {
59 pub name: String,
61}
62
63impl ResourceDefinition for SigningVerifier {
64 fn get_resource_type(&self) -> ResourceType {
65 Self::RESOURCE_TYPE
66 }
67
68 fn id(&self) -> &str {
69 &self.id
70 }
71
72 fn get_dependencies(&self) -> Vec<ResourceRef> {
73 Vec::new()
74 }
75
76 fn validate_update(&self, new_config: &dyn ResourceDefinition) -> crate::error::Result<()> {
77 match new_config.as_any().downcast_ref::<SigningVerifier>() {
78 Some(new) if new.id == self.id => Ok(()),
79 Some(_) => Err(AlienError::new(
80 crate::error::ErrorData::InvalidResourceUpdate {
81 resource_id: self.id.clone(),
82 reason: "the 'id' field is immutable".to_string(),
83 },
84 )),
85 None => Err(AlienError::new(
86 crate::error::ErrorData::UnexpectedResourceType {
87 resource_id: self.id.clone(),
88 expected: Self::RESOURCE_TYPE,
89 actual: new_config.get_resource_type(),
90 },
91 )),
92 }
93 }
94
95 fn as_any(&self) -> &dyn Any {
96 self
97 }
98
99 fn as_any_mut(&mut self) -> &mut dyn Any {
100 self
101 }
102
103 fn box_clone(&self) -> Box<dyn ResourceDefinition> {
104 Box::new(self.clone())
105 }
106
107 fn resource_eq(&self, other: &dyn ResourceDefinition) -> bool {
108 other.as_any().downcast_ref::<SigningVerifier>() == Some(self)
109 }
110
111 fn to_json_value(&self) -> serde_json::Result<serde_json::Value> {
112 serde_json::to_value(self)
113 }
114}
115
116impl ResourceOutputsDefinition for SigningVerifierOutputs {
117 fn get_resource_type(&self) -> ResourceType {
118 SigningVerifier::RESOURCE_TYPE.clone()
119 }
120
121 fn as_any(&self) -> &dyn Any {
122 self
123 }
124
125 fn box_clone(&self) -> Box<dyn ResourceOutputsDefinition> {
126 Box::new(self.clone())
127 }
128
129 fn outputs_eq(&self, other: &dyn ResourceOutputsDefinition) -> bool {
130 other.as_any().downcast_ref::<SigningVerifierOutputs>() == Some(self)
131 }
132
133 fn to_json_value(&self) -> serde_json::Result<serde_json::Value> {
134 serde_json::to_value(self)
135 }
136}