drasi_bootstrap_platform/
descriptor.rs1use drasi_lib::bootstrap::BootstrapProvider;
18use drasi_plugin_sdk::prelude::*;
19use utoipa::OpenApi;
20
21use crate::PlatformBootstrapConfig;
22use crate::PlatformBootstrapProvider;
23
24fn default_timeout_seconds() -> ConfigValue<u64> {
27 ConfigValue::Static(300)
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, utoipa::ToSchema)]
32#[schema(as = bootstrap::platform::PlatformBootstrapConfig)]
33#[serde(rename_all = "camelCase", deny_unknown_fields)]
34pub struct PlatformBootstrapConfigDto {
35 #[serde(skip_serializing_if = "Option::is_none")]
36 #[schema(value_type = Option<ConfigValueString>)]
37 pub query_api_url: Option<ConfigValue<String>>,
38
39 #[serde(default = "default_timeout_seconds")]
40 #[schema(value_type = ConfigValueU64)]
41 pub timeout_seconds: ConfigValue<u64>,
42}
43
44#[derive(OpenApi)]
47#[openapi(components(schemas(PlatformBootstrapConfigDto)))]
48struct PlatformBootstrapSchemas;
49
50pub struct PlatformBootstrapDescriptor;
52
53#[async_trait]
54impl BootstrapPluginDescriptor for PlatformBootstrapDescriptor {
55 fn kind(&self) -> &str {
56 "platform"
57 }
58
59 fn config_version(&self) -> &str {
60 "1.0.0"
61 }
62
63 fn config_schema_name(&self) -> &str {
64 "bootstrap.platform.PlatformBootstrapConfig"
65 }
66
67 fn config_schema_json(&self) -> String {
68 let api = PlatformBootstrapSchemas::openapi();
69 serde_json::to_string(
70 &api.components
71 .as_ref()
72 .expect("OpenAPI components missing")
73 .schemas,
74 )
75 .expect("Failed to serialize config schema")
76 }
77
78 async fn create_bootstrap_provider(
79 &self,
80 config_json: &serde_json::Value,
81 _source_config_json: &serde_json::Value,
82 ) -> anyhow::Result<Box<dyn BootstrapProvider>> {
83 let dto: PlatformBootstrapConfigDto = serde_json::from_value(config_json.clone())?;
84 let mapper = DtoMapper::new();
85
86 let query_api_url = mapper.resolve_optional_string(&dto.query_api_url)?;
87 let timeout_seconds = mapper.resolve_typed(&dto.timeout_seconds)?;
88
89 let config = PlatformBootstrapConfig {
90 query_api_url,
91 timeout_seconds,
92 };
93
94 let provider = PlatformBootstrapProvider::new(config)?;
95 Ok(Box::new(provider))
96 }
97}