MCPcopy Create free account
hub / github.com/PowerShell/DSC / discover

Method discover

lib/dsc-lib/src/discovery/command_discovery.rs:214–351  ·  view source on GitHub ↗
(&mut self, kind: &DiscoveryKind, filter: &TypeNameFilter)

Source from the content-addressed store, hash-verified

212
213 #[allow(clippy::too_many_lines)]
214 fn discover(&mut self, kind: &DiscoveryKind, filter: &TypeNameFilter) -> Result<(), DscError> {
215 if self.discovery_mode == ResourceDiscoveryMode::PreDeployment && !locked_is_empty!(RESOURCES) {
216 return Ok(());
217 } else if self.discovery_mode == ResourceDiscoveryMode::DuringDeployment {
218 locked_clear!(RESOURCES);
219 locked_clear!(ADAPTERS);
220 }
221
222 // if kind is DscResource, we need to discover extensions first
223 if *kind == DiscoveryKind::Resource && (self.discovery_mode == ResourceDiscoveryMode::DuringDeployment || locked_is_empty!(EXTENSIONS)){
224 self.discover(&DiscoveryKind::Extension, &TypeNameFilter::default())?;
225 }
226
227 info!("{}", t!("discovery.commandDiscovery.discoverResources", kind = kind : {:?}, filter = filter.to_string()));
228
229 debug!("Using type name filter '{filter}' for adapter name");
230 let mut progress = ProgressBar::new(1, self.progress_format)?;
231 match kind {
232 DiscoveryKind::Resource => {
233 progress.write_activity(t!("discovery.commandDiscovery.progressSearching").to_string().as_str());
234 },
235 DiscoveryKind::Extension => {
236 progress.write_activity(t!("discovery.commandDiscovery.extensionSearching").to_string().as_str());
237 }
238 }
239
240 let mut adapters = DiscoveryResourceCache::new();
241 let mut resources = DiscoveryResourceCache::new();
242 let mut extensions = DiscoveryExtensionCache::new();
243
244 if let Ok(paths) = CommandDiscovery::get_resource_paths() {
245 for path in paths {
246 if path.exists() && path.is_dir() {
247 for entry in path.read_dir().unwrap() {
248 let entry = entry.unwrap();
249 let path = entry.path();
250 if path.is_file() {
251 let Some(os_file_name) = path.file_name() else {
252 // skip if not a file
253 continue;
254 };
255 let Some(file_name) = os_file_name.to_str() else {
256 // skip if not a valid file name
257 continue;
258 };
259 let file_name_lowercase = file_name.to_lowercase();
260 if DSC_MANIFEST_LIST_EXTENSIONS.iter().any(|ext| file_name_lowercase.ends_with(ext)) ||
261 (kind == &DiscoveryKind::Resource && (DSC_RESOURCE_EXTENSIONS.iter().any(|ext| file_name_lowercase.ends_with(ext))) || DSC_ADAPTED_RESOURCE_EXTENSIONS.iter().any(|ext| file_name_lowercase.ends_with(ext))) ||
262 (kind == &DiscoveryKind::Extension && DSC_EXTENSION_EXTENSIONS.iter().any(|ext| file_name_lowercase.ends_with(ext))) {
263 trace!("{}", t!("discovery.commandDiscovery.foundManifest", path = path.to_string_lossy()));
264 let imported_manifests = match load_manifest(&path)
265 {
266 Ok(r) => r,
267 Err(e) => {
268 // At this point we can't determine whether or not the bad manifest contains
269 // resource that is requested by resource/config operation
270 // if it is, then "ResouceNotFound" error will be issued later
271 // and here we just write as info

Callers 4

list_availableMethod · 0.45
find_resourcesMethod · 0.45
get_extensionsMethod · 0.45

Calls 9

load_manifestFunction · 0.85
insert_resourceFunction · 0.85
write_activityMethod · 0.80
as_strMethod · 0.80
write_incrementMethod · 0.80
valuesMethod · 0.80
defaultFunction · 0.50
newFunction · 0.50
is_matchMethod · 0.45

Tested by

no test coverage detected