Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerShell adapter PR #363

Merged
merged 115 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 111 commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
46af53d
vscode powershell formatting
mgreenegit Mar 8, 2024
e296241
apply formatter again
mgreenegit Mar 8, 2024
1559c45
List and Get only
mgreenegit Mar 11, 2024
efac0dc
Merge branch 'main' into powershell_group
mgreenegit Mar 11, 2024
b5bf80d
Add capabilities and manifest
mgreenegit Mar 12, 2024
3d76d9e
adds support for class based resources
mgreenegit Mar 13, 2024
503555a
Merge remote-tracking branch 'upstream/main' into powershell_group
mgreenegit Mar 14, 2024
0df0846
restore debug output
mgreenegit Mar 14, 2024
ad096c9
remove manifest; changes from review
mgreenegit Mar 14, 2024
87be1ae
comment out tests for test/set/export
mgreenegit Mar 15, 2024
c53fd38
comment export command tests
mgreenegit Mar 18, 2024
caef28f
expect invalid schema to error
mgreenegit Mar 18, 2024
3eaa216
woraround for modulename property
mgreenegit Mar 18, 2024
602c60c
different approach to should throw
mgreenegit Mar 18, 2024
0c3e80b
shouldn't need to null the output
mgreenegit Mar 18, 2024
278e84e
trap error, exclude null from list
mgreenegit Mar 18, 2024
c758f46
workaround for null type
mgreenegit Mar 18, 2024
c512000
null or empty
mgreenegit Mar 18, 2024
b9c74de
bad char
mgreenegit Mar 18, 2024
84567d1
resolved list issues
mgreenegit Mar 19, 2024
cfed4e0
pester nuance for capturing errors, test
mgreenegit Mar 19, 2024
357c24d
try pester output match
mgreenegit Mar 19, 2024
b439202
capture error as stdout and select text
mgreenegit Mar 19, 2024
721f757
LASTEXITCODE 2
mgreenegit Mar 19, 2024
59e701b
error match and arg type
mgreenegit Mar 19, 2024
4717d0f
correct class example for test
mgreenegit Mar 19, 2024
4bb4b01
powershell test fixes
mgreenegit Mar 20, 2024
79ee41a
type
mgreenegit Mar 20, 2024
9fc6a5e
Merge branch 'PowerShell:main' into powershell_group
mgreenegit Mar 26, 2024
ebfff63
many changes from first review
mgreenegit Apr 1, 2024
51da439
Merge remote-tracking branch 'upstream/main' into powershell_group
mgreenegit Apr 1, 2024
ea2ba05
revert Pester change
mgreenegit Apr 1, 2024
71cbe17
additional test pattern
mgreenegit Apr 1, 2024
16ff984
changes lost in previous merge
mgreenegit Apr 2, 2024
6d05cdd
schema change
mgreenegit Apr 2, 2024
fb31f63
requiredAdapter
mgreenegit Apr 2, 2024
d4c77d3
changes from feedback
mgreenegit Apr 2, 2024
7784682
wrong quote type for variable
mgreenegit Apr 2, 2024
cd166fd
move common functions to adapter module
mgreenegit Apr 2, 2024
552a913
copyfiles; missed match strings
mgreenegit Apr 2, 2024
7d7e940
troubleshooting why result is not being returned
mgreenegit Apr 3, 2024
c24fdb0
corrected build copy files
mgreenegit Apr 3, 2024
5e687d2
add debug output for psDscAdapter module
mgreenegit Apr 3, 2024
a9f984a
Only write to debug for adapter if files are missing
mgreenegit Apr 3, 2024
3754a95
Merge branch 'main' into powershell_group
mgreenegit Apr 3, 2024
ab70fec
improve feedback from adapter and stub windows adapter
mgreenegit Apr 3, 2024
3f26e1b
Merge branch 'powershell_group' of https://github.com/mgreenegit/dsc …
mgreenegit Apr 3, 2024
eeb72f9
Merge branch 'PowerShell:main' into powershell_group
mgreenegit Apr 3, 2024
e479ac0
removing winps files
mgreenegit Apr 4, 2024
b539db4
Merge branch 'powershell_group' of https://github.com/mgreenegit/dsc …
mgreenegit Apr 4, 2024
907f597
try to fix line ending issue
mgreenegit Apr 4, 2024
d8201c0
end with new line
mgreenegit Apr 4, 2024
ae646d4
Merge branch 'main' into powershell_group
SteveL-MSFT Apr 4, 2024
703ac73
variables should be 'dsc'; add support for binary resources; start wo…
mgreenegit Apr 5, 2024
7b8c475
supporting windowspowershell adapter
mgreenegit Apr 5, 2024
ed5028e
Add a few tests for winps
mgreenegit Apr 5, 2024
6732749
file must run elevated so accept null for now
mgreenegit Apr 5, 2024
722bcda
try to capture error if import module fails
mgreenegit Apr 6, 2024
1007b31
force windowspowershell adapter to use psdsc in windows
mgreenegit Apr 6, 2024
942919b
condition on error output
mgreenegit Apr 6, 2024
8eab956
contain psdscadapter to pwsh
mgreenegit Apr 6, 2024
4ca4356
module input type; dsc version checks
mgreenegit Apr 6, 2024
6712c9e
iswindows didn't exist in 5.1
mgreenegit Apr 6, 2024
3d50b70
condition was backwards
mgreenegit Apr 6, 2024
9c47e42
simpler condition
mgreenegit Apr 6, 2024
0c4336b
implementationdetail special case for binary
mgreenegit Apr 7, 2024
ab8da32
debugging build agent difference from local
mgreenegit Apr 7, 2024
af576d8
remove module name
mgreenegit Apr 7, 2024
dcb0e6e
try moving resource to psdesiredstateconfiguration rather than windows
mgreenegit Apr 7, 2024
951e331
output module version
mgreenegit Apr 7, 2024
e349948
suppress warning
mgreenegit Apr 7, 2024
4ef4538
empty string instead of json
mgreenegit Apr 7, 2024
9108dd8
check for resource
mgreenegit Apr 7, 2024
a319d59
Specify version
mgreenegit Apr 7, 2024
49b8f8e
Update psDscAdapter.psm1
mgreenegit Apr 7, 2024
6a896d3
new example
mgreenegit Apr 7, 2024
7482840
check name
mgreenegit Apr 7, 2024
9d511ce
diagnostic
mgreenegit Apr 7, 2024
66556f2
Merge branch 'PowerShell:main' into powershell_group
mgreenegit Apr 8, 2024
868524e
diagnostics
mgreenegit Apr 8, 2024
0e64fc6
diag
mgreenegit Apr 8, 2024
b70bbd9
diag
mgreenegit Apr 8, 2024
e9954e8
for version; add more tests
mgreenegit Apr 8, 2024
fc19607
add to gitignore
mgreenegit Apr 8, 2024
efcd851
comment
mgreenegit Apr 8, 2024
2b30caa
make sure psmodulepath has system modules
mgreenegit Apr 8, 2024
e3679b0
bad param name
mgreenegit Apr 8, 2024
9fe9887
trust
mgreenegit Apr 8, 2024
3194fb7
adapting to psresource
mgreenegit Apr 8, 2024
38643e7
correct build and test errors
mgreenegit Apr 8, 2024
ad75cfa
replace null properties in resource list with empty strings
mgreenegit Apr 8, 2024
ce01a1b
cleanup module imports
mgreenegit Apr 8, 2024
4631fc7
fix condition
mgreenegit Apr 8, 2024
39ff59c
bad param
mgreenegit Apr 8, 2024
bbca66a
solve issue in binary output
mgreenegit Apr 8, 2024
2a096a5
cleaner workaround for binary resources
mgreenegit Apr 8, 2024
9758b1f
remove cim properties from script output
mgreenegit Apr 9, 2024
a735c6d
Fix issues with PowerShell adapter tests and module imports
mgreenegit Apr 10, 2024
cd1f1c2
Fix issue with loading Windows resources in PSDesiredStateConfigurati…
mgreenegit Apr 10, 2024
dd66689
confirm winrm quickconfig during build
mgreenegit Apr 11, 2024
44e31f7
condition winrm
mgreenegit Apr 11, 2024
5b80546
gitignore
mgreenegit Apr 11, 2024
bb16a0d
create test file
mgreenegit Apr 11, 2024
67d9dde
Fix typo in PowerShell adapter test script
mgreenegit Apr 11, 2024
6f28cb2
Fix issue with GetScript output
mgreenegit Apr 11, 2024
305eebe
Fix issue with GetScript output in PowerShell adapter tests
mgreenegit Apr 11, 2024
49c34f7
Merge branch 'main' into powershell_group
mgreenegit Apr 11, 2024
93683be
Refactor file paths in PowerShell adapter tests to use TestDrive:\ in…
mgreenegit Apr 11, 2024
cd877c3
Merge branch 'powershell_group' of https://github.com/mgreenegit/dsc …
mgreenegit Apr 11, 2024
eb9be57
remove testdrive experiment
mgreenegit Apr 11, 2024
238b3be
wrong quotes
mgreenegit Apr 11, 2024
ec7d58c
Refactor PowerShell adapter tests to use winrm quickconfig -quiet on …
mgreenegit Apr 11, 2024
cac542f
Refactor PowerShell adapter tests to use Microsoft.Windows/WindowsPow…
mgreenegit Apr 12, 2024
4efac72
chore: Write PSModulePath to debug logs in Invoke-DscCacheRefresh
mgreenegit Apr 12, 2024
98f4126
chore: Remove PSModulePath debug logs in Invoke-DscCacheRefresh
mgreenegit Apr 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ node_modules/
tree-sitter-dscexpression/bindings/
tree-sitter-dscexpression/src/
tree-sitter-dscexpression/parser.*
tree-sitter-dscexpression/binding.gyp
tree-sitter-dscexpression/binding.gyp
27 changes: 21 additions & 6 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ param(
[switch]$SkipLinkCheck
)

