Documentation ¶
Index ¶
- Variables
- func Basename(path cty.Value) (cty.Value, error)
- func Dirname(path cty.Value) (cty.Value, error)
- func File(baseDir string, path cty.Value) (cty.Value, error)
- func FileBase64(baseDir string, path cty.Value) (cty.Value, error)
- func FileExists(baseDir string, path cty.Value) (cty.Value, error)
- func FileSet(baseDir string, path, pattern cty.Value) (cty.Value, error)
- func Functions(basedir string, allowFS bool) map[string]function.Function
- func MakeFileExistsFunc(baseDir string) function.Function
- func MakeFileFunc(baseDir string, encBase64 bool) function.Function
- func MakeFileSetFunc(baseDir string) function.Function
- func MakeTemplateFileFunc(baseDir string, funcsCb func() map[string]function.Function) function.Function
- func Pathexpand(path cty.Value) (cty.Value, error)
Constants ¶
This section is empty.
Variables ¶
var AbsPathFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "path", Type: cty.String, }, }, Type: function.StaticReturnType(cty.String), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { absPath, err := filepath.Abs(args[0].AsString()) return cty.StringVal(filepath.ToSlash(absPath)), err }, })
AbsPathFunc constructs a function that converts a filesystem path to an absolute path
var BasenameFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "path", Type: cty.String, }, }, Type: function.StaticReturnType(cty.String), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { return cty.StringVal(filepath.Base(args[0].AsString())), nil }, })
BasenameFunc constructs a function that takes a string containing a filesystem path and removes all except the last portion from it.
var DirnameFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "path", Type: cty.String, }, }, Type: function.StaticReturnType(cty.String), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { return cty.StringVal(filepath.Dir(args[0].AsString())), nil }, })
DirnameFunc constructs a function that takes a string containing a filesystem path and removes the last portion from it.
var PathExpandFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "path", Type: cty.String, }, }, Type: function.StaticReturnType(cty.String), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { homePath, err := homedir.Expand(args[0].AsString()) return cty.StringVal(homePath), err }, })
PathExpandFunc constructs a function that expands a leading ~ character to the current user's home directory.
Functions ¶
func Basename ¶
Basename takes a string containing a filesystem path and removes all except the last portion from it.
The underlying function implementation works only with the path string and does not access the filesystem itself. It is therefore unable to take into account filesystem features such as symlinks.
If the path is empty then the result is ".", representing the current working directory.
func Dirname ¶
Dirname takes a string containing a filesystem path and removes the last portion from it.
The underlying function implementation works only with the path string and does not access the filesystem itself. It is therefore unable to take into account filesystem features such as symlinks.
If the path is empty then the result is ".", representing the current working directory.
func File ¶
File reads the contents of the file at the given path.
The file must contain valid UTF-8 bytes, or this function will return an error.
The underlying function implementation works relative to a particular base directory, so this wrapper takes a base directory string and uses it to construct the underlying function before calling it.
func FileBase64 ¶
FileBase64 reads the contents of the file at the given path.
The bytes from the file are encoded as base64 before returning.
The underlying function implementation works relative to a particular base directory, so this wrapper takes a base directory string and uses it to construct the underlying function before calling it.
func FileExists ¶
FileExists determines whether a file exists at the given path.
The underlying function implementation works relative to a particular base directory, so this wrapper takes a base directory string and uses it to construct the underlying function before calling it.
func FileSet ¶
FileSet enumerates a set of files given a glob pattern
The underlying function implementation works relative to a particular base directory, so this wrapper takes a base directory string and uses it to construct the underlying function before calling it.
func Functions ¶
Functions returns the set of functions that should be used to when evaluating expressions in the receiving scope.
basedir is used with file functions and allows a user to reference a file using local path. Usually basedir is the directory in which the config file is located
func MakeFileExistsFunc ¶
MakeFileExistsFunc constructs a function that takes a path and determines whether a file exists at that path
func MakeFileFunc ¶
MakeFileFunc constructs a function that takes a file path and returns the contents of that file, either directly as a string (where valid UTF-8 is required) or as a string containing base64 bytes.
func MakeFileSetFunc ¶
MakeFileSetFunc constructs a function that takes a glob pattern and enumerates a file set from that pattern
func MakeTemplateFileFunc ¶
func MakeTemplateFileFunc(baseDir string, funcsCb func() map[string]function.Function) function.Function
MakeTemplateFileFunc constructs a function that takes a file path and an arbitrary object of named values and attempts to render the referenced file as a template using HCL template syntax.
The template itself may recursively call other functions so a callback must be provided to get access to those functions. The template cannot, however, access any variables defined in the scope: it is restricted only to those variables provided in the second function argument, to ensure that all dependencies on other graph nodes can be seen before executing this function.
As a special exception, a referenced template file may not recursively call the templatefile function, since that would risk the same file being included into itself indefinitely.
func Pathexpand ¶
Pathexpand takes a string that might begin with a `~` segment, and if so it replaces that segment with the current user's home directory path.
The underlying function implementation works only with the path string and does not access the filesystem itself. It is therefore unable to take into account filesystem features such as symlinks.
If the leading segment in the path is not `~` then the given path is returned unmodified.
Types ¶
This section is empty.