Skip to content

Commit 623d593

Browse files
committed
Use .NET with enumeration option
1 parent 649b804 commit 623d593

File tree

8 files changed

+141
-82
lines changed

8 files changed

+141
-82
lines changed

.vscode/launch.json

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
// {
2-
// // Use IntelliSense to learn about possible attributes.
3-
// // Hover to view descriptions of existing attributes.
4-
// // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5-
// "version": "0.2.0",
6-
// "configurations": [
7-
// {
8-
// "type": "lldb",
9-
// "request": "launch",
10-
// "name": "Debug config",
11-
// "program": "${workspaceFolder}/config/target/debug/config",
12-
// "args": [
13-
// "list",
14-
// "r*"
15-
// ],
16-
// "cwd": "${workspaceFolder}"
17-
// },
18-
// {
19-
// "name": "(macOS) Attach",
20-
// "type": "lldb",
21-
// "request": "attach",
22-
// "pid": "${command:pickMyProcess}",
23-
// },
24-
// {
25-
// "name": "(Windows) Attach",
26-
// "type": "cppvsdbg",
27-
// "request": "attach",
28-
// "processId": "${command:pickProcess}",
29-
// },
30-
// {
31-
// "name": "Debug sshdconfig",
32-
// "type": "cppvsdbg",
33-
// "request": "launch",
34-
// "program": "${workspaceFolder}/sshdconfig/target/debug/sshdconfig.exe",
35-
// "args": ["get"],
36-
// "cwd": "${workspaceFolder}"
37-
// }
38-
// ]
39-
// }
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "lldb",
9+
"request": "launch",
10+
"name": "Debug config",
11+
"program": "${workspaceFolder}/config/target/debug/config",
12+
"args": [
13+
"list",
14+
"r*"
15+
],
16+
"cwd": "${workspaceFolder}"
17+
},
18+
{
19+
"name": "(macOS) Attach",
20+
"type": "lldb",
21+
"request": "attach",
22+
"pid": "${command:pickMyProcess}",
23+
},
24+
{
25+
"name": "(Windows) Attach",
26+
"type": "cppvsdbg",
27+
"request": "attach",
28+
"processId": "${command:pickProcess}",
29+
},
30+
{
31+
"name": "Debug sshdconfig",
32+
"type": "cppvsdbg",
33+
"request": "launch",
34+
"program": "${workspaceFolder}/sshdconfig/target/debug/sshdconfig.exe",
35+
"args": ["get"],
36+
"cwd": "${workspaceFolder}"
37+
}
38+
]
39+
}

