account

package
v0.30.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 10 Imported by: ? 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

Overview

Package account is the domain layer for the Account entity: what policies bind to and usage is charged to. A provider account is one provider organization at one host, whose tier limits every host key of the organization shares. A caller account is one relay keeps in step with the tenancy rows: one per team and per project, a personal account per user, one per service account, and a member account per user and team or project the user is a member of. A key lands in one account its principal holds, its default lane. A shared account is a provider account owned by the user, team or project it was shared with (a service account's by its project, held by it) that holds no keys and reaches those of the real account it names.

This package validates one row's shape, stores it, and creates a caller account idempotently (Store.EnsureManaged). A provider account is only ever created on request: a host key names one, and nothing makes one for it. Out of scope: learning org ids from upstream responses, deciding which caller accounts should exist (app/plan) and applying an account's policy to requests.

Index

Constants

This section is empty.

Variables

View Source
var ErrManagedTaken = errors.New("account: another account already holds this place")

ErrManagedTaken is a write of a caller account whose place another row holds.

View Source
var ErrShareTaken = errors.New("account: the account is already shared with this receiver")

ErrShareTaken is a second share of one account with one receiver.

View Source
var ErrShared = errors.New("account: shares still name the account")

ErrShared is a delete of a real account shares still name: they are revoked first, never taken along.

Functions

func MemberKey

func MemberKey(scope meta.Owner, userID string) string

MemberKey is the managed key of userID's member account in scope.

Types

type Account

type Account struct {
	Meta meta.Metadata `json:"metadata" yaml:"metadata"`
	Spec Spec          `json:"spec"     yaml:"spec"`

	// FollowsRoleBindings marks a member account made from a role binding: it closes when the last such grant goes. One made on first use, after a group grant relay cannot list, stays open.
	FollowsRoleBindings bool `json:"-" yaml:"-"`
}

Account is a provider organization at one host, or a caller account.

func ForProject

func ForProject(projectID, projectName, display string) *Account

ForProject is the project's own account.

func ForServiceAccount

func ForServiceAccount(saID, saName, display, projectID string) *Account

ForServiceAccount is the service account's account, in its project.

func ForTeam

func ForTeam(teamID, teamName, display string) *Account

ForTeam is the team's own account, named after it; EnsureManaged mints the final name.

func Member

func Member(userID, username string, scope meta.Owner, scopeName, scopeDisplay string) *Account

Member is the user's member account in a team or project scope, named after the user and the scope.

func Personal

func Personal(userID, username string) *Account

Personal is the user's personal account.

func Share

func Share(src *Account, r Receiver, owner meta.Owner, receiverName string) *Account

Share is the account sharing src with r, owned by owner (r itself, or a service account's project) and named after src and receiverName; the store mints the final name.

func (*Account) DerivedKind

func (a *Account) DerivedKind() Kind

DerivedKind is the account's kind from its host, holder and owner; "" when they fit no kind.

func (*Account) IsProvider

func (a *Account) IsProvider() bool

IsProvider reports whether the account is a provider org at a host.

func (*Account) IsShared

func (a *Account) IsShared() bool

IsShared reports whether a is a shared account: one that reaches another provider account's keys and holds none of its own.

func (*Account) ManagedKey

func (a *Account) ManagedKey() string

ManagedKey names a caller account's place, the identity concurrent writers converge on: "team:<id>", "project:<id>", "personal:<user>", "service:<sa>" or "member:<team|project>:<id>:<user>". "" for a provider account.

func (*Account) Receiver

func (a *Account) Receiver() Receiver

Receiver is who a shared account was shared with: its holder for a service account's share, else its owner.

func (*Account) TakesKeysOf

func (a *Account) TakesKeysOf(principal Holder) bool

TakesKeysOf reports whether a relay key of principal may run in a. A key outlives the membership it was made under, so it lands only where relay re-checks that membership itself: the principal's personal or service account, a member account that follows role bindings, or a provider account the key's user owns personally. A member account opened on first use (a group or team-level grant relay cannot see) serves minted tokens only, and team, project and system provider accounts are reached through the caller ladder, never as a lane.

func (*Account) Validate

func (a *Account) Validate() error

Validate runs intra-row rules via the shared meta.Validator, derives Spec.Kind, and enforces each kind's shape: a provider account has a host, an owner of kind organization, system, team, project or user, and no holder; a caller account has no host or org id.

Cross-row checks (the host and holder exist) live in app/refcheck.

type Holder

type Holder struct {
	Kind HolderKind `` /* 159-byte string literal not displayed */
	ID   string     `json:"id"   yaml:"id"   validate:"required,uuid" doc:"Id of the user or service account."`
	// Derived: filled on control API reads, never stored; compare holders by Kind and ID.
	Name string `` /* 195-byte string literal not displayed */
}

Holder is the principal acting in an account.

func (*Holder) Key

func (h *Holder) Key() string

Key renders the holder as a principal string, "user:<id>" or "serviceaccount:<id>".

type HolderKind

type HolderKind string

HolderKind names the principal an account is held by.

const (
	HolderUser           HolderKind = "user"
	HolderServiceAccount HolderKind = "serviceaccount"
)

type Kind

type Kind string

Kind is what an account is, derived from its host, holder and owner.

const (
	KindTeam     Kind = "team"
	KindProject  Kind = "project"
	KindPersonal Kind = "personal"
	KindMember   Kind = "member"
	KindService  Kind = "service"
	KindProvider Kind = "provider"
)

type PayloadLogging

type PayloadLogging string

PayloadLogging is an account's say on capturing request and response bodies; empty leaves it to the account above on the ladder, then to the key.

const (
	PayloadLoggingOn  PayloadLogging = "on"
	PayloadLoggingOff PayloadLogging = "off"
)

type Receiver

type Receiver struct {
	Kind ReceiverKind `` /* 211-byte string literal not displayed */
	ID   string       `json:"id"   yaml:"id"   validate:"required,uuid" doc:"Id of the user, team, project or service account."`
}

Receiver is who a provider account is shared with.

func (Receiver) Key

func (r Receiver) Key() string

Key renders the receiver as "<kind>:<id>", the form one share per receiver is keyed by.

type ReceiverKind

type ReceiverKind string

ReceiverKind names who a provider account is shared with.

const (
	ReceiverUser           ReceiverKind = "user"
	ReceiverTeam           ReceiverKind = "team"
	ReceiverProject        ReceiverKind = "project"
	ReceiverServiceAccount ReceiverKind = "serviceaccount"
)

type ShareParty

type ShareParty struct {
	Kind string `` /* 174-byte string literal not displayed */
	ID   string `json:"id,omitempty"   doc:"Id of the user, team, project or service account; empty for the organization and the system."`
	Name string `` /* 151-byte string literal not displayed */
}

ShareParty names one side of a share: the owner of the real account, or the receiver.

type Spec

type Spec struct {
	// Kind is derived on every write; a value sent is ignored.
	Kind Kind `` /* 347-byte string literal not displayed */

	// Holder is the principal acting in the account: set on personal, member and service accounts, empty on team, project and provider accounts. Fixed at create.
	Holder *Holder `` /* 228-byte string literal not displayed */

	// HostID is the host a provider account is held at; empty on caller accounts.
	HostID string `` /* 156-byte string literal not displayed */

	// OrgID is the provider's organization id: the org, never a person or an email, since one login can belong to several orgs with separate limits. Empty until known.
	OrgID string `` /* 164-byte string literal not displayed */

	// GroupedByRelay marks a provider account relay made by grouping an owner's keys at a host, before keys had to name their account: an upstream 429 then stays with the key, since its keys are not known to share one org.
	GroupedByRelay bool `` /* 315-byte string literal not displayed */

	PayloadLogging PayloadLogging `` /* 458-byte string literal not displayed */

	// Closed is set on a member account whose membership ended; its keys are refused.
	Closed bool `` /* 218-byte string literal not displayed */

	// SourceAccountID marks a shared account: the provider account whose keys it reaches. It holds no keys of its own, and is fixed at create.
	SourceAccountID string `` /* 429-byte string literal not displayed */

	// SharedBy is derived on read from the real account's owner.
	SharedBy *ShareParty `` /* 214-byte string literal not displayed */
}

Spec carries the holder, the host and org of a provider account, and the account's flags.

type Store

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

Store is the Account data-access type.

func NewStore

func NewStore(q *gen.Queries) *Store

NewStore constructs a Store from an existing sqlc Queries handle.

func (*Store) CreateShare

func (s *Store) CreateShare(ctx context.Context, a *Account) error

CreateShare writes the new shared account a under a fresh id, with a's name suffixed -2, -3, … when taken. A second share with one receiver is ErrShareTaken.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id string) error

Delete removes an Account by id.

func (*Store) EnsureManaged

func (s *Store) EnsureManaged(ctx context.Context, want *Account) (string, error)

EnsureManaged returns the id of the caller account want describes, creating it on first use with want's name, suffixed -2, -3, … when taken, and want's id when it carries one. Concurrent first saves converge on one row, whose id the caller gets back.

func (*Store) Get

func (s *Store) Get(ctx context.Context, id string) (*Account, error)

Get returns the Account with the given id, or (nil, nil) if not found.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]*Account, error)

List returns every Account row.

func (*Store) SetMembership

func (s *Store) SetMembership(ctx context.Context, a *Account, closed, followsRoleBindings bool) error

SetMembership marks member account a closed or open and whether it follows role bindings, only while the row is still at the version a was read at: a decision made from an older read (a close racing a reopen) changes nothing. A row already so is left alone.

func (*Store) Upsert

func (s *Store) Upsert(ctx context.Context, a *Account) error

Upsert writes a. The caller sets Meta.ID.

Jump to

Keyboard shortcuts

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