From 08b832bad4e133e12f28507fb9cba383ebe129f7 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Mon, 13 Jan 2025 13:34:05 -0800 Subject: [PATCH] Add support for `contentVersion` property --- dsc/tests/dsc_config_get.tests.ps1 | 19 +++++++++++++++++++ dsc/tests/dsc_export.tests.ps1 | 3 +++ dsc_lib/src/configure/config_doc.rs | 12 ++++-------- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/dsc/tests/dsc_config_get.tests.ps1 b/dsc/tests/dsc_config_get.tests.ps1 index b5c248ee..14adb978 100644 --- a/dsc/tests/dsc_config_get.tests.ps1 +++ b/dsc/tests/dsc_config_get.tests.ps1 @@ -55,4 +55,23 @@ Describe 'dsc config get tests' { $result.metadata.'Microsoft.DSC'.securityContext | Should -Not -BeNullOrEmpty $LASTEXITCODE | Should -Be 0 } + + It 'contentVersion is ignored' { + $config_yaml = @" + `$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json + contentVersion: 1.0.0.0 + resources: + - name: Echo + type: Microsoft.DSC.Debug/Echo + properties: + output: hello +"@ + $result = $config_yaml | dsc config get -f - | ConvertFrom-Json + $result.hadErrors | Should -BeFalse + $result.results.Count | Should -Be 1 + $result.results[0].Name | Should -Be 'Echo' + $result.results[0].type | Should -BeExactly 'Microsoft.DSC.Debug/Echo' + $result.results[0].result.actualState.output | Should -Be 'hello' + $LASTEXITCODE | Should -Be 0 + } } diff --git a/dsc/tests/dsc_export.tests.ps1 b/dsc/tests/dsc_export.tests.ps1 index a0dd47aa..179b104a 100644 --- a/dsc/tests/dsc_export.tests.ps1 +++ b/dsc/tests/dsc_export.tests.ps1 @@ -26,6 +26,7 @@ Describe 'resource export tests' { $yaml = @' $schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json + contentVersion: 1.2.3 resources: - name: Processes type: Microsoft/Process @@ -39,6 +40,8 @@ Describe 'resource export tests' { $config_with_process_list.'resources' | Should -Not -BeNullOrEmpty $config_with_process_list.resources.count | Should -BeGreaterThan 1 $config_with_process_list.metadata.'Microsoft.DSC'.operation | Should -BeExactly 'Export' + # contentVersion on export is always 1.0.0 + $config_with_process_list.contentVersion | Should -BeExactly '1.0.0' } It 'Configuration Export can be piped to configuration Set' -Skip:(!$IsWindows) { diff --git a/dsc_lib/src/configure/config_doc.rs b/dsc_lib/src/configure/config_doc.rs index ceb4ea84..19d27d54 100644 --- a/dsc_lib/src/configure/config_doc.rs +++ b/dsc_lib/src/configure/config_doc.rs @@ -72,7 +72,8 @@ pub struct Metadata { pub struct Configuration { #[serde(rename = "$schema")] pub schema: DocumentSchemaUri, - // `contentVersion` is required by ARM, but doesn't serve a purpose here + #[serde(rename = "contentVersion")] + pub content_version: Option, #[serde(skip_serializing_if = "Option::is_none")] pub parameters: Option>, #[serde(skip_serializing_if = "Option::is_none")] @@ -164,13 +165,7 @@ pub enum DocumentSchemaUri { impl Default for Configuration { fn default() -> Self { - Self { - schema: DocumentSchemaUri::Version2024_04, - parameters: None, - variables: None, - resources: Vec::new(), - metadata: None, - } + Self::new() } } @@ -179,6 +174,7 @@ impl Configuration { pub fn new() -> Self { Self { schema: DocumentSchemaUri::Version2024_04, + content_version: Some("1.0.0".to_string()), parameters: None, variables: None, resources: Vec::new(),