approval

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SendNotification

func SendNotification(socketPath, token, resource string)

SendNotification sends a data-change notification to the desktop app (fire-and-forget). resource indicates what changed, e.g. "asset".

func SocketPath

func SocketPath(dataDir string) string

SocketPath returns the approval socket path for the given data directory.

Types

type ApprovalHandler

type ApprovalHandler func(req ApprovalRequest) ApprovalResponse

ApprovalHandler processes an approval request and returns a response.

type ApprovalRequest

type ApprovalRequest struct {
	Token       string          `json:"token,omitempty"` // 认证 token
	Type        string          `json:"type"`            // "exec"|"cp"|"create"|"update"|"grant"|"batch"|"ext_tool"
	AssetID     int64           `json:"asset_id,omitempty"`
	AssetName   string          `json:"asset_name,omitempty"`
	Command     string          `json:"command,omitempty"`
	Detail      string          `json:"detail"`
	SessionID   string          `json:"session_id,omitempty"`  // 统一 session 标识(审批 session 或 grant session)
	GrantItems  []GrantItem     `json:"grant_items,omitempty"` // type="grant" 时使用
	BatchItems  []BatchItem     `json:"batch_items,omitempty"` // type="batch" 时使用
	Description string          `json:"description,omitempty"` // 授权描述
	Extension   string          `json:"extension,omitempty"`   // type="ext_tool": extension name
	Tool        string          `json:"tool,omitempty"`        // type="ext_tool": tool name
	ToolArgs    json.RawMessage `json:"tool_args,omitempty"`   // type="ext_tool": tool arguments
}

ApprovalRequest is sent from opsctl to the desktop app.

type ApprovalResponse

type ApprovalResponse struct {
	Approved       bool        `json:"approved"`
	Reason         string      `json:"reason,omitempty"`
	SessionID      string      `json:"session_id,omitempty"`      // grant 审批返回 / session 标识
	ApproveGrant   bool        `json:"approve_grant,omitempty"`   // 用户选择了"记住并允许"
	MatchedPattern string      `json:"matched_pattern,omitempty"` // session 匹配时命中的规则模式
	EditedItems    []GrantItem `json:"edited_items,omitempty"`    // 用户编辑后的 grant items
	ToolResult     string      `json:"tool_result,omitempty"`     // type="ext_tool": execution result (JSON)
	ToolError      string      `json:"tool_error,omitempty"`      // type="ext_tool": execution error message
}

ApprovalResponse is sent from the desktop app back to opsctl.

func RequestApproval

func RequestApproval(socketPath string, req ApprovalRequest) (ApprovalResponse, error)

RequestApproval connects to the Unix socket and sends an approval request. Blocks until a response is received.

func RequestApprovalWithToken

func RequestApprovalWithToken(socketPath, token string, req ApprovalRequest) (ApprovalResponse, error)

RequestApprovalWithToken connects to the Unix socket and sends an approval request with auth token.

type BatchItem

type BatchItem struct {
	Type      string `json:"type"` // "exec"|"sql"|"redis"
	AssetID   int64  `json:"asset_id"`
	AssetName string `json:"asset_name"`
	Command   string `json:"command"`
}

BatchItem 批量执行中的单条操作

type GrantItem

type GrantItem struct {
	Type      string `json:"type"` // "exec", "cp", "create", "update"
	AssetID   int64  `json:"asset_id"`
	AssetName string `json:"asset_name"`
	GroupID   int64  `json:"group_id"`
	GroupName string `json:"group_name"`
	Command   string `json:"command"`
	Detail    string `json:"detail"`
}

GrantItem 授权中的单条操作

type Server

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

Server listens on a Unix socket for approval requests from opsctl.

func NewServer

func NewServer(handler ApprovalHandler, authToken string) *Server

NewServer creates a new approval server.

func (*Server) Start

func (s *Server) Start(socketPath string) error

Start begins listening on the Unix socket at socketPath. Removes stale socket file if it exists.

func (*Server) Stop

func (s *Server) Stop()

Stop closes the listener, removes the socket file, and waits for goroutines.

Jump to

Keyboard shortcuts

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