Documentation
¶
Overview ¶
Package policy allows, checks, and confirms. A destructive call waits for a stored approval.
Index ¶
- Constants
- Variables
- func ConfirmAsk(caller, operationID string, params map[string]string) string
- func ConfirmSentence(operationID string, params map[string]string) string
- func DefaultApprovalDir() (string, error)
- func WithInput(ctx context.Context, in Input) context.Context
- type Around
- type Builtin
- type CommandNotifier
- type Decision
- type Files
- func (f *Files) Claim(ctx context.Context, id string) (bool, error)
- func (f *Files) FindApproved(ctx context.Context, id string) (Record, bool, error)
- func (f *Files) Get(ctx context.Context, id string) (Record, bool, error)
- func (f *Files) Put(ctx context.Context, rec Record) error
- func (f *Files) Remove(ctx context.Context, rec Record)
- type HTTPNotifier
- type Hook
- type Input
- type Memory
- func (m *Memory) Claim(ctx context.Context, id string) (bool, error)
- func (m *Memory) FindApproved(ctx context.Context, id string) (Record, bool, error)
- func (m *Memory) Get(ctx context.Context, id string) (Record, bool, error)
- func (m *Memory) Put(ctx context.Context, rec Record) error
- func (m *Memory) Remove(ctx context.Context, rec Record)
- type Notice
- type Notifier
- type PendingConfirmation
- type Record
- type State
- func (s *State) Approve(ctx context.Context, id string) (string, error)
- func (s *State) ConsumeFor(ctx context.Context, caller, approvalID, opID string, params map[string]string) (bool, error)
- func (s *State) Open(ctx context.Context, opt StoreOptions) error
- func (s *State) Pending(ctx context.Context, id string) *PendingConfirmation
- func (s *State) RequestFor(ctx context.Context, caller, opID string, params map[string]string) (string, error)
- func (s *State) SetNonceDir(dir string)
- func (s *State) SetSigner(secret []byte, ttl time.Duration) error
- func (s *State) SetStore(store Store)
- type Store
- type StoreOptions
- type Wrapped
Constants ¶
const ( // StatusPending is a recorded call that has not been approved. StatusPending = "pending" // StatusApproved is a yes that ConsumeFor accepts once. StatusApproved = "approved" // StatusConsumed is a yes that already ran. StatusConsumed = "consumed" )
Variables ¶
var ErrPendingApproval = errors.New("pending id does not run the call")
ErrPendingApproval is a pending id submitted as if it were already approved.
var ErrUnknownApproval = errors.New("unknown approval")
ErrUnknownApproval is an id approve cannot find, or one that is already consumed or expired.
Functions ¶
func ConfirmAsk ¶ added in v0.1.5
ConfirmAsk is the confirmation form. The call does not run until accept.
func ConfirmSentence ¶
ConfirmSentence is the text shown for a held call.
func DefaultApprovalDir ¶
DefaultApprovalDir is the user-config path serve and approve share.
Types ¶
type CommandNotifier ¶
type CommandNotifier struct {
// contains filtered or unexported fields
}
type Decision ¶
type Decision string
Decision is allow, deny, or confirmation required.
type Files ¶ added in v0.1.1
Files keeps records as JSON under Dir/confirmations.
func (*Files) FindApproved ¶ added in v0.1.1
type HTTPNotifier ¶
type HTTPNotifier struct {
// contains filtered or unexported fields
}
type Memory ¶ added in v0.1.1
type Memory struct {
// contains filtered or unexported fields
}
Memory keeps records in this process.
func (*Memory) FindApproved ¶ added in v0.1.1
type PendingConfirmation ¶
type PendingConfirmation struct {
ID string `json:"ID"`
OperationID string `json:"OperationID"`
Params map[string]string `json:"Params"`
Caller string `json:"Caller,omitempty"`
}
PendingConfirmation is a held call. The id does not authorize HTTP.
type Record ¶ added in v0.1.1
type Record struct {
ID string `json:"id"`
OperationID string `json:"operation_id"`
Params map[string]string `json:"params,omitempty"`
Status string `json:"status"`
Expiry int64 `json:"expiry,omitempty"`
ApprovedID string `json:"approved_id,omitempty"`
Caller string `json:"caller,omitempty"`
}
Record is one confirmation.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State is the confirmation use case. Memory is the store. SetStore, SetNonceDir, and SetSigner attach adapters.
func (*State) Approve ¶
Approve records a separate decision. The returned id is what a later invoke accepts once.
func (*State) ConsumeFor ¶
func (s *State) ConsumeFor(ctx context.Context, caller, approvalID, opID string, params map[string]string) (bool, error)
ConsumeFor accepts an approved id once, and only for the caller that received it.
func (*State) Open ¶ added in v0.1.5
func (s *State) Open(ctx context.Context, opt StoreOptions) error
Open points state at the store, files dir, and signer. Empty URL keeps Files or Memory.
func (*State) Pending ¶
func (s *State) Pending(ctx context.Context, id string) *PendingConfirmation
func (*State) RequestFor ¶
func (s *State) RequestFor(ctx context.Context, caller, opID string, params map[string]string) (string, error)
RequestFor records a pending call for one caller. The id it returns does not authorize HTTP. A store error means the file was not written, so there is no pending id to approve.
type Store ¶ added in v0.1.1
type Store interface {
Put(ctx context.Context, rec Record) error
Get(ctx context.Context, id string) (Record, bool, error)
FindApproved(ctx context.Context, approvedID string) (Record, bool, error)
Claim(ctx context.Context, id string) (bool, error)
Remove(ctx context.Context, rec Record)
}
Store persists confirmation records. Memory is the default. Files is one machine. Claim is consume-once. valkey is the replica adapter: SET NX on the pending id.
type StoreOptions ¶ added in v0.1.5
type StoreOptions struct {
URL string
Dir string
Secret []byte
TTL time.Duration
Dial func(context.Context, string) (Store, error)
}
StoreOptions attaches a store, a files dir, and a signer. Dial opens a URL.