Skip to content

Commit a42f4a2

Browse files
authored
Merge pull request #1535 from SteveL-MSFT/v3.2.1
Backport `includeQuotes` to 3.2.1 release
2 parents 119832c + a8d806c commit a42f4a2

8 files changed

Lines changed: 60 additions & 15 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adapters/powershell/PowerShell_adapter.dsc.resource.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"resourceTypeArg": "-ResourceType"
4242
},
4343
{
44-
"resourcePathArg": "-ResourcePath"
44+
"resourcePathArg": "-ResourcePath",
45+
"includeQuotes": true
4546
}
4647
],
4748
"input": "stdin"
@@ -61,7 +62,8 @@
6162
"resourceTypeArg": "-ResourceType"
6263
},
6364
{
64-
"resourcePathArg": "-ResourcePath"
65+
"resourcePathArg": "-ResourcePath",
66+
"includeQuotes": true
6567
}
6668
],
6769
"input": "stdin",
@@ -83,7 +85,8 @@
8385
"resourceTypeArg": "-ResourceType"
8486
},
8587
{
86-
"resourcePathArg": "-ResourcePath"
88+
"resourcePathArg": "-ResourcePath",
89+
"includeQuotes": true
8790
}
8891
],
8992
"input": "stdin",
@@ -104,7 +107,8 @@
104107
"resourceTypeArg": "-ResourceType"
105108
},
106109
{
107-
"resourcePathArg": "-ResourcePath"
110+
"resourcePathArg": "-ResourcePath",
111+
"includeQuotes": true
108112
}
109113
],
110114
"input": "stdin",

adapters/powershell/Tests/PSAdapted.tests.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,19 @@ Describe 'Tests for PS adapted manifests' {
1919
$out.actualState.Name | Should -BeExactly 'hello' -Because ($out | ConvertTo-Json)
2020
$out.actualState.Value | Should -Be 42
2121
}
22+
23+
It 'Get operation works if adapted resource is in a path with spaces' {
24+
$resourcePath = Join-Path -Path $TestDrive -ChildPath 'Path with spaces'
25+
New-Item -Path $resourcePath -ItemType Directory | Out-Null
26+
Copy-Item -Path (Join-Path -Path $PSScriptRoot -ChildPath 'PSAdaptedTestClassResource*') -Destination $resourcePath
27+
$oldPath = $env:PATH
28+
try {
29+
$env:PATH = $resourcePath + [System.IO.Path]::PathSeparator + $env:PATH
30+
$out = dsc resource get -r 'PSAdaptedTestClassResource/PSAdaptedTestClass' -i '{"name":"hello"}' | ConvertFrom-Json
31+
$LASTEXITCODE | Should -Be 0
32+
$out.actualState.Name | Should -BeExactly 'hello'
33+
} finally {
34+
$env:PATH = $oldPath
35+
}
36+
}
2237
}

dsc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dsc"
3-
version = "3.2.0"
3+
version = "3.2.1"
44
edition = "2024"
55

66
[dependencies]

dsc/tests/dsc_adapter.tests.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ Describe 'Tests for adapter support' {
179179
$out.schema | Should -Not -BeNullOrEmpty
180180
}
181181