build.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ $filesForWindowsPackage = @(
6060
'NOTICE.txt',
6161
'osinfo.exe',
6262
'osinfo.dsc.resource.json',
63+
'powershell.discover.ps1',
64+
'powershell.dsc.extension.json',
6365
'powershell.dsc.resource.json',
6466
'psDscAdapter/',
6567
'psscript.ps1',
@@ -98,6 +100,8 @@ $filesForLinuxPackage = @(
98100
'NOTICE.txt',
99101
'osinfo',
100102
'osinfo.dsc.resource.json',
103+
'powershell.discover.ps1',
104+
'powershell.dsc.extension.json',
101105
'powershell.dsc.resource.json',
102106
'psDscAdapter/',
103107
'psscript.ps1',
@@ -123,6 +127,8 @@ $filesForMacPackage = @(
123127
'NOTICE.txt',
124128
'osinfo',
125129
'osinfo.dsc.resource.json',
130+
'powershell.discover.ps1',
131+
'powershell.dsc.extension.json',
126132
'powershell.dsc.resource.json',
127133
'psDscAdapter/',
128134
'psscript.ps1',
@@ -324,9 +330,9 @@ if (!$SkipBuild) {
324330
}
325331

326332
# make sure dependencies are built first so clippy runs correctly
327-
$windows_projects = @("pal", "registry_lib", "registry", "reboot_pending", "wmi-adapter", "configurations/windows", 'extensions/appx')
328-
$macOS_projects = @("resources/brew")
329-
$linux_projects = @("resources/apt")
333+
$windows_projects = @("pal", "registry_lib", "registry", "reboot_pending", "wmi-adapter", "configurations/windows", "extensions/appx", "extensions/powershell")
334+
$macOS_projects = @("resources/brew", "extensions/powershell")
335+
$linux_projects = @("resources/apt", "extensions/powershell")
330336

331337
# projects are in dependency order
332338
$projects = @(

dsc/tests/dsc_extension_discover.tests.ps1

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,30 @@ Describe 'Discover extension tests' {
2323
It 'Discover extensions' {
2424
$out = dsc extension list | ConvertFrom-Json
2525
$LASTEXITCODE | Should -Be 0
26-
if ($IsWindows) {
27-
$out.Count | Should -Be 3 -Because ($out | Out-String)
28-
$out[0].type | Should -Be 'Microsoft.DSC.Extension/Bicep'
29-
$out[0].version | Should -Be '0.1.0'
30-
$out[0].capabilities | Should -BeExactly @('import')
31-
$out[0].manifest | Should -Not -BeNullOrEmpty
32-
$out[1].type | Should -Be 'Microsoft.Windows.Appx/Discover'
33-
$out[1].version | Should -Be '0.1.0'
34-
$out[1].capabilities | Should -BeExactly @('discover')
35-
$out[1].manifest | Should -Not -BeNullOrEmpty
36-
$out[2].type | Should -BeExactly 'Test/Discover'
37-
$out[2].version | Should -BeExactly '0.1.0'
38-
$out[2].capabilities | Should -BeExactly @('discover')
39-
$out[2].manifest | Should -Not -BeNullOrEmpty
26+
$expectedExtensions = if ($IsWindows) {
27+
@(
28+
@{ type = 'Microsoft.DSC.Extension/Bicep'; version = '0.1.0'; capabilities = @('import') }
29+
@{ type = 'Microsoft.DSC.Transitional/PSDesiredStateConfiguration'; version = '0.1.0'; capabilities = @('import') }
30+
@{ type = 'Microsoft.Windows.Appx/Discover'; version = '0.1.0'; capabilities = @('discover') }
31+
@{ type = 'Microsoft.PowerShell/Discover'; version = '0.1.0'; capabilities = @('discover') }
32+
@{ type = 'Test/Discover'; version = '0.1.0'; capabilities = @('discover') }
33+
)
4034
} else {
41-
$out.Count | Should -Be 2 -Because ($out | Out-String)
42-
$out[0].type | Should -Be 'Microsoft.DSC.Extension/Bicep'
43-
$out[0].version | Should -Be '0.1.0'
44-
$out[0].capabilities | Should -BeExactly @('import')
45-
$out[0].manifest | Should -Not -BeNullOrEmpty
46-
$out[1].type | Should -BeExactly 'Test/Discover'
47-
$out[1].version | Should -BeExactly '0.1.0'
48-
$out[1].capabilities | Should -BeExactly @('discover')
49-
$out[1].manifest | Should -Not -BeNullOrEmpty
35+
@(
36+
@{ type = 'Microsoft.DSC.Extension/Bicep'; version = '0.1.0'; capabilities = @('import') }
37+
@{ type = 'Microsoft.PowerShell/Discover'; version = '0.1.0'; capabilities = @('discover') }
38+
@{ type = 'Test/Discover'; version = '0.1.0'; capabilities = @('discover') }
39+
)
40+
}
41+
42+
$out.Count | Should -Be $expectedExtensions.Count -Because ($out | Out-String)
43+
44+
foreach ($expected in $expectedExtensions) {
45+
$extension = $out | Where-Object { $_.type -eq $expected.type }
46+
$extension | Should -Not -BeNullOrEmpty -Because "Extension $($expected.type) should exist"
47+
$extension.version | Should -BeExactly $expected.version
48+
$extension.capabilities | Should -BeExactly $expected.capabilities
49+
$extension.manifest | Should -Not -BeNullOrEmpty
5050
}
5151
}
5252

extensions/powershell/copy_files.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
powershell.discover.ps1
2+
powershell.dsc.extension.json

extensions/powershell/powershell-discover.ps1

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
$psPaths = $env:PSModulePath -split [System.IO.Path]::PathSeparator | Where-Object { $_ -notmatch 'WindowsPowerShell' }
5+
6+
$manifests = $psPaths | ForEach-Object -Parallel {
7+
$searchPatterns = @('*.dsc.resource.json', '*.dsc.resource.yaml', '*.dsc.resource.yml')
8+
$enumOptions = [System.IO.EnumerationOptions]@{ IgnoreInaccessible = $false; RecurseSubdirectories = $true }
9+
foreach ($pattern in $searchPatterns) {
10+
try {
11+
[System.IO.Directory]::EnumerateFiles($_, $pattern, $enumOptions) | ForEach-Object {
12+
@{ manifestPath = $_ }
13+
}
14+
} catch { }
15+
}
16+
} -ThrottleLimit 10
17+
18+
$manifests | ForEach-Object { $_ | ConvertTo-Json -Compress }
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
BeforeAll {
5+
$fakeManifest = @{
6+
'$schema' = "https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json"
7+
type = "Test/FakeResource"
8+
version = "0.1.0"
9+
get = @{
10+
executable = "fakeResource"
11+
args = @(
12+
"get",
13+
@{
14+
jsonInputArg = "--input"
15+
mandatory = $true
16+
}
17+
)
18+
}
19+
}
20+
21+
$manifestPath = Join-Path $TestDrive "fake.dsc.resource.json"
22+
$fakeManifest | ConvertTo-Json -Depth 10 | Set-Content -Path $manifestPath
23+
$env:PSModulePath += [System.IO.Path]::PathSeparator + $TestDrive
24+
}
25+
26+
Describe 'Tests for PowerShell resource discovery' {
27+
It 'Should find DSC PowerShell resources' {
28+
$out = dsc resource list | ConvertFrom-Json
29+
$LASTEXITCODE | Should -Be 0
30+
$out.directory | Should -Contain $TestDrive
31+
}
32+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"$schema": "https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json",
3+
"type": "Microsoft.PowerShell/Discover",
4+
"version": "0.1.0",
5+
"description": "Discovers DSC resources packaged in PowerShell 7 modules.",
6+
"discover": {
7+
"executable": "pwsh",
8+
"args": [
9+
"-NoLogo",
10+
"-NonInteractive",
11+
"-ExecutionPolicy",
12+
"Bypass",
13+
"-NoProfile",
14+
"-Command",
15+
"./powershell.discover.ps1"
16+
]
17+
}
18+
}

0 commit comments

Comments
 (0)