Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions dsc/src/resource_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::args::{GetOutputFormat, OutputFormat};
use crate::util::{EXIT_DSC_ERROR, EXIT_INVALID_ARGS, EXIT_JSON_ERROR, EXIT_DSC_RESOURCE_NOT_FOUND, write_object};
use dsc_lib::configure::config_doc::{Configuration, ExecutionKind};
use dsc_lib::configure::config_doc::{Configuration, ExecutionInformation, ExecutionKind};
use dsc_lib::configure::add_resource_export_results_to_configuration;
use dsc_lib::discovery::discovery_trait::DiscoveryFilter;
use dsc_lib::dscresources::{resource_manifest::Kind, invoke_result::{DeleteResultKind, GetResult, ResourceGetResponse, ResourceSetResponse, SetResult}};
Expand Down Expand Up @@ -339,7 +339,8 @@ pub fn export(dsc: &mut DscManager, resource_type: &str, version: Option<&str>,
}

let mut conf = Configuration::new();
if let Err(err) = add_resource_export_results_to_configuration(dsc_resource, &mut conf, input) {
let execution_information = ExecutionInformation::new();
if let Err(err) = add_resource_export_results_to_configuration(dsc_resource, &mut conf, input, &execution_information) {
error!("{err}");
exit(EXIT_DSC_ERROR);
}
Expand Down
34 changes: 34 additions & 0 deletions dsc/tests/dsc_config_export.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

Describe 'config export tests' {
It 'Execution information is included in config export results' {
$config_yaml = @'
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: os
type: Microsoft/OSInfo
'@

$out = dsc config export -i $config_yaml | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0
$out.executionInformation | Should -Not -BeNullOrEmpty
$out.executionInformation.startDatetime | Should -Not -BeNullOrEmpty
$out.executionInformation.endDatetime | Should -Not -BeNullOrEmpty
$out.executionInformation.duration | Should -Not -BeNullOrEmpty
$out.executionInformation.operation | Should -BeExactly 'export'
$out.executionInformation.executionType | Should -BeExactly 'actual'
$out.executionInformation.securityContext | Should -Not -BeNullOrEmpty
$out.executionInformation.version | Should -BeExactly (dsc --version).replace("dsc ", "")
$out.resources | Should -Not -BeNullOrEmpty
$out.resources.count | Should -Be 1
$out.resources[0].Name | Should -Not -BeNullOrEmpty
$out.resources[0].type | Should -BeExactly 'Microsoft/OSInfo'
$out.resources[0].executionInformation | Should -Not -BeNullOrEmpty
$out.resources[0].executionInformation.duration | Should -Not -BeNullOrEmpty
$out.resources[0].properties.family | Should -BeIn @('Windows', 'Linux', 'macOS')
$out.resources[0].properties.architecture | Should -BeIn @('x64', 'arm64')
$out.resources[0].properties.version | Should -Not -BeNullOrEmpty
$out.resources[0].properties.bitness | Should -BeIn @(32, 64)
}
}
6 changes: 3 additions & 3 deletions lib/dsc-lib/src/configure/config_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ pub struct Output {
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, DscRepoSchema)]
#[serde(deny_unknown_fields)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
#[dsc_repo_schema(
base_name = "document",
folder_path = "config",
Expand Down Expand Up @@ -464,15 +464,15 @@ pub struct Sku {
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema, DscRepoSchema)]
#[serde(deny_unknown_fields)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
#[dsc_repo_schema(base_name = "document.resource", folder_path = "config")]
pub struct Resource {
#[serde(skip_serializing_if = "Option::is_none")]
pub condition: Option<String>,
/// The fully qualified name of the resource type
#[serde(rename = "type")]
pub resource_type: FullyQualifiedTypeName,
#[serde(skip_serializing_if = "Option::is_none", rename = "requireVersion", alias = "apiVersion")]
#[serde(skip_serializing_if = "Option::is_none", alias = "apiVersion")]
pub require_version: Option<String>,
/// A friendly name for the resource instance
#[serde(default)]
Expand Down
12 changes: 9 additions & 3 deletions lib/dsc-lib/src/configure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub struct Configurator {
/// # Errors
///
/// This function will return an error if the underlying resource fails.
pub fn add_resource_export_results_to_configuration(resource: &DscResource, conf: &mut Configuration, input: &str) -> Result<ExportResult, DscError> {
pub fn add_resource_export_results_to_configuration(resource: &DscResource, conf: &mut Configuration, input: &str, execution_information: &ExecutionInformation) -> Result<ExportResult, DscError> {

let export_result = resource.export(input)?;

Expand Down Expand Up @@ -105,7 +105,7 @@ pub fn add_resource_export_results_to_configuration(resource: &DscResource, conf
}
r.properties = escape_property_values(&props)?;
let mut properties = serde_json::to_value(&r.properties)?;
let mut execution_information = ExecutionInformation::new();
let mut execution_information = execution_information.clone();
get_metadata_from_result(None, &mut properties, &mut metadata, &mut execution_information)?;
r.properties = Some(properties.as_object().cloned().unwrap_or_default());
r.metadata = if metadata.microsoft.is_some() || !metadata.other.is_empty() {
Expand Down Expand Up @@ -868,9 +868,12 @@ impl Configurator {
};
let properties = self.get_properties(resource, &dsc_resource.kind)?;
debug!("resource_type {}", &resource.resource_type);
let start_datetime = chrono::Local::now();
let input = add_metadata(&dsc_resource, properties, resource.metadata.clone())?;
let end_datetime = chrono::Local::now();
let execution_information = ExecutionInformation::new_with_duration(&start_datetime, &end_datetime);
trace!("{}", t!("configure.mod.exportInput", input = input));
let export_result = match add_resource_export_results_to_configuration(&dsc_resource, &mut conf, input.as_str()) {
let export_result = match add_resource_export_results_to_configuration(&dsc_resource, &mut conf, input.as_str(), &execution_information) {
Ok(result) => result,
Err(e) => {
progress.set_failure(get_failure_from_error(&e));
Expand All @@ -894,6 +897,9 @@ impl Configurator {
},
}

let mut execution_information = ExecutionInformation::new();
self.get_execution_information(Operation::Export, &mut execution_information);
conf.execution_information = Some(execution_information);
result.result = Some(conf);
self.process_output()?;
if !self.context.outputs.is_empty() {
Expand Down
Loading