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
- func HashToken(token string) string
- type Service
- func (s *Service) Authenticate(ctx context.Context, token string) (*user.User, error)
- func (s *Service) CreateUser(ctx context.Context, actor string, tenantID string, name string, ...) (*user.User, string, error)
- func (s *Service) EnsureBootstrapAdmin(ctx context.Context, token string) error
- func (s *Service) List(ctx context.Context) ([]*user.User, error)
Constants ¶
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 ¶
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 ¶
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 ¶
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.