182+
It 'Specifying includeQuotes should include quotes for path' {
183+
$out = dsc -l trace resource set -r Adapted/Two -i '{"two":"2"}' 2>$TestDrive/error.log | ConvertFrom-Json -Depth 10
184+
$errorLog = Get-Content $TestDrive/error.log -Raw
185+
$LASTEXITCODE | Should -Be 0 -Because $errorLog
186+
$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
187+
$out.afterState.two | Should -BeExactly 'value2' -Because $errorLog
188+
}
189+
182190
It 'Adapted resource with condition false should not be returned' {
183191
$out = dsc -l debug resource list 'Adapted/Four' 2>$TestDrive/error.log
184192
$errorLog = Get-Content $TestDrive/error.log -Raw

lib/dsc-lib/src/dscresources/command_resource.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -961,10 +961,14 @@ pub fn process_get_args(args: Option<&Vec<GetArgKind>>, input: &str, command_res
961961
processed_args.push(resource_type_arg.clone());
962962
processed_args.push(command_resource_info.type_name.to_string());
963963
},
964-
GetArgKind::ResourcePath { resource_path_arg } => {
964+
GetArgKind::ResourcePath { resource_path_arg, include_quotes} => {
965965
if let Some(path) = &command_resource_info.path {
966966
processed_args.push(resource_path_arg.clone());
967-
processed_args.push(path.to_string_lossy().to_string());
967+
if *include_quotes {
968+
processed_args.push(format!("\"{}\"", path.to_string_lossy()));
969+
} else {
970+
processed_args.push(path.to_string_lossy().to_string());
971+
}
968972
}
969973
},
970974
}
@@ -1026,10 +1030,14 @@ fn process_set_delete_args(args: Option<&Vec<SetDeleteArgKind>>, input: &str, co
10261030
processed_args.push(json_input_arg.clone());
10271031
processed_args.push(input.to_string());
10281032
},
1029-
SetDeleteArgKind::ResourcePath { resource_path_arg } => {
1033+
SetDeleteArgKind::ResourcePath { resource_path_arg, include_quotes} => {
10301034
if let Some(path) = &command_resource_info.path {
10311035
processed_args.push(resource_path_arg.clone());
1032-
processed_args.push(path.to_string_lossy().to_string());
1036+
if *include_quotes {
1037+
processed_args.push(format!("\"{}\"", path.to_string_lossy()));
1038+
} else {
1039+
processed_args.push(path.to_string_lossy().to_string());
1040+
}
10331041
}
10341042
},
10351043
SetDeleteArgKind::ResourceType { resource_type_arg } => {

lib/dsc-lib/src/dscresources/resource_manifest.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,17 @@ pub enum GetArgKind {
112112
/// Indicates if argument is mandatory which will pass an empty string if no JSON input is provided. Default is false.
113113
mandatory: Option<bool>,
114114
},
115+
#[serde(rename_all = "camelCase")]
115116
ResourcePath {
116117
/// The argument that accepts the resource path.
117-
#[serde(rename = "resourcePathArg")]
118118
resource_path_arg: String,
119+
/// Indicates if the argument should be wrapped in quotes. Default is false.
120+
#[serde(default)]
121+
include_quotes: bool,
119122
},
123+
#[serde(rename_all = "camelCase")]
120124
ResourceType {
121125
/// The argument that accepts the resource type name.
122-
#[serde(rename = "resourceTypeArg")]
123126
resource_type_arg: String,
124127
},
125128
}
@@ -138,20 +141,23 @@ pub enum SetDeleteArgKind {
138141
/// Indicates if argument is mandatory which will pass an empty string if no JSON input is provided. Default is false.
139142
mandatory: Option<bool>,
140143
},
144+
#[serde(rename_all = "camelCase")]
141145
ResourcePath {
142146
/// The argument that accepts the resource path.
143-
#[serde(rename = "resourcePathArg")]
144147
resource_path_arg: String,
148+
/// Indicates if the resource path should be passed with quotes. Default is false.
149+
#[serde(default)]
150+
include_quotes: bool,
145151
},
152+
#[serde(rename_all = "camelCase")]
146153
ResourceType {
147154
/// The argument that accepts the resource type name.
148-
#[serde(rename = "resourceTypeArg")]
149155
resource_type_arg: String,
150156
},
151157
/// The argument is passed when the resource is invoked in what-if mode.
158+
#[serde(rename_all = "camelCase")]
152159
WhatIf {
153160
/// The argument to pass when in what-if mode.
154-
#[serde(rename = "whatIfArg")]
155161
what_if_arg: String,
156162
}
157163
}

tools/dsctest/dsctest.dsc.manifests.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,10 @@
966966
},
967967
{
968968
"resourceTypeArg": "--resource-type"
969+
},
970+
{
971+
"resourcePathArg": "--resource-path",
972+
"includeQuotes": true
969973
}
970974
]
971975
},

0 commit comments

Comments
 (0)