Documentation ¶
Index ¶
- Variables
- func Base64Decode(str cty.Value) (cty.Value, error)
- func Base64Encode(str cty.Value) (cty.Value, error)
- func Base64Gzip(str cty.Value) (cty.Value, error)
- func Basename(path cty.Value) (cty.Value, error)
- func Datetime() map[string]function.Function
- func Dirname(path cty.Value) (cty.Value, error)
- func Docs() map[string]string
- func Encoding() map[string]function.Function
- func File(path cty.Value) (cty.Value, error)
- func FileBase64(path cty.Value) (cty.Value, error)
- func FileExists(path cty.Value) (cty.Value, error)
- func FileSet(path, pattern cty.Value) (cty.Value, error)
- func Filesystem() map[string]function.Function
- func MakeFileExistsFunc() function.Function
- func MakeFileFunc(encBase64 bool) function.Function
- func MakeFileSetFunc() function.Function
- func MakeTemplateFileFunc(baseDir string, funcsCb func() map[string]function.Function) function.Function
- func MakeTemplateFuncs(hclCtx *hcl.EvalContext) map[string]function.Function
- func Pathexpand(path cty.Value) (cty.Value, error)
- func Stdlib() map[string]function.Function
- func URLEncode(str cty.Value) (cty.Value, error)
- func VCSGitFuncs(path string) map[string]function.Function
- type VCSGit
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 Base64DecodeFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "str", Type: cty.String, }, }, Type: function.StaticReturnType(cty.String), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { s := args[0].AsString() sDec, err := base64.StdEncoding.DecodeString(s) if err != nil { return cty.UnknownVal(cty.String), fmt.Errorf("failed to decode base64 data '%s'", s) } if !utf8.Valid([]byte(sDec)) { log.Printf("[DEBUG] the result of decoding the provided string is not valid UTF-8: %s", sDec) return cty.UnknownVal(cty.String), fmt.Errorf("the result of decoding the provided string is not valid UTF-8") } return cty.StringVal(string(sDec)), nil }, })
Base64DecodeFunc constructs a function that decodes a string containing a base64 sequence.
var Base64EncodeFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "str", Type: cty.String, }, }, Type: function.StaticReturnType(cty.String), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { return cty.StringVal(base64.StdEncoding.EncodeToString([]byte(args[0].AsString()))), nil }, })
Base64EncodeFunc constructs a function that encodes a string to a base64 sequence.
var Base64GzipFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "str", Type: cty.String, }, }, Type: function.StaticReturnType(cty.String), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { s := args[0].AsString() var b bytes.Buffer gz := gzip.NewWriter(&b) if _, err := gz.Write([]byte(s)); err != nil { return cty.UnknownVal(cty.String), fmt.Errorf("failed to write gzip raw data: '%s'", s) } if err := gz.Flush(); err != nil { return cty.UnknownVal(cty.String), fmt.Errorf("failed to flush gzip writer: '%s'", s) } if err := gz.Close(); err != nil { return cty.UnknownVal(cty.String), fmt.Errorf("failed to close gzip writer: '%s'", s) } return cty.StringVal(base64.StdEncoding.EncodeToString(b.Bytes())), nil }, })
Base64GzipFunc constructs a function that compresses a string with gzip and then encodes the result in Base64 encoding.
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.
var TimestampFunc = function.New(&function.Spec{ Params: []function.Parameter{}, Type: function.StaticReturnType(cty.String), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { return cty.StringVal(time.Now().UTC().Format(time.RFC3339)), nil }, })
TimestampFunc constructs a function that returns a string representation of the current date and time.
var URLEncodeFunc = function.New(&function.Spec{ Params: []function.Parameter{ { Name: "str", Type: cty.String, }, }, Type: function.StaticReturnType(cty.String), Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { return cty.StringVal(url.QueryEscape(args[0].AsString())), nil }, })
URLEncodeFunc constructs a function that applies URL encoding to a given string.
Functions ¶
func Base64Decode ¶
Base64Decode decodes a string containing a base64 sequence.
Waypoint uses the "standard" Base64 alphabet as defined in RFC 4648 section 4.
Strings in the Waypoint language are sequences of unicode characters rather than bytes, so this function will also interpret the resulting bytes as UTF-8. If the bytes after Base64 decoding are _not_ valid UTF-8, this function produces an error.
func Base64Encode ¶
Base64Encode applies Base64 encoding to a string.
Waypoint uses the "standard" Base64 alphabet as defined in RFC 4648 section 4.
Strings in the Waypoint language are sequences of unicode characters rather than bytes, so this function will first encode the characters from the string as UTF-8, and then apply Base64 encoding to the result.
func Base64Gzip ¶
Base64Gzip compresses a string with gzip and then encodes the result in Base64 encoding.
Waypoint uses the "standard" Base64 alphabet as defined in RFC 4648 section 4.
Strings in the Waypoint language are sequences of unicode characters rather than bytes, so this function will first encode the characters from the string as UTF-8, then apply gzip compression, and then finally apply Base64 encoding.
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 Filesystem ¶
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 MakeTemplateFuncs ¶ added in v0.2.0
MakeTemplateFuncs adds the template functions to the function map. The template family of functions has access to the context, except they cannot call further template functions.
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.
func URLEncode ¶
URLEncode applies URL encoding to a given string.
This function identifies characters in the given string that would have a special meaning when included as a query string argument in a URL and escapes them using RFC 3986 "percent encoding".
If the given string contains non-ASCII characters, these are first encoded as UTF-8 and then percent encoding is applied separately to each UTF-8 byte.
Types ¶
type VCSGit ¶
type VCSGit struct { // Path of the git repository. Parent directories will be searched for // a ".git" folder automatically. Path string // contains filtered or unexported fields }
func (*VCSGit) RefPrettyFunc ¶
RefPrettyFunc returns a string format of the current Git ref. This function takes some liberties to humanize the output: it will use a tag if the ref matches a tag, it will append "+CHANGES" to the commit if there are uncommitted changed files, etc.
You may use direct functions such as `gitrefhash` if you want the direct hash. Or `gitreftag` to get the current tag.
waypoint:gitrefpretty
func (*VCSGit) RefTagFunc ¶
RefTagFunc returns the tag of the HEAD ref or empty if not tag is found.
waypoint:gitreftag
func (*VCSGit) RemoteUrlFunc ¶
RemoteUrlFunc returns the URL for the matching remote or unknown if it can't be found.
waypoint:gitremoteurl