Skip to main content

alien_core/import/
context.rs

1use crate::{ManagementConfig, Platform, ResourceEntry, SetupPins, 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    /// What the CLI build pins for a protected setup: the verifier images and the
26    /// machine-image publisher.
27    pub pins: &'a SetupPins,
28}
29
30impl<'a> EmitContext<'a> {
31    /// Returns the precomputed format-specific name for a resource id.
32    pub fn name_for(&self, resource_id: &str) -> Option<&'a str> {
33        self.names.get(resource_id).map(String::as_str)
34    }
35}
36
37/// Context passed to manager- or agent-side importers.
38#[derive(Debug, Clone, Copy)]
39pub struct ImportContext<'a> {
40    /// Resource id currently being imported.
41    pub resource_id: &'a str,
42    /// Target platform for this imported resource.
43    pub platform: Platform,
44    /// Region or location reported by the setup artifact.
45    pub region: &'a str,
46    /// Stack settings supplied by the setup artifact.
47    pub stack_settings: &'a StackSettings,
48    /// Platform-derived management configuration, when this setup created a
49    /// cross-account/cross-tenant management identity.
50    pub management_config: Option<&'a ManagementConfig>,
51    /// Original resource entry from the active stack.
52    pub resource: &'a ResourceEntry,
53}