access

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package access holds the use cases of the access context: members, the instance admin, API tokens and the authentication of their callers.

Index

Constants

View Source
const AuthRetentionBatch = 1000

AuthRetentionBatch is how many rows one transaction of the purge deletes, so a backlog never holds locks or a transaction open for long.

Variables

View Source
var ErrGrantNotFound = apperrors.NotFound("not_found", "no grant of the project has this identifier")

ErrGrantNotFound answers an identifier no grant of the project has.

View Source
var ErrInstanceAdminExists = apperrors.Conflict("instance_admin_exists", "an instance admin already exists")

ErrInstanceAdminExists refuses a bootstrap once the instance has an instance admin: from then on, they add the others.

View Source
var ErrInvalidCredentials = apperrors.Unauthenticated("invalid_credentials", "the email or password is wrong")

ErrInvalidCredentials refuses a sign-in whatever went wrong with the email or the password, so nobody learns from it which emails exist, nor whether the password of a member who may not sign in was right.

View Source
var ErrMemberNotFound = apperrors.NotFound("not_found", "no member has this identifier")

ErrMemberNotFound answers an identifier no member has.

View Source
var ErrNoMemberWithEmail = apperrors.NotFound("not_found", "no member has this email")

ErrNoMemberWithEmail refuses a command naming an email no member has.

View Source
var ErrNoSession = errors.New("access: not a session cookie")

ErrNoSession answers a cookie that is not one the server issued: it is no credential at all, dropped before any lookup.

View Source
var ErrNotFound = errors.New("access: not found")

ErrNotFound is what a store answers for an entity it does not hold.

View Source
var ErrSessionNotFound = apperrors.NotFound("not_found", "no live session of the member has this identifier")

ErrSessionNotFound answers a session that is not a live one of the member addressed: another member's, one that has ended, or none at all.

View Source
var ErrTokenNotFound = apperrors.NotFound("not_found", "no unrevoked token of the member has this identifier")

ErrTokenNotFound answers a token that is not an unrevoked one of the member addressed: another member's, one revoked already, or none at all.

View Source
var ErrWrongCurrentPassword = apperrors.Invalid("invalid_credentials", "the current password is wrong",
	apperrors.Violation{Pointer: "/current_password", Code: "invalid_credentials", Detail: "the current password is wrong"})

ErrWrongCurrentPassword refuses a password change whose current password is wrong, with the code a wrong sign-in gets, as a violation of the field that holds it. It is no 401: the caller is signed in and stays so, and a 401 would send the console to its sign-in page.

Functions

func ActorOf

func ActorOf(caller access.Caller) governance.Actor

ActorOf returns the actor audit entries name for a change caller makes: the token presented, with the member it acts for, or the member signed in. A caller without a credential has no actor: the zero one, which no audit entry accepts.

Types

type AcceptInvitation

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

AcceptInvitation lets an invited person set their first password, and signs them in.

func NewAcceptInvitation

func NewAcceptInvitation(d AcceptInvitationDeps) *AcceptInvitation

NewAcceptInvitation returns the handler.

func (*AcceptInvitation) Handle

Handle sets the member's first password, makes them active, consumes their invitations and opens a session, recording member.invitation_accepted and auth.signed_in. The attempt counts as a failure of its source before the secret is looked up, so a source hammering acceptance is throttled with its sign-ins; a throttled source is refused rate_limited before anything else. A secret that opens no invitation keeps its failure and is answered invitation_gone; one that does takes it back, whatever happens next. The password policy applies (weak_password), before any hash.

type AcceptInvitationCommand

type AcceptInvitationCommand struct {
	Secret   secret.String
	Password secret.String
	// ClientIP and UserAgent describe the device signing in.
	ClientIP  netip.Addr
	UserAgent string
	RequestID string
}

AcceptInvitationCommand is one attempt at accepting an invitation.

type AcceptInvitationDeps

type AcceptInvitationDeps struct {
	Tx    Transactor
	Store AcceptStore
	// Settings give the password policy's minimum length and the timeouts
	// the session opens with.
	Settings AuthSettingsReader
	Hasher   PasswordHasher
	Audit    AuditLog
	Clock    clock.Clock
	IDs      *id.Source
	// Random draws session cookies, which are signed with Key.
	Random io.Reader
	Key    []byte
}

AcceptInvitationDeps are what accepting an invitation works with.

type AcceptStore

type AcceptStore interface {
	InvitationReader
	InvitationStore
	// LockMember returns the member, locked until the unit of work ends;
	// ErrNotFound when none has the identifier.
	LockMember(ctx context.Context, member access.MemberID) (access.Member, bool, error)
	// LockInvitationByHash returns the invitation, locked until the unit of
	// work ends, and its member; ErrNotFound when none has the hash.
	LockInvitationByHash(ctx context.Context, hash access.InvitationHash) (access.Invitation, access.Member, error)
	SaveMember(ctx context.Context, m access.Member, at time.Time) error
	SetPasswordHash(ctx context.Context, member access.MemberID, hash string, at time.Time) error
	RecordSignIn(ctx context.Context, member access.MemberID, at time.Time) error
	CreateSession(ctx context.Context, s access.Session) error
	// ReserveSourceAttempt counts a as a failure of its source alone,
	// before what it presents is checked, and returns what it found.
	ReserveSourceAttempt(ctx context.Context, a access.Attempt) (access.Reservation, error)
	// ReleaseAttempt takes back the failure r reserved.
	ReleaseAttempt(ctx context.Context, r access.Reservation) error
}

AcceptStore is what accepting an invitation needs.

type AttemptStore

type AttemptStore interface {
	// ReserveAttempt counts a as a failure before its password is verified,
	// in one atomic step, and returns what it found.
	ReserveAttempt(ctx context.Context, a access.Attempt) (access.Reservation, error)
	// ClearAttempt takes back the failure r reserved, and ends the email's
	// consecutive failures, once the password proved right.
	ClearAttempt(ctx context.Context, r access.Reservation) error
	// ReleaseAttempt takes back the failure r reserved when the attempt
	// guessed nothing: its password could not be verified, or proved right.
	ReleaseAttempt(ctx context.Context, r access.Reservation) error
}

AttemptStore counts the failed attempts at a password, per email and per source, which lock an email and throttle a source.

