Documentation ¶
Index ¶
- Variables
- func BuildStdLibFunctions(baseDir string) map[string]function.Function
- func DecodeExpressionFromReflection(exp hcl.Expression, field StructField, eval *hcl.EvalContext) hcl.Diagnostics
- func DecodeExpressions(src interface{}, dest interface{}, eval *hcl.EvalContext) error
- func DeepMergeFunc() function.Function
- func DiagToErrWrap(diag hcl.Diagnostics) (err error)
- func FileFromPath(filename string) (*hcl.File, hcl.Diagnostics)
- func FileFromString(rawHCL string) (*hcl.File, hcl.Diagnostics)
- func HashFile(file *hclwrite.File, hasher hash.Hash) (hash.Hash, error)
- func IsolateBlocks(sourceBytes []byte, matcher BlockMatcher, fileName string) (*hclwrite.File, error)
- func MapStringInterfaceToCty(v map[string]interface{}) (variables map[string]cty.Value)
- func MapStringStringToCtyObject(v map[string]string) cty.Value
- func MergeMapStringCtyValue(maps ...map[string]cty.Value) map[string]cty.Value
- func PathRelTo(baseDir string) function.Function
- func StringSliceToCtyTuple(v []string) cty.Value
- func StructFields(v interface{}) (map[string]StructField, error)
- func TraversalToKeys(traversal hcl.Traversal) []string
- func TraversalToString(traversal hcl.Traversal) string
- type BlockMatcher
- type FormatOpts
- type Isolator
- type SortedAttrs
- type StructField
Constants ¶
This section is empty.
Variables ¶
var Glob = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "pattern", Type: cty.String, }, }, Type: function.StaticReturnType(cty.List(cty.String)), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { pattern := args[0].AsString() var paths []cty.Value glob, err := filepath.Glob(pattern) if err != nil { return cty.NilVal, fmt.Errorf("failed to build file list from pattern: %s", err) } for _, i := range glob { paths = append(paths, cty.StringVal(i)) } return cty.ListVal(paths), nil }, })
Functions ¶
func BuildStdLibFunctions ¶
BuildStdLibFunctions returns a combined map of stdlib functions and feeds scope into filesystem functions
func DecodeExpressionFromReflection ¶
func DecodeExpressionFromReflection(exp hcl.Expression, field StructField, eval *hcl.EvalContext) hcl.Diagnostics
DecodeExpressionFromReflection takes a reflected value and decodes an hcl expression into it with an eval context.
func DecodeExpressions ¶
func DecodeExpressions(src interface{}, dest interface{}, eval *hcl.EvalContext) error
DecodeExpressions takes a set of struct pointers (src, dest) extracts src and dest struct fields by tag of HCL checks each hcl field for type of hcl.Expression and decodes the value of that expression into the matching dest struct field.
func DeepMergeFunc ¶
DeepMergeFunc works the same as the regular merge() but is able to do deeply nested data structures
func DiagToErrWrap ¶
func DiagToErrWrap(diag hcl.Diagnostics) (err error)
DiagToErrWrap combines all diag errors into a single error value If diag.HasErrors() returns false this function returns a nil error
func FileFromPath ¶
func FileFromPath(filename string) (*hcl.File, hcl.Diagnostics)
FileFromPath reads data from a file, parses it as HCL and returns a pointer to an HCLFile struct
func FileFromString ¶
func FileFromString(rawHCL string) (*hcl.File, hcl.Diagnostics)
FileFromString uses a new parser and attempts to load HCL from a string we generate a hash of the string and use it as the filename as the ParseHCL function requires a filename to avoid parsing the same file
func HashFile ¶
HashFile a convenience method for writing bytes to a hasher. if a hasher isn't provided it defaults to sha256
func IsolateBlocks ¶
func IsolateBlocks(sourceBytes []byte, matcher BlockMatcher, fileName string) (*hclwrite.File, error)
IsolateBlocks takes source HCL bytes and a blockMatcher to isolate matching blocks to a single file (useful for hashing)
func MapStringInterfaceToCty ¶
MapStringInterfaceToCty attempts to case a map[string]interface{} to a map[string]cty.Value This will panic if it cannot convert a specified interface
func MapStringStringToCtyObject ¶
MapStringStringToCtyObject returns a cty.Object from map[string]string
func MergeMapStringCtyValue ¶
MergeMapStringCtyValue merges n number of map[string]string
func PathRelTo ¶
PathRelTo constructs a function that takes a dir path, cleans, mkdirs, and returns it
func StringSliceToCtyTuple ¶
StringSliceToCtyTuple returns a slice of strings as a slice of cty.Value
func StructFields ¶
func StructFields(v interface{}) (map[string]StructField, error)
StructFields extracts all HCL tagged struct fields and returns a map of reflections by name If a tagged field does not have a name (hcl:",label") it is excluded
func TraversalToKeys ¶
func TraversalToKeys(traversal hcl.Traversal) []string
TraversalToKeys translates an hcl.Traversal to a slice of string keys.
func TraversalToString ¶
func TraversalToString(traversal hcl.Traversal) string
TraversalToString the same as TraversalToKeys but returns a string representation
Types ¶
type BlockMatcher ¶
BlockMatcher an interface that accepts an HCL file and queries it for matching blocks
type FormatOpts ¶
FormatOpts aggregates all of the flags that are available for working with the HCL formatter
type SortedAttrs ¶
type SortedAttrs []*hcl.Attribute
SortedAttrs is a slice of HCL attributes that implements sort.Interface
func SortAttributes ¶
func SortAttributes(attributes hcl.Attributes) SortedAttrs
SortAttributes returns a sorted slice of attributes so variable decoding happens in the correct order
func (SortedAttrs) Less ¶
func (s SortedAttrs) Less(i, j int) bool
Less returns a boolean for which item is less than a comparison item
func (SortedAttrs) Swap ¶
func (s SortedAttrs) Swap(i, j int)
Swap exchanges the values between two indexes
type StructField ¶
type StructField struct { Value reflect.Value Field reflect.StructField Tag reflect.StructTag TagString string TagValues []string }
StructField a reflected struct field, and it's parsed tags.