Skip to content

Commit 32076fb

Browse files
committed
fix resource manifests
1 parent 79d30ca commit 32076fb

File tree

10 files changed

+101
-112
lines changed

10 files changed

+101
-112
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

@@ -290,16 +284,16 @@ pub fn invoke_test(resource: &ResourceManifest, cwd: &str, expected: &str) -> Re
290284

291285
let mut env: Option<HashMap<String, String>> = None;
292286
let mut input_expected: Option<&str> = None;
293-
let mut args: Option<Vec<String>> = None;
287+
let args = process_args(&test.args, expected);
294288
match &test.input {
295-
InputKind::Env => {
289+
Some(InputKind::Env) => {
296290
env = Some(json_to_hashmap(expected)?);
297291
},
298-
InputKind::Stdin => {
292+
Some(InputKind::Stdin) => {
299293
input_expected = Some(expected);
300294
},
301-
InputKind::Arg => {
302-
args = process_args(&test.args, expected);
295+
None => {
296+
// leave input as none
303297
},
304298
}
305299

@@ -416,19 +410,20 @@ pub fn invoke_delete(resource: &ResourceManifest, cwd: &str, filter: &str) -> Re
416410
return Err(DscError::NotImplemented("delete".to_string()));
417411
};
418412

413+
verify_json(resource, cwd, filter)?;
414+
419415
let mut env: Option<HashMap<String, String>> = None;
420416
let mut input_filter: Option<&str> = None;
421-
let mut args: Option<Vec<String>> = None;
422-
verify_json(resource, cwd, filter)?;
417+
let args = process_args(&delete.args, filter);
423418
match &delete.input {
424-
InputKind::Env => {
419+
Some(InputKind::Env) => {
425420
env = Some(json_to_hashmap(filter)?);
426421
},
427-
InputKind::Stdin => {
422+
Some(InputKind::Stdin) => {
428423
input_filter = Some(filter);
429424
},
430-
InputKind::Arg => {
431-
args = process_args(&delete.args, filter);
425+
None => {
426+
// leave input as none
432427
},
433428
}
434429

@@ -466,16 +461,16 @@ pub fn invoke_validate(resource: &ResourceManifest, cwd: &str, config: &str) ->
466461

467462
let mut env: Option<HashMap<String, String>> = None;
468463
let mut input_config: Option<&str> = None;
469-
let mut args: Option<Vec<String>> = None;
464+
let args = process_args(&validate.args, config);
470465
match &validate.input {
471-
InputKind::Env => {
466+
Some(InputKind::Env) => {
472467
env = Some(json_to_hashmap(config)?);
473468
},
474-
InputKind::Stdin => {
469+
Some(InputKind::Stdin) => {
475470
input_config = Some(config);
476471
},
477-
InputKind::Arg => {
478-
args = process_args(&validate.args, config);
472+
None => {
473+
// leave input as none
479474
},
480475
}
481476

@@ -551,24 +546,29 @@ pub fn invoke_export(resource: &ResourceManifest, cwd: &str, input: Option<&str>
551546
return Err(DscError::Operation(format!("Export is not supported by resource {}", &resource.resource_type)))
552547
};
553548

549+
554550
let mut env: Option<HashMap<String, String>> = None;
555551
let mut export_input: Option<&str> = None;
556-
let mut args: Option<Vec<String>> = None;
552+
let args: Option<Vec<String>>;
557553
if let Some(input) = input {
558-
match &export.input {
559-
Some(InputKind::Env) => {
560-
env = Some(json_to_hashmap(input)?);
561-
},
562-
Some(InputKind::Stdin) => {
563-
export_input = Some(input);
564-
},
565-
Some(InputKind::Arg) => {
566-
args = process_args(&export.args, input);
567-
},
568-
None => {
569-
// leave input as none
570-
},
554+
if !input.is_empty() {
555+
verify_json(resource, cwd, input)?;
556+
match &export.input {
557+
Some(InputKind::Env) => {
558+
env = Some(json_to_hashmap(input)?);
559+
},
560+
Some(InputKind::Stdin) => {
561+
export_input = Some(input);
562+
},
563+
None => {
564+
// leave input as none
565+
},
566+
}
571567
}
568+
569+
args = process_args(&export.args, input);
570+
} else {
571+
args = process_args(&export.args, "");
572572
}
573573

574574
let (exit_code, stdout, stderr) = invoke_command(&export.executable, args, export_input, Some(cwd), env)?;
@@ -682,7 +682,7 @@ fn process_args(args: &Option<Vec<ArgKind>>, value: &str) -> Option<Vec<String>>
682682
processed_args.push(s.clone());
683683
},
684684
ArgKind::Json { json_input_arg, mandatory } => {
685-
if value.is_empty() && *mandatory == Some(true) {
685+
if value.is_empty() && *mandatory != Some(true) {
686686
continue;
687687
}
688688

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: 16 additions & 19 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",
37-
"delete",
38-
"--input",
39-
"{json}"
40-
],
41-
"input": {
42-
"arg": "{json}"
43-
}
35+
"remove",
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)