Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

v1 source pure

Package policies is the Remix Lab permission block. A Policy maps named operations to an eligibility rule evaluated a...

Overview

Package policies is the Remix Lab permission block. A Policy maps named operations to an eligibility rule evaluated against a membership reader.

Each operation is defined once with a floor: the most permissive rule it may ever be set to. Administrative operations get a floor of RuleReviewer or RuleOwner, so reconfiguring a policy can never hand admin powers to ordinary members or the public.

Operations with an owner floor (typically policy changes and owner appointment) can never be disabled: setting them to RuleNobody would lock the owners out permanently.

Policy changes affect future operations only. Ballot eligibility follows the electorate frozen when the ballot opened, not the current policy.

Constants 2

const MaxOperations

1const MaxOperations = 64
source

MaxOperations bounds the number of operations one policy defines.

Functions 2

func New

1func New(members core.MembershipReader) *Policy
source

New creates a policy reading roles from members. members may be the host's own membership set or an adapter to a reviewed shared realm.

func ParseRule

1func ParseRule(s string) (Rule, error)
source

ParseRule converts the canonical rule name to a Rule.

Types 3

type Policy

struct
1type Policy struct {
2	members core.MembershipReader
3	ops     *avl.Tree // op -> *entry
4}
source

Policy evaluates named operations. Hold it in an unexported host-realm variable; its Set method changes authorization.

Methods on Policy

func Allowed

method on Policy
1func (p *Policy) Allowed(op string, actor address) bool
source

Allowed reports whether actor may perform op, without building an error.

func Authorize

method on Policy
1func (p *Policy) Authorize(op string, actor address) error
source

Authorize implements core.AuthorizationPolicy. Unknown operations are denied.

func Define

method on Policy
1func (p *Policy) Define(op string, rule, floor Rule)
source

Define registers op with an initial rule and a floor. It panics on invalid input because host realms call it from init with constant arguments.

func List

method on Policy
1func (p *Policy) List() []RuleView
source

List returns every operation's rule, ordered by operation name.

func Rule

method on Policy
1func (p *Policy) Rule(op string) (Rule, bool)
source

Rule returns the current rule for op.

func Set

method on Policy
1func (p *Policy) Set(op string, rule Rule) error
source

Set changes the rule for a defined op. The host must have authorized the actor (typically through a "policy.set" operation with an owner floor).

type Rule

ident
1type Rule int
source

Rule is an eligibility requirement. Rules are ordered from most to least permissive.

Methods on Rule

func String

method on Rule
1func (r Rule) String() string
source

type RuleView

struct
1type RuleView struct {
2	Op    string
3	Rule  Rule
4	Floor Rule
5}
source

RuleView is an inert description of one operation's rule.

Dependencies

Imports 2

/p/g1lnkytfqcjwllws63gvf0mv9yt04aswy4y9amhm/remixlab/policies/v1

Imported by indexer

Source Files 2