type AuditLog

type AuditLog interface {
	Record(ctx context.Context, e governance.Entry) error
}

AuditLog records the audit entry of a change, in the unit of work of the change.

type AuthPurged

type AuthPurged struct {
	Sessions       int
	EmailFailures  int
	SourceFailures int
	Invitations    int
}

AuthPurged counts the rows one purge deleted.

type AuthRetentionStore

type AuthRetentionStore interface {
	// TryLockAuthRetention takes, until the transaction ends, the lock that
	// lets one replica purge at a time; false when another holds it.
	TryLockAuthRetention(ctx context.Context) (bool, error)
	// PurgeSessions deletes at most limit sessions the cutoffs end.
	PurgeSessions(ctx context.Context, cut access.SessionCutoffs, limit int) (int, error)
	// PurgeEmailFailures deletes at most limit emails' failures that no lock
	// holds and whose last failure is past the cutoff.
	PurgeEmailFailures(ctx context.Context, cut access.FailureCutoffs, limit int) (int, error)
	// PurgeSourceFailures deletes at most limit sources' failures whose
	// window is over.
	PurgeSourceFailures(ctx context.Context, cut access.FailureCutoffs, limit int) (int, error)
	// PurgeInvitations deletes at most limit invitations that ended at or
	// before the cutoff, except each member's latest.
	PurgeInvitations(ctx context.Context, cut access.InvitationCutoffs, limit int) (int, error)
}

AuthRetentionStore deletes what signing in leaves behind once it can no longer matter.

type AuthSettingsCache

type AuthSettingsCache interface {
	// Forget drops the copy, so the replica's next read sees a change it
	// just made.
	Forget()
}

AuthSettingsCache is a replica's copy of the settings.

type AuthSettingsReader

type AuthSettingsReader interface {
	AuthSettings(ctx context.Context) (access.AuthSettings, error)
}

AuthSettingsReader reads the auth settings in force.

type AuthSettingsStore

type AuthSettingsStore interface {
	// LockAuthSettings returns the settings and locks them until the
	// transaction ends.
	LockAuthSettings(ctx context.Context) (access.AuthSettings, error)
	// SaveAuthSettings stores the settings and announces the change to
	// every replica once the transaction commits.
	SaveAuthSettings(ctx context.Context, s access.AuthSettings) error
}

AuthSettingsStore keeps the auth settings.

type AuthenticateSession

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

AuthenticateSession resolves a session cookie into the member signed in.

func NewAuthenticateSession

func NewAuthenticateSession(store SessionStore, settings AuthSettingsReader, c clock.Clock, key []byte) *AuthenticateSession

NewAuthenticateSession returns the handler, which checks cookies' tags under key and judges sessions by the timeouts settings holds.

func (*AuthenticateSession) Handle

func (h *AuthenticateSession) Handle(ctx context.Context, cookie string) (access.Caller, error)

Handle returns the caller signed in to the session cookie names: ErrNoSession for a cookie the server did not issue, found without a lookup, and session_expired for a session that no longer signs anyone in. A live session's last request is written at most once a minute.

type AuthenticateToken

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

AuthenticateToken resolves the value of an API token presented as Bearer into the caller presenting it.

func NewAuthenticateToken

func NewAuthenticateToken(store TokenStore, uses *TokenUses, c clock.Clock) *AuthenticateToken

NewAuthenticateToken returns the handler, which notes each token's use in uses.

func (*AuthenticateToken) Handle

func (h *AuthenticateToken) Handle(ctx context.Context, value string, ip netip.Addr) (access.Caller, error)

Handle returns the caller presenting value from the address ip, or the refusal a script tells apart: invalid_token for a value that is malformed or unknown alike, token_revoked, token_expired. A token accepted has its use noted.

type Bootstrap

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

Bootstrap creates the first instance admin of a fresh instance, with a password and a personal access token, so a platform engineer gets in without the console.

func NewBootstrap

func NewBootstrap(tx Transactor, store BootstrapStore, hasher PasswordHasher, audit AuditLog, c clock.Clock, ids *id.Source, random io.Reader) *Bootstrap

NewBootstrap returns the handler. random is the source token values and generated passwords are drawn from.

func (*Bootstrap) Handle

Handle creates the instance admin and their token, carrying every scope and no expiry: whoever runs bootstrap holds the database's credentials already, so the token gives them nothing they lack.

type BootstrapCommand

type BootstrapCommand struct {
	Email string
	// DisplayName is "" to name the member after their email's local part.
	DisplayName string
	// Password is the instance admin's password, or zero to have one
	// generated: unattended provisioning need not invent one.
	Password secret.String
	// Request names who bootstraps, for the audit entries.
	Request governance.Request
}

BootstrapCommand names the first instance admin.

type BootstrapResult

type BootstrapResult struct {
	Member access.Member
	Token  secret.String
	// GeneratedPassword is the password generated for a command that gave
	// none, shown once; zero when the command gave one.
	GeneratedPassword secret.String
}

BootstrapResult is the instance admin created and their token's value, which is shown once and never stored.

type BootstrapStore

type BootstrapStore interface {
	InstanceAdmins
	// AuthSettingsReader gives the password policy's minimum length.
	AuthSettingsReader
	// LockBootstrap serializes bootstraps until the unit of work ends, so two
	// running at once cannot both find no instance admin.
	LockBootstrap(ctx context.Context) error
	CreateMember(ctx context.Context, m access.Member, passwordHash string) error
	CreateToken(ctx context.Context, t access.APIToken) error
}

BootstrapStore is what bootstrapping needs of the stored members and tokens.

type ChangeMyPassword

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

ChangeMyPassword lets a signed-in member set a new password.

func NewChangeMyPassword

func NewChangeMyPassword(d ChangeMyPasswordDeps) *ChangeMyPassword

NewChangeMyPassword returns the handler.

func (*ChangeMyPassword) Handle

Handle sets the caller's new password, revokes every other live session of theirs and consumes their open invitations, in one unit of work, and records password.changed with how many sessions it revoked. The session the caller is signed in to stays.

The new password is held to the policy (weak_password at /new_password) before the current one is checked, so a weak one costs no attempt. The current one is checked as a sign-in checks a password, counting against the member's email and the source: a right one takes the failure back, a wrong one keeps it and is refused invalid_credentials, so a session left open on a shared device cannot be used to guess the password, and the email locks after the same failures a sign-in locks it after, recording auth.locked_out.