if ($isWindows) {
winrm quickconfig -quiet
mgreenegit marked this conversation as resolved.
Show resolved Hide resolved
}

if ($GetPackageVersion) {
$match = Select-String -Path $PSScriptRoot/dsc/Cargo.toml -Pattern '^version\s*=\s*"(?<ver>.*?)"$'
if ($null -eq $match) {
Expand Down Expand Up @@ -188,7 +192,18 @@ $skip_test_projects_on_windows = @("tree-sitter-dscexpression")

if (Test-Path "./copy_files.txt") {
Get-Content "./copy_files.txt" | ForEach-Object {
Copy-Item $_ $target -Force -ErrorAction Ignore
# if the line contains a '\' character, throw an error
if ($_ -match '\\') {
throw "copy_files.txt should use '/' as the path separator"
}
# copy the file to the target directory, creating the directory path if needed
mgreenegit marked this conversation as resolved.
Show resolved Hide resolved
$fileCopyPath = $_.split('/')
if ($fileCopyPath.Length -gt 1) {
$fileCopyPath = $fileCopyPath[0..($fileCopyPath.Length - 2)]
$fileCopyPath = $fileCopyPath -join '/'
New-Item -ItemType Directory -Path "$target/$fileCopyPath" -Force -ErrorAction Ignore | Out-Null
}
Copy-Item $_ "$target/$_" -Force -ErrorAction Ignore
}
}

Expand All @@ -199,6 +214,8 @@ $skip_test_projects_on_windows = @("tree-sitter-dscexpression")
}
}

