Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ConcatFunc returns the concatenation of two string arguments. ConcatFunc = function.New(&function.Spec{ VarParam: nil, Params: []function.Parameter{ { Name: "first", Type: cty.String, }, { Name: "second", Type: cty.String, }, }, Type: func(args []cty.Value) (cty.Type, error) { return cty.String, nil }, Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { var first, second string if err := gocty.FromCtyValue(args[0], &first); err != nil { return cty.StringVal(""), err } if err := gocty.FromCtyValue(args[1], &second); err != nil { return cty.StringVal(""), err } return cty.StringVal(first + second), nil }, }) )
var FunctionRunAsUnitTestOption = func(oa *functionOptionArg) { oa.runAsUnitTest = true }
FunctionRunAsUnitTestOption allows implementations to change their behavior when invoked within a unit-test
var ( // HostnameFunc attempts to determine the current system's hostname as the // environment variable HOSTNAME is not available on every platform. HostnameFunc = function.New(&function.Spec{ VarParam: nil, Params: nil, Type: func(args []cty.Value) (cty.Type, error) { return cty.String, nil }, Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { if hostname, ok := os.LookupEnv("HOSTNAME"); ok { return cty.StringVal(hostname), nil } if hostname, err := os.Hostname(); err == nil && len(hostname) > 0 { return cty.StringVal(hostname), nil } hostname, _ := os.LookupEnv("HOST") return cty.StringVal(hostname), nil }, }) )
var ( // RandomFunc generates length cryptographically secure random bytes and returns // an encoding encoded string. RandomFunc = function.New(&function.Spec{ VarParam: nil, Params: []function.Parameter{ { Name: "length", Type: cty.Number, }, { Name: "encoding", Type: cty.String, }, }, Type: func(args []cty.Value) (cty.Type, error) { return cty.String, nil }, Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) { var length int var encoding string if err := gocty.FromCtyValue(args[0], &length); err != nil { return cty.StringVal(""), err } if err := gocty.FromCtyValue(args[1], &encoding); err != nil { return cty.StringVal(""), err } encodingF, ok := encodingMap[encoding] if !ok { return cty.StringVal(""), base.NewErrInvalidArg( "invalid or unsupported encoding scheme %q", encoding) } b := make([]byte, length) if _, err := rand.Read(b); err != nil { return cty.StringVal(""), err } return cty.StringVal(encodingF(b)), nil }, }) )
Functions ¶
func Concat ¶ added in v0.0.4
func Concat(first, second string, options ...FunctionOption) (string, error)
Concat returns the concatenation of two string arguments.
func Hostname ¶
func Hostname(options ...FunctionOption) (string, error)
Hostname attempts to determine the current system's hostname as the environment variable HOSTNAME is not available on every platform.
func Random ¶
func Random(length int, encoding EncodingID, options ...FunctionOption) (string, error)
Random generates length cryptographically secure random bytes and returns an encoding encoded string.
Types ¶
type EncodingID ¶
type EncodingID = string
EncodingID identifies supported encoding schemes.
const ( EncodingIDBase64 EncodingID = "base64" EncodingIDHex EncodingID = "hex" )
encoding identifiers
type FunctionOption ¶
type FunctionOption func(*functionOptionArg)
A FunctionOption modifies the execution behavior of a cty function, e.g., to produce a predictable output.
func FunctionRunAsUnitTestOptionWithArg ¶
func FunctionRunAsUnitTestOptionWithArg(arg interface{}) FunctionOption
FunctionRunAsUnitTestOptionWithArg allows to pass an argument to a function when call within a unit-test.