Skip to main content

xianyun_core/config/
container.rs

1//! Port of `internal/config/container.go`: a wrapper bundling a Caproni
2//! config with a [`GlobalConfig`] and an injected variable resolver.
3
4use super::global::GlobalConfig;
5use super::latest::CaproniConfig;
6use crate::variables::resolver::Resolver;
7
8pub struct Container {
9    pub global: GlobalConfig,
10    pub caproni: CaproniConfig,
11    pub resolver: Box<dyn Resolver>,
12}
13
14/// Builds a [`Container`] and injects a variable resolver derived from the
15/// config, resolved profile name, and embedded tool versions.
16pub fn new_container(mut global: GlobalConfig, caproni: CaproniConfig) -> Container {
17    use crate::variables::predefined::Options;
18    use crate::variables::resolver::new_resolver;
19
20    let tool_versions = global.tool_versions();
21
22    let opts = Options {
23        profile_name: global.profile_name.clone(),
24        cluster: Some(caproni.cluster.clone()),
25    };
26
27    let static_vars: std::collections::HashMap<String, String> = caproni
28        .variables
29        .as_ref()
30        .map(|vars| {
31            vars.iter()
32                .map(|(name, vc)| (name.clone(), vc.value.clone()))
33                .collect()
34        })
35        .unwrap_or_default();
36
37    let resolver = new_resolver(opts, Some(static_vars), Some(tool_versions));
38
39    Container {
40        global,
41        caproni,
42        resolver,
43    }
44}