Skip to content

Commit 6337045

Browse files
committed
Merge branch 'implement-powershell-discover' of https://github.com/Gijsreyn/operation-methods into implement-powershell-discover
2 parents 1e80819 + 991f7ce commit 6337045

File tree

5 files changed

+106
-86
lines changed

5 files changed

+106
-86
lines changed

build.ps1

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,26 @@ param(
1515
[switch]$GetPackageVersion,
1616
[switch]$SkipLinkCheck,
1717
[switch]$UseX64MakeAppx,
18-
[switch]$UseCratesIO,
18+
[switch]$UseCFS,
1919
[switch]$UpdateLockFile,
2020
[switch]$Audit,
2121
[switch]$UseCFSAuth,
2222
[switch]$Clean,
2323
[switch]$Verbose
2424
)
2525

26-
$env:RUSTC_LOG=$null
27-
$env:RUSTFLAGS='-Dwarnings'
28-
$usingADO = ($null -ne $env:TF_BUILD)
29-
3026
trap {
3127
Write-Error "An error occurred: $($_ | Out-String)"
3228
exit 1
3329
}
3430

31+
$env:RUSTC_LOG=$null
32+
$env:RUSTFLAGS='-Dwarnings'
33+
$usingADO = ($null -ne $env:TF_BUILD)
34+
if ($usingADO -or $UseCFSAuth) {
35+
$UseCFS = $true
36+
}
37+
3538
if ($Verbose) {
3639
$env:RUSTC_LOG='rustc_codegen_ssa::back::link=info'
3740
}
@@ -177,6 +180,39 @@ if ($null -ne (Get-Command msrustup -CommandType Application -ErrorAction Ignore
177180
if ($null -ne $packageType) {
178181
$SkipBuild = $true
179182
} else {
183+
if ($UseCFS) {
184+
Write-Host "Using CFS for cargo source replacement"
185+
${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = $null
186+
$env:CARGO_REGISTRIES_CRATESIO_INDEX = $null
187+
188+
if ($UseCFSAuth) {
189+
if ($null -eq (Get-Command 'az' -ErrorAction Ignore)) {
190+
throw "Azure CLI not found"
191+
}
192+
193+
if ($null -ne (Get-Command az -ErrorAction Ignore)) {
194+
Write-Host "Getting token"
195+
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv
196+
if ($LASTEXITCODE -ne 0) {
197+
Write-Warning "Failed to get access token, use 'az login' first, or use '-useCratesIO' to use crates.io. Proceeding with anonymous access."
198+
} else {
199+
$header = "Bearer $accessToken"
200+
$env:CARGO_REGISTRIES_POWERSHELL_TOKEN = $header
201+
$env:CARGO_REGISTRIES_POWERSHELL_CREDENTIAL_PROVIDER = 'cargo:token'
202+
$env:CARGO_REGISTRIES_POWERSHELL_INDEX = "sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell~force-auth/Cargo/index/"
203+
}
204+
}
205+
else {
206+
Write-Warning "Azure CLI not found, proceeding with anonymous access."
207+
}
208+
}
209+
} else {
210+
# this will override the config.toml
211+
Write-Host "Setting CARGO_SOURCE_crates-io_REPLACE_WITH to 'crates-io'"
212+
${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = 'CRATESIO'
213+
$env:CARGO_REGISTRIES_CRATESIO_INDEX = 'sparse+https://index.crates.io/'
214+
}
215+
180216
## Test if Rust is installed
181217
if (!$usingADO -and !(Get-Command 'cargo' -ErrorAction Ignore)) {
182218
Write-Verbose -Verbose "Rust not found, installing..."
@@ -235,7 +271,11 @@ if ($null -ne $packageType) {
235271
## Test if tree-sitter is installed
236272
if ($null -eq (Get-Command tree-sitter -ErrorAction Ignore)) {
237273
Write-Verbose -Verbose "tree-sitter not found, installing..."
238-
cargo install tree-sitter-cli --config .cargo/config.toml
274+
if ($UseCFS) {
275+
cargo install tree-sitter-cli --config .cargo/config.toml
276+
} else {
277+
cargo install tree-sitter-cli
278+
}
239279
if ($LASTEXITCODE -ne 0) {
240280
throw "Failed to install tree-sitter-cli"
241281
}
@@ -296,39 +336,6 @@ if (!$SkipBuild) {
296336
}
297337
New-Item -ItemType Directory $target -ErrorAction Ignore > $null
298338

299-
if ($UseCratesIO) {
300-
# this will override the config.toml
301-
Write-Host "Setting CARGO_SOURCE_crates-io_REPLACE_WITH to 'crates-io'"
302-
${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = 'CRATESIO'
303-
$env:CARGO_REGISTRIES_CRATESIO_INDEX = 'sparse+https://index.crates.io/'
304-
} else {
305-
Write-Host "Using CFS for cargo source replacement"
306-
${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = $null
307-
$env:CARGO_REGISTRIES_CRATESIO_INDEX = $null
308-
309-
if ($UseCFSAuth) {
310-
if ($null -eq (Get-Command 'az' -ErrorAction Ignore)) {
311-
throw "Azure CLI not found"
312-
}
313-
314-
if ($null -ne (Get-Command az -ErrorAction Ignore)) {
315-
Write-Host "Getting token"
316-
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv
317-
if ($LASTEXITCODE -ne 0) {
318-
Write-Warning "Failed to get access token, use 'az login' first, or use '-useCratesIO' to use crates.io. Proceeding with anonymous access."
319-
} else {
320-
$header = "Bearer $accessToken"
321-
$env:CARGO_REGISTRIES_POWERSHELL_TOKEN = $header
322-
$env:CARGO_REGISTRIES_POWERSHELL_CREDENTIAL_PROVIDER = 'cargo:token'
323-
$env:CARGO_REGISTRIES_POWERSHELL_INDEX = "sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell~force-auth/Cargo/index/"
324-
}
325-
}
326-
else {
327-
Write-Warning "Azure CLI not found, proceeding with anonymous access."
328-
}
329-
}
330-
}
331-
332339
# make sure dependencies are built first so clippy runs correctly
333340
$windows_projects = @("pal", "registry_lib", "registry", "reboot_pending", "wmi-adapter", "configurations/windows", "extensions/appx", "extensions/powershell")
334341
$macOS_projects = @("resources/brew", "extensions/powershell")
@@ -386,7 +393,11 @@ if (!$SkipBuild) {
386393
else {
387394
if ($Audit) {
388395
if ($null -eq (Get-Command cargo-audit -ErrorAction Ignore)) {
389-
cargo install cargo-audit --features=fix --config .cargo/config.toml
396+
if ($UseCFS) {
397+
cargo install cargo-audit --features=fix --config .cargo/config.toml
398+
} else {
399+
cargo install cargo-audit --features=fix
400+
}
390401
}
391402

392403
cargo audit fix
@@ -419,7 +430,11 @@ if (!$SkipBuild) {
419430
else {
420431
if ($Audit) {
421432
if ($null -eq (Get-Command cargo-audit -ErrorAction Ignore)) {
422-
cargo install cargo-audit --features=fix --config .cargo/config.toml
433+
if ($UseCFS) {
434+
cargo install cargo-audit --features=fix --config .cargo/config.toml
435+
} else {
436+
cargo install cargo-audit --features=fix
437+
}
423438
}
424439

425440
cargo audit fix

docs/reference/schemas/config/functions/array.md

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,31 @@ title: array
99

1010
## Synopsis
1111

12-
Creates an array from the given elements (strings, numbers, arrays, or objects).
12+
Wraps a single value (string, number, array, or object) in an array.
1313

1414
## Syntax
1515

1616
```Syntax
17-
array(<element1>, <element2>, ...)
17+
array(<value>)
1818
```
1919

2020
## Description
2121

22-
The `array()` function creates an array from the provided arguments, allowing
23-
mixed data types within the same array. Unlike `createArray()` which requires
24-
all elements to be the same type, `array()` accepts any combination of strings,
25-
numbers, arrays, and objects as arguments.
22+
The `array()` function returns a new array containing the single input value.
23+
The value can be a string, number, array, or object. Use
24+
`createArray()` to construct arrays with multiple elements of the same type.
2625

27-
This function is useful when you need to combine different types of data into a
28-
single collection, such as mixing configuration values, computed results, and
29-
structured metadata in deployment scenarios.
26+
This function is useful when a schema expects an array, but you only have a
27+
single value, or when you need to nest an existing array or object inside an
28+
outer array.
3029

3130
## Examples
3231

33-
### Example 1 - Build a deployment plan
32+
### Example 1 - Wrap an existing array as a single element
3433

35-
This example demonstrates combining different data types to create a comprehensive
36-
deployment configuration. The array contains an existing server list, a numeric
37-
batch size, and a configuration object with deployment strategy details.
34+
This example demonstrates wrapping an existing server list into a single array
35+
element, producing a nested array. This can be useful when a downstream schema
36+
expects an array of arrays.
3837

3938
```yaml
4039
# array.example.1.dsc.config.yaml
@@ -52,7 +51,7 @@ resources:
5251
- name: Deployment Plan
5352
type: Microsoft.DSC.Debug/Echo
5453
properties:
55-
output: "[array(parameters('webServers'), parameters('batchSize'), createObject('strategy', 'blue-green'))]"
54+
output: "[array(parameters('webServers'))]"
5655
```
5756
5857
```bash
@@ -68,17 +67,14 @@ results:
6867
output:
6968
- - web01
7069
- web02
71-
- 2
72-
- strategy: blue-green
7370
messages: []
7471
hadErrors: false
7572
```
7673
77-
### Example 2 - Compose mixed telemetry payload parts
74+
### Example 2 - Wrap a single object for payloads
7875
79-
This example shows how to construct a telemetry payload by combining a string
80-
identifier, structured metadata object, and numeric status code into a single
81-
array for logging or monitoring systems.
76+
This example shows how to wrap a structured metadata object into an array for
77+
logging or monitoring systems that expect arrays.
8278
8379
```yaml
8480
# array.example.2.dsc.config.yaml
@@ -92,7 +88,7 @@ resources:
9288
type: Microsoft.DSC.Debug/Echo
9389
properties:
9490
output:
95-
payload: "[array(parameters('correlationId'), createObject('severity', 'info'), 200)]"
91+
payload: "[array(createObject('severity', 'info'))]"
9692
```
9793
9894
```bash
@@ -107,18 +103,15 @@ results:
107103
actualState:
108104
output:
109105
payload:
110-
- ABC123
111106
- severity: info
112-
- 200
113107
messages: []
114108
hadErrors: false
115109
```
116110
117-
### Example 3 - Combine generated and literal collections
111+
### Example 3 - Wrap generated collections
118112
119-
This example demonstrates nesting arrays and objects within a parent array,
120-
showing how `array()` can combine results from other DSC functions like
121-
`createArray()` and `createObject()` with literal values.
113+
This example demonstrates wrapping a generated collection (like one from
114+
`createArray()` or `createObject()`) into an outer array.
122115

123116
```yaml
124117
# array.example.3.dsc.config.yaml
@@ -128,7 +121,8 @@ resources:
128121
type: Microsoft.DSC.Debug/Echo
129122
properties:
130123
output:
131-
combined: "[array(createArray('a','b'), array(1,2), createObject('k','v'))]"
124+
combinedArray: "[array(createArray('a','b'))]"
125+
combinedObject: "[array(createObject('k','v'))]"
132126
```
133127

134128
```bash
@@ -142,31 +136,31 @@ results:
142136
result:
143137
actualState:
144138
output:
145-
combined:
139+
combinedArray:
146140
- - a
147141
- b
148-
- - 1
149-
- 2
142+
combinedObject:
150143
- k: v
151144
messages: []
152145
hadErrors: false
153146
```
154147

155148
## Parameters
156149

157-
### element1, element2, ...
150+
### value
158151

159-
The elements to include in the array.
152+
The single value to wrap in the array.
160153

161154
```yaml
162155
Type: string, number, array, or object
163156
Required: false
164-
Multiplicity: 0 or more
157+
MinimumCount: 1
158+
MaximumCount: 1
165159
```
166160

167-
Each element provided as an argument will be added to the resulting array in the
168-
order specified. All elements must be one of the four accepted types: string,
169-
number (integer), array, or object. Boolean and null values are not supported.
161+
The provided value will be wrapped into the resulting array. The value must be
162+
one of the four accepted types: string, number (integer), array, or object.
163+
Boolean and null values are not supported.
170164

171165
## Output
172166

docs/reference/schemas/config/functions/first.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ hadErrors: false
109109
### Example 3 - Chain with array construction
110110
111111
This example shows how `first()` can be combined with `array()` to get the
112-
first element from a dynamically constructed array containing mixed data types.
112+
first element from a dynamically constructed array, by wrapping a single
113+
generated collection.
113114

114115
```yaml
115116
# first.example.3.dsc.config.yaml
@@ -119,7 +120,7 @@ resources:
119120
type: Microsoft.DSC.Debug/Echo
120121
properties:
121122
output:
122-
firstMixed: "[first(array(createArray('a','b'), createObject('k','v')))]"
123+
firstMixed: "[first(array(createArray('a','b')))]"
123124
```
124125

125126
```bash
@@ -133,9 +134,7 @@ results:
133134
result:
134135
actualState:
135136
output:
136-
firstMixed:
137-
- a
138-
- b
137+
firstMixed: a
139138
messages: []
140139
hadErrors: false
141140
```

docs/reference/schemas/config/functions/indexOf.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ resources:
9494
type: Microsoft.DSC.Debug/Echo
9595
properties:
9696
output:
97-
hasFeature: "[indexOf(array(createObject('name','Preview'), createObject('name','Beta')), createObject('name','Beta'))]"
97+
hasFeature: "[indexOf(array(createObject('name','Beta')), createObject('name','Beta'))]"
9898
```
9999
100100
```bash
@@ -108,7 +108,7 @@ results:
108108
result:
109109
actualState:
110110
output:
111-
hasFeature: 1
111+
hasFeature: 0
112112
messages: []
113113
hadErrors: false
114114
```

docs/reference/schemas/metadata/Microsoft.DSC/properties.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@ Metadata properties used and returned by DSC for configuration and resource oper
1313

1414
## Description
1515

16-
Blah
16+
The `Microsoft.DSC` metadata object captures execution details that DSC adds to
17+
command output and, when applicable, to resource results. It describes what
18+
operation ran, when it started and finished, how long it took, the security
19+
context DSC ran under, and the DSC version that produced the output. These
20+
properties are informational and help with diagnostics, auditing, and tooling.
21+
22+
Not every property is present for every operation. For example, `executionType`
23+
is only meaningful for `Set` (and is `WhatIf` when you invoke DSC with
24+
`--whatIf`), while `operation` is always provided. Timestamps use RFC 3339
25+
`date-time` format, and durations use the ISO 8601 `duration` format.
26+
27+
Consumers should tolerate additional, future metadata fields. Producers should
28+
preserve unknown metadata they do not interpret.
1729

1830
## Properties
1931

0 commit comments

Comments
 (0)