Sha256: 4604ca04bb458fbae340c5e20385eb56ca42497052cd921810dabd712823e6f6
Contents?: true
Size: 1.54 KB
Versions: 2
Compression:
Stored size: 1.54 KB
Contents
# frozen_string_literal: true # auto_register: false require 'ed25519' require 'net/ssh' require 'net/scp' class PgExport module Gateways class Ssh CHUNK_SIZE = (2**16).freeze def initialize(host:, user:, password:) @host, @user, @password, @logger = host, user, password end def open @ssh = if password.nil? Net::SSH.start(host, user) else Net::SSH.start(host, user, password) end end def welcome open.exec!('hostname') end def close @ssh&.close end 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 def delete(name) # @TODO end def persist(file, name) ssh.scp.upload(file.path, name).wait end def get(file, name) ssh.scp.download(name, file.path).wait end def to_s host end def ssh @ssh ||= open end private attr_reader :host, :user, :password def extract_meaningful_attributes(item) MEANINGFUL_KEYS.zip(item.split(' ').values_at(8, 4)).to_h end MEANINGFUL_KEYS = %i[name size].freeze private_constant :MEANINGFUL_KEYS end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pg_export-1.0.0.rc5 | lib/pg_export/lib/pg_export/gateways/ssh.rb |
pg_export-1.0.0.rc4 | lib/pg_export/lib/pg_export/gateways/ssh.rb |