MCPcopy Index your code
hub / github.com/PowerShell/DSC / validate_config

Function validate_config

dsc/src/subcommand.rs:478–530  ·  view source on GitHub ↗

Validate configuration. # Arguments `config` - The configuration to validate. # Returns Nothing on success. # Errors `DscError` - The error that occurred.

(config: &Configuration, progress_format: ProgressFormat)

Source from the content-addressed store, hash-verified

476///
477/// * `DscError` - The error that occurred.
478pub fn validate_config(config: &Configuration, progress_format: ProgressFormat) -> Result<(), DscError> {
479 // first validate against the config schema
480 debug!("{}", t!("subcommand.validatingConfiguration"));
481 let schema = serde_json::to_value(get_schema(SchemaType::Configuration))?;
482 let config_value = serde_json::to_value(config)?;
483 validate_json("Configuration", &schema, &config_value)?;
484 let mut dsc = DscManager::new();
485
486 // then validate each resource
487 let Some(resources) = config_value["resources"].as_array() else {
488 return Err(DscError::Validation(t!("subcommand.noResources").to_string()));
489 };
490
491 // discover the resources
492 let mut resource_types = Vec::<DiscoveryFilter>::new();
493 for resource_block in resources {
494 let Some(type_name) = resource_block["type"].as_str() else {
495 return Err(DscError::Validation(t!("subcommand.resourceTypeNotSpecified").to_string()));
496 };
497 let type_name = &FullyQualifiedTypeName::parse(type_name)?;
498 let require_version = resource_block["requireVersion"]
499 .as_str()
500 .map(ResourceVersionReq::parse)
501 .transpose()?;
502 resource_types.push(DiscoveryFilter::new(type_name, require_version, None));
503 }
504 dsc.find_resources(&resource_types, progress_format)?;
505
506 for resource_block in resources {
507 let Some(type_name) = resource_block["type"].as_str() else {
508 return Err(DscError::Validation(t!("subcommand.resourceTypeNotSpecified").to_string()));
509 };
510 let type_name = &FullyQualifiedTypeName::parse(type_name)?;
511 let require_version = resource_block["requireVersion"]
512 .as_str()
513 .map(ResourceVersionReq::parse)
514 .transpose()?;
515
516 trace!("{} '{}'", t!("subcommand.validatingResource"), resource_block["name"].as_str().unwrap_or_default());
517
518 // get the actual resource
519 let Some(resource) = get_resource(&mut dsc, type_name, require_version.as_ref()) else {
520 return Err(DscError::Validation(format!("{}: '{type_name}'", t!("subcommand.resourceNotFound"))));
521 };
522
523 // see if the resource is command based
524 if resource.implemented_as == Some(ImplementedAs::Command) {
525 validate_properties(resource, &resource_block["properties"])?;
526 }
527 }
528
529 Ok(())
530}
531
532pub fn extension(subcommand: &ExtensionSubCommand, progress_format: ProgressFormat) {
533 let mut dsc = DscManager::new();

Callers 1

configFunction · 0.70

Calls 9

validate_jsonFunction · 0.85
get_resourceFunction · 0.85
validate_propertiesFunction · 0.85
as_strMethod · 0.80
get_schemaFunction · 0.70
newFunction · 0.50
parseFunction · 0.50
find_resourcesMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected