|
1 | 1 | // Copyright (c) Microsoft Corporation.
|
2 | 2 | // Licensed under the MIT License.
|
3 | 3 |
|
4 |
| -use crate::{configure::config_doc::ExecutionKind, dscresources::resource_manifest::Kind}; |
| 4 | +use crate::{configure::{config_doc::{Configuration, ExecutionKind, Resource}, Configurator}, dscresources::resource_manifest::Kind}; |
5 | 5 | use dscerror::DscError;
|
6 | 6 | use rust_i18n::t;
|
7 | 7 | use schemars::JsonSchema;
|
8 | 8 | use serde::{Deserialize, Serialize};
|
9 |
| -use serde_json::Value; |
| 9 | +use serde_json::{Map, Value}; |
10 | 10 | use std::collections::HashMap;
|
11 | 11 | use tracing::{debug, info};
|
12 | 12 |
|
@@ -191,6 +191,31 @@ pub trait Invoke {
|
191 | 191 | impl Invoke for DscResource {
|
192 | 192 | fn get(&self, filter: &str) -> Result<GetResult, DscError> {
|
193 | 193 | debug!("{}", t!("dscresources.dscresource.invokeGet", resource = self.type_name));
|
| 194 | + if let Some(adapter) = &self.require_adapter { |
| 195 | + // create new configuration with adapter and use this as the resource |
| 196 | + let mut configuration = Configuration::new(); |
| 197 | + let mut property_map = Map::new(); |
| 198 | + property_map.insert("name".to_string(), Value::String(self.type_name.clone())); |
| 199 | + property_map.insert("type".to_string(), Value::String(self.type_name.clone())); |
| 200 | + let mut resource_properties = Map::new(); |
| 201 | + for property in &self.properties { |
| 202 | + resource_properties.insert(property.clone(), Value::Null); |
| 203 | + } |
| 204 | + property_map.insert("properties".to_string(), Value::Object(resource_properties)); |
| 205 | + let adapter_resource = Resource { |
| 206 | + name: self.type_name.clone(), |
| 207 | + resource_type: adapter.clone(), |
| 208 | + depends_on: None, |
| 209 | + metadata: None, |
| 210 | + properties: Some(property_map), |
| 211 | + }; |
| 212 | + configuration.resources.push(adapter_resource); |
| 213 | + let config_json = serde_json::to_string(&configuration)?; |
| 214 | + let mut configurator = Configurator::new(&config_json, crate::progress::ProgressFormat::None)?; |
| 215 | + let result = configurator.invoke_get()?; |
| 216 | + return Ok(result.results[0].result.clone()); |
| 217 | + } |
| 218 | + |
194 | 219 | match &self.implemented_as {
|
195 | 220 | ImplementedAs::Custom(_custom) => {
|
196 | 221 | Err(DscError::NotImplemented(t!("dscresources.dscresource.customResourceNotSupported").to_string()))
|
|
0 commit comments