Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

NameTypeDescription
idUuidUnique identifier for the template.
created_atDateTime < Utc >Timestamp when the template was created.
updated_atDateTime < Utc >Timestamp when the template was last updated.
deleted_atOption < DateTime < Utc > >Timestamp for soft deletion, if applicable.
generator_idOption < Uuid >Generator ID - NULL for system templates (admin-only).
nameStringName of the template.
descriptionOption < String >Optional description of the template.
versioni32Version number (auto-incremented per name+generator_id).
template_contentStringTera template content.
parameters_schemaStringJSON Schema for parameter validation.
checksumStringSHA-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

NameTypeDescription
generator_idOption < Uuid >Generator ID - NULL for system templates (admin-only).
nameStringName of the template.
descriptionOption < String >Optional description of the template.
versioni32Version number.
template_contentStringTera template content.
parameters_schemaStringJSON Schema for parameter validation.
checksumStringSHA-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:

NameTypeDescription
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())
}
}