Skip to content

Commit 33e2a2f

Browse files
authored
Merge branch 'main' into implicit-ps-set
2 parents 43e153a + 7f90fbb commit 33e2a2f

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

powershell-adapter/psDscAdapter/psDscAdapter.psm1

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function Get-DSCResourceModules {
4040
}
4141
}
4242
}
43-
43+
4444
return $dscModulePsd1List
4545
}
4646

@@ -83,7 +83,7 @@ function Add-AstMembers {
8383
[DscResourcePropertyInfo]$prop = [DscResourcePropertyInfo]::new()
8484
$prop.Name = $property.Name
8585
$prop.PropertyType = $property.PropertyType.TypeName.Name
86-
$prop.IsMandatory = $isKeyProperty
86+
$prop.IsMandatory = $isKeyProperty
8787
$Properties.Add($prop)
8888
}
8989
}
@@ -104,7 +104,7 @@ function FindAndParseResourceDefinitions {
104104
if (".psm1", ".ps1" -notcontains ([System.IO.Path]::GetExtension($filePath))) {
105105
return
106106
}
107-
107+
108108
"Loading resources from file '$filePath'" | Write-DscTrace -Operation Trace
109109
#TODO: Ensure embedded instances in properties are working correctly
110110
[System.Management.Automation.Language.Token[]] $tokens = $null
@@ -134,13 +134,13 @@ function FindAndParseResourceDefinitions {
134134
$DscResourceInfo.Module = $filePath
135135
$DscResourceInfo.Path = $filePath
136136
#TODO: ModuleName, Version and ParentPath should be taken from psd1 contents
137-
$DscResourceInfo.ModuleName = [System.IO.Path]::GetFileNameWithoutExtension($filePath)
137+
$DscResourceInfo.ModuleName = [System.IO.Path]::GetFileNameWithoutExtension($filePath)
138138
$DscResourceInfo.ParentPath = [System.IO.Path]::GetDirectoryName($filePath)
139139
$DscResourceInfo.Version = $moduleVersion
140140

141141
$DscResourceInfo.Properties = [System.Collections.Generic.List[DscResourcePropertyInfo]]::new()
142142
Add-AstMembers $typeDefinitions $typeDefinitionAst $DscResourceInfo.Properties
143-
143+
144144
$resourceList.Add($DscResourceInfo)
145145
}
146146
}
@@ -157,7 +157,7 @@ function LoadPowerShellClassResourcesFromModule {
157157
)
158158

