Skip to content

Commit 22c034b

Browse files
(GH-642) Ensure camelCase for items in dsc_lib
Prior to this change, the structs and enums in `dsc_lib` didn't consistently use camelCase - most property names and enum values use camelCase, but not all - and this inconsistency isn't predictable for end users, who need to consult the JSON Schemas to be sure. This change updates the definitions to rename the fields and values when serializing and deserializing, which also updates their JSON Schema. A future change is required to update the canonical schemas in the repository to match these updates.
1 parent 3963389 commit 22c034b

30 files changed

+58
-50
lines changed

configurations/windows/windows_baseline.dsc.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
33
metadata:
44
Microsoft.DSC:
5-
securityContext: Elevated
5+
securityContext: elevated
66
resources:
77
- name: Validate the OS is Windows
88
type: Microsoft.DSC/Assertion

dsc/assertion.dsc.resource.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "Microsoft.DSC/Assertion",
44
"version": "0.1.0",
55
"description": "`test` will be invoked for all resources in the supplied configuration.",
6-
"kind": "Group",
6+
"kind": "group",
77
"get": {
88
"executable": "dsc",
99
"args": [

dsc/examples/groups.dsc.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
33
metadata:
44
Microsoft.DSC:
5-
requiredSecurityContext: Current # this is the default and just used as an example indicating this config works for admins and non-admins
5+
requiredSecurityContext: current # this is the default and just used as an example indicating this config works for admins and non-admins
66
resources:
77
- name: Last Group
88
type: Microsoft.DSC/Group

dsc/examples/require_admin.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
55
metadata:
66
Microsoft.DSC:
7-
securityContext: Elevated
7+
securityContext: elevated
88
resources:
99
- name: os
1010
type: Microsoft/OSInfo

dsc/examples/require_nonadmin.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
44
metadata:
55
Microsoft.DSC:
6-
securityContext: Restricted
6+
securityContext: restricted
77
resources:
88
- name: os
99
type: Microsoft/OSInfo

dsc/examples/winps_script.dsc.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
22
metadata:
33
Microsoft.DSC:
4-
securityContext: Elevated
4+
securityContext: elevated
55
resources:
66
- type: Microsoft.Windows/WindowsPowerShell
77
name: Run WinPS script

dsc/group.dsc.resource.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "Microsoft.DSC/Group",
44
"version": "0.1.0",
55
"description": "All resources in the supplied configuration is treated as a group.",
6-
"kind": "Group",
6+
"kind": "group",
77
"get": {
88
"executable": "dsc",
99
"args": [

dsc/include.dsc.resource.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "Microsoft.DSC/Include",
44
"version": "0.1.0",
55
"description": "Allows including a configuration file with optional parameter file.",
6-
"kind": "Importer",
6+
"kind": "importer",
77
"get": {
88
"executable": "dsc",
99
"args": [

dsc/tests/dsc_args.tests.ps1

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ actualState:
9797
$resource = $obj | y2j | ConvertFrom-Json
9898
$resource | Should -Not -BeNullOrEmpty
9999
$resource.Type | Should -BeLike '*/*'
100-
$resource.Kind | Should -BeIn ('Resource', 'Group', 'Importer', 'Adapter')
100+
$resource.Kind | Should -BeIn ('resource', 'group', 'importer', 'adapter')
101101
}
102102
}
103103

@@ -242,7 +242,7 @@ resources:
242242
$a = dsc resource list '*' -a Test* -o json | ConvertFrom-Json
243243
foreach ($r in $a) {
244244
$r.requireAdapter.StartsWith("Test") | Should -Be $true
245-
$r.kind | Should -Be "Resource"
245+
$r.kind | Should -Be "resource"
246246
}
247247
}
248248

@@ -253,7 +253,7 @@ resources:
253253
$r = $a[0]
254254
$r.requireAdapter | Should -Not -BeNullOrEmpty
255255
$r.requireAdapter.StartsWith("Test") | Should -Be $true
256-
$r.kind | Should -Be "Resource"
256+
$r.kind | Should -Be "resource"
257257
}
258258

259259
It 'passing filepath to document arg should error' {

dsc/tests/dsc_config_get.tests.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ Describe 'dsc config get tests' {
4747
$result.results[0].type | Should -BeExactly 'Microsoft.DSC.Debug/Echo'
4848
$result.results[0].result.actualState.output | Should -Be 'hello'
4949
$result.metadata.'Microsoft.DSC'.version | Should -BeLike '3.*'
50-
$result.metadata.'Microsoft.DSC'.operation | Should -BeExactly 'Get'
51-
$result.metadata.'Microsoft.DSC'.executionType | Should -BeExactly 'Actual'
50+
$result.metadata.'Microsoft.DSC'.operation | Should -BeExactly 'get'
51+
$result.metadata.'Microsoft.DSC'.executionType | Should -BeExactly 'actual'
5252
$result.metadata.'Microsoft.DSC'.startDatetime | Should -Not -BeNullOrEmpty
5353
$result.metadata.'Microsoft.DSC'.endDatetime | Should -Not -BeNullOrEmpty
5454
$result.metadata.'Microsoft.DSC'.duration | Should -Not -BeNullOrEmpty

dsc/tests/dsc_config_set.tests.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Describe 'dsc config set tests' {
2929
$out.results[1].result.afterState.deleteCalled | Should -BeTrue
3030
$out.results[1].result.afterState._exist | Should -BeFalse
3131
$out.metadata.'Microsoft.DSC'.version | Should -BeLike '3.*'
32-
$out.metadata.'Microsoft.DSC'.operation | Should -BeExactly 'Set'
33-
$out.metadata.'Microsoft.DSC'.executionType | Should -BeExactly 'Actual'
32+
$out.metadata.'Microsoft.DSC'.operation | Should -BeExactly 'set'
33+
$out.metadata.'Microsoft.DSC'.executionType | Should -BeExactly 'actual'
3434
$out.metadata.'Microsoft.DSC'.startDatetime | Should -Not -BeNullOrEmpty
3535
$out.metadata.'Microsoft.DSC'.endDatetime | Should -Not -BeNullOrEmpty
3636
$out.metadata.'Microsoft.DSC'.duration | Should -Not -BeNullOrEmpty

dsc/tests/dsc_export.tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Describe 'resource export tests' {
3939
$config_with_process_list.'$schema' | Should -BeExactly 'https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json'
4040
$config_with_process_list.'resources' | Should -Not -BeNullOrEmpty
4141
$config_with_process_list.resources.count | Should -BeGreaterThan 1
42-
$config_with_process_list.metadata.'Microsoft.DSC'.operation | Should -BeExactly 'Export'
42+
$config_with_process_list.metadata.'Microsoft.DSC'.operation | Should -BeExactly 'export'
4343
# contentVersion on export is always 1.0.0
4444
$config_with_process_list.contentVersion | Should -BeExactly '1.0.0'
4545
}

dsc/tests/dsc_resource_list.tests.ps1

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Describe 'Tests for listing resources' {
1010
$resources.type | Should -Contain 'Microsoft.DSC/Assertion'
1111
$resources.type | Should -Contain 'Microsoft.DSC/Group'
1212
$resources.type | Should -Contain 'Microsoft/OSInfo'
13-
($resources | Where-Object { $_.type -eq 'Microsoft.DSC/Group' }).Kind | Should -BeExactly 'Group'
14-
($resources | Where-Object { $_.type -eq 'Microsoft/OSInfo' }).Kind | Should -BeExactly 'Resource'
15-
($resources | Where-Object { $_.type -eq 'Microsoft.DSC/PowerShell' }).Kind | Should -BeExactly 'Adapter'
13+
($resources | Where-Object { $_.type -eq 'Microsoft.DSC/Group' }).Kind | Should -BeExactly 'group'
14+
($resources | Where-Object { $_.type -eq 'Microsoft/OSInfo' }).Kind | Should -BeExactly 'resource'
15+
($resources | Where-Object { $_.type -eq 'Microsoft.DSC/PowerShell' }).Kind | Should -BeExactly 'adapter'
1616
}
1717

1818
It 'dsc resource list --tags "<tags>" and --description "<description> work' -TestCases @(
@@ -77,8 +77,8 @@ Describe 'Tests for listing resources' {
7777
$resource = dsc resource list Microsoft/OSInfo | ConvertFrom-Json
7878
$LASTEXITCODE | Should -Be 0
7979
$resource.capabilities.Count | Should -Be 2
80-
$resource.capabilities | Should -Contain 'Get'
81-
$resource.capabilities | Should -Contain 'Export'
80+
$resource.capabilities | Should -Contain 'get'
81+
$resource.capabilities | Should -Contain 'export'
8282
}
8383

8484
It 'Invalid adapter returns an error' {

dsc/tests/dsc_whatif.tests.ps1

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Describe 'whatif tests' {
1616
"@
1717
$what_if_result = $config_yaml | dsc config set -w -f - | ConvertFrom-Json
1818
$set_result = $config_yaml | dsc config set -f - | ConvertFrom-Json
19-
$what_if_result.metadata.'Microsoft.DSC'.executionType | Should -BeExactly 'WhatIf'
19+
$what_if_result.metadata.'Microsoft.DSC'.executionType | Should -BeExactly 'whatIf'
2020
$what_if_result.results.result.beforeState.output | Should -Be $set_result.results.result.beforeState.output
2121
$what_if_result.results.result.afterState.output | Should -Be $set_result.results.result.afterState.output
2222
$what_if_result.results.result.changedProperties | Should -Be $set_result.results.result.changedProperties
@@ -37,7 +37,7 @@ Describe 'whatif tests' {
3737
"@
3838
$what_if_result = dsc config set -w -i $config_yaml | ConvertFrom-Json
3939
$set_result = dsc config set -i $config_yaml | ConvertFrom-Json
40-
$what_if_result.metadata.'Microsoft.DSC'.executionType | Should -BeExactly 'WhatIf'
40+
$what_if_result.metadata.'Microsoft.DSC'.executionType | Should -BeExactly 'whatIf'
4141
$what_if_result.results.result.beforeState._exist | Should -Be $set_result.results.result.beforeState._exist
4242
$what_if_result.results.result.beforeState.keyPath | Should -Be $set_result.results.result.beforeState.keyPath
4343
$what_if_result.results.result.afterState.KeyPath | Should -Be $set_result.results.result.afterState.keyPath
@@ -80,7 +80,7 @@ Describe 'whatif tests' {
8080
executionType: Actual
8181
"@
8282
$result = $config_yaml | dsc config set -f - | ConvertFrom-Json
83-
$result.metadata.'Microsoft.DSC'.executionType | Should -BeExactly 'Actual'
83+
$result.metadata.'Microsoft.DSC'.executionType | Should -BeExactly 'actual'
8484
$result.results.result.afterState.executionType | Should -BeExactly 'Actual'
8585
$result.results.result.changedProperties | Should -Be $null
8686
$result.hadErrors | Should -BeFalse
@@ -98,7 +98,7 @@ Describe 'whatif tests' {
9898
executionType: Actual
9999
"@
100100
$result = $config_yaml | dsc config set -w -f - | ConvertFrom-Json
101-
$result.metadata.'Microsoft.DSC'.executionType | Should -BeExactly 'WhatIf'
101+
$result.metadata.'Microsoft.DSC'.executionType | Should -BeExactly 'whatIf'
102102
$result.results.result.afterState.executionType | Should -BeExactly 'WhatIf'
103103
$result.results.result.changedProperties | Should -BeExactly 'executionType'
104104
$result.hadErrors | Should -BeFalse

dsc_lib/src/configure/config_doc.rs

+4
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@ use serde_json::{Map, Value};
77
use std::{collections::HashMap, hash::Hash};
88

99
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
10+
#[serde(rename_all = "camelCase")]
1011
pub enum ContextKind {
1112
Configuration,
1213
Resource,
1314
}
1415

1516
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
17+
#[serde(rename_all = "camelCase")]
1618
pub enum SecurityContextKind {
1719
Current,
1820
Elevated,
1921
Restricted,
2022
}
2123

2224
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
25+
#[serde(rename_all = "camelCase")]
2326
pub enum Operation {
2427
Get,
2528
Set,
@@ -28,6 +31,7 @@ pub enum Operation {
2831
}
2932

3033
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
34+
#[serde(rename_all = "camelCase")]
3135
pub enum ExecutionKind {
3236
Actual,
3337
WhatIf,

dsc_lib/src/configure/config_progress.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct ConfigurationResourceStartedEvent {
1212
}
1313

1414
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
15+
#[serde(rename_all = "camelCase")]
1516
pub enum ConfigurationResourceCompletionStatus {
1617
Success,
1718
Failure,

dsc_lib/src/configure/config_result.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::dscresources::invoke_result::{GetResult, SetResult, TestResult};
77
use crate::configure::config_doc::{Configuration, Metadata};
88

99
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
10+
#[serde(rename_all = "camelCase")]
1011
pub enum MessageLevel {
1112
Error,
1213
Warning,

dsc_lib/src/dscresources/dscresource.rs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub struct DscResource {
4545
}
4646

4747
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, JsonSchema)]
48+
#[serde(rename_all = "camelCase")]
4849
pub enum Capability {
4950
/// The resource supports retrieving configuration.
5051
Get,

dsc_lib/src/dscresources/resource_manifest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::collections::HashMap;
1010
use crate::dscerror::DscError;
1111

1212
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
13+
#[serde(rename_all = "camelCase")]
1314
pub enum Kind {
1415
Adapter,
1516
Group,

powershell-adapter/Tests/PSTestModule/1.0.0/PSTestModule.psd1

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'PSEdition_Core',
2222
'Linux',
2323
'Mac')
24-
DscCapabilities = @('Get', 'Test')
24+
DscCapabilities = @('get', 'test')
2525
}
2626
}
2727
}

powershell-adapter/Tests/TestAdapter/testadapter.dsc.resource.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/bundled/resource/manifest.json",
33
"type": "Test/TestAdapter",
44
"version": "0.1.0",
5-
"kind": "Adapter",
5+
"kind": "adapter",
66
"description": "Resource adapter for testing.",
77
"tags": [
88
"PowerShell"

powershell-adapter/Tests/TestAdapter/testadapter.resource.ps1

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ switch ($Operation) {
3636
'List' {
3737
@{
3838
type = "Test/TestCase"
39-
kind = 'Resource'
39+
kind = 'resource'
4040
version = '1'
41-
capabilities = @('Get', 'Set', 'Test', 'Export')
41+
capabilities = @('get', 'set', 'test', 'export')
4242
path = $PSScriptRoot
4343
directory = Split-Path $PSScriptRoot
44-
implementedAs = 'Adapter'
44+
implementedAs = 'adapter'
4545
author = 'Test'
4646
properties = @('TestCaseId', 'Input', 'Result')
4747
requireAdapter = 'Test/TestAdapter'

powershell-adapter/Tests/TestClassResource/0.0.1/TestClassResource.psd1

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ DscResourcesToExport = @('TestClassResource', 'NoExport')
4040
PrivateData = @{
4141
PSData = @{
4242
DscCapabilities = @(
43-
'Get'
44-
'Test'
43+
'get'
44+
'test'
4545
)
4646
}
4747
}

powershell-adapter/powershell.dsc.resource.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/bundled/resource/manifest.json",
33
"type": "Microsoft.DSC/PowerShell",
44
"version": "0.1.0",
5-
"kind": "Adapter",
5+
"kind": "adapter",
66
"description": "Resource adapter to classic DSC Powershell resources.",
77
"tags": [
88
"PowerShell"

powershell-adapter/psDscAdapter/powershell.resource.ps1

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Write-DscTrace {
1818
[string]$Message
1919
)
2020

21-
$trace = @{$Operation = $Message } | ConvertTo-Json -Compress
21+
$trace = @{$Operation.ToLower() = $Message } | ConvertTo-Json -Compress
2222
$host.ui.WriteErrorLine($trace)
2323
}
2424

@@ -47,7 +47,7 @@ if ($Operation -eq 'ClearCache') {
4747

4848
if ('Validate' -ne $Operation) {
4949
# write $jsonInput to STDERR for debugging
50-
$trace = @{'Debug' = 'jsonInput=' + $jsonInput } | ConvertTo-Json -Compress
50+
$trace = @{'debug' = 'jsonInput=' + $jsonInput } | ConvertTo-Json -Compress
5151
$host.ui.WriteErrorLine($trace)
5252

5353
# load private functions of psDscAdapter stub module
@@ -92,7 +92,7 @@ switch ($Operation) {
9292
$capabilities = $module.PrivateData.PSData.DscCapabilities
9393
}
9494
else {
95-
$capabilities = @('Get', 'Set', 'Test')
95+
$capabilities = @('get', 'set', 'test')
9696
}
9797
}
9898

@@ -119,7 +119,7 @@ switch ($Operation) {
119119
# OUTPUT dsc is expecting the following properties
120120
[resourceOutput]@{
121121
type = $dscResource.Type
122-
kind = 'Resource'
122+
kind = 'resource'
123123
version = [string]$DscResourceInfo.version
124124
capabilities = $capabilities
125125
path = $DscResourceInfo.Path
@@ -135,22 +135,22 @@ switch ($Operation) {
135135
{ @('Get','Set','Test','Export') -contains $_ } {
136136
$desiredState = $psDscAdapter.invoke( { param($jsonInput) Get-DscResourceObject -jsonInput $jsonInput }, $jsonInput )
137137
if ($null -eq $desiredState) {
138-
$trace = @{'Debug' = 'ERROR: Failed to create configuration object from provided input JSON.' } | ConvertTo-Json -Compress
138+
$trace = @{'debug' = 'ERROR: Failed to create configuration object from provided input JSON.' } | ConvertTo-Json -Compress
139139
$host.ui.WriteErrorLine($trace)
140140
exit 1
141141
}
142142

143143
# only need to cache the resources that are used
144144
$dscResourceModules = $desiredState | ForEach-Object { $_.Type.Split('/')[0] }
145145
if ($null -eq $dscResourceModules) {
146-
$trace = @{'Debug' = 'ERROR: Could not get list of DSC resource types from provided JSON.' } | ConvertTo-Json -Compress
146+
$trace = @{'debug' = 'ERROR: Could not get list of DSC resource types from provided JSON.' } | ConvertTo-Json -Compress
147147
$host.ui.WriteErrorLine($trace)
148148
exit 1
149149
}
150150

151151
$dscResourceCache = Invoke-DscCacheRefresh -module $dscResourceModules
152152
if ($dscResourceCache.count -lt $dscResourceModules.count) {
153-
$trace = @{'Debug' = 'ERROR: DSC resource module not found.' } | ConvertTo-Json -Compress
153+
$trace = @{'debug' = 'ERROR: DSC resource module not found.' } | ConvertTo-Json -Compress
154154
$host.ui.WriteErrorLine($trace)
155155
exit 1
156156
}
@@ -159,7 +159,7 @@ switch ($Operation) {
159159
# process the INPUT (desiredState) for each resource as dscresourceInfo and return the OUTPUT as actualState
160160
$actualState = $psDscAdapter.invoke( { param($op, $ds, $dscResourceCache) Invoke-DscOperation -Operation $op -DesiredState $ds -dscResourceCache $dscResourceCache }, $Operation, $ds, $dscResourceCache)
161161
if ($null -eq $actualState) {
162-
$trace = @{'Debug' = 'ERROR: Incomplete GET for resource ' + $ds.Name } | ConvertTo-Json -Compress
162+
$trace = @{'debug' = 'ERROR: Incomplete GET for resource ' + $ds.Name } | ConvertTo-Json -Compress
163163
$host.ui.WriteErrorLine($trace)
164164
exit 1
165165
}
@@ -168,7 +168,7 @@ switch ($Operation) {
168168

169169
# OUTPUT json to stderr for debug, and to stdout
170170
$result = @{ result = $result } | ConvertTo-Json -Depth 10 -Compress
171-
$trace = @{'Debug' = 'jsonOutput=' + $result } | ConvertTo-Json -Compress
171+
$trace = @{'debug' = 'jsonOutput=' + $result } | ConvertTo-Json -Compress
172172
$host.ui.WriteErrorLine($trace)
173173
return $result
174174
}

powershell-adapter/windowspowershell.dsc.resource.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/bundled/resource/manifest.json",
33
"type": "Microsoft.Windows/WindowsPowerShell",
44
"version": "0.1.0",
5-
"kind": "Adapter",
5+
"kind": "adapter",
66
"description": "Resource adapter to classic DSC Powershell resources in Windows PowerShell.",
77
"tags": [
88
"PowerShell"

0 commit comments

Comments
 (0)