safety

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSafetyBlocked = &SafetyError{
		Message:  "operation blocked by read-only mode",
		ExitCode: output.CodeSafetyBlocked,
	}

	ErrNeedsConfirm = &SafetyError{
		Message:  "operation requires --confirm",
		ExitCode: output.CodeSafetyBlocked,
	}
)

Functions

func FormatPreview

func FormatPreview(p Preview) string

FormatPreview renders a dry-run preview showing method, path, resource IDs, and a payload summary. The payload summary is truncated to 200 characters.

Types

type Policy

type Policy struct {
	ReadOnly bool
	DryRun   bool
	Confirm  bool
}

Policy holds the safety flags for a command invocation.

func NewPolicy

func NewPolicy(readOnly, dryRun, confirm bool) Policy

func (Policy) Check

func (p Policy) Check(level SafetyLevel) error

Check verifies that the policy allows the operation at the given safety level. It returns nil if allowed, or a *SafetyError if blocked. --dry-run is always allowed; --read-only blocks all writes even with --confirm.

type Preview

type Preview struct {
	Method         string
	Path           string
	ResourceIDs    []string
	PayloadSummary string
}

Preview holds the information needed to display a dry-run summary.

type SafetyError

type SafetyError struct {
	Message  string
	ExitCode int
}

SafetyError is returned when a safety policy blocks an operation.

func (*SafetyError) Error

func (e *SafetyError) Error() string

type SafetyLevel

type SafetyLevel int

SafetyLevel represents the risk level of an operation.

const (
	ReadLevel SafetyLevel = iota
	LowRiskWrite
	HighRiskWrite
)

func (SafetyLevel) String

func (l SafetyLevel) String() string

Jump to

Keyboard shortcuts

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