Skip to main content

alien_core/import/
context.rs

1use crate::{ManagementConfig, Platform, ResourceEntry, Stack, StackSettings};
2use indexmap::IndexMap;
3
4/// Context passed to generator-side import emitters.
5#[derive(Debug, Clone, Copy)]
6pub struct EmitContext<'a> {
7    /// The source stack being rendered.
8    pub stack: &'a Stack,
9    /// The stack resource entry currently being emitted.
10    pub resource: &'a ResourceEntry,
11    /// Stable resource id for the current entry.
12    pub resource_id: &'a str,
13    /// Target platform for this emission pass.
14    pub platform: Platform,
15    /// Whether the artifact runs workloads on Kubernetes rather than on the cloud's own compute.
16    ///
17    /// `platform` names the cloud the cluster runs in, so it reads the same for an EKS package as
18    /// for a plain AWS one. Anything whose answer differs between the two — a resource skipped on
19    /// Kubernetes, and every expression that has to agree with that skip — needs this instead.
20    pub targets_kubernetes: bool,
21    /// User-selected stack settings for the setup artifact.
22    pub stack_settings: &'a StackSettings,
23    /// Stable names precomputed by the outer generator.
24    pub names: &'a IndexMap<String, String>,
25}
26
27impl<'a> EmitContext<'a> {
28    /// Returns the precomputed format-specific name for a resource id.
29    pub fn name_for(&self, resource_id: &str) -> Option<&'a str> {
30        self.names.get(resource_id).map(String::as_str)
31    }
32}
33
34/// Context passed to manager- or agent-side importers.
35#[derive(Debug, Clone, Copy)]
36pub struct ImportContext<'a> {
37    /// Resource id currently being imported.
38    pub resource_id: &'a str,
39    /// Target platform for this imported resource.
40    pub platform: Platform,
41    /// Region or location reported by the setup artifact.
42    pub region: &'a str,
43    /// Stack settings supplied by the setup artifact.
44    pub stack_settings: &'a StackSettings,
45    /// Platform-derived management configuration, when this setup created a
46    /// cross-account/cross-tenant management identity.
47    pub management_config: Option<&'a ManagementConfig>,
48    /// Original resource entry from the active stack.
49    pub resource: &'a ResourceEntry,
50}