Skip to content

Commit 58dbffe

Browse files
author
Andrew
committed
Merge branch 'pscacheupdates' of https://github.com/anmenaga/DSC-New into pscacheupdates
2 parents c184786 + 1105a54 commit 58dbffe

File tree

6 files changed

+91
-66
lines changed

6 files changed

+91
-66
lines changed

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
@@ -119,4 +119,13 @@ Describe 'PowerShell adapter resource tests' {
119119
$LASTEXITCODE | Should -Be 0
120120
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly 'Incompatible version of cache in file'
121121
}
122+
123+
It 'Verify inheritance works in class-based resources' {
124+
125+
$r = dsc resource list '*' -a Microsoft.DSC/PowerShell
126+
$LASTEXITCODE | Should -Be 0
127+
$resources = $r | ConvertFrom-Json
128+
$t = $resources | ? {$_.Type -eq 'TestClassResource/TestClassResource'}
129+
$t.properties | Should -Contain "BaseProperty"
130+
}
122131
}

powershell-adapter/psDscAdapter/psDscAdapter.psm1

Lines changed: 71 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,57 @@ function Get-DSCResourceModules
5151
return $dscModulePsd1List
5252
}
5353

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

72123
"Loading resources from file '$filePath'" | Write-DscTrace -Operation Trace
73-
#TODO: Handle class inheritance
74124
#TODO: Ensure embedded instances in properties are working correctly
75125
[System.Management.Automation.Language.Token[]] $tokens = $null
76126
[System.Management.Automation.Language.ParseError[]] $errors = $null
@@ -80,76 +130,38 @@ function FindAndParseResourceDefinitions
80130
$e | Out-String | Write-DscTrace -Operation Error
81131
}
82132

83-
$resourceDefinitions = $ast.FindAll(
133+
$typeDefinitions = $ast.FindAll(
84134
{
85135
$typeAst = $args[0] -as [System.Management.Automation.Language.TypeDefinitionAst]
86-
if ($typeAst)
87-
{
88-
foreach($a in $typeAst.Attributes)
89-
{
90-
if ($a.TypeName.Name -eq 'DscResource')
91-
{
92-
return $true;
93-
}
94-
}
95-
}
96-
97-
return $false;
136+
return $typeAst -ne $null;
98137
},
99138
$false);
100139

101140
$resourceList = [System.Collections.Generic.List[DscResourceInfo]]::new()
102141

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

155167
return $resourceList

0 commit comments

Comments
 (0)