Class: Trocla::Formats::Sshkey
- Defined in:
- lib/trocla/formats/sshkey.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
expensive, #expensive?, expensive?, #initialize
Constructor Details
This class inherits a constructor from Trocla::Formats::Base
Instance Method Details
#format(plain_password, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/trocla/formats/sshkey.rb', line 6 def format(plain_password,={}) if plain_password.match(/-----BEGIN RSA PRIVATE KEY-----.*-----END RSA PRIVATE KEY/m) # Import, validate ssh key begin sshkey = ::SSHKey.new(plain_password) rescue Exception => e raise "SSH key import failed: #{e.}" end return sshkey.private_key + sshkey.ssh_public_key end type = ['type'] || 'rsa' bits = ['bits'] || 2048 begin sshkey = ::SSHKey.generate( type: type, bits: bits, comment: ['comment'], passphrase: ['passphrase'] ) rescue Exception => e raise "SSH key creation failed: #{e.}" end sshkey.private_key + sshkey.ssh_public_key end |
#render(output, render_options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/trocla/formats/sshkey.rb', line 33 def render(output, = {}) if ['privonly'] ::SSHKey.new(output).private_key elsif ['pubonly'] ::SSHKey.new(output).ssh_public_key else super(output, ) end end |