Documentation ¶
Overview ¶
Package schema defines the schema, parsing, validation and evaluation logic for .hops files and automations
Index ¶
- Constants
- Variables
- func BlockErrsToDiagnostics(ast hclReader, errs validator.ValidationErrors) hcl.Diagnostics
- func CreateSourceEvent(rawEvent map[string]any, source string, event string, action string) ([]byte, string, error)deprecated
- func EvaluateBoolExpression(expr hcl.Expression, unsetVal bool, evalCtx *hcl.EvalContext) (bool, hcl.Diagnostics)
- func EvaluateGenericExpression[T any](expr hcl.Expression, evalCtx *hcl.EvalContext) (T, bool, hcl.Diagnostics)
- func EvaluateInputsExpression(expr hcl.Expression, evalCtx *hcl.EvalContext) ([]byte, hcl.Diagnostics)
- func HCLTagName(fl reflect.StructField) string
- func ValidateCron(fl validator.FieldLevel) bool
- func ValidateDir(automationDir string, pretty bool) error
- func ValidateLabel(fl validator.FieldLevel) bool
- func ValidateTaskInput(t *TaskAST, input map[string]any) map[string][]string
- type AutomationFile
- type Automations
- func (a *Automations) EventCalls(callASTs []*CallAST, evalCtx *hcl.EvalContext) ([]*Call, hcl.Diagnostics)
- func (a *Automations) EventDefaultDone(calls []*Call, responseVars map[string]cty.Value) *Done
- func (a *Automations) EventDone(doneASTs []*DoneAST, evalCtx *hcl.EvalContext) (*Done, hcl.Diagnostics)
- func (a *Automations) EventOns(eventBundle map[string][]byte) ([]*On, hcl.Diagnostics)
- func (a *Automations) GetSchedules() []*ScheduleAST
- func (a *Automations) GetTask(label string) (*TaskAST, error)
- func (a *Automations) GetTasks() []*TaskAST
- func (a *Automations) GetTasksInPath(path string) []*TaskAST
- type Call
- type CallAST
- type DiagnosticResult
- type Done
- type DoneAST
- type EvaluationCtx
- type FileType
- type Hops
- type HopsAST
- func (h *HopsAST) DecodeCallAST(call *CallAST, slugPrefix string, idx int) hcl.Diagnostics
- func (h *HopsAST) DecodeHopsAST() hcl.Diagnostics
- func (h *HopsAST) DecodeOnAST(on *OnAST, idx int) hcl.Diagnostics
- func (h *HopsAST) DecodeParamAST(param *ParamAST, namePrefix string) hcl.Diagnostics
- func (h *HopsAST) DecodeScheduleAST(schedule *ScheduleAST) hcl.Diagnostics
- func (h *HopsAST) DecodeTaskAST(task *TaskAST) hcl.Diagnostics
- type HopsValidator
- type Manifest
- type ManifestStep
- type On
- type OnAST
- type ParamAST
- type ScheduleAST
- type SourceMeta
- type TaskAST
- type ValidationResult
Constants ¶
const ( BlockIDOn = "on" BlockIDCall = "call" BlockIDDone = "done" BlockIDTask = "task" BlockIDParam = "param" BlockIDSchedule = "schedule" )
const ( TagValidateCron = "standard_cron" TagValidateLabel = "block_label" ValidateLabelMaxLen = 50 InvalidRequired string = "Required" InvalidNotString string = "Should be a string" InvalidNotText string = "Should be text" InvalidNotNumber string = "Should be a number" InvalidNotBool string = "Should be a boolean" )
const HopsMetaKey = "hops"
Variables ¶
var (
SchemaCall, _ = gohcl.ImpliedBodySchema(CallAST{})
SchemaDone, _ = gohcl.ImpliedBodySchema(DoneAST{})
SchemaHops, _ = gohcl.ImpliedBodySchema(HopsAST{})
SchemaOn, _ = gohcl.ImpliedBodySchema(OnAST{})
SchemaParam, _ = gohcl.ImpliedBodySchema(ParamAST{})
SchemaSchedule, _ = gohcl.ImpliedBodySchema(ScheduleAST{})
SchemaTask, _ = gohcl.ImpliedBodySchema(TaskAST{})
)
var ManifestNames = []string{"manifest.yaml", "manifest.yml"}
Functions ¶
func BlockErrsToDiagnostics ¶ added in v0.17.0
func BlockErrsToDiagnostics(ast hclReader, errs validator.ValidationErrors) hcl.Diagnostics
BlockErrsToDiagnostics converts validation errors into hcl.Diagnostics
Note that this _only_ works for hcl attributes and labels, not block fields. Labels must have a name starting with `label` e.g. `hcl:"label,label" or hcl:"label_1,label"`
func EvaluateBoolExpression ¶ added in v0.17.0
func EvaluateGenericExpression ¶ added in v0.17.0
func EvaluateInputsExpression ¶ added in v0.17.0
func EvaluateInputsExpression(expr hcl.Expression, evalCtx *hcl.EvalContext) ([]byte, hcl.Diagnostics)
func HCLTagName ¶ added in v0.17.0
func HCLTagName(fl reflect.StructField) string
func ValidateCron ¶ added in v0.17.0
func ValidateCron(fl validator.FieldLevel) bool
func ValidateDir ¶ added in v0.17.0
ValidateDir validates a given automation dir and prints the result to the console
This is intended for end users to validate their automations are syntactically correct
func ValidateLabel ¶ added in v0.17.0
func ValidateLabel(fl validator.FieldLevel) bool
func ValidateTaskInput ¶ added in v0.17.0
ValidateTaskInput validates a struct of param inputs against a task
Returns a map of parameter names with an array of validation error messages if any. Map will be empty (but not nil) if all input is valid.
Types ¶
type AutomationFile ¶ added in v0.17.0
type Automations ¶ added in v0.17.0
type Automations struct { Files map[string][]byte Hash string Hops *HopsAST Manifests map[string]*Manifest }
func NewAutomations ¶ added in v0.17.0
func NewAutomations(files []*AutomationFile) (*Automations, hcl.Diagnostics)
func NewAutomationsFromContent ¶ added in v0.17.0
func NewAutomationsFromContent(contents map[string][]byte) (*Automations, hcl.Diagnostics)
func NewAutomationsFromDir ¶ added in v0.17.0
func NewAutomationsFromDir(dirPath string) (*Automations, hcl.Diagnostics, error)
func (*Automations) EventCalls ¶ added in v0.17.0
func (a *Automations) EventCalls(callASTs []*CallAST, evalCtx *hcl.EvalContext) ([]*Call, hcl.Diagnostics)
EventCalls evaluates the calls for an on block against a populated event bundle returning all calls that have their conditions for dispatch met.
func (*Automations) EventDefaultDone ¶ added in v0.17.0
EventDefaultDone checks if an on block is done by default, regardless of explicit done blocks.
An on block becomes done if all dispatchable calls already have results
func (*Automations) EventDone ¶ added in v0.17.0
func (a *Automations) EventDone(doneASTs []*DoneAST, evalCtx *hcl.EvalContext) (*Done, hcl.Diagnostics)
EventDone returns the first done block that is either errored or completed, or nil
func (*Automations) EventOns ¶ added in v0.17.0
func (a *Automations) EventOns(eventBundle map[string][]byte) ([]*On, hcl.Diagnostics)
func (*Automations) GetSchedules ¶ added in v0.17.0
func (a *Automations) GetSchedules() []*ScheduleAST
func (*Automations) GetTask ¶ added in v0.17.0
func (a *Automations) GetTask(label string) (*TaskAST, error)
func (*Automations) GetTasks ¶ added in v0.17.0
func (a *Automations) GetTasks() []*TaskAST
func (*Automations) GetTasksInPath ¶ added in v0.17.0
func (a *Automations) GetTasksInPath(path string) []*TaskAST
type CallAST ¶
type CallAST struct { Label string `json:"label" hcl:"label,label" validate:"block_label"` IfExpr hcl.Expression `json:"-" hcl:"if,optional"` InputsExpr hcl.Expression `json:"-" hcl:"inputs,optional"` Name string `json:"name,omitempty" hcl:"name,optional"` Slug string `json:"-"` // contains filtered or unexported fields }
type DiagnosticResult ¶ added in v0.17.0
type DiagnosticResult struct { Severity hcl.DiagnosticSeverity `json:"Severity"` Summary string `json:"Summary"` Detail string `json:"Detail,omitempty"` Subject *hcl.Range `json:"Subject,omitempty"` Context *hcl.Range `json:"Context,omitempty"` Expression hcl.Expression `json:"-"` EvalContext *hcl.EvalContext `json:"-"` Extra interface{} `json:"Extra,omitempty"` }
DiagnosticResult mirrors hcl.Diagnostic + json tags to control marshalling We keep uppercase field names as this matches the runtime logged diagnostics
type EvaluationCtx ¶ added in v0.17.0
type EvaluationCtx struct {
// contains filtered or unexported fields
}
func NewEvaluationCtx ¶ added in v0.17.0
func NewEvaluationCtx(automations *Automations, variables map[string]cty.Value) *EvaluationCtx
func (*EvaluationCtx) BlockScopedEvalContext ¶ added in v0.17.0
func (e *EvaluationCtx) BlockScopedEvalContext(block *hcl.Block, slug string) *hcl.EvalContext
func (*EvaluationCtx) EvalContext ¶ added in v0.17.0
func (e *EvaluationCtx) EvalContext() *hcl.EvalContext
type HopsAST ¶ added in v0.17.0
type HopsAST struct { Ons []*OnAST `json:"ons,omitempty" hcl:"on,block"` Schedules []*ScheduleAST `json:"schedules,omitempty" hcl:"schedule,block"` Tasks []*TaskAST `json:"tasks,omitempty" hcl:"task,block"` Body hcl.Body `json:"-" hcl:",body"` // contains filtered or unexported fields }
func DecodeToHopsAST ¶ added in v0.17.0
func DecodeToHopsAST(body hcl.Body, evaluationCtx *EvaluationCtx) (*HopsAST, hcl.Diagnostics)
DecodeToHopsAST takes a parsed hcl.File and partially decodes it into an AST
Any diagnostic errors will be gathered and returned rather than causing early exit. This means the returned HopsAST may be partially populated. This function will not evaluate runtime expressions (e.g. 'if' statements).
func (*HopsAST) DecodeCallAST ¶ added in v0.17.0
func (*HopsAST) DecodeHopsAST ¶ added in v0.17.0
func (h *HopsAST) DecodeHopsAST() hcl.Diagnostics
func (*HopsAST) DecodeOnAST ¶ added in v0.17.0
func (*HopsAST) DecodeParamAST ¶ added in v0.17.0
func (*HopsAST) DecodeScheduleAST ¶ added in v0.17.0
func (h *HopsAST) DecodeScheduleAST(schedule *ScheduleAST) hcl.Diagnostics
func (*HopsAST) DecodeTaskAST ¶ added in v0.17.0
type HopsValidator ¶ added in v0.17.0
type HopsValidator struct {
// contains filtered or unexported fields
}
func NewHopsValidator ¶ added in v0.17.0
func NewHopsValidator() *HopsValidator
func (*HopsValidator) BlockStruct ¶ added in v0.17.0
func (h *HopsValidator) BlockStruct(ast hclReader) hcl.Diagnostics
func (*HopsValidator) SlugRegister ¶ added in v0.17.0
func (h *HopsValidator) SlugRegister(slugRegister []slugRange) hcl.Diagnostics
type Manifest ¶ added in v0.17.0
type Manifest struct { Description string `json:"description" validate:"omitempty,gte=1"` Emoji string `json:"emoji"` Name string `json:"name" validate:"required,gte=1"` RequiredApps []string `json:"required_apps"` Steps []ManifestStep `json:"steps"` Tags []string `json:"tags"` Version string `json:"version" validate:"required,gte=1"` }
func NewManifest ¶ added in v0.17.0
type ManifestStep ¶ added in v0.17.0
type OnAST ¶
type OnAST struct { Calls []*CallAST `json:"calls,omitempty" hcl:"call,block"` Done []*DoneAST `json:"done,omitempty" hcl:"done,block"` Label string `json:"label" hcl:"label,label" validate:"block_label"` IfExpr hcl.Expression `json:"-" hcl:"if,optional"` Name string `json:"name,omitempty" hcl:"name,optional"` Slug string `json:"-"` // contains filtered or unexported fields }
type ParamAST ¶
type ParamAST struct { Default any `json:"default,omitempty"` DefaultExpr hcl.Expression `json:"-" hcl:"default,optional"` DisplayName string `json:"display_name,omitempty" hcl:"display_name,optional"` Flag string `json:"flag,omitempty" hcl:"flag,optional"` Help string `json:"help,omitempty" hcl:"help,optional"` Name string `json:"name" hcl:"label,label" validate:"block_label"` Required bool `json:"required" hcl:"required,optional"` ShortFlag string `json:"shortflag,omitempty" hcl:"shortflag,optional"` Type string `json:"type" hcl:"type,optional" validate:"omitempty,oneof=string text number bool"` // contains filtered or unexported fields }
type ScheduleAST ¶ added in v0.7.0
type ScheduleAST struct { Cron string `json:"cron" hcl:"cron,attr" validate:"standard_cron"` Inputs []byte `json:"inputs,omitempty"` InputsExpr hcl.Expression `json:"-" hcl:"inputs,optional"` Name string `json:"name" hcl:"label,label" validate:"block_label"` // contains filtered or unexported fields }
type SourceMeta ¶
type TaskAST ¶
type TaskAST struct { Description string `json:"description,omitempty" hcl:"description,optional"` DisplayName string `json:"display_name,omitempty" hcl:"display_name,optional"` Emoji string `json:"emoji,omitempty" hcl:"emoji,optional"` Name string `json:"name" hcl:"label,label" validate:"block_label"` Params []*ParamAST `json:"params,omitempty" hcl:"param,block"` Summary string `json:"summary,omitempty" hcl:"summary,optional"` FilePath string `json:"filepath"` // contains filtered or unexported fields }