type ChangeMyPasswordCommand

type ChangeMyPasswordCommand struct {
	Caller          access.Caller
	CurrentPassword secret.String
	NewPassword     secret.String
	// ClientIP is the source of the attempt, which a wrong current password
	// counts against.
	ClientIP netip.Addr
	Request  governance.Request
}

ChangeMyPasswordCommand is one attempt at changing one's password.

type ChangeMyPasswordDeps

type ChangeMyPasswordDeps struct {
	Tx    Transactor
	Store PasswordChangeStore
	// Settings give the password policy's minimum length and the timeouts
	// that tell the live sessions from the ended ones.
	Settings AuthSettingsReader
	Hasher   PasswordVerifier
	Audit    AuditLog
	Clock    clock.Clock
	IDs      *id.Source
}

ChangeMyPasswordDeps are what changing one's password works with.

type CountProjectMembers

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

CountProjectMembers answers how many members work in projects.

func NewCountProjectMembers

func NewCountProjectMembers(store ProjectMemberDirectory) *CountProjectMembers

NewCountProjectMembers returns the query.

func (*CountProjectMembers) Handle

Handle returns how many active members hold a grant in each of projects, whatever their number, at the cost of one query; a project none holds is absent.

type CreateGrant

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

CreateGrant grants a member a role in a project.

func NewCreateGrant

func NewCreateGrant(tx Transactor, store GrantStore, audit AuditLog, c clock.Clock, ids *id.Source) *CreateGrant

NewCreateGrant returns the handler.

func (*CreateGrant) Handle

Handle makes the grant and records grant.created in the project. A role holding a permission the caller lacks in the project is refused role_not_allowed, an unknown member or role invalid_grant, a deactivated member member_deactivated, a grant the member holds already already_granted.

type CreateGrantCommand

type CreateGrantCommand struct {
	Caller  access.Caller
	Project ProjectRef
	Member  access.MemberID
	Role    access.RoleName
	Request governance.Request
}

CreateGrantCommand grants Member the role Role in Project.

type CreateInstanceAdmin

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

CreateInstanceAdmin adds an instance admin with a password from the command line, for a second admin or one who lost their way in.

func NewCreateInstanceAdmin

func NewCreateInstanceAdmin(tx Transactor, store MemberStore, hasher PasswordHasher, audit AuditLog, c clock.Clock,
	ids *id.Source, random io.Reader,
) *CreateInstanceAdmin

NewCreateInstanceAdmin returns the handler. random is the source generated passwords are drawn from.

func (*CreateInstanceAdmin) Handle

Handle creates the active instance admin. A password the command gives is refused weak_password before it is hashed; an email the instance holds is refused already_exists.

type CreateInstanceAdminCommand

type CreateInstanceAdminCommand struct {
	Email string
	// DisplayName is "" to name the member after their email's local part.
	DisplayName string
	// Password is checked against the password policy, or zero to have one
	// generated.
	Password secret.String
	Request  governance.Request
}

CreateInstanceAdminCommand names the instance admin to create.

type CreateInstanceAdminResult

type CreateInstanceAdminResult struct {
	Member            access.Member
	GeneratedPassword secret.String
}

CreateInstanceAdminResult is the instance admin created and the password generated for a command that gave none, shown once.

type CreatePersonalToken

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

CreatePersonalToken creates a personal access token for the member signed in.

func NewCreatePersonalToken

func NewCreatePersonalToken(tx Transactor, store PersonalTokenStore, settings AuthSettingsReader, audit AuditLog, c clock.Clock,
	ids *id.Source, random io.Reader,
) *CreatePersonalToken

NewCreatePersonalToken returns the handler; random draws token values.

func (*CreatePersonalToken) Handle

Handle creates the token and records api_token.created with its hint. Only a session creates one, so a leaked token can neither multiply itself nor outlive its revocation; its scopes are those the session's member holds, and its expiry is within what the auth settings allow.

type CreatePersonalTokenCommand

type CreatePersonalTokenCommand struct {
	Caller    access.Caller
	Name      string
	Scopes    []access.Scope
	ExpiresAt *time.Time
	Request   governance.Request
}

CreatePersonalTokenCommand is a member asking for a personal access token.

type CreateProjectToken

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

CreateProjectToken creates a token belonging to a project, for a pipeline.

func NewCreateProjectToken

func NewCreateProjectToken(tx Transactor, store ProjectTokenStore, settings AuthSettingsReader, audit AuditLog, c clock.Clock,
	ids *id.Source, random io.Reader,
) *CreateProjectToken

NewCreateProjectToken returns the handler; random draws token values.

func (*CreateProjectToken) Handle

Handle creates the token and records api_token.created in its project, with its hint. Only a session creates one, so no token can mint another; a session holds every scope a project token may carry, which never includes instance:admin, so only its role is capped, by what the caller may hand out in the project; its expiry is within what the auth settings allow. It acts for no member and survives its creator.

type CreateProjectTokenCommand

type CreateProjectTokenCommand struct {
	Caller    access.Caller
	Project   ProjectRef
	Name      string
	Role      access.RoleName
	Scopes    []access.Scope
	ExpiresAt *time.Time
	Request   governance.Request
}

CreateProjectTokenCommand asks for a token of Project holding Role.

type CreatedToken

type CreatedToken struct {
	Token access.APIToken
	Value secret.String
}

CreatedToken is a token just created, with its value, shown this once.

type DeactivateMember

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

DeactivateMember offboards a member.

func NewDeactivateMember

func NewDeactivateMember(tx Transactor, store DeactivationStore, audit AuditLog, c clock.Clock, ids *id.Source) *DeactivateMember

NewDeactivateMember returns the handler.

func (*DeactivateMember) Handle

Handle deactivates the member and, in the same unit of work, revokes every session and personal access token they hold and consumes their open invitations, recording member.deactivated with how many sessions and tokens it revoked. A deactivated member is left as they are; the last active instance admin is refused last_instance_admin.

type DeactivationStore

