(path: &Path, manifest: &ExtensionManifest)
| 836 | } |
| 837 | |
| 838 | fn load_extension_manifest(path: &Path, manifest: &ExtensionManifest) -> Result<DscExtension, DscError> { |
| 839 | let mut capabilities: Vec<dscextension::Capability> = vec![]; |
| 840 | if let Some(discover) = &manifest.discover { |
| 841 | verify_executable(&manifest.r#type, "discover", &discover.executable, path.parent().unwrap()); |
| 842 | capabilities.push(dscextension::Capability::Discover); |
| 843 | } |
| 844 | if let Some(secret) = &manifest.secret { |
| 845 | verify_executable(&manifest.r#type, "secret", &secret.executable, path.parent().unwrap()); |
| 846 | capabilities.push(dscextension::Capability::Secret); |
| 847 | } |
| 848 | let import = if let Some(import) = &manifest.import { |
| 849 | verify_executable(&manifest.r#type, "import", &import.executable, path.parent().unwrap()); |
| 850 | capabilities.push(dscextension::Capability::Import); |
| 851 | if import.file_extensions.is_empty() { |
| 852 | warn!("{}", t!("discovery.commandDiscovery.importExtensionsEmpty", extension = manifest.r#type)); |
| 853 | None |
| 854 | } else { |
| 855 | Some(import.clone()) |
| 856 | } |
| 857 | } else { |
| 858 | None |
| 859 | }; |
| 860 | |
| 861 | let extension = DscExtension { |
| 862 | type_name: manifest.r#type.clone(), |
| 863 | deprecation_message: manifest.deprecation_message.clone(), |
| 864 | description: manifest.description.clone(), |
| 865 | version: manifest.version.clone(), |
| 866 | capabilities, |
| 867 | import, |
| 868 | path: path.to_path_buf(), |
| 869 | directory: path.parent().unwrap().to_path_buf(), |
| 870 | manifest: serde_json::to_value(manifest)?, |
| 871 | ..Default::default() |
| 872 | }; |
| 873 | |
| 874 | Ok(extension) |
| 875 | } |
| 876 | |
| 877 | fn verify_executable(resource: &str, operation: &str, executable: &str, directory: &Path) { |
| 878 | if canonicalize_which(executable, Some(directory)).is_err() { |
no test coverage detected