Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions adapters/powershell/PowerShell_adapter.dsc.resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"resourceTypeArg": "-ResourceType"
},
{
"resourcePathArg": "-ResourcePath"
"resourcePathArg": "-ResourcePath",
"includeQuotes": true
Comment thread
SteveL-MSFT marked this conversation as resolved.
}
],
"input": "stdin"
Expand All @@ -61,7 +62,8 @@
"resourceTypeArg": "-ResourceType"
},
{
"resourcePathArg": "-ResourcePath"
"resourcePathArg": "-ResourcePath",
"includeQuotes": true
Comment thread
SteveL-MSFT marked this conversation as resolved.
}
],
"input": "stdin",
Expand All @@ -83,7 +85,8 @@
"resourceTypeArg": "-ResourceType"
},
{
"resourcePathArg": "-ResourcePath"
"resourcePathArg": "-ResourcePath",
"includeQuotes": true
Comment thread
SteveL-MSFT marked this conversation as resolved.
}
],
"input": "stdin",
Expand All @@ -104,7 +107,8 @@
"resourceTypeArg": "-ResourceType"
},
{
"resourcePathArg": "-ResourcePath"
"resourcePathArg": "-ResourcePath",
"includeQuotes": true
Comment thread
SteveL-MSFT marked this conversation as resolved.
}
],
"input": "stdin",
Expand Down
15 changes: 15 additions & 0 deletions adapters/powershell/Tests/PSAdapted.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,19 @@ Describe 'Tests for PS adapted manifests' {
$out.actualState.Name | Should -BeExactly 'hello' -Because ($out | ConvertTo-Json)
$out.actualState.Value | Should -Be 42
}

It 'Get operation works if adapted resource is in a path with spaces' {
$resourcePath = Join-Path -Path $TestDrive -ChildPath 'Path with spaces'
New-Item -Path $resourcePath -ItemType Directory | Out-Null
Copy-Item -Path (Join-Path -Path $PSScriptRoot -ChildPath 'PSAdaptedTestClassResource*') -Destination $resourcePath
Comment thread
tgauth marked this conversation as resolved.
$oldPath = $env:PATH
try {
$env:PATH = $resourcePath + [System.IO.Path]::PathSeparator + $env:PATH
$out = dsc resource get -r 'PSAdaptedTestClassResource/PSAdaptedTestClass' -i '{"name":"hello"}' | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0
$out.actualState.Name | Should -BeExactly 'hello'
} finally {
$env:PATH = $oldPath
}
}
}
8 changes: 8 additions & 0 deletions dsc/tests/dsc_adapter.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ Describe 'Tests for adapter support' {
$out.schema | Should -Not -BeNullOrEmpty
}

It 'Specifying includeQuotes should include quotes for path' {
$out = dsc -l trace resource set -r Adapted/Two -i '{"two":"2"}' 2>$TestDrive/error.log | ConvertFrom-Json -Depth 10
$errorLog = Get-Content $TestDrive/error.log -Raw
$LASTEXITCODE | Should -Be 0 -Because $errorLog
$errorLog | Should -BeLike '*Invoking command ''dsctest'' with args Some(`["adapter", "--operation", "set", "--input", "{\"two\":\"2\"}", "--resource-type", "Adapted/Two", "--resource-path", "\"*adaptedTest.dsc.adaptedResource.json\""`])*' -Because $errorLog
$out.afterState.two | Should -BeExactly 'value2' -Because $errorLog
}

It 'Adapted resource with condition false should not be returned' {
$out = dsc -l debug resource list 'Adapted/Four' 2>$TestDrive/error.log
$errorLog = Get-Content $TestDrive/error.log -Raw
Expand Down
16 changes: 12 additions & 4 deletions lib/dsc-lib/src/dscresources/command_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,10 +963,14 @@ pub fn process_get_args(args: Option<&Vec<GetArgKind>>, input: &str, command_res
processed_args.push(resource_type_arg.clone());
processed_args.push(command_resource_info.type_name.to_string());
},
GetArgKind::ResourcePath { resource_path_arg } => {
GetArgKind::ResourcePath { resource_path_arg, include_quotes} => {
if let Some(path) = &command_resource_info.path {
processed_args.push(resource_path_arg.clone());
processed_args.push(path.to_string_lossy().to_string());
if *include_quotes {
processed_args.push(format!("\"{}\"", path.to_string_lossy()));
} else {
processed_args.push(path.to_string_lossy().to_string());
}
}
},
}
Expand Down Expand Up @@ -1028,10 +1032,14 @@ fn process_set_delete_args(args: Option<&Vec<SetDeleteArgKind>>, input: &str, co
processed_args.push(json_input_arg.clone());
processed_args.push(input.to_string());
},
SetDeleteArgKind::ResourcePath { resource_path_arg } => {
SetDeleteArgKind::ResourcePath { resource_path_arg, include_quotes} => {
if let Some(path) = &command_resource_info.path {
processed_args.push(resource_path_arg.clone());
processed_args.push(path.to_string_lossy().to_string());
if *include_quotes {
processed_args.push(format!("\"{}\"", path.to_string_lossy()));
} else {
processed_args.push(path.to_string_lossy().to_string());
}
}
},
SetDeleteArgKind::ResourceType { resource_type_arg } => {
Expand Down
16 changes: 11 additions & 5 deletions lib/dsc-lib/src/dscresources/resource_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,17 @@ pub enum GetArgKind {
/// Indicates if argument is mandatory which will pass an empty string if no JSON input is provided. Default is false.
mandatory: Option<bool>,
},
#[serde(rename_all = "camelCase")]
ResourcePath {
/// The argument that accepts the resource path.
#[serde(rename = "resourcePathArg")]
resource_path_arg: String,
Comment thread
SteveL-MSFT marked this conversation as resolved.
/// Indicates if the argument should be wrapped in quotes. Default is false.
#[serde(default)]
include_quotes: bool,
},
#[serde(rename_all = "camelCase")]
ResourceType {
/// The argument that accepts the resource type name.
#[serde(rename = "resourceTypeArg")]
resource_type_arg: String,
},
}
Expand All @@ -138,20 +141,23 @@ pub enum SetDeleteArgKind {
/// Indicates if argument is mandatory which will pass an empty string if no JSON input is provided. Default is false.
mandatory: Option<bool>,
},
#[serde(rename_all = "camelCase")]
ResourcePath {
/// The argument that accepts the resource path.
#[serde(rename = "resourcePathArg")]
resource_path_arg: String,
Comment thread
SteveL-MSFT marked this conversation as resolved.
/// Indicates if the resource path should be passed with quotes. Default is false.
#[serde(default)]
include_quotes: bool,
},
#[serde(rename_all = "camelCase")]
ResourceType {
/// The argument that accepts the resource type name.
#[serde(rename = "resourceTypeArg")]
resource_type_arg: String,
},
/// The argument is passed when the resource is invoked in what-if mode.
#[serde(rename_all = "camelCase")]
WhatIf {
/// The argument to pass when in what-if mode.
#[serde(rename = "whatIfArg")]
what_if_arg: String,
}
}
Expand Down
4 changes: 4 additions & 0 deletions tools/dsctest/dsctest.dsc.manifests.json
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,10 @@
},
{
"resourceTypeArg": "--resource-type"
},
{
"resourcePathArg": "--resource-path",
"includeQuotes": true
}
]
},
Expand Down
Loading