approval

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package approval models tool approval decisions and permission prompts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateReplayPreventionNonce

func GenerateReplayPreventionNonce() (string, error)

func GenerateToken

func GenerateToken() (string, error)

Types

type Audit

type Audit struct {
	Kind                  string          `json:"kind"`
	Token                 string          `json:"token"`
	ReplayPreventionNonce string          `json:"replay_prevention_nonce"`
	Scope                 Scope           `json:"scope"`
	ApprovingActor        string          `json:"approving_actor"`
	RequestingActor       string          `json:"requesting_actor"`
	ExecutingActor        string          `json:"executing_actor"`
	ExecutionMode         string          `json:"execution_mode"`
	Status                Status          `json:"status"`
	DelegatedExecution    bool            `json:"delegated_execution"`
	DelegationChain       []DelegationHop `json:"delegation_chain"`
	Uses                  int             `json:"uses"`
	MaxUses               int             `json:"max_uses"`
	VerifiedAt            time.Time       `json:"verified_at"`
}

type DelegationHop

type DelegationHop struct {
	Actor     string `json:"actor"`
	SessionID string `json:"session_id,omitempty"`
	Reason    string `json:"reason"`
}

type Error

type Error struct {
	Kind     string `json:"kind"`
	Message  string `json:"message"`
	Expected any    `json:"expected,omitempty"`
	Actual   any    `json:"actual,omitempty"`
}

func (Error) Error

func (e Error) Error() string

type Grant

type Grant struct {
	Token                 string          `json:"token"`
	ReplayPreventionNonce string          `json:"replay_prevention_nonce"`
	Scope                 Scope           `json:"scope"`
	ApprovingActor        string          `json:"approving_actor"`
	RequestingActor       string          `json:"requesting_actor"`
	ApprovedExecutor      string          `json:"approved_executor"`
	Status                Status          `json:"status"`
	State                 UsageState      `json:"state"`
	Usable                bool            `json:"usable"`
	ExpiresAt             *time.Time      `json:"expires_at,omitempty"`
	MaxUses               int             `json:"max_uses"`
	Uses                  int             `json:"uses"`
	RemainingUses         int             `json:"remaining_uses"`
	DelegationChain       []DelegationHop `json:"delegation_chain,omitempty"`
	CreatedAt             time.Time       `json:"created_at"`
	UpdatedAt             time.Time       `json:"updated_at"`
	LastAuditErrorKind    string          `json:"last_audit_error_kind,omitempty"`
}

type GrantOptions

type GrantOptions struct {
	Token            string
	Scope            Scope
	ApprovingActor   string
	RequestingActor  string
	ApprovedExecutor string
	Status           Status
	ExpiresAt        *time.Time
	MaxUses          int
	DelegationChain  []DelegationHop
	Now              time.Time
}

type Ledger

type Ledger struct {
	Kind   string  `json:"kind"`
	Grants []Grant `json:"grants"`
}

type Scope

type Scope struct {
	Policy     string `json:"policy"`
	Action     string `json:"action"`
	Repository string `json:"repository,omitempty"`
	Branch     string `json:"branch,omitempty"`
	Commit     string `json:"commit,omitempty"`
}

type Status

type Status string
const (
	StatusPending  Status = "approval_pending"
	StatusGranted  Status = "approval_granted"
	StatusConsumed Status = "approval_consumed"
	StatusExpired  Status = "approval_expired"
	StatusRevoked  Status = "approval_revoked"
)

type Store

type Store struct {
	ConfigHome string
}

func NewStore

func NewStore(configHome string) Store

func (Store) Approve

func (s Store) Approve(token string, opts GrantOptions) (Grant, error)

Approve transitions an existing pending token into a granted approval.

func (Store) Consume

func (s Store) Consume(token string, scope Scope, executingActor string, now time.Time) (Audit, error)

func (Store) Grant

func (s Store) Grant(opts GrantOptions) (Grant, error)

func (Store) List

func (s Store) List() (Ledger, error)

func (Store) Revoke

func (s Store) Revoke(token string, now time.Time) (Audit, error)

func (Store) Verify

func (s Store) Verify(token string, scope Scope, executingActor string, now time.Time) (Audit, error)

type UsageState

type UsageState string

UsageState summarizes whether an approval token can still authorize work.

const (
	// UsagePending means the token exists but is not owner-approved yet.
	UsagePending UsageState = "pending"
	// UsageUnused means the token is granted and has all uses available.
	UsageUnused UsageState = "unused"
	// UsagePartiallyConsumed means the token is granted and has some remaining uses.
	UsagePartiallyConsumed UsageState = "partially_consumed"
	// UsageConsumed means the token exhausted its allowed uses.
	UsageConsumed UsageState = "consumed"
	// UsageExpired means the token's time window has elapsed.
	UsageExpired UsageState = "expired"
	// UsageRevoked means the token was explicitly revoked.
	UsageRevoked UsageState = "revoked"
)

Jump to

Keyboard shortcuts

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