brokkr-models::models::stack_templates Rust
Structs
brokkr-models::models::stack_templates::StackTemplate
pub
Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash, ToSchema, ``
Represents a stack template in the database.
Fields
| Name | Type | Description |
|---|---|---|
id | Uuid | Unique identifier for the template. |
created_at | DateTime < Utc > | Timestamp when the template was created. |
updated_at | DateTime < Utc > | Timestamp when the template was last updated. |
deleted_at | Option < DateTime < Utc > > | Timestamp for soft deletion, if applicable. |
generator_id | Option < Uuid > | Generator ID - NULL for system templates (admin-only). |
name | String | Name of the template. |
description | Option < String > | Optional description of the template. |
version | i32 | Version number (auto-incremented per name+generator_id). |
template_content | String | Tera template content. |
parameters_schema | String | JSON Schema for parameter validation. |
checksum | String | SHA-256 checksum of template_content. |
brokkr-models::models::stack_templates::NewStackTemplate
pub
Derives: Insertable, Debug, Clone, Serialize, Deserialize, ToSchema
Represents a new stack template to be inserted into the database.
Fields
| Name | Type | Description |
|---|---|---|
generator_id | Option < Uuid > | Generator ID - NULL for system templates (admin-only). |
name | String | Name of the template. |
description | Option < String > | Optional description of the template. |
version | i32 | Version number. |
template_content | String | Tera template content. |
parameters_schema | String | JSON Schema for parameter validation. |
checksum | String | SHA-256 checksum of template_content. |
Methods
new pub
#![allow(unused)]
fn main() {
fn new (generator_id : Option < Uuid > , name : String , description : Option < String > , version : i32 , template_content : String , parameters_schema : String ,) -> Result < Self , String >
}
Creates a new NewStackTemplate instance.
Parameters:
| Name | Type | Description |
|---|---|---|
generator_id | - | Optional generator ID. NULL means system template. |
name | - | Name of the template. Must be non-empty. |
description | - | Optional description. If provided, must not be empty. |
version | - | Version number for this template. |
template_content | - | Tera template content. |
parameters_schema | - | JSON Schema as a string. |
Returns:
Returns Ok(NewStackTemplate) if all parameters are valid, otherwise returns an Err with a description of the validation failure.
Source
#![allow(unused)]
fn main() {
pub fn new(
generator_id: Option<Uuid>,
name: String,
description: Option<String>,
version: i32,
template_content: String,
parameters_schema: String,
) -> Result<Self, String> {
// Validate name
if name.trim().is_empty() {
return Err("Template name cannot be empty".to_string());
}
// Validate description (if provided)
if let Some(desc) = &description {
if desc.trim().is_empty() {
return Err("Template description cannot be empty if provided".to_string());
}
}
// Validate template_content is not empty
if template_content.trim().is_empty() {
return Err("Template content cannot be empty".to_string());
}
// Validate parameters_schema is not empty
if parameters_schema.trim().is_empty() {
return Err("Parameters schema cannot be empty".to_string());
}
// Validate version is positive
if version < 1 {
return Err("Version must be at least 1".to_string());
}
// Generate checksum
let checksum = generate_checksum(&template_content);
Ok(NewStackTemplate {
generator_id,
name,
description,
version,
template_content,
parameters_schema,
checksum,
})
}
}
Functions
brokkr-models::models::stack_templates::generate_checksum
pub
#![allow(unused)]
fn main() {
fn generate_checksum (content : & str) -> String
}
Generates a SHA-256 checksum for the given content.
Source
#![allow(unused)]
fn main() {
pub fn generate_checksum(content: &str) -> String {
let mut hasher = Sha256::new();
hasher.update(content.as_bytes());
format!("{:x}", hasher.finalize())
}
}