type DeactivationStore interface {
	MemberChanger
	// RevokeMemberSessions ends every session of member not ended yet, and
	// returns how many it ended.
	RevokeMemberSessions(ctx context.Context, member access.MemberID, at time.Time) (int, error)
	// RevokePersonalTokens revokes every personal access token of member
	// not revoked yet, and returns how many it revoked. The project tokens
	// the member created belong to their projects and stay.
	RevokePersonalTokens(ctx context.Context, member access.MemberID, at time.Time) (int, error)
	InvitationStore
}

DeactivationStore is what offboarding a member needs.

type DeleteGrant

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

DeleteGrant removes one grant, leaving the member's others.

func NewDeleteGrant

func NewDeleteGrant(tx Transactor, store GrantStore, audit AuditLog, c clock.Clock, ids *id.Source) *DeleteGrant

NewDeleteGrant returns the handler.

func (*DeleteGrant) Handle

func (h *DeleteGrant) Handle(ctx context.Context, cmd DeleteGrantCommand) error

Handle removes the grant and records grant.deleted in the project. The grant of a role holding a permission the caller lacks in the project is refused role_not_allowed, so nobody narrows access beyond their own reach; an unknown grant is ErrGrantNotFound. Removing the last owner grant is allowed: an instance admin can always step in.

type DeleteGrantCommand

type DeleteGrantCommand struct {
	Project ProjectRef
	Grant   access.GrantID
	Request governance.Request
}

DeleteGrantCommand removes the grant Grant of Project.

type GetAuthSettings

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

GetAuthSettings answers the auth settings in force.

func NewGetAuthSettings

func NewGetAuthSettings(settings AuthSettingsReader) *GetAuthSettings

NewGetAuthSettings returns the query.

func (*GetAuthSettings) Handle

Handle returns the settings.

type GetInvitation

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

GetInvitation answers what an invitation's link opens, before anyone is signed in.

func NewGetInvitation

func NewGetInvitation(store InvitationReader, c clock.Clock) *GetInvitation

NewGetInvitation returns the query.

func (*GetInvitation) Handle

Handle returns the invitation the secret opens; invitation_gone when it opens none that can be accepted, whatever the reason.

type GetMember

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

GetMember answers one member.

func NewGetMember

func NewGetMember(store MemberDirectory) *GetMember

NewGetMember returns the query.

func (*GetMember) Handle

func (h *GetMember) Handle(ctx context.Context, member access.MemberID) (MemberView, error)

Handle returns the member; ErrMemberNotFound when none has the identifier.

type GrantReader

type GrantReader interface {
	// MemberGrants returns the grants member holds in project, oldest
	// first.
	MemberGrants(ctx context.Context, member access.MemberID, project workspace.ProjectID) ([]access.Grant, error)
	// GrantedProjects returns the projects member holds a grant in.
	GrantedProjects(ctx context.Context, member access.MemberID) ([]workspace.ProjectID, error)
}

GrantReader reads the grants members hold.

type GrantStore

type GrantStore interface {
	// LockMember returns the member, locked until the unit of work ends,
	// and whether they hold a password; ErrNotFound when none has the
	// identifier.
	LockMember(ctx context.Context, member access.MemberID) (access.Member, bool, error)
	// MemberByID returns the member with the identifier; ErrNotFound when
	// none has it.
	MemberByID(ctx context.Context, member access.MemberID) (access.Member, error)
	// ProjectGrants returns every grant of project, oldest first.
	ProjectGrants(ctx context.Context, project workspace.ProjectID) ([]access.Grant, error)
	// CreateGrant stores g; one the member holds already from the same
	// source is refused already_granted.
	CreateGrant(ctx context.Context, g access.Grant) error
	// LockGrant returns the grant of project with the identifier, locked
	// until the unit of work ends; ErrNotFound when the project holds none.
	LockGrant(ctx context.Context, project workspace.ProjectID, grant access.GrantID) (access.Grant, error)
	// DeleteGrant removes the grant of project with the identifier.
	DeleteGrant(ctx context.Context, project workspace.ProjectID, grant access.GrantID) (access.Grant, error)
}

GrantStore keeps the grants of projects.

type InstanceAdminExists

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

InstanceAdminExists answers whether the instance has an instance admin, so provisioning that bootstraps on every deploy learns there is nothing to do before it prepares anything.

func NewInstanceAdminExists

func NewInstanceAdminExists(store InstanceAdmins) *InstanceAdminExists

NewInstanceAdminExists returns the handler.

func (*InstanceAdminExists) Handle

func (h *InstanceAdminExists) Handle(ctx context.Context) (bool, error)

Handle reports whether an instance admin exists.

type InstanceAdmins

type InstanceAdmins interface {
	// AnyInstanceAdmin reports whether an instance admin exists, whatever
	// their status.
	AnyInstanceAdmin(ctx context.Context) (bool, error)
}

InstanceAdmins tells whether the instance has an instance admin.

type InvitationReader

type InvitationReader interface {
	// InvitationByHash returns the invitation and its member; ErrNotFound
	// when no invitation has the hash.
	InvitationByHash(ctx context.Context, hash access.InvitationHash) (access.Invitation, access.Member, error)
}

InvitationReader finds invitations by the hash of their secret.

type InvitationStore

type InvitationStore interface {
	CreateInvitation(ctx context.Context, inv access.Invitation) error
	// ConsumeInvitations ends every open invitation of member, and returns
	// how many it ended.
	ConsumeInvitations(ctx context.Context, member access.MemberID, at time.Time) (int, error)
}

InvitationStore keeps invitations.

type InvitationView

type InvitationView struct {
	// MaskedEmail is the member's email with most of its local part hidden.
	MaskedEmail string
	DisplayName string
	ExpiresAt   time.Time
}

InvitationView is what the page an invitation opens shows.

type InviteMember

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

InviteMember invites someone to the instance by email.

func NewInviteMember

func NewInviteMember(tx Transactor, store InviteStore, audit AuditLog, c clock.Clock, ids *id.Source, random io.Reader) *InviteMember

NewInviteMember returns the handler; random draws invitation secrets.

func (*InviteMember) Handle

Handle creates an invited member and their invitation, recording member.invited; an email the instance holds is refused already_exists.

type InviteMemberCommand

type InviteMemberCommand struct {
	Email       string
	DisplayName string
	Request     governance.Request
}

InviteMemberCommand names the person to invite.

type InviteStore

