Skip to content

Commit c777328

Browse files
authored
Merge pull request #1399 from SteveL-MSFT/requireVersion
Replace `apiVersion` with `requireVersion`
2 parents 8d9c559 + a206f30 commit c777328

4 files changed

Lines changed: 41 additions & 26 deletions

File tree

dsc/src/subcommand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ pub fn validate_config(config: &Configuration, progress_format: ProgressFormat)
495495
let Some(type_name) = resource_block["type"].as_str() else {
496496
return Err(DscError::Validation(t!("subcommand.resourceTypeNotSpecified").to_string()));
497497
};
498-
resource_types.push(DiscoveryFilter::new(type_name, resource_block["api_version"].as_str(), None));
498+
resource_types.push(DiscoveryFilter::new(type_name, resource_block["requireVersion"].as_str(), None));
499499
}
500500
dsc.find_resources(&resource_types, progress_format)?;
501501

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

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

dsc/tests/dsc_config_version.tests.ps1

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Describe 'Tests for resource versioning' {
1919
resources:
2020
- name: Test Version
2121
type: Test/Version
22-
apiVersion: $version
22+
requireVersion: $version
2323
properties:
2424
version: $version
2525
"@
@@ -48,7 +48,7 @@ Describe 'Tests for resource versioning' {
4848
resources:
4949
- name: Test Version
5050
type: Test/Version
51-
apiVersion: '$req'
51+
requireVersion: '$req'
5252
properties:
5353
version: $expected
5454
"@
@@ -63,18 +63,33 @@ Describe 'Tests for resource versioning' {
6363
resources:
6464
- name: Test Version 1
6565
type: Test/Version
66-
apiVersion: '1.1.2'
66+
requireVersion: '1.1.2'
6767
- name: Test Version 2
6868
type: Test/Version
69-
apiVersion: '1.1.0'
69+
requireVersion: '1.1.0'
7070
- name: Test Version 3
7171
type: Test/Version
72-
apiVersion: '2'
72+
requireVersion: '2'
7373
"@
7474
$out = dsc -l trace config get -i $config_yaml 2> $TestDrive/error.log | ConvertFrom-Json
7575
$LASTEXITCODE | Should -Be 0 -Because (Get-Content $TestDrive/error.log -Raw)
7676
$out.results[0].result.actualState.version | Should -BeExactly '1.1.2'
7777
$out.results[1].result.actualState.version | Should -BeExactly '1.1.0'
7878
$out.results[2].result.actualState.version | Should -BeExactly '2.0.0'
7979
}
80+
81+
It 'apiVersion alias works' {
82+
$config_yaml = @"
83+
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
84+
resources:
85+
- name: Test Version
86+
type: Test/Version
87+
apiVersion: '1.1.2'
88+
properties:
89+
version: '1.1.2'
90+
"@
91+
$out = dsc -l trace config get -i $config_yaml 2> $TestDrive/error.log | ConvertFrom-Json
92+
$LASTEXITCODE | Should -Be 0 -Because (Get-Content $TestDrive/error.log -Raw)
93+
$out.results[0].result.actualState.version | Should -BeExactly '1.1.2'
94+
}
8095
}

lib/dsc-lib/src/configure/config_doc.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ pub struct Resource {
353353
/// The fully qualified name of the resource type
354354
#[serde(rename = "type")]
355355
pub resource_type: FullyQualifiedTypeName,
356-
#[serde(skip_serializing_if = "Option::is_none", rename = "apiVersion")]
357-
pub api_version: Option<String>,
356+
#[serde(skip_serializing_if = "Option::is_none", rename = "requireVersion", alias = "apiVersion")]
357+
pub require_version: Option<String>,
358358
/// A friendly name for the resource instance
359359
#[serde(default)]
360360
pub name: String, // friendly unique instance name
@@ -429,7 +429,7 @@ impl Resource {
429429
comments: None,
430430
location: None,
431431
tags: None,
432-
api_version: None,
432+
require_version: None,
433433
}
434434
}
435435
}
@@ -517,12 +517,12 @@ mod test {
517517
{
518518
"type": "Microsoft.DSC.Debug/Echo",
519519
"name": "echoResource",
520-
"apiVersion": "1.0.0"
520+
"requireVersion": "1.0.0"
521521
},
522522
{
523523
"type": "Microsoft/Process",
524524
"name": "processResource",
525-
"apiVersion": "0.1.0"
525+
"requireVersion": "0.1.0"
526526
}
527527
]
528528
}"#;
@@ -532,11 +532,11 @@ mod test {
532532
assert_eq!(config.resources.len(), 2);
533533
assert_eq!(config.resources[0].name, "echoResource");
534534
assert_eq!(config.resources[0].resource_type, "Microsoft.DSC.Debug/Echo");
535-
assert_eq!(config.resources[0].api_version.as_deref(), Some("1.0.0"));
535+
assert_eq!(config.resources[0].require_version.as_deref(), Some("1.0.0"));
536536

537537
assert_eq!(config.resources[1].name, "processResource");
538538
assert_eq!(config.resources[1].resource_type, "Microsoft/Process");
539-
assert_eq!(config.resources[1].api_version.as_deref(), Some("0.1.0"));
539+
assert_eq!(config.resources[1].require_version.as_deref(), Some("0.1.0"));
540540
}
541541

