Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/dsc-lib-jsonschema/.versions.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"latestMajor": "V3",
"latestMinor": "V3_2",
"latestPatch": "V3_2_0",
"latestPatch": "V3_2_1",
"all": [
"V3",
"V3_2",
"V3_2_1",
"V3_2_0",
"V3_1",
"V3_1_3",
Expand Down
2 changes: 2 additions & 0 deletions lib/dsc-lib/locales/en-us.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ exportNotSupportedUsingGet = "Export is not supported by resource '%{resource}'
runProcessError = "Failed to run process '%{executable}': %{error}"
whatIfWarning = "Resource '%{resource}' uses deprecated 'whatIf' operation. See https://github.com/PowerShell/DSC/issues/1361 for migration information."
securityContextRequired = "Operation '%{operation}' for resource '%{resource}' requires security context '%{context}'"
noAdaptedContent = "No adapted content available for resource '%{resource}'"
invalidAdaptedContent = "Invalid adapted content for resource '%{resource}': %{error}"

[dscresources.dscresource]
invokeGet = "Invoking get for '%{resource}'"
Expand Down
77 changes: 43 additions & 34 deletions lib/dsc-lib/src/discovery/command_discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use crate::{discovery::{DiscoveryExtensionCache, DiscoveryManifestCache, DiscoveryResourceCache, discovery_trait::{DiscoveryFilter, DiscoveryKind, ResourceDiscovery}, matches_adapter_requirement}, dscresources::{adapted_resource_manifest::AdaptedDscResourceManifest, resource_manifest::SetDeleteArgKind}, parser::Statement, types::{FullyQualifiedTypeName, TypeNameFilter}};
use crate::{locked_clear, locked_is_empty, locked_extend, locked_clone, locked_get};
use crate::configure::{config_doc::ResourceDiscoveryMode, context::Context};
use crate::dscresources::adapted_resource_manifest::AdaptedPathOrContent;
use crate::dscresources::dscresource::{Capability, DscResource, ImplementedAs};
use crate::dscresources::resource_manifest::{Kind, ResourceManifest, SchemaKind};
use crate::dscresources::command_resource::invoke_command;
Expand Down Expand Up @@ -31,7 +32,6 @@ const DSC_EXTENSION_EXTENSIONS: [&str; 3] = [".dsc.extension.json", ".dsc.extens
const DSC_MANIFEST_LIST_EXTENSIONS: [&str; 3] = [".dsc.manifests.json", ".dsc.manifests.yaml", ".dsc.manifests.yml"];
const DSC_RESOURCE_EXTENSIONS: [&str; 3] = [".dsc.resource.json", ".dsc.resource.yaml", ".dsc.resource.yml"];

// use BTreeMap so that the results are sorted by the typename, the Vec is sorted by version
static ADAPTERS: LazyLock<RwLock<DiscoveryResourceCache>> = LazyLock::new(|| RwLock::new(DiscoveryResourceCache::new()));
static RESOURCES: LazyLock<RwLock<DiscoveryResourceCache>> = LazyLock::new(|| RwLock::new(DiscoveryResourceCache::new()));
static EXTENSIONS: LazyLock<RwLock<DiscoveryExtensionCache>> = LazyLock::new(|| RwLock::new(DiscoveryExtensionCache::new()));
Expand Down Expand Up @@ -391,38 +391,39 @@ impl ResourceDiscovery for CommandDiscovery {

let mut adapter_resources_count = 0;
// invoke the list command
let list_command = &manifest.adapter.clone().unwrap().list;
let (exit_code, stdout, stderr) = match invoke_command(&list_command.executable, list_command.args.clone(), None, Some(&adapter.directory), None, manifest.exit_codes.as_ref())
{
Ok((exit_code, stdout, stderr)) => (exit_code, stdout, stderr),
Err(e) => {
// In case of error, log and continue
warn!("{e}");
continue;
},
};
if let Some(list_command) = &manifest.adapter.clone().unwrap().list {
let (exit_code, stdout, stderr) = match invoke_command(&list_command.executable, list_command.args.clone(), None, Some(&adapter.directory), None, manifest.exit_codes.as_ref())
{
Ok((exit_code, stdout, stderr)) => (exit_code, stdout, stderr),
Err(e) => {
// In case of error, log and continue
warn!("{e}");
continue;
},
};

if exit_code != 0 {
// in case of failure, log and continue
warn!("Adapter failed to list resources with exit code {exit_code}: {stderr}");
continue;
}
if exit_code != 0 {
// in case of failure, log and continue
warn!("Adapter failed to list resources with exit code {exit_code}: {stderr}");
continue;
}

for line in stdout.lines() {
match serde_json::from_str::<DscResource>(line){
Result::Ok(resource) => {
if resource.require_adapter.is_none() {
warn!("{}", DscError::MissingRequires(adapter_name.to_string(), resource.type_name.to_string()).to_string());
continue;
}
for line in stdout.lines() {
match serde_json::from_str::<DscResource>(line){
Result::Ok(resource) => {
if resource.require_adapter.is_none() {
warn!("{}", DscError::MissingRequires(adapter_name.to_string(), resource.type_name.to_string()).to_string());
continue;
}

if name_filter.is_match(&resource.type_name) {
insert_resource(&mut adapted_resources, &resource);
adapter_resources_count += 1;
if name_filter.is_match(&resource.type_name) {
insert_resource(&mut adapted_resources, &resource);
adapter_resources_count += 1;
}
},
Result::Err(err) => {
warn!("Failed to parse resource: {line} -> {err}");
}
},
Result::Err(err) => {
warn!("Failed to parse resource: {line} -> {err}");
}
}
}
Expand Down Expand Up @@ -748,13 +749,22 @@ fn load_adapted_resource_manifest(path: &Path, manifest: &AdaptedDscResourceMani
));
}

let mut resource = DscResource::new();
let directory = path.parent().unwrap();
let resource_path = directory.join(&manifest.path);
if !resource_path.exists() {
return Err(DscError::InvalidManifest(t!("discovery.commandDiscovery.adaptedResourcePathNotFound", path = resource_path.to_string_lossy(), resource = manifest.type_name).to_string()));
match &manifest.path_or_content {
AdaptedPathOrContent::Path(resource_path) => {
let resource_path = directory.join(resource_path);
if !resource_path.exists() {
return Err(DscError::InvalidManifest(t!("discovery.commandDiscovery.adaptedResourcePathNotFound", path = resource_path.to_string_lossy(), resource = manifest.type_name).to_string()));
}
resource.path = resource_path;
},
AdaptedPathOrContent::Content(content) => {
resource.path = path.to_path_buf();
resource.adapted_content = Some(content.clone());
}
}

let mut resource = DscResource::new();
resource.type_name = manifest.type_name.clone();
resource.kind = Kind::Resource;
resource.implemented_as = None;
Expand All @@ -763,7 +773,6 @@ fn load_adapted_resource_manifest(path: &Path, manifest: &AdaptedDscResourceMani
resource.version = manifest.version.clone();
resource.capabilities = manifest.capabilities.clone();
resource.require_adapter = Some(manifest.require_adapter.clone());
resource.path = resource_path;
resource.directory = directory.to_path_buf();
resource.manifest = None;
resource.schema = Some(manifest.schema.clone());
Expand Down
12 changes: 10 additions & 2 deletions lib/dsc-lib/src/dscresources/adapted_resource_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use std::path::PathBuf;

#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub enum AdaptedPathOrContent {
Path(PathBuf),
Content(Map<String, Value>),
}

#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, DscRepoSchema)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
#[dsc_repo_schema(
Expand Down Expand Up @@ -45,8 +52,9 @@ pub struct AdaptedDscResourceManifest {
/// An optional message indicating the resource is deprecated. If provided, the message will be shown when the resource is used.
#[serde(skip_serializing_if = "Option::is_none")]
pub deprecation_message: Option<String>,
/// The file path to the resource.
pub path: PathBuf,
/// The file path to the resource or the content of the resource itself.
#[serde(flatten)]
pub path_or_content: AdaptedPathOrContent,
/// The description of the resource.
pub description: Option<String>,
/// The author of the resource.
Expand Down
Loading
Loading