type InviteStore interface {
	InvitationStore
	MemberDirectory
	CreateMember(ctx context.Context, m access.Member, passwordHash string) error
}

InviteStore is what inviting someone needs.

type InvitedMember

type InvitedMember struct {
	Member     MemberView
	Invitation *IssuedInvitation
}

InvitedMember is a member with the invitation just issued to them, if one was.

type IssuedInvitation

type IssuedInvitation struct {
	access.Invitation
	Secret secret.String
}

IssuedInvitation is an invitation just issued, with its secret, shown once to whoever issued it.

type ListGrants

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

ListGrants answers the grants of a project.

func NewListGrants

func NewListGrants(store GrantStore) *ListGrants

NewListGrants returns the query.

func (*ListGrants) Handle

func (h *ListGrants) Handle(ctx context.Context, project workspace.ProjectID) ([]access.Grant, error)

Handle returns every grant of project, oldest first.

type ListMembers

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

ListMembers answers the instance's members.

func NewListMembers

func NewListMembers(store MemberDirectory) *ListMembers

NewListMembers returns the query.

func (*ListMembers) Handle

func (h *ListMembers) Handle(ctx context.Context, f MemberFilter) ([]MemberView, error)

Handle returns the members f selects, ordered by email.

type ListPersonalTokens

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

ListPersonalTokens answers a member's personal access tokens.

func NewListPersonalTokens

func NewListPersonalTokens(store PersonalTokenStore) *ListPersonalTokens

NewListPersonalTokens returns the query.

func (*ListPersonalTokens) Handle

func (h *ListPersonalTokens) Handle(ctx context.Context, caller access.Caller, member access.MemberID) ([]access.APIToken, error)

Handle returns the personal access tokens of member, the caller's own when member is zero, the newest first; an unknown member is ErrMemberNotFound.

type ListProjectMembers

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

ListProjectMembers answers who holds grants in a project.

func NewListProjectMembers

func NewListProjectMembers(store ProjectMemberDirectory) *ListProjectMembers

NewListProjectMembers returns the query.

func (*ListProjectMembers) Handle

Handle returns the members holding grants in project with their grants.

type ListProjectTokens

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

ListProjectTokens answers the tokens of a project.

func NewListProjectTokens

func NewListProjectTokens(store ProjectTokenStore) *ListProjectTokens

NewListProjectTokens returns the query.

func (*ListProjectTokens) Handle

Handle returns every token of project, the newest first.

type ListSessions

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

ListSessions answers the devices a member is signed in on.

func NewListSessions

func NewListSessions(store MemberSessionStore, settings AuthSettingsReader, c clock.Clock) *ListSessions

NewListSessions returns the query.

func (*ListSessions) Handle

func (h *ListSessions) Handle(ctx context.Context, caller access.Caller, member access.MemberID) ([]SessionView, error)

Handle returns the live sessions of member, the caller's own when member is zero, the newest first; the one caller is signed in to is marked current. An unknown member is ErrMemberNotFound.

type MemberChanger

type MemberChanger interface {
	MemberDirectory
	// LockInstanceAdmins serializes, until the unit of work ends, every
	// change that could leave the instance without an active instance
	// admin, so two of them made at once each see the other's outcome.
	LockInstanceAdmins(ctx context.Context) error
	// LockMember returns the member, locked until the unit of work ends,
	// and whether they hold a password; ErrNotFound when none has the
	// identifier.
	LockMember(ctx context.Context, member access.MemberID) (access.Member, bool, error)
	// OtherActiveInstanceAdmins counts the active instance admins other
	// than member.
	OtherActiveInstanceAdmins(ctx context.Context, member access.MemberID) (int, error)
	// SaveMember stores m's email, display name, status, instance admin
	// switch and locale; an email another member holds is refused
	// already_exists.
	SaveMember(ctx context.Context, m access.Member, at time.Time) error
}

MemberChanger changes a member under the lock that keeps the instance an active instance admin.

type MemberDirectory

type MemberDirectory interface {
	// Members returns the members f selects, ordered by email, with their
	// project counts read in the same query.
	Members(ctx context.Context, f MemberFilter) ([]MemberView, error)
	// MemberView returns one member; ErrNotFound when none has the
	// identifier.
	MemberView(ctx context.Context, member access.MemberID) (MemberView, error)
}

MemberDirectory reads members as an instance admin sees them.

type MemberFilter

type MemberFilter struct {
	Status access.MemberStatus
	Q      string
}

MemberFilter narrows the members listed: to one status when Status is not "", to those whose email or display name holds Q whatever its case when Q is not "".

type MemberSessionStore

type MemberSessionStore interface {
	// MemberByID returns the member with the identifier; ErrNotFound when
	// none has it.
	MemberByID(ctx context.Context, member access.MemberID) (access.Member, error)
	// MemberSessions returns the sessions of member not yet revoked, the
	// newest first.
	MemberSessions(ctx context.Context, member access.MemberID) ([]access.Session, error)
}

MemberSessionStore reads a member's sessions.

type MemberStore

type MemberStore interface {
	CreateMember(ctx context.Context, m access.Member, passwordHash string) error
	// AuthSettingsReader gives the password policy's minimum length.
	AuthSettingsReader
}

MemberStore creates members.

type MemberView

type MemberView struct {
	access.Member
	// LastSignInAt is when the member last signed in; nil until they do.
	LastSignInAt *time.Time
	// ProjectCount is how many projects the member holds a grant in.
	ProjectCount int
}

MemberView is a member as an instance admin sees them.

type Ownership

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

Ownership answers whether a member may be named owner of a flag in a project: someone the project's members can ask before deleting it.

func NewOwnership

func NewOwnership(store OwnershipReader) *Ownership

NewOwnership returns the handler.

func (*Ownership) MayOwn

func (h *Ownership) MayOwn(ctx context.Context, project workspace.ProjectID, member access.MemberID) (bool, error)

MayOwn reports whether member is active and either an instance admin or holds a grant in project. An unknown member may not.

type OwnershipReader

type OwnershipReader interface {
	GrantReader
	// MemberByID returns the member, or ErrNotFound.
	MemberByID(ctx context.Context, member access.MemberID) (access.Member, error)
}

OwnershipReader reads what decides whether a member may own a flag.

type PasswordChangeStore

