evidence

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package evidence は runbook の実行中の送受信を、ステップごとの証跡ファイルとして保存する。

runn の Capturer を実装し、runn が渡す HTTP / gRPC / DB / exec の送受信を、 実行中のステップ (runn の Trail) ごとに集めて JSON ファイルに書き出す。 詳細は docs/design/evidence-report.md の 4 章。

Index

Constants

View Source
const Masked = "***"

Masked は隠した値の置き換え先。

View Source
const MaxBody = 1 << 20

MaxBody は証跡に書く本文の上限 (これを超える分は切り捨てて truncated を付ける)。

Variables

This section is empty.

Functions

func SafeName

func SafeName(s string) string

SafeName はキーやシナリオ ID をファイル名・ディレクトリ名に使える形にする。

func StepKey

func StepKey(trs runn.Trails) (key string, index int, ok bool)

StepKey は Trail から、ステップのキーとトップレベルのステップの番号 (1 始まり) を作る。

  • トップレベルのステップ: "create_loan"
  • include 先のステップ: "inspect_history_book_0.call" (呼び出したステップのキーと . でつなぐ)
  • loop の回 (0 始まり): "member_loans[2]"
  • steps が配列で書かれた runbook: 配列の添字をキーにする ("3")

ステップの Trail がなければ ok は false。

func ValidatePaths

func ValidatePaths(paths []string) error

ValidatePaths は evidence.mask.paths の書き方を確かめる (runnora validate 用)。

Types

type Capturer

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

Capturer は runn の Capturer を実装し、1 つの runbook の送受信をステップごとに集める。 runbook ごとに New で作り、実行後に Flush で書き出す。

func New

func New(scenarioID string, mode Mode, mask *Mask) *Capturer

New は scenarioID の runbook 用の Capturer を作る。mask が nil なら決まったヘッダだけを隠す。

func (*Capturer) CaptureAgentRequest

func (c *Capturer) CaptureAgentRequest(string, *runn.AgentRequest)

func (*Capturer) CaptureAgentResponse

func (c *Capturer) CaptureAgentResponse(string, *runn.AgentResponse)

func (*Capturer) CaptureCDPAction

func (c *Capturer) CaptureCDPAction(runn.CDPAction)

func (*Capturer) CaptureCDPEnd

func (c *Capturer) CaptureCDPEnd(string)

func (*Capturer) CaptureCDPResponse

func (c *Capturer) CaptureCDPResponse(runn.CDPAction, map[string]any)

func (*Capturer) CaptureCDPStart

func (c *Capturer) CaptureCDPStart(string)

func (*Capturer) CaptureDBResponse

func (c *Capturer) CaptureDBResponse(name string, res *runn.DBResponse)

func (*Capturer) CaptureDBStatement

func (c *Capturer) CaptureDBStatement(name string, stmt string)

func (*Capturer) CaptureEnd

func (c *Capturer) CaptureEnd(runn.Trails, string, string)

func (*Capturer) CaptureExecCommand

func (c *Capturer) CaptureExecCommand(command, shell string, _ bool)

func (*Capturer) CaptureExecStderr

func (c *Capturer) CaptureExecStderr(stderr string)

func (*Capturer) CaptureExecStdin

func (c *Capturer) CaptureExecStdin(stdin string)

func (*Capturer) CaptureExecStdout

func (c *Capturer) CaptureExecStdout(stdout string)

func (*Capturer) CaptureGRPCClientClose

func (c *Capturer) CaptureGRPCClientClose()

func (*Capturer) CaptureGRPCEnd

func (c *Capturer) CaptureGRPCEnd(string, runn.GRPCType, string, string)

func (*Capturer) CaptureGRPCRequestHeaders

func (c *Capturer) CaptureGRPCRequestHeaders(h map[string][]string)

func (*Capturer) CaptureGRPCRequestMessage

func (c *Capturer) CaptureGRPCRequestMessage(m map[string]any)

func (*Capturer) CaptureGRPCResponseHeaders

func (c *Capturer) CaptureGRPCResponseHeaders(h map[string][]string)

func (*Capturer) CaptureGRPCResponseMessage

func (c *Capturer) CaptureGRPCResponseMessage(m map[string]any)

func (*Capturer) CaptureGRPCResponseStatus

func (c *Capturer) CaptureGRPCResponseStatus(s *status.Status)

func (*Capturer) CaptureGRPCResponseTrailers

