Skip to main content

Mountain/RPC/CocoonService/Extension/
GetExtension.rs

1#![allow(non_snake_case)]
2
3//! Look up a single scanned extension by id and project the manifest into
4//! the gRPC `ExtensionInfo` shape.
5
6use tonic::{Response, Status};
7use CommonLibrary::ExtensionManagement::ExtensionManagementService::ExtensionManagementService;
8
9use crate::{
10	RPC::CocoonService::CocoonServiceImpl,
11	Vine::Generated::{ExtensionInfo, GetExtensionRequest, GetExtensionResponse},
12	dev_log,
13};
14
15pub async fn Fn(
16	Service:&CocoonServiceImpl,
17
18	Request:GetExtensionRequest,
19) -> Result<Response<GetExtensionResponse>, Status> {
20	dev_log!("cocoon", "[CocoonService] get_extension: {}", Request.extension_id);
21
22	let Found = Service
23		.environment
24		.GetExtension(Request.extension_id.clone())
25		.await
26		.ok()
27		.flatten();
28
29	let Info = Found.map(|Value| {
30		ExtensionInfo {
31			id:Request.extension_id,
32			display_name:Value.get("Name").and_then(|V| V.as_str()).unwrap_or("").to_string(),
33			version:Value.get("Version").and_then(|V| V.as_str()).unwrap_or("").to_string(),
34			is_active:true,
35			extension_path:Value
36				.get("ExtensionLocation")
37				.and_then(|V| V.as_str())
38				.unwrap_or("")
39				.to_string(),
40		}
41	});
42
43	Ok(Response::new(GetExtensionResponse { extension:Info }))
44}