Skip to main content

drasi_bootstrap_scriptfile/
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 ScriptFile bootstrap provider.
16
17use drasi_lib::bootstrap::BootstrapProvider;
18use drasi_plugin_sdk::prelude::*;
19use utoipa::OpenApi;
20
21use crate::ScriptFileBootstrapConfig;
22use crate::ScriptFileBootstrapProvider;
23
24// ── DTO types ────────────────────────────────────────────────────────────────
25
26/// Configuration DTO for the ScriptFile bootstrap provider.
27#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, utoipa::ToSchema)]
28#[schema(as = bootstrap::scriptfile::ScriptFileBootstrapConfig)]
29#[serde(rename_all = "camelCase", deny_unknown_fields)]
30pub struct ScriptFileBootstrapConfigDto {
31    #[serde(default)]
32    pub file_paths: Vec<String>,
33}
34
35// ── Descriptor ───────────────────────────────────────────────────────────────
36
37#[derive(OpenApi)]
38#[openapi(components(schemas(ScriptFileBootstrapConfigDto)))]
39struct ScriptFileBootstrapSchemas;
40
41/// Plugin descriptor for the ScriptFile bootstrap provider.
42pub struct ScriptFileBootstrapDescriptor;
43
44#[async_trait]
45impl BootstrapPluginDescriptor for ScriptFileBootstrapDescriptor {
46    fn kind(&self) -> &str {
47        "scriptfile"
48    }
49
50    fn config_version(&self) -> &str {
51        "1.0.0"
52    }
53
54    fn config_schema_name(&self) -> &str {
55        "bootstrap.scriptfile.ScriptFileBootstrapConfig"
56    }
57
58    fn config_schema_json(&self) -> String {
59        let api = ScriptFileBootstrapSchemas::openapi();
60        serde_json::to_string(
61            &api.components
62                .as_ref()
63                .expect("OpenAPI components missing")
64                .schemas,
65        )
66        .expect("Failed to serialize config schema")
67    }
68
69    async fn create_bootstrap_provider(
70        &self,
71        config_json: &serde_json::Value,
72        _source_config_json: &serde_json::Value,
73    ) -> anyhow::Result<Box<dyn BootstrapProvider>> {
74        let dto: ScriptFileBootstrapConfigDto = serde_json::from_value(config_json.clone())?;
75
76        let config = ScriptFileBootstrapConfig {
77            file_paths: dto.file_paths,
78        };
79
80        Ok(Box::new(ScriptFileBootstrapProvider::new(config)))
81    }
82}