Class: Comet::SSHConnection
- Inherits:
-
Object
- Object
- Comet::SSHConnection
- Defined in:
- lib/comet/models/sshconnection.rb
Overview
SSHConnection is a typed class wrapper around the underlying Comet Server API data structure.
Instance Attribute Summary collapse
-
#sshauth_mode ⇒ Object
One of the SSHCONNECTION_AUTHMODE_ constants.
-
#sshcustom_auth__known_hosts_file ⇒ Object
If SSHCustomAuth_UseKnownHostsFile is true, the path to the SSH known_hosts file.
-
#sshcustom_auth__use_known_hosts_file ⇒ Object
If true, then the SSHCustomAuth_KnownHostsFile will be used to verify the remote SSH server’s host key, using Trust On First Use (TOFU).
-
#sshpassword ⇒ Object
For use with SSHCONNECTION_AUTHMODE_PASSWORD only: the SSH password to connect with.
-
#sshprivate_key ⇒ Object
For use with SSHCONNECTION_AUTHMODE_PRIVATEKEY only: the SSH private key to connect with, in OpenSSH format.
-
#sshserver ⇒ Object
Returns the value of attribute sshserver.
-
#sshusername ⇒ Object
Returns the value of attribute sshusername.
-
#unknown_json_fields ⇒ Object
Returns the value of attribute unknown_json_fields.
Instance Method Summary collapse
- #clear ⇒ Object
- #from_hash(obj) ⇒ Object
- #from_json(json_string) ⇒ Object
-
#initialize ⇒ SSHConnection
constructor
A new instance of SSHConnection.
-
#to_h ⇒ Hash
The complete object as a Ruby hash.
-
#to_hash ⇒ Hash
The complete object as a Ruby hash.
-
#to_json(options = {}) ⇒ String
The complete object as a JSON string.
Constructor Details
#initialize ⇒ SSHConnection
Returns a new instance of SSHConnection.
46 47 48 |
# File 'lib/comet/models/sshconnection.rb', line 46 def initialize clear end |
Instance Attribute Details
#sshauth_mode ⇒ Object
One of the SSHCONNECTION_AUTHMODE_ constants
23 24 25 |
# File 'lib/comet/models/sshconnection.rb', line 23 def sshauth_mode @sshauth_mode end |
#sshcustom_auth__known_hosts_file ⇒ Object
If SSHCustomAuth_UseKnownHostsFile is true, the path to the SSH known_hosts file.
41 42 43 |
# File 'lib/comet/models/sshconnection.rb', line 41 def sshcustom_auth__known_hosts_file @sshcustom_auth__known_hosts_file end |
#sshcustom_auth__use_known_hosts_file ⇒ Object
If true, then the SSHCustomAuth_KnownHostsFile will be used to verify the remote SSH server’s host key, using Trust On First Use (TOFU).
37 38 39 |
# File 'lib/comet/models/sshconnection.rb', line 37 def sshcustom_auth__use_known_hosts_file @sshcustom_auth__use_known_hosts_file end |
#sshpassword ⇒ Object
For use with SSHCONNECTION_AUTHMODE_PASSWORD only: the SSH password to connect with
27 28 29 |
# File 'lib/comet/models/sshconnection.rb', line 27 def sshpassword @sshpassword end |
#sshprivate_key ⇒ Object
For use with SSHCONNECTION_AUTHMODE_PRIVATEKEY only: the SSH private key to connect with, in OpenSSH format.
32 33 34 |
# File 'lib/comet/models/sshconnection.rb', line 32 def sshprivate_key @sshprivate_key end |
#sshserver ⇒ Object
Returns the value of attribute sshserver.
16 17 18 |
# File 'lib/comet/models/sshconnection.rb', line 16 def sshserver @sshserver end |
#sshusername ⇒ Object
Returns the value of attribute sshusername.
19 20 21 |
# File 'lib/comet/models/sshconnection.rb', line 19 def sshusername @sshusername end |
#unknown_json_fields ⇒ Object
Returns the value of attribute unknown_json_fields.
44 45 46 |
# File 'lib/comet/models/sshconnection.rb', line 44 def unknown_json_fields @unknown_json_fields end |
Instance Method Details
#clear ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/comet/models/sshconnection.rb', line 50 def clear @sshserver = '' @sshusername = '' @sshauth_mode = 0 @sshpassword = '' @sshprivate_key = '' @sshcustom_auth__known_hosts_file = '' @unknown_json_fields = {} end |
#from_hash(obj) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/comet/models/sshconnection.rb', line 68 def from_hash(obj) raise TypeError, "'obj' expected Hash, got #{obj.class}" unless obj.is_a? Hash obj.each do |k, v| case k when 'SSHServer' raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String @sshserver = v when 'SSHUsername' raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String @sshusername = v when 'SSHAuthMode' raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric @sshauth_mode = v when 'SSHPassword' raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String @sshpassword = v when 'SSHPrivateKey' raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String @sshprivate_key = v when 'SSHCustomAuth_UseKnownHostsFile' @sshcustom_auth__use_known_hosts_file = v when 'SSHCustomAuth_KnownHostsFile' raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String @sshcustom_auth__known_hosts_file = v else @unknown_json_fields[k] = v end end end |
#from_json(json_string) ⇒ Object
61 62 63 64 65 |
# File 'lib/comet/models/sshconnection.rb', line 61 def from_json(json_string) raise TypeError, "'json_string' expected String, got #{json_string.class}" unless json_string.is_a? String from_hash(JSON.parse(json_string)) end |
#to_h ⇒ Hash
Returns The complete object as a Ruby hash.
122 123 124 |
# File 'lib/comet/models/sshconnection.rb', line 122 def to_h to_hash end |
#to_hash ⇒ Hash
Returns The complete object as a Ruby hash.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/comet/models/sshconnection.rb', line 106 def to_hash ret = {} ret['SSHServer'] = @sshserver ret['SSHUsername'] = @sshusername ret['SSHAuthMode'] = @sshauth_mode ret['SSHPassword'] = @sshpassword ret['SSHPrivateKey'] = @sshprivate_key ret['SSHCustomAuth_UseKnownHostsFile'] = @sshcustom_auth__use_known_hosts_file ret['SSHCustomAuth_KnownHostsFile'] = @sshcustom_auth__known_hosts_file @unknown_json_fields.each do |k, v| ret[k] = v end ret end |
#to_json(options = {}) ⇒ String
Returns The complete object as a JSON string.
127 128 129 |
# File 'lib/comet/models/sshconnection.rb', line 127 def to_json( = {}) to_hash.to_json() end |