542542
}

lib/dsc-lib/src/configure/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ impl Configurator {
395395
continue;
396396
}
397397
let adapter = get_require_adapter_from_metadata(&resource.metadata);
398-
let Some(dsc_resource) = discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.api_version.as_deref(), adapter.as_deref()))? else {
399-
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.api_version.as_deref().unwrap_or("").to_string()));
398+
let Some(dsc_resource) = discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.require_version.as_deref(), adapter.as_deref()))? else {
399+
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.require_version.as_deref().unwrap_or("").to_string()));
400400
};
401401
let properties = self.get_properties(&resource, &dsc_resource.kind)?;
402402
let filter = add_metadata(&dsc_resource, properties, resource.metadata.clone())?;
@@ -480,8 +480,8 @@ impl Configurator {
480480
continue;
481481
}
482482
let adapter = get_require_adapter_from_metadata(&resource.metadata);
483-
let Some(dsc_resource) = discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.api_version.as_deref(), adapter.as_deref()))? else {
484-
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.api_version.as_deref().unwrap_or("").to_string()));
483+
let Some(dsc_resource) = discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.require_version.as_deref(), adapter.as_deref()))? else {
484+
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.require_version.as_deref().unwrap_or("").to_string()));
485485
};
486486
let properties = self.get_properties(&resource, &dsc_resource.kind)?;
487487
debug!("resource_type {}", &resource.resource_type);
@@ -665,8 +665,8 @@ impl Configurator {
665665
continue;
666666
}
667667
let adapter = get_require_adapter_from_metadata(&resource.metadata);
668-
let Some(dsc_resource) = discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.api_version.as_deref(), adapter.as_deref()))? else {
669-
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.api_version.as_deref().unwrap_or("").to_string()));
668+
let Some(dsc_resource) = discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.require_version.as_deref(), adapter.as_deref()))? else {
669+
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.require_version.as_deref().unwrap_or("").to_string()));
670670
};
671671
let properties = self.get_properties(&resource, &dsc_resource.kind)?;
672672
debug!("resource_type {}", &resource.resource_type);
@@ -749,8 +749,8 @@ impl Configurator {
749749
continue;
750750
}
751751
let adapter = get_require_adapter_from_metadata(&resource.metadata);
752-
let Some(dsc_resource) = discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.api_version.as_deref(), adapter.as_deref()))? else {
753-
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.api_version.as_deref().unwrap_or("").to_string()));
752+
let Some(dsc_resource) = discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.require_version.as_deref(), adapter.as_deref()))? else {
753+
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.require_version.as_deref().unwrap_or("").to_string()));
754754
};
755755
let properties = self.get_properties(resource, &dsc_resource.kind)?;
756756
debug!("resource_type {}", &resource.resource_type);
@@ -1045,12 +1045,12 @@ impl Configurator {
10451045

10461046
if !skip_resource_validation {
10471047
// Perform discovery of resources used in config
1048-
// create an array of DiscoveryFilter using the resource types and api_versions from the config
1048+
// create an array of DiscoveryFilter using the resource types and requireVersion from the config
10491049
let mut discovery_filter: Vec<DiscoveryFilter> = Vec::new();
10501050
let config_copy = config.clone();
10511051
for resource in config_copy.resources {
10521052
let adapter = get_require_adapter_from_metadata(&resource.metadata);
1053-
let filter = DiscoveryFilter::new(&resource.resource_type, resource.api_version.as_deref(), adapter.as_deref());
1053+
let filter = DiscoveryFilter::new(&resource.resource_type, resource.require_version.as_deref(), adapter.as_deref());
10541054
if !discovery_filter.contains(&filter) {
10551055
discovery_filter.push(filter);
10561056
}
@@ -1070,8 +1070,8 @@ impl Configurator {
10701070
// now check that each resource in the config was found
10711071
for resource in config.resources.iter() {
10721072
let adapter = get_require_adapter_from_metadata(&resource.metadata);
1073-
let Some(_dsc_resource) = self.discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.api_version.as_deref(), adapter.as_deref()))? else {
1074-
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.api_version.as_deref().unwrap_or("").to_string()));
1073+
let Some(_dsc_resource) = self.discovery.find_resource(&DiscoveryFilter::new(&resource.resource_type, resource.require_version.as_deref(), adapter.as_deref()))? else {
1074+
return Err(DscError::ResourceNotFound(resource.resource_type.to_string(), resource.require_version.as_deref().unwrap_or("").to_string()));
10751075
};
10761076
}
10771077
}

0 commit comments

Comments
 (0)