summaryrefslogtreecommitdiff
path: root/provider_base/lib/macros/secrets.rb
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2014-06-20 15:42:51 -0700
committerelijah <elijah@riseup.net>2014-06-20 15:42:51 -0700
commit73ef324c993f03b2b8f47418f8b2cf7ff97314c6 (patch)
tree6cad01c2a6018d925ef133f64bcb22f67f74a294 /provider_base/lib/macros/secrets.rb
parent34ab06778ef23203454c27ae41773568b8aae506 (diff)
moved json macros to provider_base/lib/macros. requires new unreleased leap_cli
Diffstat (limited to 'provider_base/lib/macros/secrets.rb')
-rw-r--r--provider_base/lib/macros/secrets.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/provider_base/lib/macros/secrets.rb b/provider_base/lib/macros/secrets.rb
new file mode 100644
index 00000000..51bf3971
--- /dev/null
+++ b/provider_base/lib/macros/secrets.rb
@@ -0,0 +1,39 @@
+# encoding: utf-8
+
+require 'base32'
+
+module LeapCli
+ module Macro
+
+ #
+ # inserts a named secret, generating it if needed.
+ #
+ # manager.export_secrets should be called later to capture any newly generated secrets.
+ #
+ # +length+ is the character length of the generated password.
+ #
+ def secret(name, length=32)
+ @manager.secrets.set(name, Util::Secret.generate(length), @node[:environment])
+ end
+
+ # inserts a base32 encoded secret
+ def base32_secret(name, length=20)
+ @manager.secrets.set(name, Base32.encode(Util::Secret.generate(length)), @node[:environment])
+ end
+
+ # Picks a random obfsproxy port from given range
+ def rand_range(name, range)
+ @manager.secrets.set(name, rand(range), @node[:environment])
+ end
+
+ #
+ # inserts an hexidecimal secret string, generating it if needed.
+ #
+ # +bit_length+ is the bits in the secret, (ie length of resulting hex string will be bit_length/4)
+ #
+ def hex_secret(name, bit_length=128)
+ @manager.secrets.set(name, Util::Secret.generate_hex(bit_length), @node[:environment])
+ end
+
+ end
+end \ No newline at end of file