func (c *Capturer) CaptureGRPCResponseTrailers(t map[string][]string)

func (*Capturer) CaptureGRPCStart

func (c *Capturer) CaptureGRPCStart(name string, typ runn.GRPCType, service, method string)

func (*Capturer) CaptureHTTPRequest

func (c *Capturer) CaptureHTTPRequest(name string, req *http.Request)

func (*Capturer) CaptureHTTPResponse

func (c *Capturer) CaptureHTTPResponse(name string, res *http.Response)

func (*Capturer) CaptureResult

func (c *Capturer) CaptureResult(runn.Trails, *runn.RunResult)

func (*Capturer) CaptureResultByStep

func (c *Capturer) CaptureResultByStep(runn.Trails, *runn.RunResult)

func (*Capturer) CaptureSSHCommand

func (c *Capturer) CaptureSSHCommand(string)

func (*Capturer) CaptureSSHStderr

func (c *Capturer) CaptureSSHStderr(string)

func (*Capturer) CaptureSSHStdout

func (c *Capturer) CaptureSSHStdout(string)

func (*Capturer) CaptureStart

func (c *Capturer) CaptureStart(runn.Trails, string, string)

func (*Capturer) CurrentStep

func (c *Capturer) CurrentStep() (key string, index int)

CurrentStep は実行中のステップのキーと、トップレベルのステップの番号を返す (diffEps の記録用)。

func (*Capturer) Errs

func (c *Capturer) Errs() error

Errs は runn に証跡の取得中のエラーを返す (runn はこれを実行結果のエラーにしない)。 取得中のエラーは Flush が返す。

func (*Capturer) Files

func (c *Capturer) Files() []File

Files は集めた送受信を、書き出す形 (File) で返す。

func (*Capturer) Flush

func (c *Capturer) Flush(dir, base string) ([]Written, error)

Flush は集めた証跡を dir (シナリオの証跡フォルダ) に書き出す。 base は Written.Path の基準 (証跡のフォルダ evidence/)。

func (*Capturer) SetCurrentTrails

func (c *Capturer) SetCurrentTrails(trs runn.Trails)

SetCurrentTrails は runn が実行するステップを切り替えるたびに呼ばれる。

type File

type File struct {
	ScenarioID string   `json:"scenarioId"`
	Key        string   `json:"key"`
	Index      int      `json:"index"`
	Runner     string   `json:"runner"`
	RunnerKey  string   `json:"runnerKey,omitempty"`
	StartedAt  string   `json:"startedAt"`
	Request    any      `json:"request,omitempty"`
	Response   any      `json:"response,omitempty"`
	Masked     []string `json:"masked,omitempty"`
}

File は 1 ステップ分の証跡ファイルの中身。

type Mask

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

Mask は証跡に書く前に秘密情報を隠す規則。

func NewMask

func NewMask(headers, paths []string) (*Mask, error)

NewMask は、必ず隠すヘッダに headers を加え、本文の JSON で隠す場所 paths (jq 形式) を解釈する。

func (*Mask) Body

func (m *Mask) Body(v any, masked *[]string) any

Body は JSON の値 v の中の、evidence.mask.paths に当たる値を *** にした写しを返す。 JSON でない値 (文字列の本文など) や、パスが当てはまらない値はそのまま返す。

func (*Mask) HTTPHeaders

func (m *Mask) HTTPHeaders(h http.Header, where string, masked *[]string) map[string][]string

HTTPHeaders は http.Header を Headers で隠す。

func (*Mask) Headers

func (m *Mask) Headers(h map[string][]string, where string, masked *[]string) map[string][]string

Headers はヘッダの写しを返す。隠すヘッダの値は *** にし、隠した名前を masked に加える。

type Mode

type Mode string

Mode は証跡に書く範囲。

const (
	// ModeResponse は応答だけを書く (既定)。
	ModeResponse Mode = "response"
	// ModeFull はリクエストと応答の両方を書く。
	ModeFull Mode = "full"
	// ModeOff は送受信を記録せず、実行中のステップだけを追う (--no-evidence でも diffEps の記録に使う)。
	ModeOff Mode = "off"
)

type Written

type Written struct {
	Key   string
	Index int
	// Path は証跡のフォルダ (evidence/) からの相対パス (/ 区切り)。
	Path string
}

Written は書き出した証跡ファイル 1 つ。

Jump to

Keyboard shortcuts

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