policybinding

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 9 Imported by: 1 module, 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 policybinding is the domain layer for the PolicyBinding entity: it applies one Policy to a set of accounts inside its owner's scope (the system, a team, a project or a user). Accounts are the only subjects: a team-wide cap binds the team's account, a member's the member account. An account is held by at most one binding.

Authorization and the cross-row scope rules are app/authz's and app/refcheck's concern; this package validates shape only.

Index

Constants

This section is empty.

Variables

View Source
var ErrAccountBound = errors.New("policybinding: account is already bound by another policy binding")

ErrAccountBound is a write naming an account another binding already holds: an account is bound to at most one policy.

Functions

This section is empty.

Types

type PolicyBinding

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

PolicyBinding attaches Spec.PolicyID to Spec.AccountIDs inside the scope Meta.Owner names.

func (*PolicyBinding) IsEnabled

func (b *PolicyBinding) IsEnabled() bool

IsEnabled returns true when Enabled is unset or explicitly true.

func (*PolicyBinding) ScopeKey added in v0.20.0

func (b *PolicyBinding) ScopeKey() string

ScopeKey names the owner scope ("team:<id>", "project:<id>", "user:<id>"), "" for the system.

func (*PolicyBinding) Validate

func (b *PolicyBinding) Validate() error

Validate runs intra-row rules via the shared meta.Validator and enforces:

  • Owner.Kind is system (no id), or team, project or user with an id.
  • no account is listed twice.

type Spec

type Spec struct {
	PolicyID   string   `json:"policyId"   yaml:"policyId"   validate:"required,uuid" doc:"Id of the policy the accounts are bound to."`
	AccountIDs []string `` /* 239-byte string literal not displayed */
	Enabled    *bool    `` /* 128-byte string literal not displayed */
}

Spec carries the policy, the accounts, and the enabled flag.

type Store

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

Store holds a DB rather than Queries so Upsert can run a multi-table transaction.

func NewStore

func NewStore(db storage.DB) *Store

func (*Store) Delete

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

Delete relies on the FK to cascade the junction rows.

func (*Store) Get

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

Get returns (nil, nil) when no row has id.

func (*Store) Holding added in v0.20.0

func (s *Store) Holding(ctx context.Context, accountID string) (*PolicyBinding, error)

Holding returns the binding that holds accountID, nil when none does.

func (*Store) List

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

func (*Store) Upsert

func (s *Store) Upsert(ctx context.Context, b *PolicyBinding) error

Upsert writes the binding and its accounts in one transaction.

Jump to

Keyboard shortcuts

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