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

Generators API Reference

This reference documents the API endpoints for managing generators in Brokkr.

Overview

Generators are identity principals that enable external systems (CI/CD pipelines, automation tools) to authenticate with Brokkr and manage resources. Each generator has its own Pre-Authentication Key (PAK) and can only access resources it created.

Data Model

Generator Object

FieldTypeDescription
idUUIDUnique identifier
namestringHuman-readable name (unique, non-null)
descriptionstringOptional description
pak_hashstringHashed PAK (never returned in API responses)
created_attimestampCreation timestamp
updated_attimestampLast update timestamp
deleted_attimestampSoft-delete timestamp (null if active)
last_active_attimestampLast activity timestamp (null if never active)
is_activebooleanWhether the generator is currently active

NewGenerator Object

Used when creating a generator:

FieldTypeRequiredDescription
namestringYesUnique name for the generator
descriptionstringNoOptional description

API Endpoints

List Generators

List all generators. Requires admin access.

GET /api/v1/generators
Authorization: Bearer <admin_pak>

Response: 200 OK

[
  {
    "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "name": "github-actions-prod",
    "description": "Production deployment pipeline",
    "created_at": "2025-01-02T10:00:00Z",
    "updated_at": "2025-01-02T10:00:00Z",
    "deleted_at": null
  }
]

Error Responses:

StatusDescription
403Admin access required
500Internal server error

Create Generator

Create a new generator and receive its PAK. Requires admin access.

POST /api/v1/generators
Authorization: Bearer <admin_pak>
Content-Type: application/json

Request Body:

{
  "name": "github-actions-prod",
  "description": "Production deployment pipeline"
}
FieldTypeRequiredDescription
namestringYesUnique name (max 255 characters)
descriptionstringNoOptional description

Response: 200 OK

{
  "generator": {
    "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "name": "github-actions-prod",
    "description": "Production deployment pipeline",
    "created_at": "2025-01-02T10:00:00Z",
    "updated_at": "2025-01-02T10:00:00Z",
    "deleted_at": null
  },
  "pak": "brk_gen_abc123...xyz789"
}

The pak field is only returned once at creation time. Store it securely immediately.

Error Responses:

StatusDescription
400Invalid generator data (e.g., duplicate name)
403Admin access required
500Internal server error

Get Generator

Retrieve a specific generator by ID. Accessible by admin or the generator itself.

GET /api/v1/generators/{id}
Authorization: Bearer <admin_pak | generator_pak>

Path Parameters:

ParameterTypeDescription
idUUIDGenerator ID

Response: 200 OK

{
  "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "name": "github-actions-prod",
  "description": "Production deployment pipeline",
  "created_at": "2025-01-02T10:00:00Z",
  "updated_at": "2025-01-02T10:00:00Z",
  "deleted_at": null
}

Error Responses:

StatusDescription
403Unauthorized access (not admin and not the generator)
404Generator not found
500Internal server error

Update Generator

Update a generator’s metadata. Accessible by admin or the generator itself.

PUT /api/v1/generators/{id}
Authorization: Bearer <admin_pak | generator_pak>
Content-Type: application/json

Path Parameters:

ParameterTypeDescription
idUUIDGenerator ID

Request Body:

{
  "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "name": "github-actions-prod",
  "description": "Updated description"
}

All fields from the Generator object can be provided, though id, created_at, and pak_hash are ignored if included.

Response: 200 OK

{
  "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "name": "github-actions-prod",
  "description": "Updated description",
  "created_at": "2025-01-02T10:00:00Z",
  "updated_at": "2025-01-02T11:00:00Z",
  "deleted_at": null
}

Error Responses:

StatusDescription
403Unauthorized access
404Generator not found
500Internal server error

Delete Generator

Soft-delete a generator. Accessible by admin or the generator itself.

DELETE /api/v1/generators/{id}
Authorization: Bearer <admin_pak | generator_pak>

Path Parameters:

ParameterTypeDescription
idUUIDGenerator ID

Response: 204 No Content

The generator is soft-deleted (marked with deleted_at timestamp). A database trigger cascades the soft-delete to all stacks owned by this generator and their deployment objects.

Error Responses:

StatusDescription
403Unauthorized access
404Generator not found
500Internal server error

Rotate Generator PAK

Generate a new PAK for the generator, invalidating the previous one. Accessible by admin or the generator itself.

POST /api/v1/generators/{id}/rotate-pak
Authorization: Bearer <admin_pak | generator_pak>

Path Parameters:

ParameterTypeDescription
idUUIDGenerator ID

Response: 200 OK

{
  "generator": {
    "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "name": "github-actions-prod",
    "description": "Production deployment pipeline",
    "created_at": "2025-01-02T10:00:00Z",
    "updated_at": "2025-01-02T12:00:00Z",
    "deleted_at": null
  },
  "pak": "brk_gen_new123...newxyz"
}

The old PAK is immediately invalidated. Store the new PAK securely and update all systems using the old PAK.

Error Responses:

StatusDescription
403Unauthorized access
404Generator not found
500Internal server error

Authentication

PAK Format

Generator PAKs follow the format: brk_gen_<random_string>

The prefix identifies this as a generator PAK (as opposed to admin or agent PAKs).

Authorization Header

Include the PAK in the Authorization header:

Authorization: Bearer brk_gen_abc123...xyz789

Permission Model

OperationAdmin PAKGenerator PAK (own)Generator PAK (other)
List generatorsYesNoNo
Create generatorYesNoNo
Get generatorYesYesNo
Update generatorYesYesNo
Delete generatorYesYesNo
Rotate PAKYesYesNo

Resource Scoping

Resources created by a generator are scoped to that generator:

Stacks

When a generator creates a stack, the stack’s generator_id is set to the generator’s ID. The generator can only view and modify its own stacks.

Templates

Templates can be:

  • Generator-scoped: Created by a generator, only visible to that generator
  • System templates: Created by admin (no generator_id), visible to all generators

Deployment Objects

Deployment objects inherit the generator_id from their parent stack.

Database Schema

generators Table

ColumnTypeConstraints
idUUIDPRIMARY KEY, DEFAULT uuid_generate_v4()
nameVARCHAR(255)NOT NULL, UNIQUE
descriptionTEXT
pak_hashVARCHAR(255)
created_atTIMESTAMPNOT NULL, DEFAULT NOW()
updated_atTIMESTAMPNOT NULL, DEFAULT NOW()
deleted_atTIMESTAMPNULL (soft delete)
last_active_atTIMESTAMPNULL
is_activeBOOLEANNOT NULL, DEFAULT false

Unique Constraint

The name column has a partial unique index excluding soft-deleted rows:

CREATE UNIQUE INDEX generators_name_unique
ON generators (name)
WHERE deleted_at IS NULL;

This allows reusing names after a generator is deleted.