model

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParsePlaybook

func ParsePlaybook(entryFile string, readFile ReadFile, book *Playbook) error

Types

type Action

type Action struct {
	ID    types.ActionID   `json:"id"`
	Name  string           `json:"name"`
	Uses  types.ActionName `json:"uses"`
	Args  ActionArgs       `json:"args"`
	Force bool             `json:"force"`
}

type ActionArgs

type ActionArgs map[string]any

func (ActionArgs) Parse added in v0.0.14

func (x ActionArgs) Parse(psr ...ArgParser) error

type ActionExitRequest

type ActionExitRequest struct {
	Action ActionResult   `json:"action"`
	Called []ActionResult `json:"called"`

	Alert   Alert         `json:"alert"`
	EnvVars types.EnvVars `json:"env" masq:"secret"`
	Seq     int           `json:"seq"`
}

type ActionExitResponse

type ActionExitResponse struct {
	Exit []Next `json:"exit"`
}

func (*ActionExitResponse) Abort added in v0.0.7

func (x *ActionExitResponse) Abort() bool

func (*ActionExitResponse) Attrs added in v0.0.7

func (x *ActionExitResponse) Attrs() Attributes

type ActionInitRequest added in v0.0.7

type ActionInitRequest struct {
	Seq     int           `json:"seq"`
	Alert   Alert         `json:"alert"`
	EnvVars types.EnvVars `json:"env" masq:"secret"`
}

type ActionInitResponse added in v0.0.7

type ActionInitResponse struct {
	Init []Next `json:"init"`
}

func (*ActionInitResponse) Abort added in v0.0.7

func (x *ActionInitResponse) Abort() bool

func (*ActionInitResponse) Attrs added in v0.0.7

func (x *ActionInitResponse) Attrs() Attributes

type ActionLog

type ActionLog struct {
	Seq  int      `json:"seq"`
	Init []Next   `json:"init,omitempty"`
	Run  []Action `json:"run,omitempty"`
	Exit []Next   `json:"exit,omitempty"`
}

type ActionRecord added in v0.0.15

type ActionRecord struct {
	ID         string            `json:"id"`
	Seq        int               `json:"seq"`
	Uses       string            `json:"uses"`
	Args       []*ArgumentRecord `json:"args"`
	Result     *string           `json:"result,omitempty"`
	Next       []*NextRecord     `json:"next"`
	Error      *string           `json:"error,omitempty"`
	StartedAt  time.Time         `json:"startedAt"`
	FinishedAt time.Time         `json:"finishedAt"`
}

type ActionResult added in v0.0.10

type ActionResult struct {
	Action
	Result any `json:"result,omitempty"`
}

type ActionRunRequest

type ActionRunRequest struct {
	Alert   Alert          `json:"alert"`
	EnvVars types.EnvVars  `json:"env" masq:"secret"`
	Seq     int            `json:"seq"`
	Called  []ActionResult `json:"called"`
}

type ActionRunResponse

type ActionRunResponse struct {
	Runs []Action `json:"run"`
}

type Alert

type Alert struct {
	AlertMetaData
	ID        types.AlertID `json:"id"`
	Schema    types.Schema  `json:"schema"`
	Data      any           `json:"data,omitempty"`
	CreatedAt time.Time     `json:"created_at"`

	// Raw is a JSON string of Data. The field will be redacted by masq because of verbosity.
	Raw string `json:"raw,omitempty" masq:"quiet"`
}

func NewAlert

func NewAlert(meta AlertMetaData, schema types.Schema, data any) Alert

func (Alert) Copy

func (x Alert) Copy() Alert

type AlertMetaData

type AlertMetaData struct {
	Title       string          `json:"title"`
	Description string          `json:"description"`
	Source      string          `json:"source"`
	Namespace   types.Namespace `json:"namespace"`
	Attrs       Attributes      `json:"attrs"`
	Refs        References      `json:"refs"`
}

func (AlertMetaData) Copy added in v0.0.4

func (x AlertMetaData) Copy() AlertMetaData

type AlertPolicyResult

type AlertPolicyResult struct {
	Alerts []AlertMetaData `json:"alert"`
}

type AlertRecord added in v0.0.15

type AlertRecord struct {
	ID          types.AlertID      `json:"id"`
	Schema      string             `json:"schema"`
	Data        string             `json:"data"`
	CreatedAt   time.Time          `json:"createdAt"`
	Title       string             `json:"title"`
	Description string             `json:"description"`
	Source      string             `json:"source"`
	Namespace   *string            `json:"namespace,omitempty"`
	InitAttrs   []*AttributeRecord `json:"initAttrs"`
	LastAttrs   []*AttributeRecord `json:"lastAttrs"`
	Refs        []*ReferenceRecord `json:"refs"`
}

type ArgOption added in v0.0.14

type ArgOption func(*argParserOption)

func ArgOptional added in v0.0.14

func ArgOptional() ArgOption

type ArgParser added in v0.0.14

type ArgParser func(args ActionArgs) error

func ArgDef added in v0.0.14

func ArgDef[T any](key string, dst *T, options ...ArgOption) ArgParser

type ArgumentRecord added in v0.0.15

type ArgumentRecord struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type Attribute added in v0.0.4

