Skip to main content

alien_core/deployment/
environment.rs

1//! Environment info per cloud platform, environment variables, and snapshots.
2
3use crate::Platform;
4use serde::{Deserialize, Serialize};
5
6/// AWS-specific environment information
7#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
8#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
9#[serde(rename_all = "camelCase")]
10pub struct AwsEnvironmentInfo {
11    /// AWS account ID
12    pub account_id: String,
13    /// AWS region
14    pub region: String,
15}
16
17/// GCP-specific environment information
18#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
19#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
20#[serde(rename_all = "camelCase")]
21pub struct GcpEnvironmentInfo {
22    /// GCP project number (e.g., "123456789012")
23    pub project_number: String,
24    /// GCP project ID (e.g., "my-project")
25    pub project_id: String,
26    /// GCP region
27    pub region: String,
28}
29
30/// Azure-specific environment information
31#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
32#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
33#[serde(rename_all = "camelCase")]
34pub struct AzureEnvironmentInfo {
35    /// Azure tenant ID
36    pub tenant_id: String,
37    /// Azure subscription ID
38    pub subscription_id: String,
39    /// Azure location/region
40    pub location: String,
41}
42
43/// Local platform environment information
44#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
45#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
46#[serde(rename_all = "camelCase")]
47pub struct LocalEnvironmentInfo {
48    /// Hostname of the machine running the deployment
49    pub hostname: String,
50    /// Operating system (e.g., "linux", "macos", "windows")
51    pub os: String,
52    /// Architecture (e.g., "x86_64", "aarch64")
53    pub arch: String,
54}
55
56/// Test platform environment information (mock)
57#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
58#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
59#[serde(rename_all = "camelCase")]
60pub struct TestEnvironmentInfo {
61    /// Test identifier for this environment
62    pub test_id: String,
63}
64
65/// Platform-specific environment information
66#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
67#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
68#[serde(rename_all = "camelCase", tag = "platform")]
69pub enum EnvironmentInfo {
70    /// AWS environment information
71    Aws(AwsEnvironmentInfo),
72    /// GCP environment information
73    Gcp(GcpEnvironmentInfo),
74    /// Azure environment information
75    Azure(AzureEnvironmentInfo),
76    /// Local platform environment information
77    Local(LocalEnvironmentInfo),
78    /// Test platform environment information (mock)
79    Test(TestEnvironmentInfo),
80}
81
82impl EnvironmentInfo {
83    /// Get the platform for this environment info
84    pub fn platform(&self) -> Platform {
85        match self {
86            EnvironmentInfo::Aws(_) => Platform::Aws,
87            EnvironmentInfo::Gcp(_) => Platform::Gcp,
88            EnvironmentInfo::Azure(_) => Platform::Azure,
89            EnvironmentInfo::Local(_) => Platform::Local,
90            EnvironmentInfo::Test(_) => Platform::Test,
91        }
92    }
93}
94
95/// Type of environment variable
96#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
97#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
98#[serde(rename_all = "lowercase")]
99pub enum EnvironmentVariableType {
100    /// Plain variable (injected directly into function config)
101    Plain,
102    /// Secret variable (stored in vault, loaded at runtime)
103    Secret,
104}
105
106/// Environment variable for deployment
107#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
108#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
109#[serde(rename_all = "camelCase")]
110pub struct EnvironmentVariable {
111    /// Variable name
112    pub name: String,
113    /// Variable value (decrypted - deployment has access to decryption keys)
114    pub value: String,
115    /// Variable type (plain or secret)
116    #[serde(rename = "type")]
117    pub var_type: EnvironmentVariableType,
118    /// Target resource patterns (null = all resources, Some = wildcard patterns)
119    #[serde(skip_serializing_if = "Option::is_none")]
120    pub target_resources: Option<Vec<String>>,
121}
122
123/// Snapshot of environment variables at a point in time
124#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
125#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
126#[serde(rename_all = "camelCase")]
127pub struct EnvironmentVariablesSnapshot {
128    /// Environment variables in the snapshot
129    pub variables: Vec<EnvironmentVariable>,
130    /// Deterministic hash of all variables (for change detection)
131    pub hash: String,
132    /// ISO 8601 timestamp when snapshot was created
133    pub created_at: String,
134}