admin

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const MinPasswordLen = 8

MinPasswordLen is the minimum accepted password length, enforced at every entry point (CLI, HTTP form, GOLEM_ADMIN_PASSWORD env var).

Variables

View Source
var ErrLastAdmin = errors.New("refusing to leave the orchestrator with no admin user")

ErrLastAdmin is returned when an operation would leave the orchestrator with no admin user.

View Source
var ErrRepoInUse = errors.New("repo still has tickets")

ErrRepoInUse is returned when removing a GitHub repo row would orphan tickets that were ingested from it.

View Source
var ErrUnknownRole = errors.New("unknown role")

ErrUnknownRole is returned when a role string is not a known rbac role.

View Source
var ErrWeakPassword = errors.New("password too weak")

ErrWeakPassword is returned when a password fails ValidatePassword.

View Source
var ErrWrongPassword = errors.New("current password is incorrect")

ErrWrongPassword is returned when a change-password call presents an old password that does not match the stored hash.

Functions

func ChangePassword added in v0.0.3

func ChangePassword(gdb *gorm.DB, userID uint, oldPass, newPass string) error

ChangePassword replaces the given user's password hash after verifying the old password. Sessions are not revoked so the caller stays signed in on the device they used to change it; a separate "sign out everywhere" is a future feature. Returns ErrWrongPassword if oldPass does not match, or ErrWeakPassword if newPass fails ValidatePassword.

func ReposList added in v0.1.0

func ReposList(gdb *gorm.DB) ([]db.GitHubRepo, error)

ReposList returns every persisted GitHub repo row, oldest first.

The settings page shows the union of these rows and the remotes registered shems declare, so a remote can appear there without a row existing yet. Only rows are removable — a remote a shem declares comes back on its next registration, and the way to be rid of that one is to stop the shem declaring it.

func ReposRemove added in v0.1.0

func ReposRemove(gdb *gorm.DB, remote string, force bool) error

ReposRemove deletes the GitHub repo row for remote, along with any outbox rows queued against its tickets.

Refuses while tickets from that repo exist unless force is set: those tickets keep their issue_number and repo_remote, and the claim predicates require a matching approval, so deleting the row underneath them leaves work that can never sync and whose provenance no longer resolves. The caller is told the count so the choice is an informed one.

This exists because there was no way to remove a repo at all — not in the UI, not here — so a row saved once was permanent short of hand-written SQL against the database file.

func ShemsAdd

func ShemsAdd(gdb *gorm.DB, name string) error

ShemsAdd generates a random 32-byte hex API key, stores its bcrypt hash, and prints the raw key once to stdout.

func ShemsAddOrUpdate

func ShemsAddOrUpdate(gdb *gorm.DB, name, key string) error

ShemsAddOrUpdate creates a shem with the given name and API key, or updates its key hash if the shem already exists. Used for env-var-based auto-setup.

func ShemsRemove

func ShemsRemove(gdb *gorm.DB, name string) error

ShemsRemove hard-deletes the shem with the given name.

func UsersAdd

func UsersAdd(gdb *gorm.DB, username, role string) error

UsersAdd prompts for a password (or reads GOLEM_ADMIN_PASSWORD), bcrypt-hashes it, and inserts a new User with the given role. The env var allows non-interactive use in Docker.

func UsersAddOrUpdate

func UsersAddOrUpdate(gdb *gorm.DB, username, password, role string) error

UsersAddOrUpdate creates a user with the given username, password and role, or updates the password hash and role if the user already exists.

func UsersList added in v0.0.3

func UsersList(gdb *gorm.DB) ([]db.User, error)

UsersList returns all users ordered by username.

func UsersRemove

func UsersRemove(gdb *gorm.DB, username string) error

UsersRemove hard-deletes the user with the given username along with all their sessions, so their access is revoked immediately. It refuses to remove the last admin, and reports an error if the user does not exist.

func UsersSetRole added in v0.0.3

func UsersSetRole(gdb *gorm.DB, username, role string) error

UsersSetRole changes a user's role, refusing to demote the last admin.

func ValidatePassword added in v0.0.3

func ValidatePassword(pass string) error

ValidatePassword returns ErrWeakPassword if pass is unacceptable. Keep this the single source of truth so the UI, CLI, and env-var seed can't drift.

Types

type BackfillResult added in v0.1.0

