Class: Keypair
Overview
ssh key used to login to remote instances\
Instance Attribute Summary collapse
-
#filepath ⇒ Object
Returns the value of attribute filepath.
Instance Method Summary collapse
-
#basename ⇒ Object
Basename of the keypair.
-
#content ⇒ Object
Read the content of the key.
-
#each {|full_filepath| ... } ⇒ Object
Support to add the enumerable each to keys.
-
#exists? ⇒ Boolean
If the full_filepath is nil, then the key doesn’t exist.
-
#filename ⇒ Object
Just the filename of the keypair.
-
#full_filepath ⇒ Object
(also: #to_s)
Returns the full_filepath of the key.
-
#initialize(fpath) ⇒ Keypair
constructor
Create a new key that defaults to id_rsa as the name.
-
#public_key ⇒ Object
TODO: gracefully handle the case when a passpharase is needed Generate a public key from the private key net/ssh already has this built-in from our extension.
- #public_key=(str) ⇒ Object
-
#valid? ⇒ Boolean
Validation checks if all of the validations pass, the object is considered valid the validations are responsible for raising a PoolPartyError (StandardError).
Methods included from SearchablePaths
Constructor Details
#initialize(fpath) ⇒ Keypair
Create a new key that defaults to id_rsa as the name.
12 13 14 15 |
# File 'lib/keypair.rb', line 12 def initialize(fpath) @filepath = fpath valid? end |
Instance Attribute Details
#filepath ⇒ Object
Returns the value of attribute filepath.
9 10 11 |
# File 'lib/keypair.rb', line 9 def filepath @filepath end |
Instance Method Details
#basename ⇒ Object
Basename of the keypair
55 56 57 |
# File 'lib/keypair.rb', line 55 def basename @basename ||= ::File.basename(filepath, ::File.extname(filepath)) end |
#content ⇒ Object
Read the content of the key
23 24 25 |
# File 'lib/keypair.rb', line 23 def content @content ||= exists? ? open(full_filepath).read : nil end |
#each {|full_filepath| ... } ⇒ Object
Support to add the enumerable each to keys
65 66 67 |
# File 'lib/keypair.rb', line 65 def each yield full_filepath end |
#exists? ⇒ Boolean
If the full_filepath is nil, then the key doesn’t exist
18 19 20 |
# File 'lib/keypair.rb', line 18 def exists? full_filepath != nil end |
#filename ⇒ Object
Just the filename of the keypair
60 61 62 |
# File 'lib/keypair.rb', line 60 def filename @filename ||= ::File.basename(full_filepath) rescue filepath end |
#full_filepath ⇒ Object Also known as: to_s
Returns the full_filepath of the key. If a full filepath is passed, we just return the expanded filepath for the keypair, otherwise query where it is against known locations
29 30 31 32 33 34 35 |
# File 'lib/keypair.rb', line 29 def full_filepath @full_filepath ||= if File.file?(::File.(filepath)) ::File.(filepath) else search_in_known_locations(filepath) end end |
#public_key ⇒ Object
TODO: gracefully handle the case when a passpharase is needed Generate a public key from the private key net/ssh already has this built-in from our extension.
41 42 43 44 45 46 47 48 |
# File 'lib/keypair.rb', line 41 def public_key if !@public_key_string || @public_key_string.empty? pkey = Net::SSH::KeyFactory.load_private_key(full_filepath) @public_key_string = pkey.public_key else @public_key_string end end |
#public_key=(str) ⇒ Object
50 51 52 |
# File 'lib/keypair.rb', line 50 def public_key=(str) @public_key_string = str end |
#valid? ⇒ Boolean
Validation checks if all of the validations pass, the object is considered valid the validations are responsible for raising a PoolPartyError (StandardError)
72 73 74 |
# File 'lib/keypair.rb', line 72 def valid? validations.each {|validation| self.send(validation.to_sym) } end |