Skip to content

Commit fc3dc22

Browse files
committed
fix resource manifests
1 parent ae50e41 commit fc3dc22

File tree

10 files changed

+100
-111
lines changed

10 files changed

+100
-111
lines changed

dsc/assertion.dsc.resource.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"args": [
6161
"config",
6262
"validate"
63-
]
63+
],
64+
"input": "stdin"
6465
}
6566
}

dsc/group.dsc.resource.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"args": [
4949
"config",
5050
"validate"
51-
]
51+
],
52+
"input": "stdin"
5253
}
5354
}

dsc/parallel.dsc.resource.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"args": [
5252
"config",
5353
"validate"
54-
]
54+
],
55+
"input": "stdin"
5556
}
5657
}

dsc/tests/dsc_args.tests.ps1

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,20 @@ Describe 'config argument tests' {
5454
$env:DSC_RESOURCE_PATH = $oldPath
5555
}
5656

57-
It 'input is <type>' -Skip:(!$IsWindows) -TestCases @(
57+
It 'input is <type>' -TestCases @(
5858
@{ type = 'yaml'; text = @'
59-
keyPath: HKLM\Software\Microsoft\Windows NT\CurrentVersion
60-
valueName: ProductName
59+
output: Hello There
6160
'@ }
6261
@{ type = 'json'; text = @'
6362
{
64-
"keyPath": "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion",
65-
"valueName": "ProductName"
63+
"output": "Hello There"
6664
}
6765
'@ }
6866
) {
6967
param($text)
70-
$output = $text | dsc resource get -r Microsoft.Windows/Registry
68+
$output = $text | dsc resource get -r Test/Echo
7169
$output = $output | ConvertFrom-Json
72-
$output.actualState.keyPath | Should -BeExactly 'HKLM\Software\Microsoft\Windows NT\CurrentVersion'
73-
$output.actualState.valueName | Should -BeExactly 'ProductName'
74-
$output.actualState.valueData.String | Should -Match 'Windows .*'
70+
$output.actualState.output | Should -BeExactly 'Hello There'
7571
}
7672

7773
It '--format <format> is used even when redirected' -TestCases @(

dsc_lib/src/dscresources/command_resource.rs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn invoke_get(resource: &ResourceManifest, cwd: &str, filter: &str) -> Resul
5454

5555
let mut env: Option<HashMap<String, String>> = None;
5656
let mut input_filter: Option<&str> = None;
57-
let mut args: Option<Vec<String>> = None;
57+
let args = process_args(&resource.get.args, filter);
5858
if !filter.is_empty() {
5959
verify_json(resource, cwd, filter)?;
6060

@@ -65,9 +65,6 @@ pub fn invoke_get(resource: &ResourceManifest, cwd: &str, filter: &str) -> Resul
6565
InputKind::Stdin => {
6666
input_filter = Some(filter);
6767
},
68-
InputKind::Arg => {
69-
args = process_args(&resource.get.args, filter);
70-
},
7168
}
7269
}
7370

@@ -146,17 +143,14 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
146143

147144
let mut get_env: Option<HashMap<String, String>> = None;
148145
let mut get_input: Option<&str> = None;
149-
let mut args: Option<Vec<String>> = None;
146+
let args = process_args(&resource.get.args, desired);
150147
match &resource.get.input {
151148
Some(InputKind::Env) => {
152149
get_env = Some(json_to_hashmap(desired)?);
153150
},
154151
Some(InputKind::Stdin) => {
155152
get_input = Some(desired);
156153
},
157-
Some(InputKind::Arg) => {
158-
args = process_args(&resource.get.args, desired);
159-
},
160154
None => {
161155
// leave input as none
162156
},
@@ -183,16 +177,16 @@ pub fn invoke_set(resource: &ResourceManifest, cwd: &str, desired: &str, skip_te
183177

184178
let mut env: Option<HashMap<String, String>> = None;
185179
let mut input_desired: Option<&str> = None;
186-
let mut args: Option<Vec<String>> = None;
180+
let args = process_args(&set.args, desired);
187181
match &set.input {
188-
InputKind::Env => {
182+
Some(InputKind::Env) => {
189183
env = Some(json_to_hashmap(desired)?);
190184
},
191-
InputKind::Stdin => {
185+
Some(InputKind::Stdin) => {
192186
input_desired = Some(desired);
193187
},
194-
InputKind::Arg => {
195-
args = process_args(&set.args, desired);
188+
None => {
189+
// leave input as none
196190
},
197191
}
198192

@@ -289,16 +283,16 @@ pub fn invoke_test(resource: &ResourceManifest, cwd: &str, expected: &str) -> Re
289283

290284
let mut env: Option<HashMap<String, String>> = None;
291285
let mut input_expected: Option<&str> = None;
292-
let mut args: Option<Vec<String>> = None;
286+
let args = process_args(&test.args, expected);
293287
match &test.input {
294-
InputKind::Env => {
288+
Some(InputKind::Env) => {
295289
env = Some(json_to_hashmap(expected)?);
296290
},
297-
InputKind::Stdin => {
291+
Some(InputKind::Stdin) => {
298292
input_expected = Some(expected);
299293
},
300-
InputKind::Arg => {
301-
args = process_args(&test.args, expected);
294+
None => {
295+
// leave input as none
302296
},
303297
}
304298

@@ -391,19 +385,20 @@ pub fn invoke_delete(resource: &ResourceManifest, cwd: &str, filter: &str) -> Re
391385
return Err(DscError::NotImplemented("delete".to_string()));
392386
};
393387

388+
verify_json(resource, cwd, filter)?;
389+
394390
let mut env: Option<HashMap<String, String>> = None;
395391
let mut input_filter: Option<&str> = None;
396-
let mut args: Option<Vec<String>> = None;
397-
verify_json(resource, cwd, filter)?;
392+
let args = process_args(&delete.args, filter);
398393
match &delete.input {
399-
InputKind::Env => {
394+
Some(InputKind::Env) => {
400395
env = Some(json_to_hashmap(filter)?);
401396
},
402-
InputKind::Stdin => {
397+
Some(InputKind::Stdin) => {
403398
input_filter = Some(filter);
404399
},
405-
InputKind::Arg => {
406-
args = process_args(&delete.args, filter);
400+
None => {
401+
// leave input as none
407402
},
408403
}
409404

@@ -441,16 +436,16 @@ pub fn invoke_validate(resource: &ResourceManifest, cwd: &str, config: &str) ->
441436

442437
let mut env: Option<HashMap<String, String>> = None;
443438
let mut input_config: Option<&str> = None;
444-
let mut args: Option<Vec<String>> = None;
439+
let args = process_args(&validate.args, config);
445440
match &validate.input {
446-
InputKind::Env => {
441+
Some(InputKind::Env) => {
447442
env = Some(json_to_hashmap(config)?);
448443
},
449-
InputKind::Stdin => {
444+
Some(InputKind::Stdin) => {
450445
input_config = Some(config);
451446
},
452-
InputKind::Arg => {
453-
args = process_args(&validate.args, config);
447+
None => {
448+
// leave input as none
454449
},
455450
}
456451

@@ -526,24 +521,29 @@ pub fn invoke_export(resource: &ResourceManifest, cwd: &str, input: Option<&str>
526521
return Err(DscError::Operation(format!("Export is not supported by resource {}", &resource.resource_type)))
527522
};
528523

524+
529525
let mut env: Option<HashMap<String, String>> = None;
530526
let mut export_input: Option<&str> = None;
531-
let mut args: Option<Vec<String>> = None;
527+
let args: Option<Vec<String>>;
532528
if let Some(input) = input {
533-
match &export.input {
534-
Some(InputKind::Env) => {
535-
env = Some(json_to_hashmap(input)?);
536-
},
537-
Some(InputKind::Stdin) => {
538-
export_input = Some(input);
539-
},
540-
Some(InputKind::Arg) => {
541-
args = process_args(&export.args, input);
542-
},
543-
None => {
544-
// leave input as none
545-
},
529+
if !input.is_empty() {
530+
verify_json(resource, cwd, input)?;
531+
match &export.input {
532+
Some(InputKind::Env) => {
533+
env = Some(json_to_hashmap(input)?);
534+
},
535+
Some(InputKind::Stdin) => {
536+
export_input = Some(input);
537+
},
538+
None => {
539+
// leave input as none
540+
},
541+
}
546542
}
543+
544+
args = process_args(&export.args, input);
545+
} else {
546+
args = process_args(&export.args, "");
547547
}
548548

549549
let (exit_code, stdout, stderr) = invoke_command(&export.executable, args, export_input, Some(cwd), env)?;
@@ -657,7 +657,7 @@ fn process_args(args: &Option<Vec<ArgKind>>, value: &str) -> Option<Vec<String>>
657657
processed_args.push(s.clone());
658658
},
659659
ArgKind::Json { json_input_arg, mandatory } => {
660-
if value.is_empty() && *mandatory == Some(true) {
660+
if value.is_empty() && *mandatory != Some(true) {
661661
continue;
662662
}
663663

dsc_lib/src/dscresources/resource_manifest.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ pub enum ArgKind {
9696

9797
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
9898
pub enum InputKind {
99-
/// The input replaces arguments with this token in the command.
100-
#[serde(rename = "arg")]
101-
Arg,
10299
/// The input is accepted as environmental variables.
103100
#[serde(rename = "env")]
104101
Env,
@@ -156,7 +153,7 @@ pub struct SetMethod {
156153
/// The arguments to pass to the command to perform a Set.
157154
pub args: Option<Vec<ArgKind>>,
158155
/// How to pass required input for a Set.
159-
pub input: InputKind,
156+
pub input: Option<InputKind>,
160157
/// Whether to run the Test method before the Set method. True means the resource will perform its own test before running the Set method.
161158
#[serde(rename = "implementsPretest", skip_serializing_if = "Option::is_none")]
162159
pub pre_test: Option<bool>,
@@ -175,7 +172,7 @@ pub struct TestMethod {
175172
/// The arguments to pass to the command to perform a Test.
176173
pub args: Option<Vec<ArgKind>>,
177174
/// How to pass required input for a Test.
178-
pub input: InputKind,
175+
pub input: Option<InputKind>,
179176
/// The type of return value expected from the Test method.
180177
#[serde(rename = "return", skip_serializing_if = "Option::is_none")]
181178
pub returns: Option<ReturnKind>,
@@ -188,7 +185,7 @@ pub struct DeleteMethod {
188185
/// The arguments to pass to the command to perform a Delete.
189186
pub args: Option<Vec<ArgKind>>,
190187
/// How to pass required input for a Delete.
191-
pub input: InputKind,
188+
pub input: Option<InputKind>,
192189
}
193190

194191
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
@@ -198,7 +195,7 @@ pub struct ValidateMethod { // TODO: enable validation via schema or command
198195
/// The arguments to pass to the command to perform a Validate.
199196
pub args: Option<Vec<ArgKind>>,
200197
/// How to pass required input for a Validate.
201-
pub input: InputKind,
198+
pub input: Option<InputKind>,
202199
}
203200

204201
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]

powershell-adapter/powershell.dsc.resource.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
"-NoProfile",
7777
"-Command",
7878
"$Input | ./powershell.resource.ps1 Validate"
79-
]
79+
],
80+
"input": "stdin"
8081
},
8182
"exitCodes": {
8283
"0": "Success",

registry/registry.dsc.resource.json

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,33 @@
1111
"args": [
1212
"config",
1313
"get",
14-
"--input",
15-
"{json}"
16-
],
17-
"input": {
18-
"arg": "{json}"
19-
}
14+
{
15+
"jsonInputArg": "--input",
16+
"mandatory": true
17+
}
18+
]
2019
},
2120
"set": {
2221
"executable": "registry",
2322
"args": [
2423
"config",
2524
"set",
26-
"--input",
27-
"{json}"
28-
],
29-
"input": {
30-
"arg": "{json}"
31-
}
25+
{
26+
"jsonInputArg": "--input",
27+
"mandatory": true
28+
}
29+
]
3230
},
3331
"delete": {
3432
"executable": "registry",
3533
"args": [
3634
"config",
3735
"remove",
38-
"--input",
39-
"{json}"
40-
],
41-
"input": {
42-
"arg": "{json}"
43-
}
36+
{
37+
"jsonInputArg": "--input",
38+
"mandatory": true
39+
}
40+
]
4441
},
4542
"exitCodes": {
4643
"0": "Success",

tools/dsctest/dscexist.dsc.resource.json

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@
66
"executable": "dsctest",
77
"args": [
88
"exist",
9-
"--input",
10-
"{json}"
11-
],
12-
"input": {
13-
"arg": "{json}"
14-
}
9+
{
10+
"jsonInputArg": "--input",
11+
"mandatory": true
12+
}
13+
]
1514
},
1615
"set": {
1716
"executable": "dsctest",
1817
"args": [
1918
"exist",
20-
"--input",
21-
"{json}"
19+
{
20+
"jsonInputArg": "--input",
21+
"mandatory": true
22+
}
2223
],
23-
"input": {
24-
"arg": "{json}"
25-
},
2624
"handlesExist": true,
2725
"return": "state"
2826
},

0 commit comments

Comments
 (0)