Skip to content

Commit 26d226a

Browse files
authored
Merge pull request #789 from SteveL-MSFT/ps-export
Fix exporting an adapted resource
2 parents 65ef58f + f50a752 commit 26d226a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

dsc_lib/src/dscresources/dscresource.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,17 @@ impl Invoke for DscResource {
437437
let mut export_result = ExportResult {
438438
actual_state: Vec::new(),
439439
};
440+
debug!("Export result: {}", serde_json::to_string(&configuration)?);
440441
for resource in configuration.resources {
441442
let Some(properties) = resource.properties else {
442443
return Err(DscError::Operation(t!("dscresources.dscresource.invokeExportReturnedNoResult", resource = self.type_name).to_string()));
443444
};
444-
export_result.actual_state.push(serde_json::to_value(properties["properties"].clone())?);
445+
let results = properties
446+
.get("result").ok_or(DscError::Operation(t!("dscresources.dscresource.propertyNotFound", property = "result").to_string()))?
447+
.as_array().ok_or(DscError::Operation(t!("dscresources.dscresource.propertyIncorrectType", property = "result", property_type = "array").to_string()))?;
448+
for result in results {
449+
export_result.actual_state.push(serde_json::to_value(result.clone())?);
450+
}
445451
}
446452
return Ok(export_result);
447453
}

powershell-adapter/Tests/TestAdapter/testadapter.resource.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ switch ($Operation) {
5858

5959
}
6060
'Export' {
61-
@(@{name = $inputobj.resources.name; type = $inputobj.resources.type; properties = @{'TestCaseId' = 1; 'Input' = ''}}) | ConvertTo-Json -Depth 10 -Compress
62-
@(@{name = $inputobj.resources.name; type = $inputobj.resources.type; properties = @{'TestCaseId' = 2; 'Input' = ''}}) | ConvertTo-Json -Depth 10 -Compress
61+
@{result = @(
62+
@{'TestCaseId' = 1; 'Input' = ''},
63+
@{'TestCaseId' = 2; 'Input' = ''}
64+
)} | ConvertTo-Json -Depth 10 -Compress
6365
}
6466
'Validate' {
6567
@{ valid = $true } | ConvertTo-Json

0 commit comments

Comments
 (0)