Mountain/RPC/CocoonService/Extension/
GetExtension.rs1#![allow(non_snake_case)]
2
3use 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 Request:GetExtensionRequest,
18) -> Result<Response<GetExtensionResponse>, Status> {
19 dev_log!("cocoon", "[CocoonService] get_extension: {}", Request.extension_id);
20
21 let Found = Service
22 .environment
23 .GetExtension(Request.extension_id.clone())
24 .await
25 .ok()
26 .flatten();
27
28 let Info = Found.map(|Value| {
29 ExtensionInfo {
30 id:Request.extension_id,
31 display_name:Value.get("Name").and_then(|V| V.as_str()).unwrap_or("").to_string(),
32 version:Value.get("Version").and_then(|V| V.as_str()).unwrap_or("").to_string(),
33 is_active:true,
34 extension_path:Value
35 .get("ExtensionLocation")
36 .and_then(|V| V.as_str())
37 .unwrap_or("")
38 .to_string(),
39 }
40 });
41
42 Ok(Response::new(GetExtensionResponse { extension:Info }))
43}