Class: Keypair
Overview
ssh key used to login to remote instances\
Instance Attribute Summary collapse
-
#extra_paths ⇒ Object
readonly
Returns the value of attribute extra_paths.
-
#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, extra_paths = []) ⇒ 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
Instance Attribute Details
#extra_paths ⇒ Object (readonly)
Returns the value of attribute extra_paths.
10 11 12 |
# File 'lib/keypair.rb', line 10 def extra_paths @extra_paths end |
#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
57 58 59 |
# File 'lib/keypair.rb', line 57 def basename @basename ||= ::File.basename(filepath, ::File.extname(filepath)) end |
#content ⇒ Object
Read the content of the key
25 26 27 |
# File 'lib/keypair.rb', line 25 def content @content ||= exists? ? open(full_filepath).read : nil end |
#each {|full_filepath| ... } ⇒ Object
Support to add the enumerable each to keys
67 68 69 |
# File 'lib/keypair.rb', line 67 def each yield full_filepath end |
#exists? ⇒ Boolean
If the full_filepath is nil, then the key doesn’t exist
20 21 22 |
# File 'lib/keypair.rb', line 20 def exists? full_filepath != nil end |
#filename ⇒ Object
Just the filename of the keypair
62 63 64 |
# File 'lib/keypair.rb', line 62 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
31 32 33 34 35 36 37 |
# File 'lib/keypair.rb', line 31 def full_filepath @full_filepath ||= if File.file?(File.(filepath)) ::File.(filepath) else search_in_known_locations(filepath, extra_paths) 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.
43 44 45 46 47 48 49 50 |
# File 'lib/keypair.rb', line 43 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
52 53 54 |
# File 'lib/keypair.rb', line 52 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)
74 75 76 |
# File 'lib/keypair.rb', line 74 def valid? validations.each {|validation| self.send(validation.to_sym) } end |