type Attribute struct {
	ID     types.AttrID    `json:"id" firestore:"id"`
	Key    types.AttrKey   `json:"key" firestore:"key"`
	Value  types.AttrValue `json:"value" firestore:"value"`
	Type   types.AttrType  `json:"type" firestore:"type"`
	Global bool            `json:"global" firestore:"global"`
	TTL    int             `json:"ttl" firestore:"ttl"`
}

type AttributeRecord added in v0.0.15

type AttributeRecord struct {
	ID     string  `json:"id"`
	Key    string  `json:"key"`
	Value  string  `json:"value"`
	Type   *string `json:"type,omitempty"`
	Global bool    `json:"global"`
	TTL    int     `json:"ttl"`
}

type Attributes added in v0.0.4

type Attributes []Attribute

func (Attributes) Copy added in v0.0.4

func (x Attributes) Copy() Attributes

func (Attributes) Tidy added in v0.0.7

func (x Attributes) Tidy() Attributes

type Clock added in v0.0.15

type Clock func() time.Time

type Context

type Context struct {
	context.Context
	// contains filtered or unexported fields
}

func NewContext

func NewContext(options ...CtxOption) *Context

func (*Context) Alert

func (x *Context) Alert() Alert

func (*Context) DryRun

func (x *Context) DryRun() bool

func (*Context) Logger

func (x *Context) Logger() *slog.Logger

func (*Context) New

func (x *Context) New(options ...CtxOption) *Context

func (*Context) Now added in v0.0.15

func (x *Context) Now() time.Time

func (*Context) OnCLI added in v0.0.17

func (x *Context) OnCLI() bool

func (*Context) Stack

func (x *Context) Stack() int

type CtxOption

type CtxOption func(ctx *Context)

func WithAlert

func WithAlert(alert Alert) CtxOption

func WithBase

func WithBase(base context.Context) CtxOption

func WithCLI added in v0.0.17

func WithCLI() CtxOption

func WithClock added in v0.0.15

func WithClock(clock Clock) CtxOption

func WithDryRunMode

func WithDryRunMode() CtxOption

func WithStackIncrement

func WithStackIncrement() CtxOption

type Event added in v0.0.7

type Event struct {
	Input   any                        `json:"input"`
	Schema  types.Schema               `json:"schema"`
	Actions map[types.ActionName][]any `json:"actions"`
	// contains filtered or unexported fields
}

func (*Event) GetResult added in v0.0.7

func (x *Event) GetResult(actionName types.ActionName) any

func (*Event) Validate added in v0.0.7

func (x *Event) Validate() error

type Next added in v0.0.15

type Next struct {
	Abort bool        `json:"abort"`
	Attrs []Attribute `json:"attrs"`

	// Set by runAction
	Proc Action `json:"-"`
}

type NextRecord added in v0.0.15

type NextRecord struct {
	Abort bool               `json:"abort"`
	Attrs []*AttributeRecord `json:"attrs"`
}

type PlayLog added in v0.0.10

type PlayLog struct {
	Alert Alert `json:"alert"`

	Actions []*ActionLog `json:"actions"`
}

type Playbook

type Playbook struct {
	Scenarios []*Scenario `json:"scenarios"`
}

func (*Playbook) Validate

func (x *Playbook) Validate() error

type PubSubMessage

type PubSubMessage struct {
	Attributes  map[string]string `json:"attributes"`
	Data        []byte            `json:"data"`
	MessageID   string            `json:"message_id"`
	PublishTime string            `json:"publish_time"`
}

type PubSubRequest

type PubSubRequest struct {
	DeliveryAttempt int64         `json:"deliveryAttempt"`
	Message         PubSubMessage `json:"message"`
	Subscription    string        `json:"subscription"`
}

type ReadFile

type ReadFile func(name string) ([]byte, error)

type Reference added in v0.0.14

type Reference struct {
	Title string `json:"title"`
	URL   string `json:"url"`
}

func (Reference) Copy added in v0.0.14

func (r Reference) Copy() Reference

type ReferenceRecord added in v0.0.15

type ReferenceRecord struct {
	Title *string `json:"title,omitempty"`
	URL   *string `json:"url,omitempty"`
}

type References added in v0.0.14

type References []Reference

func (References) Copy added in v0.0.14

func (refs References) Copy() References

type Scenario

type Scenario struct {
	ID     types.ScenarioID    `json:"id"`
	Title  types.ScenarioTitle `json:"title"`
	Events []Event             `json:"events"`
	Env    types.EnvVars       `json:"env"`
}

func ParseScenario added in v0.0.17

func ParseScenario(entryFile string, readFile ReadFile) (*Scenario, error)

func (*Scenario) ToLog

func (x *Scenario) ToLog() ScenarioLog

func (*Scenario) Validate

func (x *Scenario) Validate() error

type ScenarioLog

type ScenarioLog struct {
	ID    types.ScenarioID    `json:"id"`
	Title types.ScenarioTitle `json:"title"`

	Results []*PlayLog `json:"results,omitempty"`
	Error   string     `json:"error,omitempty"`
}

type WorkflowRecord added in v0.0.15

type WorkflowRecord struct {
	ID        types.WorkflowID `json:"id"`
	CreatedAt time.Time        `json:"createdAt"`
	Alert     *AlertRecord     `json:"alert"`
	Actions   []*ActionRecord  `json:"actions"`
}

Jump to

Keyboard shortcuts

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