Skip to content

Commit c2fa7da

Browse files
authored
Merge pull request #199 from SteveL-MSFT/manifest-version
change ManifestVersion to $schema and validate
2 parents 57f2e89 + af2d284 commit c2fa7da

17 files changed

+69
-42
lines changed

dsc/assertion.dsc.resource.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"manifestVersion": "1.0",
2+
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/bundled/resource/manifest.json",
33
"type": "DSC/AssertionGroup",
44
"version": "0.1.0",
55
"description": "`test` will be invoked for all resources in the supplied configuration.",

dsc/group.dsc.resource.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"manifestVersion": "1.0",
2+
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/bundled/resource/manifest.json",
33
"type": "DSC/Group",
44
"version": "0.1.0",
55
"description": "All resources in the supplied configuration is treated as a group.",

dsc/parallel.dsc.resource.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"manifestVersion": "1.0",
2+
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/bundled/resource/manifest.json",
33
"type": "DSC/ParallelGroup",
44
"version": "0.1.0",
55
"description": "All resources in the supplied configuration run concurrently.",

dsc/src/subcommand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use dsc_lib::{
1111
configure::{Configurator, ErrorAction},
1212
DscManager,
1313
dscresources::dscresource::{ImplementedAs, Invoke},
14-
dscresources::resource_manifest::ResourceManifest,
14+
dscresources::resource_manifest::{import_manifest, ResourceManifest},
1515
};
1616
use jsonschema::{JSONSchema, ValidationError};
1717
use serde_yaml::Value;
@@ -321,7 +321,7 @@ pub fn resource(subcommand: &ResourceSubCommand, format: &Option<OutputFormat>,
321321
let Some(ref resource_manifest) = resource.manifest else {
322322
continue;
323323
};
324-
let manifest = match serde_json::from_value::<ResourceManifest>(resource_manifest.clone()) {
324+
let manifest = match import_manifest(resource_manifest.clone()) {
325325
Ok(resource_manifest) => resource_manifest,
326326
Err(err) => {
327327
eprintln!("Error in manifest for {0}: {err}", resource.type_name);

dsc/tests/dsc_discovery.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Describe 'tests for resource discovery' {
55
It 'Use DSC_RESOURCE_PATH instead of PATH when defined' {
66
$resourceJson = @'
77
{
8-
"manifestVersion": "1.0",
8+
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/bundled/resource/manifest.json",
99
"type": "DSC/TestPathResource",
1010
"version": "0.1.0",
1111
"get": {

dsc/tests/dsc_resource_input.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Describe 'tests for resource input' {
55
BeforeAll {
66
$manifest = @'
77
{
8-
"manifestVersion": "1.0.0",
8+
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/bundled/resource/manifest.json",
99
"type": "Test/EnvVarInput",
1010
"version": "0.1.0",
1111
"get": {

dsc/tests/dsc_set.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Describe 'config set tests' {
7070
It 'set can be used on a resource that does not implement test' {
7171
$manifest = @'
7272
{
73-
"manifestVersion": "1.0.0",
73+
"$schema": "https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/bundled/resource/manifest.json",
7474
"type": "Test/SetNoTest",
7575
"version": "0.1.0",
7676
"get": {

dsc_lib/src/discovery/command_discovery.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
use crate::discovery::discovery_trait::{ResourceDiscovery};
4+
use crate::discovery::discovery_trait::ResourceDiscovery;
55
use crate::dscresources::dscresource::{DscResource, ImplementedAs};
6-
use crate::dscresources::resource_manifest::ResourceManifest;
6+
use crate::dscresources::resource_manifest::{ResourceManifest, import_manifest};
77
use crate::dscresources::command_resource::invoke_command;
88
use crate::dscerror::{DscError, StreamMessage, StreamMessageType};
99
use std::collections::BTreeMap;
@@ -71,9 +71,9 @@ impl ResourceDiscovery for CommandDiscovery {
7171
if path.is_file() {
7272
let file_name = path.file_name().unwrap().to_str().unwrap();
7373
if file_name.to_lowercase().ends_with(".dsc.resource.json") {
74-
let resource = import_manifest(&path)?;
74+
let resource = load_manifest(&path)?;
7575
if resource.manifest.is_some() {
76-
let manifest = serde_json::from_value::<ResourceManifest>(resource.manifest.clone().unwrap())?;
76+
let manifest = import_manifest(resource.manifest.clone().unwrap())?;
7777
if manifest.provider.is_some() {
7878
self.provider_resources.push(resource.type_name.clone());
7979
}
@@ -90,7 +90,7 @@ impl ResourceDiscovery for CommandDiscovery {
9090
let provider_resource = self.resources.get(provider).unwrap();
9191
let provider_type_name = provider_resource.type_name.clone();
9292
let provider_path = provider_resource.path.clone();
93-
let manifest = serde_json::from_value::<ResourceManifest>(provider_resource.manifest.clone().unwrap())?;
93+
let manifest = import_manifest(provider_resource.manifest.clone().unwrap())?;
9494
// invoke the list command
9595
let list_command = manifest.provider.unwrap().list;
9696
let (exit_code, stdout, stderr) = match invoke_command(&list_command.executable, list_command.args, None, Some(&provider_resource.directory), None)
@@ -151,7 +151,7 @@ impl ResourceDiscovery for CommandDiscovery {
151151
}
152152
}
153153

154-
fn import_manifest(path: &Path) -> Result<DscResource, DscError> {
154+
fn load_manifest(path: &Path) -> Result<DscResource, DscError> {
155155
let file = File::open(path)?;
156156
let reader = BufReader::new(file);
157157
let manifest: ResourceManifest = match serde_json::from_reader(reader) {

dsc_lib/src/dscerror.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ pub enum DscError {
2525
#[error("Invalid configuration:\n{0}")]
2626
InvalidConfiguration(String),
2727

28+
#[error("Unsupported manifest version: {0}. Must be: {1}")]
29+
InvalidManifestSchemaVersion(String, String),
30+
2831
#[error("IO: {0}")]
2932
Io(#[from] std::io::Error),
3033

@@ -107,15 +110,15 @@ impl StreamMessage {
107110
}
108111

109112
/// Create a new error message
110-
///
113+
///
111114
/// # Arguments
112-
///
115+
///
113116
/// * `message` - The message to display
114117
/// * `resource_type_name` - The name of the resource type
115118
/// * `resource_path` - The path to the resource
116-
///
119+
///
117120
/// # Returns
118-
///
121+
///
119122
/// * `StreamMessage` - The new message
120123
#[must_use]
121124
pub fn new_error(message: String, resource_type_name: Option<String>, resource_path: Option<String>) -> StreamMessage {
@@ -129,15 +132,15 @@ impl StreamMessage {
129132
}
130133

131134
/// Create a new warning message
132-
///
135+
///
133136
/// # Arguments
134-
///
137+
///
135138
/// * `message` - The message to display
136139
/// * `resource_type_name` - The name of the resource type
137140
/// * `resource_path` - The path to the resource
138-
///
141+
///
139142
/// # Returns
140-
///
143+
///
141144
/// * `StreamMessage` - The new message
142145
#[must_use]
143146
pub fn new_warning(message: String, resource_type_name: Option<String>, resource_path: Option<String>) -> StreamMessage {
@@ -151,14 +154,14 @@ impl StreamMessage {
151154
}
152155

153156
/// Print the message to the console
154-
///
157+
///
155158
/// # Arguments
156-
///
159+
///
157160
/// * `error_format` - The format to use for error messages
158161
/// * `warning_format` - The format to use for warning messages
159-
///
162+
///
160163
/// # Errors
161-
///
164+
///
162165
/// * `DscError` - If there is an error writing to the console
163166
pub fn print(&self, error_format:&StreamMessageType, warning_format:&StreamMessageType) -> Result<(), DscError>{
164167
if self.message_type == StreamMessageType::Error

dsc_lib/src/dscresources/dscresource.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
// Licensed under the MIT License.
33

44
use dscerror::DscError;
5-
use resource_manifest::ResourceManifest;
65
use schemars::JsonSchema;
76
use serde::{Deserialize, Serialize};
87
use serde_json::Value;
9-
use super::{command_resource, dscerror, resource_manifest, invoke_result::{GetResult, SetResult, TestResult, ValidateResult, ExportResult}};
8+
use super::{command_resource, dscerror, resource_manifest::import_manifest, invoke_result::{GetResult, SetResult, TestResult, ValidateResult, ExportResult}};
109

1110
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
1211
#[serde(deny_unknown_fields)]
@@ -140,7 +139,7 @@ impl Invoke for DscResource {
140139
let Some(manifest) = &self.manifest else {
141140
return Err(DscError::MissingManifest(self.type_name.clone()));
142141
};
143-
let resource_manifest = serde_json::from_value::<ResourceManifest>(manifest.clone())?;
142+
let resource_manifest = import_manifest(manifest.clone())?;
144143
command_resource::invoke_get(&resource_manifest, &self.directory, filter)
145144
},
146145
}
@@ -155,7 +154,7 @@ impl Invoke for DscResource {
155154
let Some(manifest) = &self.manifest else {
156155
return Err(DscError::MissingManifest(self.type_name.clone()));
157156
};
158-
let resource_manifest = serde_json::from_value::<ResourceManifest>(manifest.clone())?;
157+
let resource_manifest = import_manifest(manifest.clone())?;
159158
command_resource::invoke_set(&resource_manifest, &self.directory, desired, skip_test)
160159
},
161160
}
@@ -172,7 +171,7 @@ impl Invoke for DscResource {
172171
};
173172

174173
// if test is not directly implemented, then we need to handle it here
175-
let resource_manifest = serde_json::from_value::<ResourceManifest>(manifest.clone())?;
174+
let resource_manifest = import_manifest(manifest.clone())?;
176175
if resource_manifest.test.is_none() {
177176
let get_result = self.get(expected)?;
178177
let desired_state = serde_json::from_str(expected)?;
@@ -201,7 +200,7 @@ impl Invoke for DscResource {
201200
let Some(manifest) = &self.manifest else {
202201
return Err(DscError::MissingManifest(self.type_name.clone()));
203202
};
204-
let resource_manifest = serde_json::from_value::<ResourceManifest>(manifest.clone())?;
203+
let resource_manifest = import_manifest(manifest.clone())?;
205204
command_resource::invoke_validate(&resource_manifest, &self.directory, config)
206205
},
207206
}
@@ -216,7 +215,7 @@ impl Invoke for DscResource {
216215
let Some(manifest) = &self.manifest else {
217216
return Err(DscError::MissingManifest(self.type_name.clone()));
218217
};
219-
let resource_manifest = serde_json::from_value::<ResourceManifest>(manifest.clone())?;
218+
let resource_manifest = import_manifest(manifest.clone())?;
220219
command_resource::get_schema(&resource_manifest, &self.directory)
221220
},
222221
}
@@ -231,7 +230,7 @@ impl Invoke for DscResource {
231230
let Some(manifest) = &self.manifest else {
232231
return Err(DscError::MissingManifest(self.type_name.clone()));
233232
};
234-
let resource_manifest = serde_json::from_value::<ResourceManifest>(manifest.clone())?;
233+
let resource_manifest = import_manifest(manifest.clone())?;
235234
command_resource::invoke_export(&resource_manifest, &self.directory)
236235
},
237236
}

0 commit comments

Comments
 (0)