summaryrefslogtreecommitdiff
path: root/qa/qa/runtime/key/base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'qa/qa/runtime/key/base.rb')
-rw-r--r--qa/qa/runtime/key/base.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/qa/qa/runtime/key/base.rb b/qa/qa/runtime/key/base.rb
new file mode 100644
index 00000000000..c7e5ebada7b
--- /dev/null
+++ b/qa/qa/runtime/key/base.rb
@@ -0,0 +1,36 @@
+module QA
+ module Runtime
+ module Key
+ class Base
+ attr_reader :name, :bits, :private_key, :public_key, :fingerprint
+
+ def initialize(name, bits)
+ @name = name
+ @bits = bits
+
+ Dir.mktmpdir do |dir|
+ path = "#{dir}/id_#{name}"
+
+ ssh_keygen(name, bits, path)
+ populate_key_data(path)
+ end
+ end
+
+ private
+
+ def ssh_keygen(name, bits, path)
+ cmd = %W[ssh-keygen -t #{name} -b #{bits} -f #{path} -N] << ''
+
+ Service::Shellout.shell(cmd)
+ end
+
+ def populate_key_data(path)
+ @private_key = File.binread(path)
+ @public_key = File.binread("#{path}.pub")
+ @fingerprint =
+ `ssh-keygen -l -E md5 -f #{path} | cut -d' ' -f2 | cut -d: -f2-`.chomp
+ end
+ end
+ end
+ end
+end