Class: Nucleon::Util::SSH::Keypair
- Inherits:
-
Object
- Object
- Nucleon::Util::SSH::Keypair
- Defined in:
- lib/core/util/ssh.rb
Overview
Keypair interface
Instance Attribute Summary collapse
-
#encrypted_key ⇒ Object
readonly
Returns the value of attribute encrypted_key.
-
#passphrase ⇒ Object
readonly
Returns the value of attribute passphrase.
-
#private_key ⇒ Object
readonly
Returns the value of attribute private_key.
-
#public_key ⇒ Object
readonly
Returns the value of attribute public_key.
-
#ssh_key ⇒ Object
readonly
Returns the value of attribute ssh_key.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(key_data, is_new, original_key, passphrase = nil) ⇒ Keypair
constructor
—.
-
#private_key_file(key_path = nil, key_base = 'id') ⇒ Object
—.
- #public_key_file(key_path = nil, key_base = 'id') ⇒ Object
-
#render(key_base = 'id') ⇒ Object
—.
-
#store(key_path = nil, key_base = 'id', secure = true) ⇒ Object
—.
Constructor Details
#initialize(key_data, is_new, original_key, passphrase = nil) ⇒ Keypair
83 84 85 86 87 88 89 90 |
# File 'lib/core/util/ssh.rb', line 83 def initialize(key_data, is_new, original_key, passphrase = nil) @type = key_data.type @private_key = key_data.private_key @encrypted_key = is_new ? key_data.encrypted_private_key : original_key @public_key = key_data.public_key @ssh_key = key_data.ssh_public_key @passphrase = passphrase end |
Instance Attribute Details
#encrypted_key ⇒ Object (readonly)
Returns the value of attribute encrypted_key.
79 80 81 |
# File 'lib/core/util/ssh.rb', line 79 def encrypted_key @encrypted_key end |
#passphrase ⇒ Object (readonly)
Returns the value of attribute passphrase.
79 80 81 |
# File 'lib/core/util/ssh.rb', line 79 def passphrase @passphrase end |
#private_key ⇒ Object (readonly)
Returns the value of attribute private_key.
79 80 81 |
# File 'lib/core/util/ssh.rb', line 79 def private_key @private_key end |
#public_key ⇒ Object (readonly)
Returns the value of attribute public_key.
79 80 81 |
# File 'lib/core/util/ssh.rb', line 79 def public_key @public_key end |
#ssh_key ⇒ Object (readonly)
Returns the value of attribute ssh_key.
79 80 81 |
# File 'lib/core/util/ssh.rb', line 79 def ssh_key @ssh_key end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
79 80 81 |
# File 'lib/core/util/ssh.rb', line 79 def type @type end |
Class Method Details
.render(type, key_base = 'id') ⇒ Object
132 133 134 |
# File 'lib/core/util/ssh.rb', line 132 def self.render(type, key_base = 'id') "#{key_base}_#{type.downcase}" end |
Instance Method Details
#private_key_file(key_path = nil, key_base = 'id') ⇒ Object
94 95 96 97 98 99 |
# File 'lib/core/util/ssh.rb', line 94 def private_key_file(key_path = nil, key_base = 'id') key_path = SSH.key_path if key_path.nil? key_name = render(key_base) File.join(key_path, "#{key_name}") end |
#public_key_file(key_path = nil, key_base = 'id') ⇒ Object
101 102 103 |
# File 'lib/core/util/ssh.rb', line 101 def public_key_file(key_path = nil, key_base = 'id') private_key_file(key_path, key_base) + '.pub' end |
#render(key_base = 'id') ⇒ Object
128 129 130 |
# File 'lib/core/util/ssh.rb', line 128 def render(key_base = 'id') self.class.render(type, key_base) end |
#store(key_path = nil, key_base = 'id', secure = true) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/core/util/ssh.rb', line 107 def store(key_path = nil, key_base = 'id', secure = true) private_key_file = private_key_file(key_path, key_base) public_key_file = public_key_file(key_path, key_base) if secure private_success = Disk.write(private_key_file, encrypted_key) else private_success = Disk.write(private_key_file, private_key) end FileUtils.chmod(0600, private_key_file) if private_success public_success = Disk.write(public_key_file, ssh_key) if private_success && public_success return { :private_key => private_key_file, :public_key => public_key_file } end false end |