tsk/assets/
mod.rs

1//! Asset management system for TSK
2//!
3//! This module provides an abstraction over asset storage and retrieval,
4//! allowing TSK to embed assets in the binary while maintaining flexibility
5//! for future extensions like user-specific or repository-specific assets.
6
7use anyhow::Result;
8use async_trait::async_trait;
9
10pub mod embedded;
11pub mod filesystem;
12pub mod layered;
13pub mod utils;
14
15/// Trait for managing TSK assets including templates and dockerfiles
16#[async_trait]
17pub trait AssetManager: Send + Sync {
18    /// Get a template by type (e.g., "feature", "fix", "doc")
19    fn get_template(&self, template_type: &str) -> Result<String>;
20
21    /// Get a dockerfile as raw bytes
22    fn get_dockerfile(&self, dockerfile_name: &str) -> Result<Vec<u8>>;
23
24    /// Get a specific file from a dockerfile directory
25    fn get_dockerfile_file(&self, dockerfile_name: &str, file_path: &str) -> Result<Vec<u8>>;
26
27    /// List all available templates
28    fn list_templates(&self) -> Vec<String>;
29
30    /// List all available dockerfiles
31    fn list_dockerfiles(&self) -> Vec<String>;
32
33    /// Get a Docker layer file
34    fn get_docker_layer(
35        &self,
36        layer_type: &str,
37        layer_name: &str,
38        _project_root: Option<&std::path::Path>,
39    ) -> Result<Vec<u8>> {
40        // Default implementation for backward compatibility
41        // Uses the existing dockerfile methods
42        let dockerfile_name = if layer_type == "base" {
43            "base".to_string()
44        } else {
45            format!("{layer_type}/{layer_name}")
46        };
47        self.get_dockerfile(&dockerfile_name)
48    }
49
50    /// List available Docker layers of a specific type
51    fn list_docker_layers(
52        &self,
53        layer_type: &str,
54        _project_root: Option<&std::path::Path>,
55    ) -> Vec<String> {
56        // Default implementation for backward compatibility
57        let prefix = if layer_type == "base" {
58            "base".to_string()
59        } else {
60            format!("{layer_type}/")
61        };
62
63        self.list_dockerfiles()
64            .into_iter()
65            .filter(|name| name.starts_with(&prefix))
66            .map(|name| {
67                if layer_type == "base" {
68                    "base".to_string()
69                } else {
70                    name.strip_prefix(&prefix).unwrap_or(&name).to_string()
71                }
72            })
73            .collect()
74    }
75}