Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeExpression(e hclsyntax.Expression, ectx *hcl.EvalContext) (any, hcl.Diagnostics, error)
- func EvaluateAttr(ctx context.Context, attr *hclsyntax.Attribute, parentctx *SudoContext, ...) hcl.Diagnostics
- func ExtractUserFuncs(ctx context.Context, ibdy hcl.Body, parent *hcl.EvalContext) (map[string]function.Function, hcl.Diagnostics)
- func ExtractVariables(ctx context.Context, bdy *hclsyntax.Body, parentctx *SudoContext) hcl.Diagnostics
- func InstanceLocationStringToHCLRange(instLoc string, msg string, cnt hclsyntax.Expression, ectx *hcl.EvalContext, ...) (hcl.Expression, hcl.Diagnostics)
- func LoadValidationErrors(ctx context.Context, cnt hclsyntax.Expression, ectx *hcl.EvalContext, ...) (hcl.Diagnostics, error)
- func MapdFile(ectx *SudoContext, file string) (map[string]cty.Value, error)
- func NewArrayItemAttribute(index int, expr hclsyntax.Expression) *hclsyntax.Attribute
- func NewContextFromFile(ctx context.Context, fle []byte, name string) (*hcl.File, *SudoContext, *BodyBuilder, hcl.Diagnostics, error)
- func NewContextFromFiles(ctx context.Context, fle map[string][]byte) (*hcl.File, *SudoContext, *BodyBuilder, hcl.Diagnostics, error)
- func NewContextualizedFunctionMap(ectx *SudoContext, file string) map[string]function.Function
- func NewDynamicContextualizedFunctionMap(ectx *SudoContext) map[string]function.Function
- func NewForCollectionAttribute(expr hclsyntax.Expression) *hclsyntax.Attribute
- func NewFuncArgAttribute(index int, expr hclsyntax.Expression) *hclsyntax.Attribute
- func NewFunctionMap() map[string]function.Function
- func NewObjectItemAttribute(key string, nameRange hcl.Range, expr hclsyntax.Expression) *hclsyntax.Attribute
- func NewRefFunctionFromPath(ctx context.Context, start string) function.Function
- func NewUnknownBlockEvaluation(ctx context.Context, parentctx *SudoContext, block *hclsyntax.Block) (diags hcl.Diagnostics)
- func ToYAML(ctx *SudoContext) (yaml.MapSlice, error)
- func UnmarkToSortedArray(me cty.Value) (any, error)
- type AnyBlockEvaluation
- type AttrMeta
- type AugmentedForValueExpr
- type BasicBlockMeta
- type BlockLabelMeta
- type BlockMeta
- type BodyBuilder
- type FileBlockEvaluation
- func NewGenBlockEvaluation(ctx context.Context, sctx *SudoContext, file *BodyBuilder) (res []*FileBlockEvaluation, diags hcl.Diagnostics, err error)
- func ProccessBulk(ctx context.Context, fs afero.Fs, files []string) ([]*FileBlockEvaluation, hcl.Diagnostics, error)
- func Process(ctx context.Context, fs afero.Fs, file string) ([]*FileBlockEvaluation, hcl.Diagnostics, error)
- type GenBlockMeta
- type Meta
- type PreCalcExpr
- type RemappableSudoContextArray
- type SimpleNameMeta
- type Sorter
- type SudoContext
- func (parent *SudoContext) ApplyBody(ctx context.Context, body *hclsyntax.Body) hcl.Diagnostics
- func (me *SudoContext) ApplyKeyVal(key string, val cty.Value, r hcl.Range)
- func (me *SudoContext) ApplyValue(met cty.Value)
- func (me *SudoContext) BlocksOfType(name string) []*SudoContext
- func (wc *SudoContext) BuildStaticEvalContext() *hcl.EvalContext
- func (wc *SudoContext) BuildStaticEvalContextWithFileData(file string) *hcl.EvalContext
- func (me *SudoContext) BuildStaticEvalVars() map[string]cty.Value
- func (me *SudoContext) BuildStaticVarsList() []cty.Value
- func (me *SudoContext) Functions() map[string]function.Function
- func (me *SudoContext) GetAllFileLevelBlocksOfType(name string) []*SudoContext
- func (wc *SudoContext) GetAllTemporaryFileLevelVars() map[string]cty.Value
- func (me *SudoContext) List() []*SudoContext
- func (me *SudoContext) NewChild(key string, rnge hcl.Range) *SudoContext
- func (me *SudoContext) NewNestedChildBlockLabels(key []string, ranges []hcl.Range) *SudoContext
- func (wc *SudoContext) Root() *SudoContext
- func (me *SudoContext) ToValue() cty.Value
- func (me *SudoContext) ToValueWithExtraContext() cty.Value
- func (me *SudoContext) ToYAML() (any, error)
- type ValidationBlock
- type WrappedExpression
Constants ¶
const ArrKey = "____arr"
const FilesKey = "____files"
const FuncKey = "____func"
const MetaKey = "____meta"
Variables ¶
var ChildMarkMergeFunc = function.New(&function.Spec{ Description: `Merges all of the elements from the given maps into a single map, or the attributes from given objects into a single object.`, Params: []function.Parameter{}, VarParam: &function.Parameter{ Name: "maps", Type: cty.DynamicPseudoType, AllowDynamicType: true, AllowNull: true, AllowMarked: true, }, Type: func(args []cty.Value) (cty.Type, error) { if len(args) == 0 { return cty.EmptyObject, nil } attrs := map[string]cty.Type{} first := cty.NilType matching := true attrsKnown := true for i, arg := range args { ty := arg.Type() if ty.Equals(cty.DynamicPseudoType) { return cty.DynamicPseudoType, nil } if !ty.IsMapType() && !ty.IsObjectType() { return cty.NilType, fmt.Errorf("arguments must be maps or objects, got %#v", ty.FriendlyName()) } arg, _ = arg.Unmark() switch { case ty.IsObjectType() && !arg.IsNull(): for attr, aty := range ty.AttributeTypes() { attrs[attr] = aty } case ty.IsMapType(): switch { case arg.IsNull(): case arg.IsKnown(): ety := arg.Type().ElementType() for it := arg.ElementIterator(); it.Next(); { attr, _ := it.Element() attrs[attr.AsString()] = ety } default: attrsKnown = false } } if i == 0 { first = arg.Type() continue } if !ty.Equals(first) && matching { matching = false } } if matching { return first, nil } if !attrsKnown { return cty.DynamicPseudoType, nil } return cty.Object(attrs), nil }, Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { outputMap := make(map[string]cty.Value) var markses []cty.ValueMarks // remember any marked maps/objects we find for _, arg := range args { if arg.IsNull() { continue } arg, argMarks := arg.Unmark() for it := arg.ElementIterator(); it.Next(); { k, v := it.Element() outputMap[k.AsString()] = v.WithMarks(argMarks) } } switch { case retType.IsMapType(): if len(outputMap) == 0 { return cty.MapValEmpty(retType.ElementType()).WithMarks(markses...), nil } return cty.MapVal(outputMap).WithMarks(markses...), nil case retType.IsObjectType(), retType.Equals(cty.DynamicPseudoType): return cty.ObjectVal(outputMap).WithMarks(markses...), nil default: panic(fmt.Sprintf("unexpected return type: %#v", retType)) } }, })
ChildMarkMergeFunc is a copy of the MergeFunc from cty stdlib, but with the ability to merge marked parents into their children. This is necessary for the `merge` function to work as expected and sort values based on location in the source file.
Functions ¶
func EncodeExpression ¶
func EncodeExpression(e hclsyntax.Expression, ectx *hcl.EvalContext) (any, hcl.Diagnostics, error)
func EvaluateAttr ¶
func EvaluateAttr(ctx context.Context, attr *hclsyntax.Attribute, parentctx *SudoContext, extra ...*hcl.EvalContext) hcl.Diagnostics
func ExtractUserFuncs ¶
func ExtractVariables ¶
func ExtractVariables(ctx context.Context, bdy *hclsyntax.Body, parentctx *SudoContext) hcl.Diagnostics
func InstanceLocationStringToHCLRange ¶
func InstanceLocationStringToHCLRange(instLoc string, msg string, cnt hclsyntax.Expression, ectx *hcl.EvalContext, file *BodyBuilder) (hcl.Expression, hcl.Diagnostics)
func LoadValidationErrors ¶
func LoadValidationErrors(ctx context.Context, cnt hclsyntax.Expression, ectx *hcl.EvalContext, errv error, bdy *BodyBuilder) (hcl.Diagnostics, error)
func NewArrayItemAttribute ¶ added in v0.53.0
func NewArrayItemAttribute(index int, expr hclsyntax.Expression) *hclsyntax.Attribute
func NewContextFromFile ¶
func NewContextFromFile(ctx context.Context, fle []byte, name string) (*hcl.File, *SudoContext, *BodyBuilder, hcl.Diagnostics, error)
func NewContextFromFiles ¶
func NewContextFromFiles(ctx context.Context, fle map[string][]byte) (*hcl.File, *SudoContext, *BodyBuilder, hcl.Diagnostics, error)
func NewContextualizedFunctionMap ¶
func NewContextualizedFunctionMap(ectx *SudoContext, file string) map[string]function.Function
func NewDynamicContextualizedFunctionMap ¶
func NewDynamicContextualizedFunctionMap(ectx *SudoContext) map[string]function.Function
func NewForCollectionAttribute ¶ added in v0.53.0
func NewForCollectionAttribute(expr hclsyntax.Expression) *hclsyntax.Attribute
func NewFuncArgAttribute ¶ added in v0.53.0
func NewFuncArgAttribute(index int, expr hclsyntax.Expression) *hclsyntax.Attribute
func NewFunctionMap ¶
return cty.StringVal(mp[str].AsString()), nil }, }) }
func NewObjectItemAttribute ¶ added in v0.53.0
func NewObjectItemAttribute(key string, nameRange hcl.Range, expr hclsyntax.Expression) *hclsyntax.Attribute
func NewRefFunctionFromPath ¶
func NewUnknownBlockEvaluation ¶
func NewUnknownBlockEvaluation(ctx context.Context, parentctx *SudoContext, block *hclsyntax.Block) (diags hcl.Diagnostics)
Types ¶
type AnyBlockEvaluation ¶
type AugmentedForValueExpr ¶ added in v0.53.0
type AugmentedForValueExpr struct { hclsyntax.Expression Sudo *SudoContext ForExpr *hclsyntax.ForExpr Ctx context.Context }
func (*AugmentedForValueExpr) Range ¶ added in v0.53.0
func (me *AugmentedForValueExpr) Range() hcl.Range
Range implements hclsyntax.Expression.
func (*AugmentedForValueExpr) StartRange ¶ added in v0.53.0
func (me *AugmentedForValueExpr) StartRange() hcl.Range
StartRange implements hclsyntax.Expression.
func (*AugmentedForValueExpr) Value ¶ added in v0.53.0
func (me *AugmentedForValueExpr) Value(ectx *hcl.EvalContext) (cty.Value, hcl.Diagnostics)
Value implements hclsyntax.Expression.
func (*AugmentedForValueExpr) Variables ¶ added in v0.53.0
func (me *AugmentedForValueExpr) Variables() []hcl.Traversal
Variables implements hclsyntax.Expression.
type BasicBlockMeta ¶ added in v0.53.0
func (*BasicBlockMeta) Block ¶ added in v0.53.0
func (me *BasicBlockMeta) Block() *hclsyntax.Block
func (*BasicBlockMeta) Range ¶ added in v0.53.0
func (me *BasicBlockMeta) Range() hcl.Range
type BlockLabelMeta ¶ added in v0.53.0
type BlockLabelMeta struct {
HCL hcl.Range
}
func (*BlockLabelMeta) Range ¶ added in v0.53.0
func (me *BlockLabelMeta) Range() hcl.Range
type BodyBuilder ¶
type BodyBuilder struct {
// contains filtered or unexported fields
}
func (*BodyBuilder) GetAllBlocksOfType ¶
func (me *BodyBuilder) GetAllBlocksOfType(name string) []*hclsyntax.Block
func (*BodyBuilder) NewRoot ¶
func (me *BodyBuilder) NewRoot() *hclsyntax.Body
func (*BodyBuilder) NewRootForFile ¶
func (me *BodyBuilder) NewRootForFile(file string) (*hclsyntax.Body, error)
type FileBlockEvaluation ¶
type FileBlockEvaluation struct { Name string Schema string Path string OrderedOutput yaml.MapSlice RawOutput any Source string }
func NewGenBlockEvaluation ¶
func NewGenBlockEvaluation(ctx context.Context, sctx *SudoContext, file *BodyBuilder) (res []*FileBlockEvaluation, diags hcl.Diagnostics, err error)
func ProccessBulk ¶
func (*FileBlockEvaluation) Encode ¶
func (me *FileBlockEvaluation) Encode() ([]byte, error)
func (*FileBlockEvaluation) WriteToFile ¶
func (*FileBlockEvaluation) WriteToReader ¶
type GenBlockMeta ¶ added in v0.53.0
type GenBlockMeta struct { BasicBlockMeta RootRelPath string }
func (*GenBlockMeta) Block ¶ added in v0.53.0
func (me *GenBlockMeta) Block() *hclsyntax.Block
func (*GenBlockMeta) Range ¶ added in v0.53.0
func (me *GenBlockMeta) Range() hcl.Range
type PreCalcExpr ¶ added in v0.53.0
type PreCalcExpr struct { hclsyntax.Expression Val cty.Value }
func (*PreCalcExpr) Range ¶ added in v0.53.0
func (me *PreCalcExpr) Range() hcl.Range
Range implements hclsyntax.Expression.
func (*PreCalcExpr) StartRange ¶ added in v0.53.0
func (me *PreCalcExpr) StartRange() hcl.Range
StartRange implements hclsyntax.Expression.
func (*PreCalcExpr) Value ¶ added in v0.53.0
func (me *PreCalcExpr) Value(ectx *hcl.EvalContext) (cty.Value, hcl.Diagnostics)
Value implements hclsyntax.Expression.
func (*PreCalcExpr) Variables ¶ added in v0.53.0
func (me *PreCalcExpr) Variables() []hcl.Traversal
Variables implements hclsyntax.Expression.
type RemappableSudoContextArray ¶ added in v0.53.0
type RemappableSudoContextArray []*SudoContext
type SimpleNameMeta ¶ added in v0.53.0
type SimpleNameMeta struct {
NameRange hcl.Range
}
func NewSimpleNameMeta ¶ added in v0.53.0
func NewSimpleNameMeta(parent hcl.Range) *SimpleNameMeta
func (*SimpleNameMeta) Range ¶ added in v0.53.0
func (me *SimpleNameMeta) Range() hcl.Range
type SudoContext ¶
type SudoContext struct { ParentKey string Parent *SudoContext Map map[string]*SudoContext Value *cty.Value UserFuncs map[string]function.Function Meta Meta TmpFileLevelVars map[string]cty.Value // contains filtered or unexported fields }
func (*SudoContext) ApplyBody ¶
func (parent *SudoContext) ApplyBody(ctx context.Context, body *hclsyntax.Body) hcl.Diagnostics
func (*SudoContext) ApplyKeyVal ¶
func (me *SudoContext) ApplyKeyVal(key string, val cty.Value, r hcl.Range)
func (*SudoContext) ApplyValue ¶
func (me *SudoContext) ApplyValue(met cty.Value)
func (*SudoContext) BlocksOfType ¶ added in v0.53.0
func (me *SudoContext) BlocksOfType(name string) []*SudoContext
func (*SudoContext) BuildStaticEvalContext ¶
func (wc *SudoContext) BuildStaticEvalContext() *hcl.EvalContext
func (*SudoContext) BuildStaticEvalContextWithFileData ¶
func (wc *SudoContext) BuildStaticEvalContextWithFileData(file string) *hcl.EvalContext
func (*SudoContext) BuildStaticEvalVars ¶
func (me *SudoContext) BuildStaticEvalVars() map[string]cty.Value
func (*SudoContext) BuildStaticVarsList ¶
func (me *SudoContext) BuildStaticVarsList() []cty.Value
func (*SudoContext) GetAllFileLevelBlocksOfType ¶ added in v0.53.0
func (me *SudoContext) GetAllFileLevelBlocksOfType(name string) []*SudoContext
func (*SudoContext) GetAllTemporaryFileLevelVars ¶ added in v0.53.0
func (wc *SudoContext) GetAllTemporaryFileLevelVars() map[string]cty.Value
func (*SudoContext) List ¶ added in v0.53.0
func (me *SudoContext) List() []*SudoContext
func (*SudoContext) NewChild ¶
func (me *SudoContext) NewChild(key string, rnge hcl.Range) *SudoContext
func (*SudoContext) NewNestedChildBlockLabels ¶ added in v0.53.0
func (me *SudoContext) NewNestedChildBlockLabels(key []string, ranges []hcl.Range) *SudoContext
func (*SudoContext) Root ¶
func (wc *SudoContext) Root() *SudoContext
func (*SudoContext) ToValue ¶
func (me *SudoContext) ToValue() cty.Value
func (*SudoContext) ToValueWithExtraContext ¶ added in v0.53.0
func (me *SudoContext) ToValueWithExtraContext() cty.Value
func (*SudoContext) ToYAML ¶ added in v0.53.0
func (me *SudoContext) ToYAML() (any, error)
type ValidationBlock ¶
type WrappedExpression ¶ added in v0.53.0
type WrappedExpression struct { hclsyntax.Node Expr hclsyntax.Expression Sudo *SudoContext }
func (*WrappedExpression) Range ¶ added in v0.53.0
func (me *WrappedExpression) Range() hcl.Range
Range implements hclsyntax.Expression.
func (*WrappedExpression) StartRange ¶ added in v0.53.0
func (me *WrappedExpression) StartRange() hcl.Range
StartRange implements hclsyntax.Expression.
func (*WrappedExpression) Value ¶ added in v0.53.0
func (me *WrappedExpression) Value(ectx *hcl.EvalContext) (cty.Value, hcl.Diagnostics)
Value implements hclsyntax.Expression.
func (*WrappedExpression) Variables ¶ added in v0.53.0
func (me *WrappedExpression) Variables() []hcl.Traversal
Variables implements hclsyntax.Expression.