Skip to content

Commit 258501e

Browse files
authored
Merge branch 'main' into winget-manifest-uploader
2 parents afde652 + 73c95ca commit 258501e

File tree

21 files changed

+566
-337
lines changed

21 files changed

+566
-337
lines changed

dsc/Cargo.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dsc/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dsc"
3-
version = "3.2.0-preview.3"
3+
version = "3.2.0-preview.4"
44
edition = "2021"
55

66
[profile.release]
@@ -19,7 +19,7 @@ crossterm = { version = "0.29" }
1919
ctrlc = { version = "3.4" }
2020
dsc_lib = { path = "../dsc_lib" }
2121
indicatif = { version = "0.18" }
22-
jsonschema = { version = "0.30", default-features = false }
22+
jsonschema = { version = "0.32", default-features = false }
2323
path-absolutize = { version = "3.1" }
2424
regex = "1.11"
2525
rust-i18n = { version = "3.1" }
@@ -28,7 +28,7 @@ serde = { version = "1.0", features = ["derive"] }
2828
serde_json = { version = "1.0", features = ["preserve_order"] }
2929
serde_yaml = { version = "0.9" }
3030
syntect = { version = "5.0", features = ["default-fancy"], default-features = false }
31-
sysinfo = { version = "0.36" }
31+
sysinfo = { version = "0.37" }
3232
thiserror = "2.0"
3333
tracing = { version = "0.1" }
3434
tracing-subscriber = { version = "0.3", features = ["ansi", "env-filter", "json"] }

dsc/tests/dsc_export.tests.ps1

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,36 @@ resources:
181181
$out.resources[0].properties.psobject.properties.name | Should -Not -Contain '_securityContext'
182182
$out.resources[0].properties.psobject.properties.name | Should -Not -Contain '_name'
183183
}
184+
185+
It 'Export can be used with a resource that only implements Get with filter' {
186+
$yaml = @'
187+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
188+
resources:
189+
- name: NoExport
190+
type: Test/Get
191+
properties:
192+
name: two
193+
'@
194+
$out = dsc config export -i $yaml | ConvertFrom-Json
195+
$LASTEXITCODE | Should -Be 0
196+
$out.resources.count | Should -Be 1
197+
$out.resources[0].type | Should -BeExactly 'Test/Get'
198+
$out.resources[0].properties.name | Should -BeExactly 'two'
199+
$out.resources[0].properties.id | Should -Be 2
200+
}
201+
202+
It 'Export can be used with a resource that only implements Get with no filter' {
203+
$yaml = @'
204+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
205+
resources:
206+
- name: NoFilter
207+
type: Test/Get
208+
'@
209+
$out = dsc config export -i $yaml | ConvertFrom-Json
210+
$LASTEXITCODE | Should -Be 0
211+
$out.resources.count | Should -Be 1
212+
$out.resources[0].type | Should -BeExactly 'Test/Get'
213+
$out.resources[0].properties.name | Should -BeExactly 'one'
214+
$out.resources[0].properties.id | Should -Be 1
215+
}
184216
}

dsc/tests/dsc_resource_list.tests.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,12 @@ Describe 'Tests for listing resources' {
8484
}
8585

8686
It 'Capabilities are returned' {
87-
$resource = dsc resource list Microsoft/OSInfo | ConvertFrom-Json
87+
$resource = dsc resource list Microsoft.DSC.Debug/Echo | ConvertFrom-Json
8888
$LASTEXITCODE | Should -Be 0
89-
$resource.capabilities.Count | Should -Be 2
89+
$resource.capabilities.Count | Should -Be 4
9090
$resource.capabilities | Should -Contain 'get'
91+
$resource.capabilities | Should -Contain 'set'
92+
$resource.capabilities | Should -Contain 'test'
9193
$resource.capabilities | Should -Contain 'export'
9294
}
9395

dsc_lib/Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dsc_lib/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dsc_lib"
3-
version = "3.1.0"
3+
version = "3.2.0"
44
edition = "2021"
55

66
[profile.release]
@@ -19,7 +19,7 @@ chrono = { version = "0.4", features = ["alloc"] }
1919
clap = { version = "4.5", features = ["derive"] }
2020
derive_builder ="0.20"
2121
indicatif = "0.18"
22-
jsonschema = { version = "0.30", default-features = false }
22+
jsonschema = { version = "0.32", default-features = false }
2323
linked-hash-map = "0.5"
2424
murmurhash64 = "0.3"
2525
num-traits = "0.2"

dsc_lib/locales/en-us.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ resourceInvalidJson = "Resource reported input JSON is not valid"
146146
invalidArrayKey = "Unsupported array value for key '%{key}'. Only string and number is supported."
147147
invalidKey = "Unsupported value for key '%{key}'. Only string, bool, number, and array is supported."
148148
inDesiredStateNotBool = "'_inDesiredState' is not a boolean"
149+
exportNotSupportedUsingGet = "Export is not supported by resource '%{resource}' using get operation"
149150

150151
[dscresources.dscresource]
151152
invokeGet = "Invoking get for '%{resource}'"

dsc_lib/src/dscresources/command_resource.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,26 @@ pub fn get_schema(resource: &ResourceManifest, cwd: &str) -> Result<String, DscE
487487
/// Error returned if the resource does not successfully export the current state
488488
pub fn invoke_export(resource: &ResourceManifest, cwd: &str, input: Option<&str>) -> Result<ExportResult, DscError> {
489489
let Some(export) = resource.export.as_ref() else {
490+
// see if get is supported and use that instead
491+
if resource.get.is_some() {
492+
info!("{}", t!("dscresources.commandResource.exportNotSupportedUsingGet", resource = &resource.resource_type));
493+
let get_result = invoke_get(resource, cwd, input.unwrap_or(""))?;
494+
let mut instances: Vec<Value> = Vec::new();
495+
match get_result {
496+
GetResult::Group(group_response) => {
497+
for result in group_response {
498+
instances.push(serde_json::to_value(result)?);
499+
}
500+
},
501+
GetResult::Resource(response) => {
502+
instances.push(response.actual_state);
503+
}
504+
}
505+
return Ok(ExportResult {
506+
actual_state: instances,
507+
});
508+
}
509+
// if neither export nor get is supported, return an error
490510
return Err(DscError::Operation(t!("dscresources.commandResource.exportNotSupported", resource = &resource.resource_type).to_string()))
491511
};
492512

@@ -840,7 +860,7 @@ fn json_to_hashmap(json: &str) -> Result<HashMap<String, String>, DscError> {
840860
},
841861
Value::Null => {
842862
// ignore null values
843-
},
863+
},
844864
Value::Object(_) => {
845865
return Err(DscError::Operation(t!("dscresources.commandResource.invalidKey", key = key).to_string()));
846866
},

pal/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ opt-level = 2
1313
lto = true
1414

1515
[build-dependencies]
16-
cc = "1.1"
16+
cc = "*"

0 commit comments

Comments
 (0)