Skip to content

Commit 71b11ef

Browse files
committed
address review feedback
1 parent f898d01 commit 71b11ef

File tree

8 files changed

+24
-46
lines changed

8 files changed

+24
-46
lines changed

dsc/tests/dsc_export.tests.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,16 @@ resources:
167167
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
168168
resources:
169169
- name: Test Export
170-
type: Test/ExportBubble
170+
type: Test/Export
171171
properties:
172+
count: 1
172173
'@
173174
$out = dsc config export -i $yaml | ConvertFrom-Json
174175
$LASTEXITCODE | Should -Be 0
175176
$out.resources.count | Should -Be 1
176177
$out.resources[0].name | Should -BeExactly 'TestName'
177178
$out.resources[0].kind | Should -BeExactly 'TestKind'
178-
$out.resources[0].securityContext | Should -BeExactly 'TestSecurityContext'
179+
$out.resources[0].metadata.securityContext | Should -BeExactly 'TestSecurityContext'
179180
$out.resources[0].properties.psobject.properties.name | Should -Not -Contain '_kind'
180181
$out.resources[0].properties.psobject.properties.name | Should -Not -Contain '_securityContext'
181182
$out.resources[0].properties.psobject.properties.name | Should -Not -Contain '_name'

dsc_lib/locales/en-us.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ parameterNotArray = "Parameter '%{name}' is not an array"
6666
parameterNotObject = "Parameter '%{name}' is not an object"
6767
invokePropertyExpressions = "Invoke property expressions"
6868
invokeExpression = "Invoke property expression for %{name}: %{value}"
69+
propertyNotString = "Property '%{name}' with value '%{value}' is not a string"
6970

7071
[discovery.commandDiscovery]
7172
couldNotReadSetting = "Could not read 'resourcePath' setting"

dsc_lib/src/configure/config_doc.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ pub struct Resource {
139139
pub properties: Option<Map<String, Value>>,
140140
#[serde(skip_serializing_if = "Option::is_none")]
141141
pub metadata: Option<Map<String, Value>>,
142-
#[serde(rename = "securityContext", skip_serializing_if = "Option::is_none")]
143-
pub security_context: Option<String>,
144142
}
145143

146144
impl Default for Configuration {
@@ -196,7 +194,6 @@ impl Resource {
196194
name: String::new(),
197195
depends_on: None,
198196
kind: None,
199-
security_context: None,
200197
properties: None,
201198
metadata: None,
202199
}

dsc_lib/src/configure/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,27 @@ pub fn add_resource_export_results_to_configuration(resource: &DscResource, conf
6666
}
6767
} else {
6868
for (i, instance) in export_result.actual_state.iter().enumerate() {
69-
let mut r = config_doc::Resource::new();
69+
let mut r: Resource = config_doc::Resource::new();
70+
r.resource_type.clone_from(&resource.type_name);
7071
let mut props: Map<String, Value> = serde_json::from_value(instance.clone())?;
7172
if let Some(kind) = props.remove("_kind") {
73+
if !kind.is_string() {
74+
return Err(DscError::Parser(t!("configure.mod.propertyNotString", name = "_kind", value = kind).to_string()));
75+
}
7276
r.kind = kind.as_str().map(std::string::ToString::to_string);
7377
}
7478
if let Some(security_context) = props.remove("_securityContext") {
75-
r.security_context = security_context.as_str().map(std::string::ToString::to_string);
79+
let mut metadata = Map::new();
80+
metadata.insert("securityContext".to_string(), security_context.clone());
81+
r.metadata = Some(metadata);
7682
}
7783
r.name = if let Some(name) = props.remove("_name") {
7884
name.as_str()
7985
.map(std::string::ToString::to_string)
80-
.ok_or_else(|| DscError::Parser(t!("configure.mod.valueCouldNotBeTransformedAsString", value = name).to_string()))?
86+
.ok_or_else(|| DscError::Parser(t!("configure.mod.propertyNotString", name = "_name", value = name).to_string()))?
8187
} else {
82-
format!("{}-{}", r.resource_type, i)
88+
format!("{}-{i}", r.resource_type)
8389
};
84-
r.resource_type.clone_from(&resource.type_name);
8590
r.properties = escape_property_values(&props)?;
8691

8792
conf.resources.push(r);

tools/dsctest/dscexportbubble.dsc.resource.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

tools/dsctest/src/args.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub enum Schemas {
1010
ExitCode,
1111
InDesiredState,
1212
Export,
13-
ExportBubble,
1413
Exporter,
1514
Sleep,
1615
Trace,
@@ -56,9 +55,6 @@ pub enum SubCommand {
5655
input: String,
5756
},
5857

59-
#[clap(name = "export-bubble", about = "Export properties that DSC will bubble up")]
60-
ExportBubble,
61-
6258
#[clap(name = "exporter", about = "Exports different types of resources")]
6359
Exporter {
6460
#[clap(name = "input", short, long, help = "The input to the exporter command as JSON")]

tools/dsctest/src/export.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,10 @@ use serde::{Deserialize, Serialize};
99
pub struct Export {
1010
/// Number of instances to return
1111
pub count: u64,
12+
#[serde(skip_serializing_if = "Option::is_none")]
13+
pub _kind: Option<String>,
14+
#[serde(skip_serializing_if = "Option::is_none")]
15+
pub _name: Option<String>,
16+
#[serde(rename = "_securityContext", skip_serializing_if = "Option::is_none")]
17+
pub _security_context: Option<String>,
1218
}

tools/dsctest/src/main.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,15 @@ fn main() {
9494
};
9595
for i in 0..export.count {
9696
let instance = Export {
97-
count: i
97+
count: i,
98+
_kind: Some("TestKind".to_string()),
99+
_name: Some("TestName".to_string()),
100+
_security_context: Some("TestSecurityContext".to_string()),
98101
};
99102
println!("{}", serde_json::to_string(&instance).unwrap());
100103
}
101104
String::new()
102105
},
103-
SubCommand::ExportBubble => {
104-
let mut properties = Map::new();
105-
properties.insert("_kind".to_string(), serde_json::Value::String("TestKind".to_string()));
106-
properties.insert("_name".to_string(), serde_json::Value::String("TestName".to_string()));
107-
properties.insert("_securityContext".to_string(), serde_json::Value::String("TestSecurityContext".to_string()));
108-
serde_json::to_string(&properties).unwrap()
109-
},
110106
SubCommand::Exporter { input } => {
111107
let exporter = match serde_json::from_str::<Exporter>(&input) {
112108
Ok(exporter) => exporter,
@@ -144,9 +140,6 @@ fn main() {
144140
Schemas::Export => {
145141
schema_for!(Export)
146142
},
147-
Schemas::ExportBubble => {
148-
schema_for!(Resource)
149-
},
150143
Schemas::Exporter => {
151144
schema_for!(Exporter)
152145
},

0 commit comments

Comments
 (0)