Skip to content

brokkr-models::models::rendered_deployment_objects

Rust

Rendered Deployment Object Module

This module defines structures and methods for tracking the provenance of deployment objects created from templates.

Data Model

Rendered deployment objects track the relationship between a deployment object and the template instance that created it. This provides provenance information for auditing, debugging, and reconstruction purposes.

  • id: UUID, primary key
  • deployment_object_id: UUID, foreign key referencing the deployment_objects table
  • template_id: UUID, foreign key referencing the stack_templates table
  • template_version: INTEGER, version of the template used (snapshot)
  • template_parameters: TEXT, JSON string of parameters used for rendering
  • created_at: TIMESTAMP, when the rendering occurred

Usage

When a template is instantiated with parameters, the system:

  1. Validates parameters against the template’s JSON Schema
  2. Renders the Tera template with the parameters
  3. Creates a deployment object with the rendered YAML
  4. Creates a rendered_deployment_object record to track the provenance

This allows reconstruction of how any deployment object was created and enables re-rendering with different parameters if needed.

Constraints

  • deployment_object_id must be a valid, non-nil UUID.
  • template_id must be a valid, non-nil UUID.
  • template_version must be at least 1.
  • template_parameters must be a valid JSON string.

pub

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

Represents a rendered deployment object provenance record in the database.

Name Type Description
id Uuid Unique identifier for this provenance record.
deployment_object_id Uuid ID of the deployment object that was created.
template_id Uuid ID of the template used to create the deployment object.
template_version i32 Version of the template at the time of rendering (snapshot).
template_parameters String JSON string of parameters used for rendering.
created_at DateTime<Utc> Timestamp when the rendering occurred.

pub

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

Represents a new rendered deployment object provenance record to be inserted.

Name Type Description
deployment_object_id Uuid ID of the deployment object that was created.
template_id Uuid ID of the template used to create the deployment object.
template_version i32 Version of the template at the time of rendering (snapshot).
template_parameters String JSON string of parameters used for rendering.

pub

fn new(
deployment_object_id: Uuid,
template_id: Uuid,
template_version: i32,
template_parameters: String,
) -> Result<Self, String>

Creates a new NewRenderedDeploymentObject instance.

Parameters:

Name Type Description
deployment_object_id Uuid UUID of the deployment object created from this rendering.
template_id Uuid UUID of the template used for rendering.
template_version i32 Version number of the template used.
template_parameters String JSON string of the parameters used for rendering.

Returns:

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

Source
pub fn new(
deployment_object_id: Uuid,
template_id: Uuid,
template_version: i32,
template_parameters: String,
) -> Result<Self, String> {
// Validate deployment_object_id
if deployment_object_id.is_nil() {
return Err("Invalid deployment object ID".to_string());
}
// Validate template_id
if template_id.is_nil() {
return Err("Invalid template ID".to_string());
}
// Validate template_version
if template_version < 1 {
return Err("Template version must be at least 1".to_string());
}
// Validate template_parameters is valid JSON
if serde_json::from_str::<serde_json::Value>(&template_parameters).is_err() {
return Err("Template parameters must be valid JSON".to_string());
}
Ok(NewRenderedDeploymentObject {
deployment_object_id,
template_id,
template_version,
template_parameters,
})
}