Skip to content

Commit bff600e

Browse files
author
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)
committed
add tracing, fix winps resource manifest
1 parent ba80ec7 commit bff600e

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

dsc_lib/src/dscresources/command_resource.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,13 +562,14 @@ pub fn invoke_command(executable: &str, args: Option<Vec<String>>, input: Option
562562
}
563563

564564
let mut child = command.spawn()?;
565-
if input.is_some() {
565+
if let Some(input) = input {
566+
trace!("Writing stdin to command: {input}");
566567
// pipe to child stdin in a scope so that it is dropped before we wait
567568
// otherwise the pipe isn't closed and the child process waits forever
568569
let Some(mut child_stdin) = child.stdin.take() else {
569570
return Err(DscError::CommandOperation("Failed to open stdin".to_string(), executable.to_string()));
570571
};
571-
child_stdin.write_all(input.unwrap_or_default().as_bytes())?;
572+
child_stdin.write_all(input.as_bytes())?;
572573
child_stdin.flush()?;
573574
}
574575

@@ -633,12 +634,15 @@ fn get_command_input(input_kind: &Option<InputKind>, input: &str) -> Result<Comm
633634
let mut stdin: Option<String> = None;
634635
match input_kind {
635636
Some(InputKind::Env) => {
637+
debug!("Parsing input as environment variables");
636638
env = Some(json_to_hashmap(input)?);
637639
},
638640
Some(InputKind::Stdin) => {
641+
debug!("Parsing input as stdin");
639642
stdin = Some(input.to_string());
640643
},
641644
None => {
645+
debug!("No input kind specified");
642646
// leave input as none
643647
},
644648
}

powershell-adapter/Tests/powershellgroup.config.tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Describe 'PowerShell adapter resource tests' {
55

66
BeforeAll {
77
if ($isWindows) {
8-
winrm quickconfig -quiet
8+
winrm quickconfig -quiet -force
99
}
1010
$OldPSModulePath = $env:PSModulePath
1111
$env:PSModulePath += [System.IO.Path]::PathSeparator + $PSScriptRoot
@@ -28,7 +28,7 @@ Describe 'PowerShell adapter resource tests' {
2828

2929
It 'Get works on config with File resource for WinPS' -Skip:(!$IsWindows){
3030

31-
$testFile = 'c:\test.txt'
31+
$testFile = "$testdrive\test.txt"
3232
'test' | Set-Content -Path $testFile -Force
3333
$r = (Get-Content -Raw $winpsConfigPath).Replace('c:\test.txt',"$testFile") | dsc config get
3434
$LASTEXITCODE | Should -Be 0

powershell-adapter/Tests/powershellgroup.resource.tests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Describe 'PowerShell adapter resource tests' {
55

66
BeforeAll {
77
if ($isWindows) {
8-
winrm quickconfig -quiet
8+
winrm quickconfig -quiet -force
99
}
1010
$OldPSModulePath = $env:PSModulePath
1111
$env:PSModulePath += [System.IO.Path]::PathSeparator + $PSScriptRoot
@@ -33,7 +33,7 @@ Describe 'PowerShell adapter resource tests' {
3333

3434
It 'Get works on Binary "File" resource' -Skip:(!$IsWindows){
3535

36-
$testFile = 'c:\test.txt'
36+
$testFile = "$testdrive\test.txt"
3737
'test' | Set-Content -Path $testFile -Force
3838
$r = '{"DestinationPath":"' + $testFile.replace('\','\\') + '"}' | dsc resource get -r 'PSDesiredStateConfiguration/File'
3939
$LASTEXITCODE | Should -Be 0
@@ -43,7 +43,7 @@ Describe 'PowerShell adapter resource tests' {
4343

4444
It 'Get works on traditional "Script" resource' -Skip:(!$IsWindows){
4545

46-
$testFile = 'c:\test.txt'
46+
$testFile = "$testdrive\test.txt"
4747
'test' | Set-Content -Path $testFile -Force
4848
$r = '{"GetScript": "@{result = $(Get-Content ' + $testFile.replace('\','\\') + ')}", "SetScript": "throw", "TestScript": "throw"}' | dsc resource get -r 'PSDesiredStateConfiguration/Script'
4949
$LASTEXITCODE | Should -Be 0

powershell-adapter/windowspowershell.dsc.resource.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"-NoProfile",
2929
"-Command",
3030
"$Input | ./powershell.resource.ps1 Get"
31-
]
31+
],
32+
"input": "stdin"
3233
},
3334
"set": {
3435
"executable": "powershell",

0 commit comments

Comments
 (0)