MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / list_gateways_with_source

Function list_gateways_with_source

crates/openshell-bootstrap/src/metadata.rs:312–376  ·  view source on GitHub ↗

List all gateways that have stored metadata, along with the config layer that supplied each record.

()

Source from the content-addressed store, hash-verified

310/// List all gateways that have stored metadata, along with the config layer
311/// that supplied each record.
312pub fn list_gateways_with_source() -> Result<Vec<ListedGateway>> {
313 let mut gateways = Vec::new();
314 let mut seen: std::collections::HashSet<String> = std::collections::HashSet::new();
315
316 let user_dir = user_gateways_dir()?;
317 if user_dir.exists() {
318 let entries = std::fs::read_dir(&user_dir)
319 .into_diagnostic()
320 .wrap_err_with(|| format!("failed to read directory {}", user_dir.display()))?;
321 for entry in entries {
322 let entry = entry.into_diagnostic()?;
323 let path = entry.path();
324 if !path.is_dir() {
325 continue;
326 }
327
328 let metadata_path = path.join("metadata.json");
329 if !user_entry_shadows_system(&metadata_path) {
330 continue;
331 }
332
333 let name = entry.file_name().to_string_lossy().to_string();
334 if !seen.insert(name) {
335 continue;
336 }
337
338 if let Ok(metadata) = parse_gateway_metadata(&metadata_path) {
339 gateways.push(ListedGateway {
340 metadata,
341 source: GatewayMetadataSource::User,
342 });
343 }
344 }
345 }
346
347 let system_dir = system_gateways_dir();
348 if system_dir.exists() {
349 let entries = std::fs::read_dir(&system_dir)
350 .into_diagnostic()
351 .wrap_err_with(|| format!("failed to read directory {}", system_dir.display()))?;
352 for entry in entries {
353 let entry = entry.into_diagnostic()?;
354 let path = entry.path();
355 if !path.is_dir() {
356 continue;
357 }
358
359 let name = entry.file_name().to_string_lossy().to_string();
360 if seen.contains(&name) {
361 continue;
362 }
363
364 let metadata_path = path.join("metadata.json");
365 if let Ok(metadata) = parse_gateway_metadata(&metadata_path) {
366 gateways.push(ListedGateway {
367 metadata,
368 source: GatewayMetadataSource::System,
369 });

Calls 7

user_gateways_dirFunction · 0.85
parse_gateway_metadataFunction · 0.85
system_gateways_dirFunction · 0.85
existsMethod · 0.80
pathMethod · 0.80
pushMethod · 0.80