Class: PgExport::Gateways::Ssh
- Inherits:
-
Object
- Object
- PgExport::Gateways::Ssh
- Defined in:
- lib/pg_export/gateways/ssh.rb
Instance Method Summary collapse
- #close ⇒ Object
- #delete(name) ⇒ Object
- #get(file, name) ⇒ Object
-
#initialize(host:, user:, password:) ⇒ Ssh
constructor
A new instance of Ssh.
- #list(name) ⇒ Object
- #open ⇒ Object
- #persist(file, name) ⇒ Object
- #ssh ⇒ Object
- #to_s ⇒ Object
- #welcome ⇒ Object
Constructor Details
#initialize(host:, user:, password:) ⇒ Ssh
Returns a new instance of Ssh.
10 11 12 |
# File 'lib/pg_export/gateways/ssh.rb', line 10 def initialize(host:, user:, password:) @host, @user, @password, @logger = host, user, password end |
Instance Method Details
#close ⇒ Object
27 28 29 |
# File 'lib/pg_export/gateways/ssh.rb', line 27 def close @ssh&.close end |
#delete(name) ⇒ Object
47 48 49 |
# File 'lib/pg_export/gateways/ssh.rb', line 47 def delete(name) ssh.exec!("rm #{name}") end |
#get(file, name) ⇒ Object
55 56 57 |
# File 'lib/pg_export/gateways/ssh.rb', line 55 def get(file, name) ssh.scp.download(name, file.path).wait end |
#list(name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pg_export/gateways/ssh.rb', line 31 def list(name) grep = if name.nil? || name.empty? '' else " | grep #{name}" end ssh .exec!("ls -l#{grep}") .split("\n").map { |row| extract_meaningful_attributes(row) } .reject { |item| item[:name].nil? } .sort_by { |item| item[:name] } .reverse end |
#open ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/pg_export/gateways/ssh.rb', line 14 def open @ssh = if password.nil? Net::SSH.start(host, user) else Net::SSH.start(host, user, password) end end |
#persist(file, name) ⇒ Object
51 52 53 |
# File 'lib/pg_export/gateways/ssh.rb', line 51 def persist(file, name) ssh.scp.upload(file.path, name).wait end |
#ssh ⇒ Object
63 64 65 |
# File 'lib/pg_export/gateways/ssh.rb', line 63 def ssh @ssh ||= open end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/pg_export/gateways/ssh.rb', line 59 def to_s host end |
#welcome ⇒ Object
23 24 25 |
# File 'lib/pg_export/gateways/ssh.rb', line 23 def welcome open.exec!('hostname; whoami') end |