Skip to content

Commit a5d12d2

Browse files
authored
Merge branch 'main' into struct-casing
2 parents e4d8e0d + 37b004e commit a5d12d2

25 files changed

+431
-47
lines changed

build.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ if (!$SkipBuild) {
354354

355355
if ($IsWindows) {
356356
Copy-Item "$path/$binary.exe" $target -ErrorAction Ignore -Verbose
357+
Copy-Item "$path/$binary.pdb" $target -ErrorAction Ignore -Verbose
357358
}
358359
else {
359360
Copy-Item "$path/$binary" $target -ErrorAction Ignore -Verbose

dsc/src/args.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ pub enum ResourceSubCommand {
213213
Export {
214214
#[clap(short, long, help = t!("args.resource").to_string())]
215215
resource: String,
216+
#[clap(short, long, help = t!("args.input").to_string(), conflicts_with = "file")]
217+
input: Option<String>,
218+
#[clap(short = 'f', long, help = t!("args.file").to_string(), conflicts_with = "input")]
219+
file: Option<String>,
216220
#[clap(short = 'o', long, help = t!("args.outputFormat").to_string())]
217221
output_format: Option<OutputFormat>,
218222
},

dsc/src/resource_command.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ pub fn schema(dsc: &DscManager, resource_type: &str, format: Option<&OutputForma
259259
}
260260
}
261261

262-
pub fn export(dsc: &mut DscManager, resource_type: &str, format: Option<&OutputFormat>) {
263-
let mut input = String::new();
262+
pub fn export(dsc: &mut DscManager, resource_type: &str, mut input: String, format: Option<&OutputFormat>) {
264263
let Some(dsc_resource) = get_resource(dsc, resource_type) else {
265264
error!("{}", DscError::ResourceNotFound(resource_type.to_string()).to_string());
266265
exit(EXIT_DSC_RESOURCE_NOT_FOUND);

dsc/src/subcommand.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,10 @@ pub fn resource(subcommand: &ResourceSubCommand, progress_format: ProgressFormat
545545
dsc.find_resources(&[resource.to_string()], progress_format);
546546
resource_command::schema(&dsc, resource, output_format.as_ref());
547547
},
548-
ResourceSubCommand::Export { resource, output_format } => {
548+
ResourceSubCommand::Export { resource, input, file, output_format } => {
549549
dsc.find_resources(&[resource.to_string()], progress_format);
550-
resource_command::export(&mut dsc, resource, output_format.as_ref());
550+
let parsed_input = get_input(input.as_ref(), file.as_ref());
551+
resource_command::export(&mut dsc, resource, parsed_input, output_format.as_ref());
551552
},
552553
ResourceSubCommand::Get { resource, input, file: path, all, output_format } => {
553554
dsc.find_resources(&[resource.to_string()], progress_format);

dsc/tests/dsc_args.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ actualState:
9797
$resource = $obj | y2j | ConvertFrom-Json
9898
$resource | Should -Not -BeNullOrEmpty
9999
$resource.Type | Should -BeLike '*/*'
100-
$resource.Kind | Should -BeIn ('resource', 'group', 'importer', 'adapter')
100+
$resource.Kind | Should -BeIn ('resource', 'group', 'exporter', 'importer', 'adapter')
101101
}
102102
}
103103

dsc/tests/dsc_config_test.tests.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,34 @@ Describe 'dsc config test tests' {
3232
$out.results[0].result.differingProperties | Should -Contain 'resources'
3333
}
3434
}
35+
36+
It '_inDesiredState returned is used when: inDesiredState = <inDesiredState> and same = <same>' -TestCases @(
37+
@{ inDesiredState = $true; valueOne = 1; valueTwo = 2; same = $true }
38+
@{ inDesiredState = $true; valueOne = 3; valueTwo = 4; same = $false }
39+
@{ inDesiredState = $false; valueOne = 1; valueTwo = 2; same = $true }
40+
@{ inDesiredState = $false; valueOne = 3; valueTwo = 4; same = $false }
41+
) {
42+
param($inDesiredState, $valueOne, $valueTwo)
43+
44+
$configYaml = @"
45+
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
46+
resources:
47+
- name: Test
48+
type: Test/InDesiredState
49+
properties:
50+
_inDesiredState: $inDesiredState
51+
valueOne: $valueOne
52+
valueTwo: $valueTwo
53+
"@
54+
55+
$out = dsc config test -i $configYaml | ConvertFrom-Json
56+
$LASTEXITCODE | Should -Be 0
57+
$out.results[0].result.inDesiredState | Should -Be $inDesiredState
58+
if ($same) {
59+
$out.results[0].result.differingProperties | Should -BeNullOrEmpty
60+
}
61+
else {
62+
$out.results[0].result.differingProperties | Should -Be @('valueOne', 'valueTwo')
63+
}
64+
}
3565
}

dsc/tests/dsc_export.tests.ps1

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ Describe 'resource export tests' {
8888
$config_with_process_list.resources.count | Should -BeGreaterThan 1
8989
}
9090

91+
It 'Export can be called on resource with input' {
92+
$out = '{"count":3}' | dsc resource export -r Test/Export -f - | ConvertFrom-Json
93+
$LASTEXITCODE | Should -Be 0
94+
$out.resources.count | Should -Be 3
95+
$out.resources[0].type | Should -BeExactly 'Test/Export'
96+
$out.resources[0].properties.count | Should -Be 0
97+
$out.resources[1].type | Should -BeExactly 'Test/Export'
98+
$out.resources[1].properties.count | Should -Be 1
99+
$out.resources[2].type | Should -BeExactly 'Test/Export'
100+
$out.resources[2].properties.count | Should -Be 2
101+
}
102+
91103
It 'Export can be called on a configuration with the use of --output-format as a subcommand' {
92104

93105
$yaml = @'
@@ -105,4 +117,48 @@ Describe 'resource export tests' {
105117
$config_with_process_list.'resources' | Should -Not -BeNullOrEmpty
106118
$config_with_process_list.resources.count | Should -BeGreaterThan 1
107119
}
120+
121+
It 'Export for config preserves metadata' {
122+
$yaml = @'
123+
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
124+
metadata:
125+
winget:
126+
processor: dscv3
127+
hello: world
128+
resources:
129+
- name: OS
130+
type: Microsoft/OSInfo
131+
'@
132+
$out = $yaml | dsc config export -f - | ConvertFrom-Json
133+
$LASTEXITCODE | Should -Be 0
134+
$out.metadata.winget.processor | Should -BeExactly 'dscv3'
135+
$out.metadata.hello | Should -BeExactly 'world'
136+
$out.metadata.'Microsoft.DSC'.operation | Should -BeExactly 'export'
137+
}
138+
139+
It 'Works with Exporter resource' {
140+
$yaml = @'
141+
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
142+
resources:
143+
- name: export this
144+
type: Test/Exporter
145+
properties:
146+
typeNames:
147+
- Test/Foo
148+
- Test/Bar
149+
'@
150+
$out = dsc config export -i $yaml | ConvertFrom-Json
151+
$LASTEXITCODE | Should -Be 0
152+
$out.resources | Should -HaveCount 2
153+
$out.resources[0].type | Should -BeExactly 'Test/Foo'
154+
$out.resources[0].name | Should -BeExactly 'test'
155+
$out.resources[0].properties.psobject.properties | Should -HaveCount 2
156+
$out.resources[0].properties.foo | Should -BeExactly 'bar'
157+
$out.resources[0].properties.hello | Should -BeExactly 'world'
158+
$out.resources[1].type | Should -BeExactly 'Test/Bar'
159+
$out.resources[1].name | Should -BeExactly 'test'
160+
$out.resources[1].properties.psobject.properties | Should -HaveCount 2
161+
$out.resources[1].properties.foo | Should -BeExactly 'bar'
162+
$out.resources[1].properties.hello | Should -BeExactly 'world'
163+
}
108164
}

dsc_lib/locales/en-us.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ setUnexpectedOutput = "Command did not return expected actual output"
9999
setUnexpectedDiff = "Command did not return expected diff output"
100100
invokeTest = "Invoking test for '%{resource}'"
101101
testSyntheticTest = "Resource '%{resource}' does not implement test, performing synthetic test"
102-
invokeTestUsing = "Invoking test on '%{resource}' using '{executable}'"
102+
invokeTestUsing = "Invoking test on '%{resource}' using '%{executable}'"
103103
testVerifyOutput = "Verifying output of test on '%{resource}' using '%{executable}'"
104104
testGroupTestResponse = "Import resource kind, returning group test response"
105105
testNoActualState = "No actual state returned"
@@ -129,6 +129,7 @@ validateJson = "Validating against JSON: %{json}"
129129
resourceInvalidJson = "Resource reported input JSON is not valid"
130130
invalidArrayKey = "Unsupported array value for key '%{key}'. Only string and number is supported."
131131
invalidKey = "Unsupported value for key '%{key}'. Only string, bool, number, and array is supported."
132+
inDesiredStateNotBool = "'_inDesiredState' is not a boolean"
132133

133134
[dscresources.dscresource]
134135
invokeGet = "Invoking get for '%{resource}'"

dsc_lib/src/configure/config_doc.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ pub struct MicrosoftDscMetadata {
7272
pub struct Metadata {
7373
#[serde(rename = "Microsoft.DSC", skip_serializing_if = "Option::is_none")]
7474
pub microsoft: Option<MicrosoftDscMetadata>,
75+
#[serde(flatten)]
76+
pub other: Map<String, Value>,
7577
}
7678

7779
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
@@ -85,7 +87,7 @@ pub struct Configuration {
8587
#[serde(skip_serializing_if = "Option::is_none")]
8688
pub parameters: Option<HashMap<String, Parameter>>,
8789
#[serde(skip_serializing_if = "Option::is_none")]
88-
pub variables: Option<HashMap<String, Value>>,
90+
pub variables: Option<Map<String, Value>>,
8991
pub resources: Vec<Resource>,
9092
#[serde(skip_serializing_if = "Option::is_none")]
9193
pub metadata: Option<Metadata>,
@@ -110,7 +112,7 @@ pub struct Parameter {
110112
#[serde(skip_serializing_if = "Option::is_none")]
111113
pub description: Option<String>,
112114
#[serde(skip_serializing_if = "Option::is_none")]
113-
pub metadata: Option<HashMap<String, Value>>,
115+
pub metadata: Option<Map<String, Value>>,
114116
}
115117

116118
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
@@ -144,7 +146,7 @@ pub struct Resource {
144146
#[serde(skip_serializing_if = "Option::is_none")]
145147
pub properties: Option<Map<String, Value>>,
146148
#[serde(skip_serializing_if = "Option::is_none")]
147-
pub metadata: Option<HashMap<String, Value>>,
149+
pub metadata: Option<Map<String, Value>>,
148150
}
149151

150152
impl Default for Configuration {

dsc_lib/src/configure/context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
use chrono::{DateTime, Local};
55
use crate::configure::config_doc::ExecutionKind;
66
use security_context_lib::{get_security_context, SecurityContext};
7-
use serde_json::Value;
7+
use serde_json::{Map, Value};
88
use std::{collections::HashMap, path::PathBuf};
99

1010
use super::config_doc::{DataType, SecurityContextKind};
1111

1212
pub struct Context {
1313
pub execution_type: ExecutionKind,
14-
pub references: HashMap<String, Value>,
14+
pub references: Map<String, Value>,
1515
pub system_root: PathBuf,
1616
pub parameters: HashMap<String, (Value, DataType)>,
1717
pub security_context: SecurityContextKind,
18-
pub variables: HashMap<String, Value>,
18+
pub variables: Map<String, Value>,
1919
pub start_datetime: DateTime<Local>,
2020
}
2121

@@ -24,14 +24,14 @@ impl Context {
2424
pub fn new() -> Self {
2525
Self {
2626
execution_type: ExecutionKind::Actual,
27-
references: HashMap::new(),
27+
references: Map::new(),
2828
system_root: get_default_os_system_root(),
2929
parameters: HashMap::new(),
3030
security_context: match get_security_context() {
3131
SecurityContext::Admin => SecurityContextKind::Elevated,
3232
SecurityContext::User => SecurityContextKind::Restricted,
3333
},
34-
variables: HashMap::new(),
34+
variables: Map::new(),
3535
start_datetime: chrono::Local::now(),
3636
}
3737
}

0 commit comments

Comments
 (0)