Documentation ¶
Index ¶
- Constants
- Variables
- func CheckForAnyIncompletedBlock(ectx []*SudoContext) error
- 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 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 LoadGlobalEnvVars(fs afero.Fs, opts *LoadGlobalEnvVarOpts) (map[string]string, error)
- func LoadValidationErrors(ctx context.Context, cnt hclsyntax.Expression, ectx *hcl.EvalContext, ...) (hcl.Diagnostics, 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, env map[string]string) (*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 NewGenBlockEvaluation(ctx context.Context, sctx *SudoContext, file *BodyBuilder) (res map[string]*FileBlockEvaluation, diags hcl.Diagnostics, err error)
- func NewObjectItemAttribute(key string, nameRange hcl.Range, expr hclsyntax.Expression) *hclsyntax.Attribute
- func NewRefFunctionFromPath(ctx context.Context, start string) function.Function
- func NewSorterList(val cty.Value) (*Sorter, []*Sorter)
- func NewUnknownBlockEvaluation(ctx context.Context, parentctx *SudoContext, block *hclsyntax.Block) (diags hcl.Diagnostics)
- func ProccessBulk(ctx context.Context, fs afero.Fs, files []string) (map[string]*FileBlockEvaluation, hcl.Diagnostics, error)
- func Process(ctx context.Context, fs afero.Fs, file string) (map[string]*FileBlockEvaluation, hcl.Diagnostics, error)
- func UnmarkToSortedArray(me cty.Value, enhance SortEnhancer) (any, error)
- type AnyBlockEvaluation
- type AttrMeta
- type AugmentedForValueExpr
- type BasicBlockMeta
- type BlockLabelMeta
- type BlockMeta
- type BodyBuilder
- type ContextFunc
- type FileBlockEvaluation
- type GenBlockMeta
- type IncomleteBlockMeta
- type LoadGlobalEnvVarOpts
- type Meta
- type PreCalcExpr
- type RemappableSudoContextArray
- type SimpleNameMeta
- type SortEnhancer
- 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) hcl.Diagnostics
- func (me *SudoContext) ApplyValue(met cty.Value)
- func (me *SudoContext) BlocksOfType(name string) ([]*SudoContext, error)
- 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, error)
- func (wc *SudoContext) GetAllTemporaryFileLevelVars() map[string]cty.Value
- func (wc *SudoContext) GetAllUserFuncs() map[string]function.Function
- func (me *SudoContext) IdentifyChild(strs ...string) *SudoContext
- func (me *SudoContext) List() []*SudoContext
- func (me *SudoContext) Match(keys []string, val cty.Value) (bool, hcl.Diagnostics)
- func (me *SudoContext) NewBlockChild(typ *hclsyntax.Block) (*SudoContext, error)
- func (me *SudoContext) NewBlockLabelChild(label string, rnge hcl.Range) (*SudoContext, error)
- func (me *SudoContext) NewChild(key string, rnge hcl.Range) *SudoContext
- func (me *SudoContext) NewNonBlockChild(key string, rnge hcl.Range) (*SudoContext, error)
- func (wc *SudoContext) ParentBlockMeta() BlockMeta
- func (wc *SudoContext) Root() *SudoContext
- func (me *SudoContext) ToValue() cty.Value
- func (me *SudoContext) ToValueWithExtraContext() cty.Value
- func (me *SudoContext) ToYAML() (yaml.MapSlice, error)
- type ValidationBlock
- type WrappedExpression
Constants ¶
const ArrKey = "____arr"
const FilesKey = "____files"
const FuncKey = "____func"
const MetaKey = "____meta"
const UserFuncBlockType = "func"
Variables ¶
var AdapedConcatFuncSpec = &function.Spec{ Description: `Concatenates together all of the given lists or tuples into a single sequence, preserving the input order.`, Params: []function.Parameter{}, VarParam: &function.Parameter{ Name: "seqs", Type: cty.DynamicPseudoType, AllowMarked: true, }, Type: func(args []cty.Value) (ret cty.Type, err error) { if len(args) == 0 { return cty.NilType, fmt.Errorf("at least one argument is required") } etys := make([]cty.Type, 0, len(args)) for i, val := range args { val, _ := val.UnmarkDeep() ety := val.Type() switch { case ety.IsTupleType(): etys = append(etys, ety.TupleElementTypes()...) default: return cty.NilType, function.NewArgErrorf( i, "all arguments must be lists or tuples; got %s", ety.FriendlyName(), ) } } return cty.Tuple(etys), nil }, Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { switch { case retType.IsTupleType(): vals := make([]cty.Value, 0, len(args)) for _, seq := range args { id := xid.New().String() seq, seqMarks := seq.Unmark() it := seq.ElementIterator() for it.Next() { _, v := it.Element() v, umrk := v.Unmark() vals = append(vals, v.WithMarks(seqMarks).Mark(&mergeMarker{umrk, id})) } } return cty.TupleVal(vals), nil default: panic("unsupported return type") } }, }
AdapedConcatFuncSpec is a copy of the ConcatFunc spec from cty stdlib, but with the ability to merge marked parents into their children. This is necessary for the `concat` function to work as expected and sort values based on location in the source file.
var AdaptedMergeFuncSpec = &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 } 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) for _, arg := range args { xid := xid.New().String() if arg.IsNull() { continue } arg, argMarks := arg.Unmark() for it := arg.ElementIterator(); it.Next(); { k, v := it.Element() v, umrk := v.Unmark() outputMap[k.AsString()] = v.WithMarks(argMarks).Mark(&mergeMarker{umrk, xid}) } } switch { case retType.IsObjectType(), retType.Equals(cty.DynamicPseudoType): return cty.ObjectVal(outputMap), nil default: panic(fmt.Sprintf("unexpected return type: %#v", retType)) } }, }
AdaptedMergeFuncSpec is a copy of the MergeFunc spec 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.
var CombinedMergeConcatFunc = function.New(&function.Spec{ Description: `Merges all of the elements from the given maps or arrays into a single map or array`, Params: []function.Parameter{}, VarParam: &function.Parameter{ Name: "items", Type: cty.DynamicPseudoType, AllowDynamicType: true, AllowNull: false, AllowMarked: true, }, Type: func(args []cty.Value) (cty.Type, error) { if len(args) == 0 { return cty.NilType, errors.New("at least one argument is required") } first := args[0].Type() if first.IsListType() || first.IsTupleType() { return AdapedConcatFuncSpec.Type(args) } return AdaptedMergeFuncSpec.Type(args) }, Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { if retType.IsListType() || retType.IsTupleType() { return AdapedConcatFuncSpec.Impl(args, retType) } return AdaptedMergeFuncSpec.Impl(args, retType) }, })
CombinedAdaptedMergeConcatFunc is a dynamic function that can merge maps or arrays it looks at the first argument to determine if it should merge maps or arrays and then delegates to the appropriate function. The AdaptedMergeFuncSpec and AdapedConcatFuncSpec are copies of the MergeFunc and ConcatFunc specs from cty stdlib, but with the ability to merge marked parents into their children.
Functions ¶
func CheckForAnyIncompletedBlock ¶ added in v0.54.0
func CheckForAnyIncompletedBlock(ectx []*SudoContext) error
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 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, sudo *SudoContext, file *BodyBuilder) (hcl.Expression, hcl.Diagnostics)
func LoadGlobalEnvVars ¶ added in v0.71.0
func LoadValidationErrors ¶
func LoadValidationErrors(ctx context.Context, cnt hclsyntax.Expression, ectx *hcl.EvalContext, errv error, bdy *BodyBuilder, sudo *SudoContext) (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, env map[string]string) (*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 ¶
func NewGenBlockEvaluation ¶
func NewGenBlockEvaluation(ctx context.Context, sctx *SudoContext, file *BodyBuilder) (res map[string]*FileBlockEvaluation, diags hcl.Diagnostics, err error)
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)
func ProccessBulk ¶
func UnmarkToSortedArray ¶ added in v0.53.0
func UnmarkToSortedArray(me cty.Value, enhance SortEnhancer) (any, error)
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 ContextFunc ¶ added in v0.81.0
type ContextFunc func() *hcl.EvalContext
type FileBlockEvaluation ¶
type FileBlockEvaluation struct { Name string Schema string Path string OrderedOutput yaml.MapSlice RawOutput any Source string }
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 IncomleteBlockMeta ¶ added in v0.54.0
func (*IncomleteBlockMeta) Block ¶ added in v0.54.0
func (me *IncomleteBlockMeta) Block() *hclsyntax.Block
func (*IncomleteBlockMeta) Range ¶ added in v0.54.0
func (me *IncomleteBlockMeta) Range() hcl.Range
type LoadGlobalEnvVarOpts ¶ added in v0.71.0
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 SortEnhancer ¶ added in v0.60.0
type Sorter ¶ added in v0.53.0
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 CheckForCompletedBlock ¶ added in v0.54.0
func CheckForCompletedBlock(ectx *SudoContext, file string) (*SudoContext, error)
func FilterSudoContextWithRegex ¶ added in v0.67.0
func FilterSudoContextWithRegex(sctx []*SudoContext, keys []string, reg cty.Value) ([]*SudoContext, error)
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) hcl.Diagnostics
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, error)
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, error)
func (*SudoContext) GetAllTemporaryFileLevelVars ¶ added in v0.53.0
func (wc *SudoContext) GetAllTemporaryFileLevelVars() map[string]cty.Value
func (*SudoContext) GetAllUserFuncs ¶ added in v0.62.0
func (wc *SudoContext) GetAllUserFuncs() map[string]function.Function
func (*SudoContext) IdentifyChild ¶ added in v0.54.0
func (me *SudoContext) IdentifyChild(strs ...string) *SudoContext
func (*SudoContext) List ¶ added in v0.53.0
func (me *SudoContext) List() []*SudoContext
func (*SudoContext) Match ¶ added in v0.67.0
func (me *SudoContext) Match(keys []string, val cty.Value) (bool, hcl.Diagnostics)
func (*SudoContext) NewBlockChild ¶ added in v0.55.0
func (me *SudoContext) NewBlockChild(typ *hclsyntax.Block) (*SudoContext, error)
func (*SudoContext) NewBlockLabelChild ¶ added in v0.55.0
func (me *SudoContext) NewBlockLabelChild(label string, rnge hcl.Range) (*SudoContext, error)
func (*SudoContext) NewChild ¶
func (me *SudoContext) NewChild(key string, rnge hcl.Range) *SudoContext
func (*SudoContext) NewNonBlockChild ¶ added in v0.55.0
func (me *SudoContext) NewNonBlockChild(key string, rnge hcl.Range) (*SudoContext, error)
func (*SudoContext) ParentBlockMeta ¶ added in v0.60.0
func (wc *SudoContext) ParentBlockMeta() BlockMeta
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
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.