From 9b12e4fe6f3c95986f1f3ec791636c58ca7e7583 Mon Sep 17 00:00:00 2001 From: Jake Champlin Date: Fri, 9 Jun 2017 17:54:32 +0000 Subject: Transfer of provider code --- .../hashicorp/terraform/config/config.go | 64 +--------------------- .../terraform/config/interpolate_funcs.go | 48 ++++++++++++++++ 2 files changed, 49 insertions(+), 63 deletions(-) (limited to 'vendor/github.com/hashicorp/terraform/config') diff --git a/vendor/github.com/hashicorp/terraform/config/config.go b/vendor/github.com/hashicorp/terraform/config/config.go index 9a764ac..a157824 100644 --- a/vendor/github.com/hashicorp/terraform/config/config.go +++ b/vendor/github.com/hashicorp/terraform/config/config.go @@ -545,7 +545,7 @@ func (c *Config) Validate() error { // Verify provisioners for _, p := range r.Provisioners { - // This validation checks that there are now splat variables + // This validation checks that there are no splat variables // referencing ourself. This currently is not allowed. for _, v := range p.ConnInfo.Variables { @@ -705,17 +705,6 @@ func (c *Config) Validate() error { } } - // Check that all variables are in the proper context - for source, rc := range c.rawConfigs() { - walker := &interpolationWalker{ - ContextF: c.validateVarContextFn(source, &errs), - } - if err := reflectwalk.Walk(rc.Raw, walker); err != nil { - errs = append(errs, fmt.Errorf( - "%s: error reading config: %s", source, err)) - } - } - // Validate the self variable for source, rc := range c.rawConfigs() { // Ignore provisioners. This is a pretty brittle way to do this, @@ -787,57 +776,6 @@ func (c *Config) rawConfigs() map[string]*RawConfig { return result } -func (c *Config) validateVarContextFn( - source string, errs *[]error) interpolationWalkerContextFunc { - return func(loc reflectwalk.Location, node ast.Node) { - // If we're in a slice element, then its fine, since you can do - // anything in there. - if loc == reflectwalk.SliceElem { - return - } - - // Otherwise, let's check if there is a splat resource variable - // at the top level in here. We do this by doing a transform that - // replaces everything with a noop node unless its a variable - // access or concat. This should turn the AST into a flat tree - // of Concat(Noop, ...). If there are any variables left that are - // multi-access, then its still broken. - node = node.Accept(func(n ast.Node) ast.Node { - // If it is a concat or variable access, we allow it. - switch n.(type) { - case *ast.Output: - return n - case *ast.VariableAccess: - return n - } - - // Otherwise, noop - return &noopNode{} - }) - - vars, err := DetectVariables(node) - if err != nil { - // Ignore it since this will be caught during parse. This - // actually probably should never happen by the time this - // is called, but its okay. - return - } - - for _, v := range vars { - rv, ok := v.(*ResourceVariable) - if !ok { - return - } - - if rv.Multi && rv.Index == -1 { - *errs = append(*errs, fmt.Errorf( - "%s: use of the splat ('*') operator must be wrapped in a list declaration", - source)) - } - } - } -} - func (c *Config) validateDependsOn( n string, v []string, diff --git a/vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go b/vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go index f1f97b0..7b7b3f2 100644 --- a/vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go +++ b/vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go @@ -24,6 +24,7 @@ import ( "github.com/hashicorp/hil" "github.com/hashicorp/hil/ast" "github.com/mitchellh/go-homedir" + "golang.org/x/crypto/bcrypt" ) // stringSliceToVariableValue converts a string slice into the value @@ -59,6 +60,7 @@ func Funcs() map[string]ast.Function { "base64encode": interpolationFuncBase64Encode(), "base64sha256": interpolationFuncBase64Sha256(), "base64sha512": interpolationFuncBase64Sha512(), + "bcrypt": interpolationFuncBcrypt(), "ceil": interpolationFuncCeil(), "chomp": interpolationFuncChomp(), "cidrhost": interpolationFuncCidrHost(), @@ -89,6 +91,7 @@ func Funcs() map[string]ast.Function { "merge": interpolationFuncMerge(), "min": interpolationFuncMin(), "pathexpand": interpolationFuncPathExpand(), + "pow": interpolationFuncPow(), "uuid": interpolationFuncUUID(), "replace": interpolationFuncReplace(), "sha1": interpolationFuncSha1(), @@ -394,6 +397,17 @@ func interpolationFuncConcat() ast.Function { } } +// interpolationFuncPow returns base x exponential of y. +func interpolationFuncPow() ast.Function { + return ast.Function{ + ArgTypes: []ast.Type{ast.TypeFloat, ast.TypeFloat}, + ReturnType: ast.TypeFloat, + Callback: func(args []interface{}) (interface{}, error) { + return math.Pow(args[0].(float64), args[1].(float64)), nil + }, + } +} + // interpolationFuncFile implements the "file" function that allows // loading contents from a file. func interpolationFuncFile() ast.Function { @@ -1310,6 +1324,40 @@ func interpolationFuncBase64Sha512() ast.Function { } } +func interpolationFuncBcrypt() ast.Function { + return ast.Function{ + ArgTypes: []ast.Type{ast.TypeString}, + Variadic: true, + VariadicType: ast.TypeString, + ReturnType: ast.TypeString, + Callback: func(args []interface{}) (interface{}, error) { + defaultCost := 10 + + if len(args) > 1 { + costStr := args[1].(string) + cost, err := strconv.Atoi(costStr) + if err != nil { + return "", err + } + + defaultCost = cost + } + + if len(args) > 2 { + return "", fmt.Errorf("bcrypt() takes no more than two arguments") + } + + input := args[0].(string) + out, err := bcrypt.GenerateFromPassword([]byte(input), defaultCost) + if err != nil { + return "", fmt.Errorf("error occured generating password %s", err.Error()) + } + + return string(out), nil + }, + } +} + func interpolationFuncUUID() ast.Function { return ast.Function{ ArgTypes: []ast.Type{}, -- cgit v1.2.3