type PasswordChangeStore interface {
	SetPasswordHash(ctx context.Context, member access.MemberID, hash string, at time.Time) error
	MemberSessions(ctx context.Context, member access.MemberID) ([]access.Session, error)
	RevokeSessions(ctx context.Context, sessions []access.SessionID, at time.Time) ([]access.SessionID, error)
	ConsumeInvitations(ctx context.Context, member access.MemberID, at time.Time) (int, error)
	// contains filtered or unexported methods
}

PasswordChangeStore is what changing one's password needs.

type PasswordHasher

type PasswordHasher interface {
	Hash(ctx context.Context, password secret.String) (string, error)
}

PasswordHasher turns a password into the string stored for it.

type PasswordVerifier

type PasswordVerifier interface {
	PasswordHasher
	// Verify reports whether password matches encoded, and whether encoded
	// was made under parameters other than the current ones. An empty
	// encoded is verified against a hash no password matches, at the same
	// cost, so an unknown email takes as long as a wrong password.
	Verify(ctx context.Context, password secret.String, encoded string) (ok, outdated bool, err error)
}

PasswordVerifier checks a password against the string stored for it.

type PersonalTokenStore

type PersonalTokenStore interface {
	// MemberByID returns the member with the identifier; ErrNotFound when
	// none has it.
	MemberByID(ctx context.Context, member access.MemberID) (access.Member, error)
	// PersonalTokens returns every personal access token of member, revoked
	// and expired ones included, the newest first.
	PersonalTokens(ctx context.Context, member access.MemberID) ([]access.APIToken, error)
	CreateToken(ctx context.Context, t access.APIToken) error
	// RevokePersonalToken revokes the personal access token of member with
	// the identifier at at and returns it as revoked; ErrNotFound unless
	// member holds it unrevoked.
	RevokePersonalToken(ctx context.Context, member access.MemberID, token access.APITokenID, at time.Time) (access.APIToken, error)
}

PersonalTokenStore keeps members' personal access tokens.

type ProjectHoldings

type ProjectHoldings struct {
	// Grants are those the caller's member holds there; none for a project
	// token, which acts for no member.
	Grants []access.Grant
	// Permissions are the caller's effective permissions there, in catalog
	// order.
	Permissions []access.Permission
}

ProjectHoldings are what a caller holds in a project.

type ProjectMember

type ProjectMember struct {
	Member access.Member
	Grants []access.Grant
}

ProjectMember is a member holding grants in a project, with those grants.

type ProjectMemberDirectory

type ProjectMemberDirectory interface {
	// ProjectMembers returns the members holding grants in project, ordered
	// by email, each with their grants there oldest first, read in one
	// query.
	ProjectMembers(ctx context.Context, project workspace.ProjectID) ([]ProjectMember, error)
	// ProjectMemberCounts returns how many active members hold a grant in
	// each of projects, read in one query; a project none holds is absent.
	ProjectMemberCounts(ctx context.Context, projects []workspace.ProjectID) (map[workspace.ProjectID]int, error)
}

ProjectMemberDirectory reads who holds grants in projects.

type ProjectPermissions

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

ProjectPermissions answers what a caller holds in a project: the permission seam judges every operation in a project by it, and the console shows or disables actions by it.

func NewProjectPermissions

func NewProjectPermissions(grants GrantReader) *ProjectPermissions

NewProjectPermissions returns the handler.

func (*ProjectPermissions) Handle

Handle returns the grants of the caller's member in project and the caller's effective permissions there: an instance admin holds every permission, a member the union of their grants' roles, narrowed by the scopes of a token; a project token its role's in its own project.

type ProjectRef

type ProjectRef struct {
	ID workspace.ProjectID
	// Held are the caller's effective permissions in the project, which
	// cap the roles they may hand out.
	Held []access.Permission
}

ProjectRef is the project a command addresses, as the request found it, with what the caller holds there.

type ProjectTokenStore

type ProjectTokenStore interface {
	// ProjectTokens returns every project token of project, revoked and
	// expired ones included, the newest first.
	ProjectTokens(ctx context.Context, project workspace.ProjectID) ([]access.APIToken, error)
	CreateToken(ctx context.Context, t access.APIToken) error
	// RevokeProjectToken revokes the project token of project with the
	// identifier at at and returns it as revoked; ErrNotFound unless the
	// project holds it unrevoked.
	RevokeProjectToken(ctx context.Context, project workspace.ProjectID, token access.APITokenID, at time.Time) (access.APIToken, error)
}

ProjectTokenStore keeps projects' tokens.

type PromoteMember

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

PromoteMember makes a member an instance admin from the command line.

func NewPromoteMember

func NewPromoteMember(tx Transactor, store PromoteStore, audit AuditLog, c clock.Clock, ids *id.Source) *PromoteMember

NewPromoteMember returns the handler.

func (*PromoteMember) Handle

func (h *PromoteMember) Handle(ctx context.Context, email string, req governance.Request) (bool, error)

Handle makes the member with email an instance admin and reports whether they were not one already; promoting an instance admin changes and records nothing.

type PromoteStore

type PromoteStore interface {
	// LockMemberByEmail returns the member whose email is email whatever
	// its case, locked until the unit of work ends; ErrNotFound when none.
	LockMemberByEmail(ctx context.Context, email string) (access.Member, error)
	SetInstanceAdmin(ctx context.Context, member access.MemberID, instanceAdmin bool, at time.Time) error
}

PromoteStore finds a member to promote and makes them an instance admin.

type PurgeAuthRecords

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

PurgeAuthRecords deletes ended sessions, emails' failures that no longer count, sources' windows that are over and invitations long past use, so their tables do not grow forever.

func NewPurgeAuthRecords

func NewPurgeAuthRecords(tx Transactor, store AuthRetentionStore, settings AuthSettingsReader, c clock.Clock) *PurgeAuthRecords

NewPurgeAuthRecords returns the handler, which ends sessions by the timeouts settings holds.

func (*PurgeAuthRecords) Handle

func (h *PurgeAuthRecords) Handle(ctx context.Context) (AuthPurged, error)

Handle purges in batches, each in a transaction of its own holding the purge lock, until a batch finds less than a full batch to delete. When another replica holds the lock it leaves the work to it and returns what it purged so far.

type ReactivateMember

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