type BackfillResult struct {
	// Scanned is the number of GitHub-linked tickets with an empty
	// body_hash that were examined.
	Scanned int
	// Repaired is the number whose body_hash was written (or, in a dry
	// run, would have been written).
	Repaired int
	// Regated is the number of GitHub-linked, unclaimed, non-closed
	// tickets carrying intake_approved with an EMPTY approved_body_hash —
	// the re-review F1 shape — that were returned to pending-approval (or,
	// in a dry run, would have been).
	Regated int
	// DryRun records which of those two the caller asked for.
	DryRun bool
}

BackfillResult reports what BackfillBodyHash found and what it did.

func BackfillBodyHash added in v0.1.0

func BackfillBodyHash(gdb *gorm.DB, dryRun bool) (BackfillResult, error)

BackfillBodyHash repairs GitHub-linked tickets left half-migrated by a deployment made partway through the GitHub integration work.

WHO NEEDS IT. Upgrades from before the GitHub integration are unaffected: issue_number did not exist, so every migrated row has issue_number NULL and short-circuits the claim predicate. Three narrower windows do need it, and they fail in two different directions. AutoMigrate adds each missing column at its zero value, so the shape a row lands in depends on which columns its last writer knew about:

[094e3f8, f9e87e0)  issue_number only.
                    -> intake_approved=0, both hashes ''.
                    Fail-CLOSED: unclaimable, and un-approvable too,
                    because actionStart refuses a row whose description
                    does not hash to its body_hash.
[f9e87e0, fef123b)  + intake_approved.
                    -> an approved ticket lands intake_approved=1 with
                    both hashes ''. Before re-review finding F1 the claim
                    predicate read that as approval, because the empty
                    string equals itself: fail-OPEN, claimable with no
                    hash binding at all, and that build's applyIssue had
                    no re-gate either, so the stored text may never have
                    been read by anyone. The predicate now refuses it;
                    regateUnboundApprovals below is how it gets un-stuck.
[fef123b, c2fe234)  + approved_body_hash.
                    -> intake_approved=1, approved_body_hash=H(text the
                    operator approved), body_hash ''. Fail-CLOSED, and
                    the one shape the body_hash write below makes
                    claimable again immediately.

A backup restored from any such deployment has the same rows.

WHY THEY DO NOT HEAL THEMSELVES. Ingest rewrites body_hash only for issues that come back from a label-filtered, cursor-bounded list query, and reconcile deliberately never writes the ticket row at all, so a quiet issue — one nobody edits — is never visited again. The ticket sits in the dashboard looking released and no shem can ever take it.

WHAT IT WRITES, AND WHAT IT MUST NEVER WRITE. body_hash and nothing else. body_hash is ghsync's column: it is the record of what the live issue currently says, and this repair restores the invariant every other site maintains —

BodyHash == ghsync.HashDescription(Description)

— using that same function over that row's own stored description. It must keep using exactly that function over exactly those bytes. Hashing anything else (the issue body alone, say, as an earlier revision of the description format did) would write a value the gate then compares against and rejects, stranding the very rows this exists to rescue.

GRANTING approval is not this tool's business and never will be: nothing here sets intake_approved or writes a non-empty approved_body_hash, because either would let it release text no human read. The one approval column it touches it only ever CLEARS — see regateUnboundApprovals — which moves a ticket away from claimability, not toward it. For the same reason this must never be wired into actionStart: stamping body_hash from an approval path would make the approval certify itself, which is exactly the gate spec Amendment 1 exists to build.

Rows that already carry a body_hash are skipped, never recomputed: a non-empty value came from ingest and is the truth about the live issue, while ticket.Description is only Golem's copy of it.

A NOTE ON THE DESCRIPTION FORMAT. A row written by a mid-upgrade build holds a body-only description, because the title was not composed into it yet. This repair hashes that stored text as it stands, which is the right thing: for the [fef123b, c2fe234) shape it matches the approved_body_hash the operator's approval left behind, so the ticket becomes claimable again immediately. The next poll then re-composes the description with the title and re-hashes it, which re-gates the ticket for one re-read like every other linked ticket in the deployment. Both steps are correct and the order does not matter.

Safe to run repeatedly, and safe to run while the orchestrator is up: each row is updated under the same "still empty" condition it was selected by, so an ingest pass that fills one in first wins and this writes nothing over it.

func (BackfillResult) String added in v0.1.0

func (r BackfillResult) String() string

String renders the result as the one line the subcommand prints.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL