diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/lang/funcs/crypto.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/lang/funcs/crypto.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/lang/funcs/crypto.go b/vendor/github.com/hashicorp/terraform/lang/funcs/crypto.go index 5cb4bc5..be006f8 100644 --- a/vendor/github.com/hashicorp/terraform/lang/funcs/crypto.go +++ b/vendor/github.com/hashicorp/terraform/lang/funcs/crypto.go | |||
@@ -14,6 +14,7 @@ import ( | |||
14 | "hash" | 14 | "hash" |
15 | 15 | ||
16 | uuid "github.com/hashicorp/go-uuid" | 16 | uuid "github.com/hashicorp/go-uuid" |
17 | uuidv5 "github.com/satori/go.uuid" | ||
17 | "github.com/zclconf/go-cty/cty" | 18 | "github.com/zclconf/go-cty/cty" |
18 | "github.com/zclconf/go-cty/cty/function" | 19 | "github.com/zclconf/go-cty/cty/function" |
19 | "github.com/zclconf/go-cty/cty/gocty" | 20 | "github.com/zclconf/go-cty/cty/gocty" |
@@ -32,6 +33,39 @@ var UUIDFunc = function.New(&function.Spec{ | |||
32 | }, | 33 | }, |
33 | }) | 34 | }) |
34 | 35 | ||
36 | var UUIDV5Func = function.New(&function.Spec{ | ||
37 | Params: []function.Parameter{ | ||
38 | { | ||
39 | Name: "namespace", | ||
40 | Type: cty.String, | ||
41 | }, | ||
42 | { | ||
43 | Name: "name", | ||
44 | Type: cty.String, | ||
45 | }, | ||
46 | }, | ||
47 | Type: function.StaticReturnType(cty.String), | ||
48 | Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { | ||
49 | var namespace uuidv5.UUID | ||
50 | switch { | ||
51 | case args[0].AsString() == "dns": | ||
52 | namespace = uuidv5.NamespaceDNS | ||
53 | case args[0].AsString() == "url": | ||
54 | namespace = uuidv5.NamespaceURL | ||
55 | case args[0].AsString() == "oid": | ||
56 | namespace = uuidv5.NamespaceOID | ||
57 | case args[0].AsString() == "x500": | ||
58 | namespace = uuidv5.NamespaceX500 | ||
59 | default: | ||
60 | if namespace, err = uuidv5.FromString(args[0].AsString()); err != nil { | ||
61 | return cty.UnknownVal(cty.String), fmt.Errorf("uuidv5() doesn't support namespace %s (%v)", args[0].AsString(), err) | ||
62 | } | ||
63 | } | ||
64 | val := args[1].AsString() | ||
65 | return cty.StringVal(uuidv5.NewV5(namespace, val).String()), nil | ||
66 | }, | ||
67 | }) | ||
68 | |||
35 | // Base64Sha256Func constructs a function that computes the SHA256 hash of a given string | 69 | // Base64Sha256Func constructs a function that computes the SHA256 hash of a given string |
36 | // and encodes it with Base64. | 70 | // and encodes it with Base64. |
37 | var Base64Sha256Func = makeStringHashFunction(sha256.New, base64.StdEncoding.EncodeToString) | 71 | var Base64Sha256Func = makeStringHashFunction(sha256.New, base64.StdEncoding.EncodeToString) |
@@ -228,6 +262,12 @@ func UUID() (cty.Value, error) { | |||
228 | return UUIDFunc.Call(nil) | 262 | return UUIDFunc.Call(nil) |
229 | } | 263 | } |
230 | 264 | ||
265 | // UUIDV5 generates and returns a Type-5 UUID in the standard hexadecimal string | ||
266 | // format. | ||
267 | func UUIDV5(namespace cty.Value, name cty.Value) (cty.Value, error) { | ||
268 | return UUIDV5Func.Call([]cty.Value{namespace, name}) | ||
269 | } | ||
270 | |||
231 | // Base64Sha256 computes the SHA256 hash of a given string and encodes it with | 271 | // Base64Sha256 computes the SHA256 hash of a given string and encodes it with |
232 | // Base64. | 272 | // Base64. |
233 | // | 273 | // |