Skip to content

Commit 280f4c0

Browse files
committed
populate resource metadata with Microsoft.DSC security context
1 parent 71b11ef commit 280f4c0

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

dsc/tests/dsc_export.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ resources:
176176
$out.resources.count | Should -Be 1
177177
$out.resources[0].name | Should -BeExactly 'TestName'
178178
$out.resources[0].kind | Should -BeExactly 'TestKind'
179-
$out.resources[0].metadata.securityContext | Should -BeExactly 'TestSecurityContext'
179+
$out.resources[0].metadata.securityContext | Should -BeExactly 'Administrator'
180180
$out.resources[0].properties.psobject.properties.name | Should -Not -Contain '_kind'
181181
$out.resources[0].properties.psobject.properties.name | Should -Not -Contain '_securityContext'
182182
$out.resources[0].properties.psobject.properties.name | Should -Not -Contain '_name'

dsc_lib/src/configure/config_doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub struct Resource {
138138
#[serde(skip_serializing_if = "Option::is_none")]
139139
pub properties: Option<Map<String, Value>>,
140140
#[serde(skip_serializing_if = "Option::is_none")]
141-
pub metadata: Option<Map<String, Value>>,
141+
pub metadata: Option<Metadata>,
142142
}
143143

144144
impl Default for Configuration {

dsc_lib/src/configure/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,16 @@ pub fn add_resource_export_results_to_configuration(resource: &DscResource, conf
7676
r.kind = kind.as_str().map(std::string::ToString::to_string);
7777
}
7878
if let Some(security_context) = props.remove("_securityContext") {
79-
let mut metadata = Map::new();
80-
metadata.insert("securityContext".to_string(), security_context.clone());
79+
let context: SecurityContextKind = serde_json::from_value(security_context)?;
80+
let metadata = Metadata {
81+
microsoft: Some(
82+
MicrosoftDscMetadata {
83+
security_context: Some(context),
84+
..Default::default()
85+
}
86+
),
87+
other: Map::new(),
88+
};
8189
r.metadata = Some(metadata);
8290
}
8391
r.name = if let Some(name) = props.remove("_name") {

tools/dsctest/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn main() {
9797
count: i,
9898
_kind: Some("TestKind".to_string()),
9999
_name: Some("TestName".to_string()),
100-
_security_context: Some("TestSecurityContext".to_string()),
100+
_security_context: Some("elevated".to_string()),
101101
};
102102
println!("{}", serde_json::to_string(&instance).unwrap());
103103
}

0 commit comments

Comments
 (0)