Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dsc/src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ pub fn validate_config(config: &Configuration, progress_format: ProgressFormat)
let Some(type_name) = resource_block["type"].as_str() else {
return Err(DscError::Validation(t!("subcommand.resourceTypeNotSpecified").to_string()));
};
resource_types.push(DiscoveryFilter::new(type_name, resource_block["api_version"].as_str(), None));
resource_types.push(DiscoveryFilter::new(type_name, resource_block["requireVersion"].as_str(), None));
}
dsc.find_resources(&resource_types, progress_format)?;

Expand All @@ -507,7 +507,7 @@ pub fn validate_config(config: &Configuration, progress_format: ProgressFormat)
trace!("{} '{}'", t!("subcommand.validatingResource"), resource_block["name"].as_str().unwrap_or_default());

// get the actual resource
let Some(resource) = get_resource(&mut dsc, type_name, resource_block["api_version"].as_str()) else {
let Some(resource) = get_resource(&mut dsc, type_name, resource_block["requireVersion"].as_str()) else {
return Err(DscError::Validation(format!("{}: '{type_name}'", t!("subcommand.resourceNotFound"))));
};

Expand Down
25 changes: 20 additions & 5 deletions dsc/tests/dsc_config_version.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Describe 'Tests for resource versioning' {
resources:
- name: Test Version
type: Test/Version
apiVersion: $version
requireVersion: $version
properties:
version: $version
"@
Expand Down Expand Up @@ -48,7 +48,7 @@ Describe 'Tests for resource versioning' {
resources:
- name: Test Version
type: Test/Version
apiVersion: '$req'
requireVersion: '$req'
properties:
version: $expected
"@
Expand All @@ -63,18 +63,33 @@ Describe 'Tests for resource versioning' {
resources:
- name: Test Version 1
type: Test/Version
apiVersion: '1.1.2'
requireVersion: '1.1.2'
- name: Test Version 2
type: Test/Version
apiVersion: '1.1.0'
requireVersion: '1.1.0'
- name: Test Version 3
type: Test/Version
apiVersion: '2'
requireVersion: '2'
"@
$out = dsc -l trace config get -i $config_yaml 2> $TestDrive/error.log | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0 -Because (Get-Content $TestDrive/error.log -Raw)
$out.results[0].result.actualState.version | Should -BeExactly '1.1.2'
$out.results[1].result.actualState.version | Should -BeExactly '1.1.0'
$out.results[2].result.actualState.version | Should -BeExactly '2.0.0'
}

It 'apiVersion alias works' {
$config_yaml = @"
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Test Version
type: Test/Version
apiVersion: '1.1.2'
properties:
version: '1.1.2'
"@
$out = dsc -l trace config get -i $config_yaml 2> $TestDrive/error.log | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0 -Because (Get-Content $TestDrive/error.log -Raw)
$out.results[0].result.actualState.version | Should -BeExactly '1.1.2'
}
}
14 changes: 7 additions & 7 deletions lib/dsc-lib/src/configure/config_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ pub struct Resource {
/// The fully qualified name of the resource type
#[serde(rename = "type")]
pub resource_type: FullyQualifiedTypeName,
#[serde(skip_serializing_if = "Option::is_none", rename = "apiVersion")]
pub api_version: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", rename = "requireVersion", alias = "apiVersion")]
pub require_version: Option<String>,
/// A friendly name for the resource instance
#[serde(default)]
pub name: String, // friendly unique instance name
Expand Down Expand Up @@ -429,7 +429,7 @@ impl Resource {
comments: None,
location: None,
tags: None,
api_version: None,
require_version: None,
}
}
}
Expand Down Expand Up @@ -517,12 +517,12 @@ mod test {
{
"type": "Microsoft.DSC.Debug/Echo",
"name": "echoResource",
"apiVersion": "1.0.0"
"requireVersion": "1.0.0"
},
{
"type": "Microsoft/Process",
"name": "processResource",
"apiVersion": "0.1.0"
"requireVersion": "0.1.0"
}
]
}"#;
Expand All @@ -532,11 +532,11 @@ mod test {
assert_eq!(config.resources.len(), 2);
assert_eq!(config.resources[0].name, "echoResource");
assert_eq!(config.resources[0].resource_type, "Microsoft.DSC.Debug/Echo");
assert_eq!(config.resources[0].api_version.as_deref(), Some("1.0.0"));
assert_eq!(config.resources[0].require_version.as_deref(), Some("1.0.0"));

assert_eq!(config.resources[1].name, "processResource");
assert_eq!(config.resources[1].resource_type, "Microsoft/Process");
assert_eq!(config.resources[1].api_version.as_deref(), Some("0.1.0"));
assert_eq!(config.resources[1].require_version.as_deref(), Some("0.1.0"));
}

}
24 changes: 12 additions & 12 deletions lib/dsc-lib/src/configure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ impl Configurator {
continue;
}
let adapter = get_require_adapter_from_metadata(&resource.metadata);
let Some(dsc_resource) = discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.api_version.as_deref(), adapter.as_deref()))? else {
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.api_version.as_deref().unwrap_or("").to_string()));
let Some(dsc_resource) = discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.require_version.as_deref(), adapter.as_deref()))? else {
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.require_version.as_deref().unwrap_or("").to_string()));
};
let properties = self.get_properties(&resource, &dsc_resource.kind)?;
let filter = add_metadata(&dsc_resource, properties, resource.metadata.clone())?;
Expand Down Expand Up @@ -480,8 +480,8 @@ impl Configurator {
continue;
}
let adapter = get_require_adapter_from_metadata(&resource.metadata);
let Some(dsc_resource) = discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.api_version.as_deref(), adapter.as_deref()))? else {
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.api_version.as_deref().unwrap_or("").to_string()));
let Some(dsc_resource) = discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.require_version.as_deref(), adapter.as_deref()))? else {
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.require_version.as_deref().unwrap_or("").to_string()));
};
let properties = self.get_properties(&resource, &dsc_resource.kind)?;
debug!("resource_type {}", &resource.resource_type);
Expand Down Expand Up @@ -665,8 +665,8 @@ impl Configurator {
continue;
}
let adapter = get_require_adapter_from_metadata(&resource.metadata);
let Some(dsc_resource) = discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.api_version.as_deref(), adapter.as_deref()))? else {
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.api_version.as_deref().unwrap_or("").to_string()));
let Some(dsc_resource) = discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.require_version.as_deref(), adapter.as_deref()))? else {
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.require_version.as_deref().unwrap_or("").to_string()));
};
let properties = self.get_properties(&resource, &dsc_resource.kind)?;
debug!("resource_type {}", &resource.resource_type);
Expand Down Expand Up @@ -749,8 +749,8 @@ impl Configurator {
continue;
}
let adapter = get_require_adapter_from_metadata(&resource.metadata);
let Some(dsc_resource) = discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.api_version.as_deref(), adapter.as_deref()))? else {
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.api_version.as_deref().unwrap_or("").to_string()));
let Some(dsc_resource) = discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.require_version.as_deref(), adapter.as_deref()))? else {
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.require_version.as_deref().unwrap_or("").to_string()));
};
let properties = self.get_properties(resource, &dsc_resource.kind)?;
debug!("resource_type {}", &resource.resource_type);
Expand Down Expand Up @@ -1045,12 +1045,12 @@ impl Configurator {

if !skip_resource_validation {
// Perform discovery of resources used in config
// create an array of DiscoveryFilter using the resource types and api_versions from the config
// create an array of DiscoveryFilter using the resource types and requireVersion from the config
let mut discovery_filter: Vec<DiscoveryFilter> = Vec::new();
let config_copy = config.clone();
for resource in config_copy.resources {
let adapter = get_require_adapter_from_metadata(&resource.metadata);
let filter = DiscoveryFilter::new(&resource.resource_type, resource.api_version.as_deref(), adapter.as_deref());
let filter = DiscoveryFilter::new(&resource.resource_type, resource.require_version.as_deref(), adapter.as_deref());
if !discovery_filter.contains(&filter) {
discovery_filter.push(filter);
}
Expand All @@ -1070,8 +1070,8 @@ impl Configurator {
// now check that each resource in the config was found
for resource in config.resources.iter() {
let adapter = get_require_adapter_from_metadata(&resource.metadata);
let Some(_dsc_resource) = self.discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.api_version.as_deref(), adapter.as_deref()))? else {
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.api_version.as_deref().unwrap_or("").to_string()));
let Some(_dsc_resource) = self.discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.require_version.as_deref(), adapter.as_deref()))? else {
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.require_version.as_deref().unwrap_or("").to_string()));
};
}
}
Expand Down