Skip to content

Commit 029cf3f

Browse files
committed
bubble up special properties from resource during export
1 parent 2f6d6b4 commit 029cf3f

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

dsc/src/subcommand.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ pub fn config_test(configurator: &mut Configurator, format: Option<&OutputFormat
141141
name: test_result.name,
142142
resource_type: test_result.resource_type,
143143
properties,
144-
depends_on: None,
145-
metadata: None,
144+
..Default::default()
146145
};
147146
result_configuration.resources.push(resource);
148147
}

dsc_lib/src/configure/config_doc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ pub struct Resource {
134134
#[schemars(regex(pattern = r"^\[resourceId\(\s*'[a-zA-Z0-9\.]+/[a-zA-Z0-9]+'\s*,\s*'[a-zA-Z0-9 ]+'\s*\)]$"))]
135135
pub depends_on: Option<Vec<String>>,
136136
#[serde(skip_serializing_if = "Option::is_none")]
137+
pub kind: Option<String>,
138+
#[serde(skip_serializing_if = "Option::is_none")]
137139
pub properties: Option<Map<String, Value>>,
138140
#[serde(skip_serializing_if = "Option::is_none")]
139141
pub metadata: Option<Map<String, Value>>,
142+
#[serde(rename = "securityContext", skip_serializing_if = "Option::is_none")]
143+
pub security_context: Option<String>,
140144
}
141145

142146
impl Default for Configuration {
@@ -191,6 +195,8 @@ impl Resource {
191195
resource_type: String::new(),
192196
name: String::new(),
193197
depends_on: None,
198+
kind: None,
199+
security_context: None,
194200
properties: None,
195201
metadata: None,
196202
}

dsc_lib/src/configure/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,21 @@ pub fn add_resource_export_results_to_configuration(resource: &DscResource, conf
6767
} else {
6868
for (i, instance) in export_result.actual_state.iter().enumerate() {
6969
let mut r = config_doc::Resource::new();
70+
let mut props: Map<String, Value> = serde_json::from_value(instance.clone())?;
71+
if let Some(kind) = props.remove("_kind") {
72+
r.kind = kind.as_str().map(|s| s.to_string());
73+
}
74+
if let Some(security_context) = props.remove("_securityContext") {
75+
r.security_context = security_context.as_str().map(|s| s.to_string());
76+
}
77+
r.name = if let Some(name) = props.remove("_name") {
78+
name.as_str()
79+
.map(|s| s.to_string())
80+
.ok_or_else(|| DscError::Parser(t!("configure.mod.valueCouldNotBeTransformedAsString", value = name).to_string()))?
81+
} else {
82+
format!("{}-{}", r.resource_type, i)
83+
};
7084
r.resource_type.clone_from(&resource.type_name);
71-
r.name = format!("{}-{i}", r.resource_type);
72-
let props: Map<String, Value> = serde_json::from_value(instance.clone())?;
7385
r.properties = escape_property_values(&props)?;
7486

7587
conf.resources.push(r);

dsc_lib/src/dscresources/dscresource.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ impl DscResource {
109109
let adapter_resource = Resource {
110110
name: self.type_name.clone(),
111111
resource_type: adapter.to_string(),
112-
depends_on: None,
113-
metadata: None,
114112
properties: Some(resources_map),
113+
..Default::default()
115114
};
116115
configuration.resources.push(adapter_resource);
117116
let config_json = serde_json::to_string(&configuration)?;

0 commit comments

Comments
 (0)