Load binary registry from a filesystem directory override.
(registry_dir: &std::path::Path)
| 251 | |
| 252 | /// Load binary registry from a filesystem directory override. |
| 253 | pub fn load_binary_registry_from_dir(registry_dir: &std::path::Path) -> Result<BinaryRegistry> { |
| 254 | let mut binaries = HashMap::new(); |
| 255 | let binaries_dir = registry_dir.join("binaries"); |
| 256 | if binaries_dir.is_dir() { |
| 257 | let entries = std::fs::read_dir(&binaries_dir) |
| 258 | .into_diagnostic() |
| 259 | .wrap_err_with(|| format!("reading directory {}", binaries_dir.display()))?; |
| 260 | for entry in entries { |
| 261 | let entry = entry.into_diagnostic()?; |
| 262 | let path = entry.path(); |
| 263 | if path.extension().is_some_and(|ext| ext == "yaml") { |
| 264 | let contents = std::fs::read_to_string(&path) |
| 265 | .into_diagnostic() |
| 266 | .wrap_err_with(|| format!("reading {}", path.display()))?; |
| 267 | let cap = parse_binary_capability(&contents, &path.display().to_string())?; |
| 268 | binaries.insert(cap.path.clone(), cap); |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | Ok(BinaryRegistry { binaries }) |
| 273 | } |
| 274 | |
| 275 | /// Accessor for the embedded registry (used by credentials module for API descriptors). |
| 276 | pub fn embedded_registry() -> &'static Dir<'static> { |
no test coverage detected