Skip to main content

Mountain/RPC/CocoonService/Extension/
GetAllExtensions.rs

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