Skip to main content

Mountain/RPC/CocoonService/Extension/
GetAllExtensions.rs

1
2//! Return every scanned extension projected into the gRPC `ExtensionInfo`
3//! shape.
4
5use tonic::{Response, Status};
6use CommonLibrary::ExtensionManagement::ExtensionManagementService::ExtensionManagementService;
7
8use crate::{
9	RPC::CocoonService::CocoonServiceImpl,
10	Vine::Generated::{Empty, ExtensionInfo, GetAllExtensionsResponse},
11};
12
13pub async fn Fn(Service:&CocoonServiceImpl, _Request:Empty) -> Result<Response<GetAllExtensionsResponse>, Status> {
14	let Extensions = Service.environment.GetExtensions().await.unwrap_or_default();
15
16	let List = Extensions
17		.iter()
18		.map(|Value| {
19			ExtensionInfo {
20				id:Value.get("Identifier").and_then(|V| V.as_str()).unwrap_or("").to_string(),
21				display_name:Value.get("Name").and_then(|V| V.as_str()).unwrap_or("").to_string(),
22				version:Value.get("Version").and_then(|V| V.as_str()).unwrap_or("").to_string(),
23				is_active:true,
24				extension_path:Value
25					.get("ExtensionLocation")
26					.and_then(|V| V.as_str())
27					.unwrap_or("")
28					.to_string(),
29			}
30		})
31		.collect();
32
33	Ok(Response::new(GetAllExtensionsResponse { extensions:List }))
34}