users

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package users manages operator identities + API keys. It issues a per-user bearer key (shown once), authenticates a presented token by its hash, and seeds a bootstrap admin from SYNAPSE_API_TOKEN so existing deployments keep working and historical "operator" attribution stays valid.

Index

Constants

View Source
const BootstrapID = "operator"

BootstrapID is the stable id of the bootstrap admin. Historical actions were attributed to "operator", so the bootstrap user owns that id and history stays coherent ("who did this?" resolves to the bootstrap admin, not a dangling string).

Variables

This section is empty.

Functions

func HashToken

func HashToken(token string) string

HashToken returns the lowercase-hex SHA-256 of a bearer token (the only form stored or compared). Exported so the auth resolver and tests agree on the format.

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service manages users + authentication.

func NewService

func NewService(repo ports.UserRepository, audit ports.AuditLogger, clock ports.Clock, ids ports.IDGenerator) (*Service, error)

NewService validates dependencies and returns the users service.

func (*Service) Authenticate

func (s *Service) Authenticate(ctx context.Context, token string) (*user.User, error)

Authenticate resolves a presented bearer token to its (enabled) user, or an error.

func (*Service) CreateUser

func (s *Service) CreateUser(ctx context.Context, actor string, tenantID string, name string, role user.Role) (*user.User, string, error)

CreateUser provisions a new operator in tenantID and returns the raw API key ONCE (it is never recoverable afterwards). tenantID is assigned server-side by the admin provisioning the user (never from the new user's own token); ” = the single default tenant (single-tenant mode). The tenant the user lands in is what scopes every read/write they later make, so it is captured in the audit record. Audited.

func (*Service) EnsureBootstrapAdmin

func (s *Service) EnsureBootstrapAdmin(ctx context.Context, token string) error

EnsureBootstrapAdmin idempotently makes the bootstrap admin (id "operator") whose key is the env SYNAPSE_API_TOKEN, so the existing token keeps authenticating – now as a real, admin user. Safe to call on every startup.

func (*Service) List

func (s *Service) List(ctx context.Context) ([]*user.User, error)

List returns all users (hash is on the struct; the adapter must not serialize it).

Jump to

Keyboard shortcuts

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