diff --git a/dsc/tests/dsc_armv2.tests.ps1 b/dsc/tests/dsc_armv2.tests.ps1 deleted file mode 100644 index 195212c21..000000000 --- a/dsc/tests/dsc_armv2.tests.ps1 +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. - -Describe 'ARM Language 2.0 tests' { - It 'config with ARM Language 2.0 format works' { -<# -This JSON config built from the following Bicep code using the -desiredStateConfiguration and moduleExtensionConfigs experimental features: - -extension dsc -targetScope = 'desiredStateConfiguration' - -resource echoResource 'Microsoft.DSC.Debug/Echo@1.0.0' = { - output: 'Hello World' -} -#> - $configJson = @' -{ - "$schema": "https://aka.ms/dsc/schemas/v3/bundled/config/document.json", - "languageVersion": "2.2-experimental", - "contentVersion": "1.0.0.0", - "metadata": { - "_EXPERIMENTAL_WARNING": "This template uses ARM features that are experimental. Experimental features should be enabled for testing purposes only, as there are no guarantees about the quality or stability of these features. Do not enable these settings for any production usage, or your production environment may be subject to breaking.", - "_EXPERIMENTAL_FEATURES_ENABLED": [ - "Enable defining extension configs for modules" - ], - "_generator": { - "name": "bicep", - "version": "0.38.33.27573", - "templateHash": "5233252217641859406" - } - }, - "extensions": { - "dsc": { - "name": "DesiredStateConfiguration", - "version": "0.1.0" - } - }, - "resources": { - "echoResource": { - "extension": "dsc", - "type": "Microsoft.DSC.Debug/Echo", - "apiVersion": "1.0.0", - "properties": { - "output": "Hello World" - } - } - } -} -'@ - $out = dsc config get -i $configJson | ConvertFrom-Json -Depth 10 - $LASTEXITCODE | Should -Be 0 - $out.results | Should -HaveCount 1 - $out.results[0].type | Should -Be 'Microsoft.DSC.Debug/Echo' - $out.results[0].result.actualState.output | Should -Be 'Hello World' - } -} diff --git a/dsc/tests/dsc_copy.tests.ps1 b/dsc/tests/dsc_copy.tests.ps1 index 101f93408..3a50db26f 100644 --- a/dsc/tests/dsc_copy.tests.ps1 +++ b/dsc/tests/dsc_copy.tests.ps1 @@ -334,48 +334,4 @@ resources: $out.results[1].name | Should -Be 'Server-1' $out.results[1].result.actualState.output | Should -Be 'web-2' } - - It 'Symbolic name loop works' { - $configYaml = @' -$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json -languageVersion: 2.2-experimental -contentVersion: 1.0.0.0 -parameters: - basePath: - type: string - defaultValue: DSCBicepTests -variables: - items: - - A - - B - - C -extensions: - dsc: - name: DesiredStateConfiguration - version: 0.1.0 -resources: - simple_loop: - copy: - name: simple_loop - count: '[length(variables(''items''))]' - extension: dsc - type: Microsoft.DSC.Debug/Echo - properties: - output: '[format(''{0}\loops_simple_{1}'', parameters(''basePath''), variables(''items'')[copyIndex()])]' -outputs: - simpleLoopCount: - type: int - value: '[length(variables(''items''))]' -'@ - $out = dsc -l trace config get -i $configYaml 2>$testdrive/error.log | ConvertFrom-Json - $LASTEXITCODE | Should -Be 0 -Because (Get-Content $testdrive/error.log -Raw | Out-String) - $out.results.Count | Should -Be 3 - $out.results[0].name | Should -Be 'simple_loop' - $out.results[0].result.actualState.output | Should -Be 'DSCBicepTests\loops_simple_A' -Because ($out | ConvertTo-Json -Depth 10) - $out.results[1].name | Should -Be 'simple_loop' - $out.results[1].result.actualState.output | Should -Be 'DSCBicepTests\loops_simple_B' - $out.results[2].name | Should -Be 'simple_loop' - $out.results[2].result.actualState.output | Should -Be 'DSCBicepTests\loops_simple_C' - $out.outputs.simpleLoopCount | Should -Be 3 - } } diff --git a/lib/dsc-lib/src/configure/config_doc.rs b/lib/dsc-lib/src/configure/config_doc.rs index df960a538..dfec3a813 100644 --- a/lib/dsc-lib/src/configure/config_doc.rs +++ b/lib/dsc-lib/src/configure/config_doc.rs @@ -4,7 +4,7 @@ use chrono::{DateTime, Local}; use rust_i18n::t; use schemars::JsonSchema; -use serde::{Deserialize, Deserializer, Serialize}; +use serde::{Deserialize, Serialize}; use serde_json::{Map, Value}; use std::{collections::HashMap, fmt::Display}; @@ -181,11 +181,6 @@ pub struct Configuration { #[serde(rename = "$schema")] #[schemars(schema_with = "Configuration::recognized_schema_uris_subschema")] pub schema: String, - /// Irrelevant Bicep metadata from using the extension - /// TODO: Potentially check this as a feature flag. - #[serde(skip_serializing_if = "Option::is_none")] - #[serde(rename = "languageVersion")] - pub language_version: Option, #[serde(rename = "contentVersion")] pub content_version: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -196,53 +191,9 @@ pub struct Configuration { pub outputs: Option>, #[serde(skip_serializing_if = "Option::is_none")] pub parameters: Option>, - #[serde(deserialize_with = "deserialize_resources")] pub resources: Vec, #[serde(skip_serializing_if = "Option::is_none")] pub variables: Option>, - /// Irrelevant Bicep metadata from using the extension - #[serde(skip_serializing_if = "Option::is_none")] - pub imports: Option>, - #[serde(skip_serializing_if = "Option::is_none")] - pub extensions: Option>, -} - -/// Simplest implementation of a custom deserializer that will map a JSON object -/// of resources (where the keys are symbolic names) as found in ARMv2 back to a -/// vector, so the rest of this codebase can remain untouched. -fn deserialize_resources<'de, D>(deserializer: D) -> Result, D::Error> -where - D: Deserializer<'de>, -{ - let value = Value::deserialize(deserializer)?; - - match value { - Value::Array(resources) => { - resources.into_iter() - .map(|resource| serde_json::from_value::(resource).map_err(serde::de::Error::custom)) - .collect() - } - Value::Object(resources) => { - resources.into_iter() - .map(|(name, resource)| { - let mut resource = serde_json::from_value::(resource).map_err(serde::de::Error::custom)?; - // Note that this is setting the symbolic name as the - // resource's name property only if that isn't already set. - // In the general use case from Bicep, it won't be, but - // we're unsure of the implications in other use cases. - // - // TODO: We will need to update the 'dependsOn' logic to - // accept both the symbolic name as mapped here in addition - // to `resourceId()`, or possibly track both. - if resource.name.is_empty() { - resource.name = name; - } - Ok(resource) - }) - .collect() - } - other => Err(serde::de::Error::custom(format!("Expected resources to be either an array or an object, but was {:?}", other))), - } } #[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, DscRepoSchema)] @@ -419,11 +370,6 @@ pub struct Resource { pub resources: Option>, #[serde(skip_serializing_if = "Option::is_none")] pub metadata: Option, - /// Irrelevant Bicep metadata from using the extension - #[serde(skip_serializing_if = "Option::is_none")] - pub import: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub extension: Option, } impl Default for Configuration { @@ -437,7 +383,6 @@ impl Configuration { pub fn new() -> Self { Self { schema: Self::default_schema_id_uri(), - language_version: None, content_version: Some("1.0.0".to_string()), metadata: None, parameters: None, @@ -445,8 +390,6 @@ impl Configuration { functions: None, variables: None, outputs: None, - imports: None, - extensions: None, } } } @@ -472,8 +415,6 @@ impl Resource { location: None, tags: None, api_version: None, - import: None, - extension: None, } } } @@ -539,22 +480,6 @@ mod test { assert!(err.starts_with("unknown field `invalidField`, expected one of `condition`, `type`,")); } - #[test] - fn test_invalid_resource_field_in_object() { - let config_json = r#"{ - "resources": { - "someResource": { - "invalidField": "someValue" - } - } - }"#; - - let result: Result = serde_json::from_str(config_json); - assert!(result.is_err()); - let err = result.unwrap_err().to_string(); - assert!(err.starts_with("unknown field `invalidField`, expected one of `condition`, `type`,")); - } - #[test] fn test_invalid_resource_type_in_array() { let config_json = r#"{ @@ -569,20 +494,6 @@ mod test { assert!(err.contains("expected struct Resource")); } - #[test] - fn test_invalid_resource_type_in_object() { - let config_json = r#"{ - "resources": { - "someResource": "invalidType" - } - }"#; - - let result: Result = serde_json::from_str(config_json); - assert!(result.is_err()); - let err = result.unwrap_err().to_string(); - assert!(err.contains("expected struct Resource")); - } - #[test] fn test_resources_as_array() { let config_json = r#"{ @@ -613,49 +524,4 @@ mod test { assert_eq!(config.resources[1].api_version.as_deref(), Some("0.1.0")); } - #[test] - fn test_resources_with_symbolic_names() { - let config_json = r#"{ - "$schema": "https://aka.ms/dsc/schemas/v3/bundled/config/document.json", - "languageVersion": "2.2-experimental", - "extensions": { - "dsc": { - "name": "DesiredStateConfiguration", - "version": "0.1.0" - } - }, - "resources": { - "echoResource": { - "extension": "dsc", - "type": "Microsoft.DSC.Debug/Echo", - "apiVersion": "1.0.0", - "properties": { - "output": "Hello World" - } - }, - "processResource": { - "extension": "dsc", - "type": "Microsoft/Process", - "apiVersion": "0.1.0", - "properties": { - "name": "pwsh", - "pid": 1234 - } - } - } - }"#; - - let config: Configuration = serde_json::from_str(config_json).unwrap(); - assert_eq!(config.resources.len(), 2); - - // Find resources by name (order may vary in HashMap) - let echo_resource = config.resources.iter().find(|r| r.name == "echoResource").unwrap(); - let process_resource = config.resources.iter().find(|r| r.name == "processResource").unwrap(); - - assert_eq!(echo_resource.resource_type, "Microsoft.DSC.Debug/Echo"); - assert_eq!(echo_resource.api_version.as_deref(), Some("1.0.0")); - - assert_eq!(process_resource.resource_type, "Microsoft/Process"); - assert_eq!(process_resource.api_version.as_deref(), Some("0.1.0")); - } }