From a8c1876f8de9dcf6c58d07397f8cf88efe080db2 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Thu, 28 Mar 2024 10:06:22 -0700 Subject: [PATCH] Rename `requires` in DscResource schema to `requireAdapter` --- dsc/src/resource_command.rs | 10 +++++----- dsc/src/subcommand.rs | 2 +- dsc_lib/src/discovery/command_discovery.rs | 2 +- dsc_lib/src/dscresources/dscresource.rs | 5 +++-- powershell-adapter/powershell.resource.ps1 | 2 +- tools/test_group_resource/src/main.rs | 6 +++--- tools/test_group_resource/tests/provider.tests.ps1 | 6 +++--- wmi-adapter/wmi.resource.ps1 | 2 +- 8 files changed, 18 insertions(+), 17 deletions(-) diff --git a/dsc/src/resource_command.rs b/dsc/src/resource_command.rs index 181eb094..7123d7d3 100644 --- a/dsc/src/resource_command.rs +++ b/dsc/src/resource_command.rs @@ -22,7 +22,7 @@ pub fn get(dsc: &DscManager, resource_type: &str, mut input: String, format: &Op }; debug!("resource.type_name - {} implemented_as - {:?}", resource.type_name, resource.implemented_as); - if let Some(requires) = &resource.requires { + if let Some(requires) = &resource.require_adapter { input = add_type_name_to_json(input, resource.type_name.clone()); if let Some(pr) = get_resource(dsc, requires) { resource = pr; @@ -59,7 +59,7 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: &Option = None; - if let Some(requires) = &dsc_resource.requires { + if let Some(requires) = &dsc_resource.require_adapter { input = add_type_name_to_json(input, dsc_resource.type_name.clone()); if let Some(pr) = get_resource(dsc, requires) { adapter_resource = Some(pr); diff --git a/dsc/src/subcommand.rs b/dsc/src/subcommand.rs index 9f87bdaf..659fe8e5 100644 --- a/dsc/src/subcommand.rs +++ b/dsc/src/subcommand.rs @@ -455,7 +455,7 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option) { format!("{:?}", resource.kind), resource.version, capabilities, - resource.requires.unwrap_or_default(), + resource.require_adapter.unwrap_or_default(), resource.description.unwrap_or_default() ]); } diff --git a/dsc_lib/src/discovery/command_discovery.rs b/dsc_lib/src/discovery/command_discovery.rs index 99a5c2eb..29a45645 100644 --- a/dsc_lib/src/discovery/command_discovery.rs +++ b/dsc_lib/src/discovery/command_discovery.rs @@ -182,7 +182,7 @@ impl CommandDiscovery { for line in stdout.lines() { match serde_json::from_str::(line){ Result::Ok(resource) => { - if resource.requires.is_none() { + if resource.require_adapter.is_none() { if return_all_resources { warn!("{}", DscError::MissingRequires(adapter.clone(), resource.type_name.clone()).to_string()); } else { diff --git a/dsc_lib/src/dscresources/dscresource.rs b/dsc_lib/src/dscresources/dscresource.rs index 1a588d76..ad7e3629 100644 --- a/dsc_lib/src/dscresources/dscresource.rs +++ b/dsc_lib/src/dscresources/dscresource.rs @@ -36,7 +36,8 @@ pub struct DscResource { /// The properties of the resource. pub properties: Vec, /// The required resource adapter for the resource. - pub requires: Option, + #[serde(rename="requireAdapter")] + pub require_adapter: Option, /// The manifest of the resource. pub manifest: Option, } @@ -72,7 +73,7 @@ impl DscResource { implemented_as: ImplementedAs::Command, author: None, properties: Vec::new(), - requires: None, + require_adapter: None, manifest: None, } } diff --git a/powershell-adapter/powershell.resource.ps1 b/powershell-adapter/powershell.resource.ps1 index 3b93d543..ca3a7b90 100644 --- a/powershell-adapter/powershell.resource.ps1 +++ b/powershell-adapter/powershell.resource.ps1 @@ -136,7 +136,7 @@ if ($Operation -eq 'List') implementedAs = $r.ImplementationDetail; author = $author_string; properties = $propertyList; - requires = $requiresString + requireAdapter = $requiresString } $z | ConvertTo-Json -Compress diff --git a/tools/test_group_resource/src/main.rs b/tools/test_group_resource/src/main.rs index a70d1dfb..b7e2b3ea 100644 --- a/tools/test_group_resource/src/main.rs +++ b/tools/test_group_resource/src/main.rs @@ -23,7 +23,7 @@ fn main() { directory: "test_directory".to_string(), author: Some("Microsoft".to_string()), properties: vec!["Property1".to_string(), "Property2".to_string()], - requires: Some("Test/TestGroup".to_string()), + require_adapter: Some("Test/TestGroup".to_string()), manifest: Some(serde_json::to_value(ResourceManifest { description: Some("This is a test resource.".to_string()), schema_version: dsc_lib::dscresources::resource_manifest::ManifestSchemaUri::Version2023_10, @@ -56,7 +56,7 @@ fn main() { directory: "test_directory".to_string(), author: Some("Microsoft".to_string()), properties: vec!["Property1".to_string(), "Property2".to_string()], - requires: Some("Test/TestGroup".to_string()), + require_adapter: Some("Test/TestGroup".to_string()), manifest: Some(serde_json::to_value(ResourceManifest { description: Some("This is a test resource.".to_string()), schema_version: dsc_lib::dscresources::resource_manifest::ManifestSchemaUri::Version2023_10, @@ -93,7 +93,7 @@ fn main() { directory: "test_directory".to_string(), author: Some("Microsoft".to_string()), properties: vec!["Property1".to_string(), "Property2".to_string()], - requires: None, + require_adapter: None, manifest: None, }; println!("{}", serde_json::to_string(&resource1).unwrap()); diff --git a/tools/test_group_resource/tests/provider.tests.ps1 b/tools/test_group_resource/tests/provider.tests.ps1 index c977b7f9..141f6118 100644 --- a/tools/test_group_resource/tests/provider.tests.ps1 +++ b/tools/test_group_resource/tests/provider.tests.ps1 @@ -11,15 +11,15 @@ Describe 'Resource adapter tests' { $out[0].version | Should -Be '1.0.0' $out[0].path | Should -BeExactly 'test_resource1' $out[0].implementedas | Should -BeExactly 'TestResource' - $out[0].requires | Should -BeExactly 'Test/TestGroup' + $out[0].requireAdapter | Should -BeExactly 'Test/TestGroup' $out[1].type | Should -BeExactly 'Test/TestResource2' $out[1].version | Should -Be '1.0.1' $out[1].path | Should -BeExactly 'test_resource2' $out[1].implementedas | Should -BeExactly 'TestResource' - $out[1].requires | Should -BeExactly 'Test/TestGroup' + $out[1].requireAdapter | Should -BeExactly 'Test/TestGroup' } - It 'Error if adapter resource is missing "requires" member' { + It 'Error if adapter resource is missing "requireAdapter" member' { $invalid_manifest = @' { "$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/bundled/resource/manifest.json", diff --git a/wmi-adapter/wmi.resource.ps1 b/wmi-adapter/wmi.resource.ps1 index d4c3ea49..f51d628f 100644 --- a/wmi-adapter/wmi.resource.ps1 +++ b/wmi-adapter/wmi.resource.ps1 @@ -55,7 +55,7 @@ if ($Operation -eq 'List') implementedAs = ""; author = $author_string; properties = $propertyList; - requires = $requiresString + requireAdapter = $requiresString } $z | ConvertTo-Json -Compress