159159
"Loading resources from module '$($moduleInfo.Path)'" | Write-DscTrace -Operation Trace
160-
160+
161161
if ($moduleInfo.RootModule) {
162162
if (".psm1", ".ps1" -notcontains ([System.IO.Path]::GetExtension($moduleInfo.RootModule)) -and
163163
(-not $moduleInfo.NestedModules)) {
@@ -190,8 +190,8 @@ function LoadPowerShellClassResourcesFromModule {
190190
This function caches the results of the Get-DscResource call to optimize performance.
191191
192192
.DESCRIPTION
193-
This function is designed to improve the performance of DSC operations by caching the results of the Get-DscResource call.
194-
By storing the results, subsequent calls to Get-DscResource can retrieve the cached data instead of making a new call each time.
193+
This function is designed to improve the performance of DSC operations by caching the results of the Get-DscResource call.
194+
By storing the results, subsequent calls to Get-DscResource can retrieve the cached data instead of making a new call each time.
195195
This can significantly speed up operations that need to repeatedly access DSC resources.
196196
197197
.EXAMPLE
@@ -240,7 +240,7 @@ function Invoke-DscCacheRefresh {
240240
foreach ($cacheEntry in $dscResourceCacheEntries) {
241241

242242
$cacheEntry.LastWriteTimes.PSObject.Properties | ForEach-Object {
243-
243+
244244
if (Test-Path $_.Name) {
245245
$file_LastWriteTime = (Get-Item $_.Name).LastWriteTime
246246
# Truncate DateTime to seconds
@@ -289,7 +289,7 @@ function Invoke-DscCacheRefresh {
289289
"Cache file not found '$cacheFilePath'" | Write-DscTrace
290290
$refreshCache = $true
291291
}
292-
292+
293293
if ($refreshCache) {
294294
'Constructing Get-DscResource cache' | Write-DscTrace
295295

@@ -306,7 +306,7 @@ function Invoke-DscCacheRefresh {
306306
$processedModuleNames.Add($mod.Name, $true)
307307

308308
# from several modules with the same name select the one with the highest version
309-
$selectedMod = $modules | Where-Object Name -EQ $mod.Name
309+
$selectedMod = $modules | Where-Object Name -EQ $mod.Name
310310
if ($selectedMod.Count -gt 1) {
311311
"Found $($selectedMod.Count) modules with name '$($mod.Name)'" | Write-DscTrace -Operation Trace
312312
$selectedMod = $selectedMod | Sort-Object -Property Version -Descending | Select-Object -First 1
@@ -407,7 +407,7 @@ function Invoke-DscOperation {
407407

408408
# workaround: script based resources do not validate Get parameter consistency, so we need to remove any parameters the author chose not to include in Get-TargetResource
409409
switch ([dscResourceType]$cachedDscResourceInfo.ImplementationDetail) {
410-
410+
411411
'ClassBased' {
412412
try {
413413
# load powershell class from external module
@@ -424,7 +424,7 @@ function Invoke-DscOperation {
424424
# handle input objects by converting them to a hash table
425425
if ($_.Value -is [System.Management.Automation.PSCustomObject]) {
426426
$validateProperty = $cachedDscResourceInfo.Properties | Where-Object -Property Name -EQ $_.Name
427-
if ($validateProperty.PropertyType -eq 'PSCredential') {
427+
if ($validateProperty -and $validateProperty.PropertyType -eq 'PSCredential') {
428428
if (-not $_.Value.Username -or -not $_.Value.Password) {
429429
"Credential object '$($_.Name)' requires both 'username' and 'password' properties" | Write-DscTrace -Operation Error
430430
exit 1
@@ -453,7 +453,7 @@ function Invoke-DscOperation {
453453
}
454454
'Test' {
455455
$Result = $dscResourceInstance.Test()
456-
$addToActualState.properties = [psobject]@{'InDesiredState' = $Result }
456+
$addToActualState.properties = [psobject]@{'InDesiredState' = $Result }
457457
}
458458
'Export' {
459459
$t = $dscResourceInstance.GetType()
@@ -464,7 +464,7 @@ function Invoke-DscOperation {
464464
break
465465
}
466466
}
467-
467+
468468
if ($null -eq $method) {
469469
"Export method not implemented by resource '$($DesiredState.Type)'" | Write-DscTrace -Operation Error
470470
exit 1
@@ -481,7 +481,7 @@ function Invoke-DscOperation {
481481
}
482482
}
483483
catch {
484-
484+
485485
'Exception: ' + $_.Exception.Message | Write-DscTrace -Operation Error
486486
exit 1
487487
}

powershell-adapter/psDscAdapter/win_psDscAdapter.psm1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ else {
3737
This function caches the results of the Get-DscResource call to optimize performance.
3838
3939
.DESCRIPTION
40-
This function is designed to improve the performance of DSC operations by caching the results of the Get-DscResource call.
41-
By storing the results, subsequent calls to Get-DscResource can retrieve the cached data instead of making a new call each time.
40+
This function is designed to improve the performance of DSC operations by caching the results of the Get-DscResource call.
41+
By storing the results, subsequent calls to Get-DscResource can retrieve the cached data instead of making a new call each time.
4242
This can significantly speed up operations that need to repeatedly access DSC resources.
4343
4444
.EXAMPLE
@@ -90,7 +90,7 @@ function Invoke-DscCacheRefresh {
9090
foreach ($cacheEntry in $dscResourceCacheEntries) {
9191

9292
$cacheEntry.LastWriteTimes.PSObject.Properties | ForEach-Object {
93-
93+
9494
if (Test-Path $_.Name) {
9595
$file_LastWriteTime = (Get-Item $_.Name).LastWriteTimeUtc
9696
# Truncate DateTime to seconds
@@ -138,7 +138,7 @@ function Invoke-DscCacheRefresh {
138138
"Cache file not found '$cacheFilePath'" | Write-DscTrace
139139
$refreshCache = $true
140140
}
141-
141+
142142
if ($refreshCache) {
143143
'Constructing Get-DscResource cache' | Write-DscTrace
144144

@@ -354,11 +354,11 @@ function Invoke-DscOperation {
354354
}
355355

356356
# morph the INPUT object into a hashtable named "property" for the cmdlet Invoke-DscResource
357-
$DesiredState.properties.psobject.properties | ForEach-Object -Begin { $property = @{} } -Process {
357+
$DesiredState.properties.psobject.properties | ForEach-Object -Begin { $property = @{} } -Process {
358358
if ($_.Value -is [System.Management.Automation.PSCustomObject]) {
359359
$validateProperty = $cachedDscResourceInfo.Properties | Where-Object -Property Name -EQ $_.Name
360-
$validateProperty | Write-DscTrace -Operation Debug
361-
if ($validateProperty.PropertyType -eq '[PSCredential]') {
360+
Write-DscTrace -Operation Debug -Message ($validateProperty | Out-String)
361+
if ($validateProperty -and $validateProperty.PropertyType -eq '[PSCredential]') {
362362
if (-not $_.Value.Username -or -not $_.Value.Password) {
363363
"Credential object '$($_.Name)' requires both 'username' and 'password' properties" | Write-DscTrace -Operation Error
364364
exit 1
@@ -386,7 +386,7 @@ function Invoke-DscOperation {
386386
# the object returned by WMI is a CIM instance with a lot of additional data. only return DSC properties
387387
$invokeResult.psobject.Properties.name | Where-Object { 'CimClass', 'CimInstanceProperties', 'CimSystemProperties' -notcontains $_ } | ForEach-Object -Begin { $ResultProperties = @{} } -Process { $ResultProperties[$_] = $invokeResult.$_ }
388388
}
389-
389+
390390
# set the properties of the OUTPUT object from the result of Get-TargetResource
391391
$addToActualState.properties = $ResultProperties
392392
}
@@ -438,7 +438,7 @@ function Invoke-DscOperation {
438438
}
439439
'Test' {
440440
$Result = $dscResourceInstance.Test()
441-
$addToActualState.properties = [psobject]@{'InDesiredState' = $Result }
441+
$addToActualState.properties = [psobject]@{'InDesiredState' = $Result }
442442
}
443443
'Export' {
444444
$t = $dscResourceInstance.GetType()
@@ -499,7 +499,7 @@ function Invoke-DscOperation {
499499
# the object returned by WMI is a CIM instance with a lot of additional data. only return DSC properties
500500
$invokeResult.psobject.Properties.name | Where-Object { 'CimClass', 'CimInstanceProperties', 'CimSystemProperties' -notcontains $_ } | ForEach-Object -Begin { $ResultProperties = @{} } -Process { $ResultProperties[$_] = $invokeResult.$_ }
501501
}
502-
502+
503503
# set the properties of the OUTPUT object from the result of Get-TargetResource
504504
$addToActualState.properties = $ResultProperties
505505
}

0 commit comments

Comments
 (0)