Skip to main content

drasi_bootstrap_platform/
descriptor.rs

1// Copyright 2025 The Drasi Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Plugin descriptor for the Platform bootstrap provider.
16
17use drasi_lib::bootstrap::BootstrapProvider;
18use drasi_plugin_sdk::prelude::*;
19use utoipa::OpenApi;
20
21use crate::PlatformBootstrapConfig;
22use crate::PlatformBootstrapProvider;
23
24// ── DTO types ────────────────────────────────────────────────────────────────
25
26fn default_timeout_seconds() -> ConfigValue<u64> {
27    ConfigValue::Static(300)
28}
29
30/// Configuration DTO for the Platform bootstrap provider.
31#[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// ── Descriptor ───────────────────────────────────────────────────────────────
45
46#[derive(OpenApi)]
47#[openapi(components(schemas(PlatformBootstrapConfigDto)))]
48struct PlatformBootstrapSchemas;
49
50/// Plugin descriptor for the Platform bootstrap provider.
51pub 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}