ReactivateMember brings a deactivated member back.

func NewReactivateMember

func NewReactivateMember(tx Transactor, store ReactivationStore, audit AuditLog, c clock.Clock, ids *id.Source, random io.Reader,
) *ReactivateMember

NewReactivateMember returns the handler; random draws invitation secrets.

func (*ReactivateMember) Handle

Handle makes a deactivated member active when they hold a password, recording member.reactivated. One who never set a password is invited again, with a fresh invitation, since the one they had was consumed when they were deactivated. What their deactivation revoked stays revoked. A member who is not deactivated is left as they are.

type ReactivationStore

type ReactivationStore interface {
	MemberChanger
	InvitationStore
}

ReactivationStore is what bringing a member back needs.

type ReissueInvitation

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

ReissueInvitation replaces an invited member's link.

func NewReissueInvitation

func NewReissueInvitation(tx Transactor, store ReissueStore, audit AuditLog, c clock.Clock, ids *id.Source, random io.Reader,
) *ReissueInvitation

NewReissueInvitation returns the handler; random draws invitation secrets.

func (*ReissueInvitation) Handle

Handle issues the member a fresh invitation, which kills every earlier one, recording member.invitation_reissued. A member who is not invited is refused member_not_invited.

type ReissueStore

type ReissueStore interface {
	InvitationStore
	MemberDirectory
	// LockMember returns the member, locked until the unit of work ends,
	// and whether they hold a password; ErrNotFound when none has the
	// identifier.
	LockMember(ctx context.Context, member access.MemberID) (access.Member, bool, error)
}

ReissueStore is what reissuing an invitation needs.

type RevokePersonalToken

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

RevokePersonalToken revokes a personal access token.

func NewRevokePersonalToken

func NewRevokePersonalToken(tx Transactor, store PersonalTokenStore, audit AuditLog, c clock.Clock, ids *id.Source,
) *RevokePersonalToken

NewRevokePersonalToken returns the handler.

func (*RevokePersonalToken) Handle

Handle revokes the token and records api_token.revoked. A member's own tokens are revoked only from a session, whichever route names them, so a leaked token cannot hide its siblings, an instance admin's included; a token the member does not hold unrevoked is ErrTokenNotFound.

type RevokePersonalTokenCommand

type RevokePersonalTokenCommand struct {
	Caller  access.Caller
	Member  access.MemberID
	Token   access.APITokenID
	Request governance.Request
}

RevokePersonalTokenCommand names the token to revoke: one of Member's, or of the caller's own when Member is zero.

type RevokeProjectToken

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

RevokeProjectToken revokes a project's token.

func NewRevokeProjectToken

func NewRevokeProjectToken(tx Transactor, store ProjectTokenStore, audit AuditLog, c clock.Clock, ids *id.Source,
) *RevokeProjectToken

NewRevokeProjectToken returns the handler.

func (*RevokeProjectToken) Handle

Handle revokes the token and records api_token.revoked in its project; a token the project does not hold unrevoked is ErrTokenNotFound.

type RevokeProjectTokenCommand

type RevokeProjectTokenCommand struct {
	Project ProjectRef
	Token   access.APITokenID
	Request governance.Request
}

RevokeProjectTokenCommand names the token of Project to revoke.

type RevokeSessions

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

RevokeSessions signs a member out of some or all of their devices.

func NewRevokeSessions

func NewRevokeSessions(tx Transactor, store SessionRevoker, settings AuthSettingsReader, audit AuditLog, c clock.Clock,
	ids *id.Source,
) *RevokeSessions

NewRevokeSessions returns the handler.

func (*RevokeSessions) Handle

Handle revokes the live sessions cmd selects and records one session.revoked entry naming them; revoking none records nothing. A member's own sessions are revoked only from a session, whichever route names them, so a leaked token cannot sign its owner out, an instance admin's included; a session the member does not hold live is ErrSessionNotFound.

type RevokeSessionsCommand

type RevokeSessionsCommand struct {
	Caller      access.Caller
	Member      access.MemberID
	Session     *access.SessionID
	KeepCurrent bool
	Request     governance.Request
}

RevokeSessionsCommand selects the sessions to revoke: every live one of Member, or of the caller when Member is zero, or only Session when given; the session the caller is signed in to is kept when KeepCurrent is set.

type RevokeSessionsResult

type RevokeSessionsResult struct {
	Revoked []access.SessionID
	// CurrentRevoked is whether the session the caller is signed in to was
	// among them, so its cookie is cleared.
	CurrentRevoked bool
}

RevokeSessionsResult is what a revocation ended.

type SessionRevoker

type SessionRevoker interface {
	MemberSessionStore
	// RevokeSessions ends each of sessions not ended yet at at, and returns
	// those it ended.
	RevokeSessions(ctx context.Context, sessions []access.SessionID, at time.Time) ([]access.SessionID, error)
}

SessionRevoker revokes sessions.

type SessionStore

type SessionStore interface {
	// SessionByHash returns the session stored under hash with its member;
	// ErrNotFound when none is.
	SessionByHash(ctx context.Context, hash access.SessionHash) (access.Session, access.Member, error)
	TouchSession(ctx context.Context, session access.SessionID, at time.Time) error
	RevokeSession(ctx context.Context, session access.SessionID, at time.Time) error
}

SessionStore finds and updates sessions.

type SessionView

type SessionView struct {
	access.Session
	// End is when the absolute timeout in force ends the session.
	End time.Time
	// Current marks the session the request is signed in to.
	Current bool
}

SessionView is a live session as its member sees it.

type SignIn

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

SignIn opens a session for a member who proves who they are with their email and password.

func NewSignIn

func NewSignIn(d SignInDeps) *SignIn

NewSignIn returns the handler.

func (*SignIn) Handle

func (h *SignIn) Handle(ctx context.Context, cmd SignInCommand) (SignInResult, error)

Handle signs the member in, opening a fresh session, or refuses with invalid_credentials. The attempt is counted as a failure of its email and its source before the password is verified, so attempts made at once cannot all pass the lockout; a locked email (locked) or a throttled source (rate_limited) is refused before any hash, and a right password takes the failure back. An unknown email is verified against a hash no password matches, so it takes as long as a wrong password; a member who is not active is refused like a wrong password even when the password is right. Failures of a known member are audited, attempts on unknown emails are not: the log records people, not an attacker's input.

