Invoke the export operation on a configuration. # Returns `ConfigurationExportResult` - The result of the export operation. # Errors This function will return an error if the underlying resource fails.
(&mut self)
| 886 | /// |
| 887 | /// This function will return an error if the underlying resource fails. |
| 888 | pub fn invoke_export(&mut self) -> Result<ConfigurationExportResult, DscError> { |
| 889 | let mut result = ConfigurationExportResult::new(); |
| 890 | self.context.operation = Some(Operation::Export); |
| 891 | let mut conf = config_doc::Configuration::new(); |
| 892 | conf.metadata.clone_from(&self.config.metadata); |
| 893 | |
| 894 | let mut progress = ProgressBar::new(self.config.resources.len() as u64, self.progress_format)?; |
| 895 | let resources = self.config.resources.clone(); |
| 896 | let discovery = &mut self.discovery.clone(); |
| 897 | for resource in &resources { |
| 898 | let evaluated_name = self.evaluate_resource_name(&resource.name)?; |
| 899 | |
| 900 | progress.set_resource(&evaluated_name, &resource.resource_type); |
| 901 | progress.write_activity(format!("Export '{evaluated_name}'").as_str()); |
| 902 | if self.skip_resource(resource)? { |
| 903 | progress.write_increment(1); |
| 904 | continue; |
| 905 | } |
| 906 | let directive_security_context = resource.directives.as_ref().and_then(|d| d.security_context.as_ref()); |
| 907 | check_security_context(resource.metadata.as_ref(), directive_security_context)?; |
| 908 | let adapter = get_require_adapter_from_directive(&resource.directives); |
| 909 | find_resource_or_error!(dsc_resource, discovery, resource, adapter); |
| 910 | let properties = self.get_properties(resource, &dsc_resource.kind)?; |
| 911 | debug!("resource_type {}", &resource.resource_type); |
| 912 | let input = add_metadata(dsc_resource, properties, resource.metadata.clone())?; |
| 913 | trace!("{}", t!("configure.mod.exportInput", input = input)); |
| 914 | let export_result = match add_resource_export_results_to_configuration(dsc_resource, &mut conf, input.as_str()) { |
| 915 | Ok(result) => result, |
| 916 | Err(e) => { |
| 917 | progress.set_failure(get_failure_from_error(&e)); |
| 918 | progress.write_increment(1); |
| 919 | return Err(e); |
| 920 | }, |
| 921 | }; |
| 922 | self.context.references.insert(resource_id(&resource.resource_type, &evaluated_name), serde_json::to_value(&export_result.actual_state)?); |
| 923 | progress.set_result(&serde_json::to_value(export_result)?); |
| 924 | progress.write_increment(1); |
| 925 | } |
| 926 | |
| 927 | let export_metadata = self.get_result_metadata(Operation::Export); |
| 928 | match conf.metadata { |
| 929 | Some(mut metadata) => { |
| 930 | metadata.microsoft = export_metadata.microsoft; |
| 931 | conf.metadata = Some(metadata); |
| 932 | }, |
| 933 | _ => { |
| 934 | conf.metadata = Some(export_metadata); |
| 935 | }, |
| 936 | } |
| 937 | |
| 938 | let mut execution_information = ExecutionInformation::new(); |
| 939 | self.get_execution_information(Operation::Export, &mut execution_information); |
| 940 | conf.execution_information = Some(execution_information); |
| 941 | result.result = Some(conf); |
| 942 | self.process_output()?; |
| 943 | if !self.context.outputs.is_empty() { |
| 944 | result.outputs = Some(self.context.outputs.clone()); |
| 945 | } |
no test coverage detected