require 'sshkey' require 'cabal/util' require 'sekrat' require 'sekrat/crypter/aes' module Cabal module API class ClusterService attr_accessor :public_keys, :private_keys def initialize(public_warehouse: STORAGE[:public], private_warehouse: STORAGE[:private]) @public_keys = Sekrat.manager(warehouse: public_warehouse) @private_keys = Sekrat.manager(warehouse: private_warehouse, crypter: Sekrat::Crypter::Aes) end def create(name) sshkey = SSHKey.generate( type: 'RSA', bits: 2048, comment: "#{name}-cabal" ) write_public_key(name, sshkey) && write_private_key(name, sshkey) end def names public_keys.ids end def public_key(name) begin public_keys.get(name, name) rescue nil end end def private_key(name) begin private_keys.get(name, public_key(name)) rescue nil end end private def write_public_key(name, key) begin public_keys.put(name, name, key.ssh_public_key) true rescue return false end end def write_private_key(name, key) begin private_keys.put( name, key.ssh_public_key, key.private_key ) true rescue false end end end end end