Skip to content

Commit eaa4ddd

Browse files
authored
Merge branch 'main' into add-registry-what-if
2 parents ca0dc61 + 75c80d5 commit eaa4ddd

File tree

8 files changed

+105
-68
lines changed

8 files changed

+105
-68
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,16 @@ changes since the last release, see the [diff on GitHub][unreleased].
233233

234234
</details>
235235

236+
- Fixed the implementation to retrieve non-zero exit code descriptions for resource errors from the
237+
resource manifest, if defined. Prior to this release, these error descriptions weren't surfaced.
238+
239+
<details><summary>Related work items</summary>
240+
241+
- Issues: [#431][#431]
242+
- PRs: [#444][#444]
243+
244+
</details>
245+
236246
<!-- Unreleased change links -->
237247
[ur-aa]: ./docs/reference/cli/config/set.md#-w---what-if
238248
[ur-ab]: ./docs/reference/schemas/outputs/config/set.md
@@ -1509,10 +1519,12 @@ For the full list of changes in this release, see the [diff on GitHub][compare-v
15091519
[#410]: https://github.com/PowerShell/DSC/issues/410
15101520
[#412]: https://github.com/PowerShell/DSC/issues/412
15111521
[#429]: https://github.com/PowerShell/DSC/issues/429
1522+
[#431]: https://github.com/PowerShell/DSC/issues/431
15121523
[#432]: https://github.com/PowerShell/DSC/issues/432
15131524
[#434]: https://github.com/PowerShell/DSC/issues/434
15141525
[#438]: https://github.com/PowerShell/DSC/issues/438
15151526
[#441]: https://github.com/PowerShell/DSC/issues/441
1527+
[#444]: https://github.com/PowerShell/DSC/issues/444
15161528
[#45]: https://github.com/PowerShell/DSC/issues/45
15171529
[#49]: https://github.com/PowerShell/DSC/issues/49
15181530
[#57]: https://github.com/PowerShell/DSC/issues/57

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.0.0-preview.8"
3+
version = "3.0.0-preview.9"
44
edition = "2021"
55

66
[profile.release]
@@ -18,14 +18,14 @@ crossterm = { version = "0.27" }
1818
ctrlc = { version = "3.4.0" }
1919
dsc_lib = { path = "../dsc_lib" }
2020
indicatif = { version = "0.17" }
21-
jsonschema = "0.17"
21+
jsonschema = "0.18"
2222
path-absolutize = { version = "3.1.1" }
2323
schemars = { version = "0.8.12" }
2424
serde = { version = "1.0", features = ["derive"] }
2525
serde_json = { version = "1.0", features = ["preserve_order"] }
2626
serde_yaml = { version = "0.9.3" }
2727
syntect = { version = "5.0", features = ["default-fancy"], default-features = false }
28-
sysinfo = { version = "0.29.10" }
28+
sysinfo = { version = "0.30" }
2929
thiserror = "1.0.52"
3030
tracing = { version = "0.1.37" }
3131
tracing-subscriber = { version = "0.3.17", features = ["ansi", "env-filter", "json"] }

dsc/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use clap::{CommandFactory, Parser};
77
use clap_complete::generate;
88
use std::io::{self, Read};
99
use std::process::exit;
10-
use sysinfo::{Process, ProcessExt, RefreshKind, System, SystemExt, get_current_pid, ProcessRefreshKind};
10+
use sysinfo::{Process, RefreshKind, System, get_current_pid, ProcessRefreshKind};
1111
use tracing::{error, info, warn, debug};
1212

1313
#[cfg(debug_assertions)]

pal/src/windows.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
#![cfg(windows)]
5-
64
//#[link(name = "ext-ms-win-cng-rng-l1-1-0")]
75
extern "C" {
86
fn ProcessPrng(data: *mut u8, len: usize) -> u32;

powershell-adapter/Tests/TestClassResource/0.0.1/TestClassResource.psm1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ enum EnumPropEnumeration {
88
Expected
99
}
1010

11+
class BaseTestClass
12+
{
13+
[DscProperty()]
14+
[string] $BaseProperty
15+
}
16+
1117
[DscResource()]
12-
class TestClassResource
18+
class TestClassResource : BaseTestClass
1319
{
1420
[DscProperty(Key)]
1521
[string] $Name

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,13 @@ Describe 'PowerShell adapter resource tests' {
8181
$res.actualState.result.count | Should -Be 5
8282
$res.actualState.result| % {$_.Name | Should -Not -BeNullOrEmpty}
8383
}
84+
85+
It 'Verify inheritance works in class-based resources' {
86+
87+
$r = dsc resource list '*' -a Microsoft.DSC/PowerShell
88+
$LASTEXITCODE | Should -Be 0
89+
$resources = $r | ConvertFrom-Json
90+
$t = $resources | ? {$_.Type -eq 'TestClassResource/TestClassResource'}
91+
$t.properties | Should -Contain "BaseProperty"
92+
}
8493
}

powershell-adapter/psDscAdapter/psDscAdapter.psm1

Lines changed: 72 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,57 @@ function Get-DSCResourceModules
4949
return $dscModulePsd1List
5050
}
5151

52+
function Add-AstMembers {
53+
param(
54+
$AllTypeDefinitions,
55+
$TypeAst,
56+
$Properties
57+
)
58+
59+
foreach($TypeConstraint in $TypeAst.BaseTypes) {
60+
$t = $AllTypeDefinitions | Where-Object {$_.Name -eq $TypeConstraint.TypeName.Name}
61+
if ($t) {
62+
Add-AstMembers $AllTypeDefinitions $t $Properties
63+
}
64+
}
65+
66+
foreach ($member in $TypeAst.Members)
67+
{
68+
$property = $member -as [System.Management.Automation.Language.PropertyMemberAst]
69+
if (($property -eq $null) -or ($property.IsStatic))
70+
{
71+
continue;
72+
}
73+
$skipProperty = $true
74+
$isKeyProperty = $false
75+
foreach($attr in $property.Attributes)
76+
{
77+
if ($attr.TypeName.Name -eq 'DscProperty')
78+
{
79+
$skipProperty = $false
80+
foreach($attrArg in $attr.NamedArguments)
81+
{
82+
if ($attrArg.ArgumentName -eq 'Key')
83+
{
84+
$isKeyProperty = $true
85+
break
86+
}
87+
}
88+
}
89+
}
90+
if ($skipProperty)
91+
{
92+
continue;
93+
}
94+
95+
[DscResourcePropertyInfo]$prop = [DscResourcePropertyInfo]::new()
96+
$prop.Name = $property.Name
97+
$prop.PropertyType = $property.PropertyType.TypeName.Name
98+
$prop.IsMandatory = $isKeyProperty
99+
$Properties.Add($prop)
100+
}
101+
}
102+
52103
function FindAndParseResourceDefinitions
53104
{
54105
[CmdletBinding(HelpUri = '')]
@@ -68,7 +119,6 @@ function FindAndParseResourceDefinitions
68119
}
69120

70121
"Loading resources from file '$filePath'" | Write-DscTrace -Operation Trace
71-
#TODO: Handle class inheritance
72122
#TODO: Ensure embedded instances in properties are working correctly
73123
[System.Management.Automation.Language.Token[]] $tokens = $null
74124
[System.Management.Automation.Language.ParseError[]] $errors = $null
@@ -78,76 +128,38 @@ function FindAndParseResourceDefinitions
78128
$e | Out-String | Write-DscTrace -Operation Error
79129
}
80130

81-
$resourceDefinitions = $ast.FindAll(
131+
$typeDefinitions = $ast.FindAll(
82132
{
83133
$typeAst = $args[0] -as [System.Management.Automation.Language.TypeDefinitionAst]
84-
if ($typeAst)
85-
{
86-
foreach($a in $typeAst.Attributes)
87-
{
88-
if ($a.TypeName.Name -eq 'DscResource')
89-
{
90-
return $true;
91-
}
92-
}
93-
}
94-
95-
return $false;
134+
return $typeAst -ne $null;
96135
},
97136
$false);
98137

99138
$resourceList = [System.Collections.Generic.List[DscResourceInfo]]::new()
100139

101-
foreach($typeDefinitionAst in $resourceDefinitions)
140+
foreach($typeDefinitionAst in $typeDefinitions)
102141
{
103-
$DscResourceInfo = [DscResourceInfo]::new()
104-
$DscResourceInfo.Name = $typeDefinitionAst.Name
105-
$DscResourceInfo.ResourceType = $typeDefinitionAst.Name
106-
$DscResourceInfo.FriendlyName = $typeDefinitionAst.Name
107-
$DscResourceInfo.ImplementationDetail = 'ClassBased'
108-
$DscResourceInfo.Module = $filePath
109-
$DscResourceInfo.Path = $filePath
110-
#TODO: ModuleName, Version and ParentPath should be taken from psd1 contents
111-
$DscResourceInfo.ModuleName = [System.IO.Path]::GetFileNameWithoutExtension($filePath)
112-
$DscResourceInfo.ParentPath = [System.IO.Path]::GetDirectoryName($filePath)
113-
114-
$DscResourceInfo.Properties = [System.Collections.Generic.List[DscResourcePropertyInfo]]::new()
115-
foreach ($member in $typeDefinitionAst.Members)
142+
foreach($a in $typeDefinitionAst.Attributes)
116143
{
117-
$property = $member -as [System.Management.Automation.Language.PropertyMemberAst]
118-
if (($property -eq $null) -or ($property.IsStatic))
144+
if ($a.TypeName.Name -eq 'DscResource')
119145
{
120-
continue;
121-
}
122-
$skipProperty = $true
123-
$isKeyProperty = $false
124-
foreach($attr in $property.Attributes)
125-
{
126-
if ($attr.TypeName.Name -eq 'DscProperty')
127-
{
128-
$skipProperty = $false
129-
foreach($attrArg in $attr.NamedArguments)
130-
{
131-
if ($attrArg.ArgumentName -eq 'Key')
132-
{
133-
$isKeyProperty = $true
134-
}
135-
}
136-
}
137-
}
138-
if ($skipProperty)
139-
{
140-
continue;
146+
$DscResourceInfo = [DscResourceInfo]::new()
147+
$DscResourceInfo.Name = $typeDefinitionAst.Name
148+
$DscResourceInfo.ResourceType = $typeDefinitionAst.Name
149+
$DscResourceInfo.FriendlyName = $typeDefinitionAst.Name
150+
$DscResourceInfo.ImplementationDetail = 'ClassBased'
151+
$DscResourceInfo.Module = $filePath
152+
$DscResourceInfo.Path = $filePath
153+
#TODO: ModuleName, Version and ParentPath should be taken from psd1 contents
154+
$DscResourceInfo.ModuleName = [System.IO.Path]::GetFileNameWithoutExtension($filePath)
155+
$DscResourceInfo.ParentPath = [System.IO.Path]::GetDirectoryName($filePath)
156+
157+
$DscResourceInfo.Properties = [System.Collections.Generic.List[DscResourcePropertyInfo]]::new()
158+
Add-AstMembers $typeDefinitions $typeDefinitionAst $DscResourceInfo.Properties
159+
160+
$resourceList.Add($DscResourceInfo)
141161
}
142-
143-
[DscResourcePropertyInfo]$prop = [DscResourcePropertyInfo]::new()
144-
$prop.Name = $property.Name
145-
$prop.PropertyType = $property.PropertyType.TypeName.Name
146-
$prop.IsMandatory = $isKeyProperty
147-
$DscResourceInfo.Properties.Add($prop)
148162
}
149-
150-
$resourceList.Add($DscResourceInfo)
151163
}
152164

153165
return $resourceList
@@ -243,7 +255,7 @@ function Invoke-DscCacheRefresh {
243255
"Checking cache for stale entries" | Write-DscTrace
244256

245257
foreach ($cacheEntry in $dscResourceCacheEntries) {
246-
"Checking cache entry '$($cacheEntry.Type) $($cacheEntry.LastWriteTimes)'" | Write-DscTrace -Operation Trace
258+
#"Checking cache entry '$($cacheEntry.Type) $($cacheEntry.LastWriteTimes)'" | Write-DscTrace -Operation Trace
247259

248260
$cacheEntry.LastWriteTimes.PSObject.Properties | ForEach-Object {
249261

powershell-adapter/psDscAdapter/win_psDscAdapter.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function Invoke-DscCacheRefresh {
8181
"Checking cache for stale entries" | Write-DscTrace
8282

8383
foreach ($cacheEntry in $dscResourceCacheEntries) {
84-
"Checking cache entry '$($cacheEntry.Type) $($cacheEntry.LastWriteTimes)'" | Write-DscTrace -Operation Trace
84+
#"Checking cache entry '$($cacheEntry.Type) $($cacheEntry.LastWriteTimes)'" | Write-DscTrace -Operation Trace
8585

8686
$cacheEntry.LastWriteTimes.PSObject.Properties | ForEach-Object {
8787

0 commit comments

Comments
 (0)