devactions

package
v0.46.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package devactions exposes app-defined dev/staging actions (wipe, reseed, create account, ...) and test accounts to hamr over one token-gated endpoint. See docs/proposed-features/staging-proxy-and-dev-actions.md.

Index

Constants

View Source
const Prefix = "/_devactions"

Prefix is where the app mounts Handler.

Variables

This section is empty.

Functions

func SessionWhoAmI

func SessionWhoAmI(sm *auth.SessionManager, lookup func(ctx context.Context, subjectID string) (*Account, error)) func(*http.Request) (*Account, error)

SessionWhoAmI builds a Registry.WhoAmI from a pkg/auth session manager: the session cookie is validated, then lookup turns the session's subject ID into the account shown in the widget (nil = not a known user).

Types

type Account

type Account struct {
	Email    string
	Password string
	Label    string
	Phone    string
}

Account is a seeded test login offered by the widget. Phone is optional; when set, the widget links the user's texts in the SMS inbox.

type Action

type Action struct {
	Name        string
	Label       string
	Description string
	Inputs      []Input
	Dangerous   bool
	Run         func(ctx context.Context, in map[string]string) (message string, err error)
}

Action is one button in the hamr widget.

type Input

type Input struct {
	Name     string
	Label    string
	Type     InputType
	Options  []string // InputSelect only
	Default  string
	Required bool
}

Input describes one action parameter.

type InputType

type InputType string

InputType is the kind of form field hamr renders for an Input.

const (
	InputText   InputType = "text"
	InputNumber InputType = "number"
	InputBool   InputType = "bool"
	InputSelect InputType = "select"
)

type Registry

type Registry struct {
	Accounts   func(ctx context.Context) ([]Account, error)
	Disposable func(ctx context.Context) (bool, error)
	// WhoAmI resolves the browser session on r (hamr forwards the browser's
	// cookies) to the logged-in user, or nil when nobody is. Optional; it
	// powers the widget's "<user>'s mail / texts" links. SessionWhoAmI builds
	// one from a pkg/auth SessionManager. Password is never sent.
	WhoAmI func(r *http.Request) (*Account, error)
	// contains filtered or unexported fields
}

Registry holds the app's actions.

func (*Registry) Handler

func (r *Registry) Handler() http.Handler

Handler returns the endpoint, or nil when the env gate fails: HAMR_ACTIONS_TOKEN must be set and HAMR_ACTIONS_ENV must be "development" or "staging". It panics if a Dangerous action exists without Disposable. The handler matches on the full request path, so mount it at the app root.

func (*Registry) Register

func (r *Registry) Register(a Action)

Register adds an action. It panics on a duplicate name or one that is not a single URL path segment: only [A-Za-z0-9._-], not "." or "..".

Jump to

Keyboard shortcuts

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