Save-PSResource -Path $target -Name 'PSDesiredStateConfiguration' -Version '2.0.7' -Repository PSGallery -TrustRepository

if ($failed) {
Write-Host -ForegroundColor Red "Build failed"
exit 1
Expand Down Expand Up @@ -243,14 +260,12 @@ if ($Test) {
$FullyQualifiedName = @{ModuleName="PSDesiredStateConfiguration";ModuleVersion="2.0.7"}
if (-not(Get-Module -ListAvailable -FullyQualifiedName $FullyQualifiedName))
{ "Installing module PSDesiredStateConfiguration 2.0.7"
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
Install-Module PSDesiredStateConfiguration -RequiredVersion 2.0.7
Install-PSResource -Name PSDesiredStateConfiguration -Version 2.0.7 -Repository PSGallery -TrustRepository
}

if (-not(Get-Module -ListAvailable -Name Pester))
{ "Installing module Pester"
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
Install-Module Pester -WarningAction Ignore
Install-PSResource Pester -WarningAction Ignore -Repository PSGallery -TrustRepository
}

foreach ($project in $projects) {
Expand Down Expand Up @@ -295,7 +310,7 @@ if ($Test) {
if (-not(Get-Module -ListAvailable -Name Pester))
{ "Installing module Pester"
$InstallTargetDir = ($env:PSModulePath -split ";")[0]
Find-Module -Name 'Pester' -Repository 'PSGallery' | Save-Module -Path $InstallTargetDir
Find-PSResource -Name 'Pester' -Repository 'PSGallery' | Save-PSResource -Path $InstallTargetDir -TrustRepository
}

"Updated Pester module location:"
Expand Down
3 changes: 2 additions & 1 deletion dsc/tests/dsc_config_get.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Describe 'dsc config get tests' {
It 'will fail if resource schema does not match' -Skip:(!$IsWindows) {
$jsonPath = Join-Path $PSScriptRoot '../examples/invalid_schema.dsc.yaml'
$config = Get-Content $jsonPath -Raw
$null = $config | dsc config get | ConvertFrom-Json
$testError = & {$config | dsc config get get 2>&1}
$testError[0] | Should -match 'error:'
$LASTEXITCODE | Should -Be 2
}

Expand Down
3 changes: 2 additions & 1 deletion dsc/tests/dsc_get.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Describe 'resource get tests' {
"Name": "ProductName"
}
'@
$json | dsc resource get -r Microsoft.Windows/registry
$testError = & {$json | dsc resource get -r Microsoft.Windows/registry get 2>&1}
$testError[0] | SHould -match 'error:'
$LASTEXITCODE | Should -Be 2
}
}
23 changes: 14 additions & 9 deletions dsc/tests/dsc_parameters.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ Describe 'Parameters tests' {
"@
$params_json = @{ parameters = @{ param1 = $value }} | ConvertTo-Json

$null = $config_yaml | dsc config -p $params_json get
$testError = & {$config_yaml | dsc config -p $params_json get 2>&1}
$testError | Should -match 'Parameter input failure:'
$LASTEXITCODE | Should -Be 4
}

Expand All @@ -108,8 +109,9 @@ Describe 'Parameters tests' {
"@
$params_json = @{ parameters = @{ param1 = $value }} | ConvertTo-Json

$null = $config_yaml | dsc config -p $params_json get
$LASTEXITCODE | Should -Be 4
$testError = & {$config_yaml | dsc config -p $params_json get get 2>&1}
$testError[0] | Should -match 'error'
$LASTEXITCODE | Should -Be 2
}

It 'Input number value is out of range for <min> and <max>' -TestCases @(
Expand All @@ -134,8 +136,9 @@ Describe 'Parameters tests' {
"@
$params_json = @{ parameters = @{ param1 = $value }} | ConvertTo-Json

$null = $config_yaml | dsc config -p $params_json get
$LASTEXITCODE | Should -Be 4
$testError = & {$config_yaml | dsc config -p $params_json get get 2>&1}
$testError[0] | Should -match 'error'
$LASTEXITCODE | Should -Be 2
}

It 'Input is not in the allowed value list for <type>' -TestCases @(
Expand All @@ -158,8 +161,9 @@ Describe 'Parameters tests' {
"@
$params_json = @{ parameters = @{ param1 = $value }} | ConvertTo-Json

$null = $config_yaml | dsc config -p $params_json get
$LASTEXITCODE | Should -Be 4
$testError = & {$config_yaml | dsc config -p $params_json get get 2>&1}
$testError[0] | Should -match 'error'
$LASTEXITCODE | Should -Be 2
}

It 'Length constraint is incorrectly applied to <type> with <constraint>' -TestCases @(
Expand All @@ -184,8 +188,9 @@ Describe 'Parameters tests' {
"@
$params_json = @{ parameters = @{ param1 = $value }} | ConvertTo-Json

$null = $config_yaml | dsc config -p $params_json get | ConvertFrom-Json
$LASTEXITCODE | Should -Be 4
$testError = & {$config_yaml | dsc config -p $params_json get get 2>&1}
$testError[0] | Should -match 'error'
$LASTEXITCODE | Should -Be 2
}

It 'Default value is used when not provided' {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

enum EnsureEnumeration {
Absent
Present
Expand All @@ -14,7 +17,7 @@ function Get-TargetResource {
)

$returnValue = @{
Ensure = [EnsureEnumeration]::Absent
Ensure = ([EnsureEnumeration]::Absent).ToString()
Name = $Name
SourceLocation = $null
ScriptSourceLocation = $null
Expand All @@ -27,7 +30,7 @@ function Get-TargetResource {
}

if ($Name -eq "TestPSRepository1") {
$returnValue.Ensure = [EnsureEnumeration]::Present
$returnValue.Ensure = ([EnsureEnumeration]::Present).ToString()
$returnValue.SourceLocation = 'https://www.powershellgallery.com/api/v2'
$returnValue.ScriptSourceLocation = 'https://www.powershellgallery.com/api/v2/items/psscript'
$returnValue.PublishLocation = 'https://www.powershellgallery.com/api/v2/package/'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
@{
RootModule = 'TestClassResource.psm1'
ModuleVersion = '1.0.0'
GUID = '5d73a601-4a6c-43c5-ba3f-619b18bbb404'
Author = 'Microsoft Corporation'
CompanyName = 'Microsoft Corporation'
Copyright = '(c) Microsoft Corporation. All rights reserved.'
Description = 'PowerShell module for testing DSCv3'
PowerShellVersion = '5.0'
DscResourcesToExport = 'TestClassResource'
PowerShellVersion = '5.1'
DscResourcesToExport = 'TestPSRepository'
FunctionsToExport = @(
'Test-World')
VariablesToExport = '@()'
VariablesToExport = @()
AliasesToExport = @()
PrivateData = @{
PSData = @{
Expand All @@ -20,6 +21,7 @@
'PSEdition_Core',
'Linux',
'Mac')
DscCapabilities = @('Get', 'Test')
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

@{

# Script module or binary module file associated with this manifest.
RootModule = 'TestClassResource.psm1'

# Version number of this module.
ModuleVersion = '0.0.1'

# ID used to uniquely identify this module
GUID = 'b267fa32-e77d-48e6-9248-676cc6f2327f'

# Author of this module
Author = 'Microsoft'

# Company or vendor of this module
CompanyName = 'Microsoft Corporation'

# Copyright statement for this module
Copyright = '(c) Microsoft. All rights reserved.'

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @()

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = '*'
mgreenegit marked this conversation as resolved.
Show resolved Hide resolved
mgreenegit marked this conversation as resolved.
Show resolved Hide resolved
mgreenegit marked this conversation as resolved.
Show resolved Hide resolved

# Variables to export from this module
VariablesToExport = @()

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()

# DSC resources to export from this module
DscResourcesToExport = 'TestClassResource'

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{
PSData = @{
DscCapabilities = @(
'Get'
'Test'
)
}
}

}

Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

using namespace System.Collections.Generic

enum EnumPropEnumeration {
Expand All @@ -15,7 +18,7 @@ class TestClassResource
[string] $Prop1

[DscProperty()]
[EnumPropEnumeration] $EnumProp
[string] $EnumProp
SteveL-MSFT marked this conversation as resolved.
Show resolved Hide resolved

[void] Set()
{
Expand Down Expand Up @@ -43,7 +46,7 @@ class TestClassResource
{
$this.Prop1 = $env:DSC_CONFIG_ROOT
}
$this.EnumProp = [EnumPropEnumeration]::Expected
$this.EnumProp = ([EnumPropEnumeration]::Expected).ToString()
return $this
}

Expand Down
7 changes: 6 additions & 1 deletion powershell-adapter/Tests/class_ps_resources.dsc.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/config/document.json
resources:
- name: Working with classic DSC resources
Expand All @@ -9,6 +12,8 @@ resources:
properties:
Name: TestPSRepository1
- name: Class-resource Info
type: PSTestModule/TestClassResource
type: TestClassResource/TestClassResource
properties:
Name: TestClassResource1
Prop1: ValueForProp1
EnumProp: Expected
5 changes: 4 additions & 1 deletion powershell-adapter/Tests/native_and_powershell.dsc.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

# Example configuration mixing native app resources with classic PS resources
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/config/document.json
resources:
Expand All @@ -20,4 +23,4 @@ resources:
properties:
keyPath: HKLM\Software\Microsoft\Windows NT\CurrentVersion
valueName: ProductName
_ensure: Present
_ensure: Present
Loading
Loading