Skip to content

brokkr-models::models::generator

Rust

Generator Module

This module defines structures and methods for managing generators in the Brokkr system.

Data Model

Generators are entities responsible for creating and managing stacks. They are stored in the generators table with the following structure:

  • id: UUID, primary key
  • created_at: TIMESTAMPTZ, creation timestamp
  • updated_at: TIMESTAMPTZ, last update timestamp
  • deleted_at: TIMESTAMPTZ, soft deletion timestamp (nullable)
  • name: VARCHAR(255), name of the generator
  • description: TEXT, optional description of the generator
  • pak_hash: TEXT, hash of the Prefixed API Key (PAK) for the generator (nullable)
  • last_active_at: TIMESTAMPTZ, timestamp of the last activity (nullable)
  • is_active: BOOLEAN, indicates if the generator is currently active

Usage

Generators are used to create and manage stacks in the Brokkr system. They can be authenticated using their PAK and can perform operations on their associated stacks.

Constraints

  • The name must be a non-empty string and cannot exceed 255 characters.
  • The pak_hash must be a valid hash when provided.
  • The is_active flag determines whether the generator can perform operations.

pub

Derives: Queryable, Selectable, Identifiable, AsChangeset, Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Hash, ToSchema

Represents a generator in the Brokkr system.

Name Type Description
id Uuid Unique identifier for the generator.
created_at DateTime<Utc> Timestamp of when the generator was created.
updated_at DateTime<Utc> Timestamp of when the generator was last updated.
deleted_at Option<DateTime<Utc>> Timestamp of when the generator was deleted, if applicable.
name String Name of the generator.
description Option<String> Optional description of the generator.
pak_hash Option<String> Hash of the Prefixed API Key (PAK) for the generator.
last_active_at Option<DateTime<Utc>> Timestamp of when the generator was last active.
is_active bool Indicates whether the generator is currently active.
is_system bool Reserved: true for the singleton system generator provisioned at broker startup.

pub

Derives: Insertable, Debug, Clone, Serialize, Deserialize, ToSchema

Represents the data required to create a new generator.

Name Type Description
name String Name of the new generator.
description Option<String> Optional description of the new generator.

pub

fn new(
name: String,
description: Option<String>,
) -> Result<Self, String>

Creates a new NewGenerator instance.

Parameters:

Name Type Description
name String The name for the generator. Must be non-empty and not exceed 255 characters.
description Option<String> An optional description for the generator.

Returns:

Returns Ok(NewGenerator) if all parameters are valid, otherwise returns an Err with a description of the validation failure.

Source
pub fn new(name: String, description: Option<String>) -> Result<Self, String> {
if name.trim().is_empty() {
return Err("Generator name cannot be empty".to_string());
}
if name.len() > 255 {
return Err("Generator name cannot exceed 255 characters".to_string());
}
Ok(NewGenerator { name, description })
}