type SignInCommand

type SignInCommand struct {
	Email    string
	Password secret.String
	// ClientIP and UserAgent describe the device signing in.
	ClientIP  netip.Addr
	UserAgent string
	// RequestID is the request attempting, for the audit entries.
	RequestID string
}

SignInCommand is one attempt to sign in.

type SignInDeps

type SignInDeps struct {
	Tx    Transactor
	Store SignInStore
	// Settings give the timeouts a session opens with.
	Settings AuthSettingsReader
	Hasher   PasswordVerifier
	Audit    AuditLog
	Clock    clock.Clock
	IDs      *id.Source
	// Random draws session cookies, which are signed with Key.
	Random io.Reader
	Key    []byte
}

SignInDeps are what signing in works with.

type SignInResult

type SignInResult struct {
	Caller access.Caller
	Cookie secret.String
}

SignInResult is the session opened and the value of its cookie, which is handed to the browser and never stored.

type SignInStore

type SignInStore interface {
	SetPasswordHash(ctx context.Context, member access.MemberID, hash string, at time.Time) error
	RecordSignIn(ctx context.Context, member access.MemberID, at time.Time) error
	CreateSession(ctx context.Context, s access.Session) error
	// contains filtered or unexported methods
}

SignInStore is what signing in needs of the stored members and sessions.

type SignOut

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

SignOut ends the session a caller is signed in to.

func NewSignOut

func NewSignOut(tx Transactor, store SessionStore, audit AuditLog, c clock.Clock, ids *id.Source) *SignOut

NewSignOut returns the handler.

func (*SignOut) Handle

func (h *SignOut) Handle(ctx context.Context, caller access.Caller, requestID string) error

Handle revokes the caller's session and records the sign-out. A caller presenting an API token has no session to end and is refused, so a script never believes it ended something.

type TokenStore

type TokenStore interface {
	// TokenByHash returns the token and, for a personal access token, the
	// member holding it; ErrNotFound when no token has the hash.
	TokenByHash(ctx context.Context, hash access.TokenHash) (access.APIToken, *access.Member, error)
}

TokenStore finds API tokens by the hash of their value.

type TokenUseStore

type TokenUseStore interface {
	// RecordTokenUse records that token was presented at at from ip, unless
	// a use less than a minute before at is recorded already, so replicas
	// writing the same token's use coalesce.
	RecordTokenUse(ctx context.Context, token access.APITokenID, at time.Time, ip netip.Addr) error
}

TokenUseStore records when and from where API tokens were last used.

type TokenUses

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

TokenUses gathers the uses of API tokens a replica sees and writes them in rounds, so authenticating a request never waits on a write and a token presented many times a minute costs one.

func NewTokenUses

func NewTokenUses(store TokenUseStore) *TokenUses

NewTokenUses returns the replica's gatherer of token uses.

func (*TokenUses) Flush

func (u *TokenUses) Flush(ctx context.Context) error

Flush writes the uses noted since the last round. A use that cannot be written is dropped rather than retried: the next use of its token is noted again, and nothing depends on the record but a member's view of their tokens. It returns the first failure, for the round's log.

func (*TokenUses) Note

func (u *TokenUses) Note(t access.APIToken, at time.Time, ip netip.Addr)

Note keeps t's use at at from ip for the next round, when it is one worth recording; the latest use of a token seen before the round is the one written.

type Transactor

type Transactor interface {
	Within(ctx context.Context, fn func(ctx context.Context) error) error
}

Transactor runs a unit of work.

type UpdateAuthSettings

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

UpdateAuthSettings replaces the auth settings.

func NewUpdateAuthSettings

func NewUpdateAuthSettings(tx Transactor, store AuthSettingsStore, cache AuthSettingsCache, audit AuditLog, c clock.Clock,
	ids *id.Source,
) *UpdateAuthSettings

NewUpdateAuthSettings returns the handler.

func (*UpdateAuthSettings) Handle

Handle checks the settings, stores them and records auth_settings.updated with the settings before and after; settings equal to those in force change nothing and record nothing. Every replica applies a change once the notification reaches it; this one at once.

type UpdateMe

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

UpdateMe lets a member rename themself and choose their console language.

func NewUpdateMe

func NewUpdateMe(tx Transactor, store MemberChanger, audit AuditLog, c clock.Clock, ids *id.Source, locales []string) *UpdateMe

NewUpdateMe returns the handler; locales are the console's languages, the ones a member may choose.

func (*UpdateMe) Handle

func (h *UpdateMe) Handle(ctx context.Context, cmd UpdateMeCommand) (MemberView, error)

Handle applies the edit to the caller's member and records member.updated naming the fields it changed; an edit changing nothing records nothing. Only a session edits its member, so a leaked token cannot rename its owner.

type UpdateMeCommand

type UpdateMeCommand struct {
	Caller  access.Caller
	Change  access.ProfileChange
	Request governance.Request
}

UpdateMeCommand is a member's edit of themself.

type UpdateMember

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

UpdateMember edits a member for an instance admin.

func NewUpdateMember

func NewUpdateMember(tx Transactor, store MemberChanger, audit AuditLog, c clock.Clock, ids *id.Source) *UpdateMember

NewUpdateMember returns the handler.

func (*UpdateMember) Handle

Handle applies the edit and records member.updated for a changed email or display name, and member.promoted or member.demoted for a changed instance admin switch; an edit changing nothing records nothing. Demoting the last active instance admin is refused last_instance_admin.

type UpdateMemberCommand

type UpdateMemberCommand struct {
	Member  access.MemberID
	Change  access.MemberChange
	Request governance.Request
}

UpdateMemberCommand is an edit of a member.

type WorkingProjects

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

WorkingProjects answers which projects a caller works in, for listing them.

func NewWorkingProjects

func NewWorkingProjects(grants GrantReader) *WorkingProjects

NewWorkingProjects returns the handler.

func (*WorkingProjects) Handle

func (h *WorkingProjects) Handle(ctx context.Context, caller access.Caller) (all bool, only []workspace.ProjectID, err error)

Handle reports whether the caller works in every project, as an instance admin does, and otherwise the projects their member holds a grant in.

Jump to

Keyboard shortcuts

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