Sha256: 25d48e7efe5cfa4ed5b9e5431ac3803a32cc162196d705f524e86aed88574f51

Contents?: true

Size: 726 Bytes

Versions: 6

Compression:

Stored size: 726 Bytes

Contents

require "sfn"

module Sfn
  module Utils

    # Helper methods for SSH interactions
    module Ssher

      # Retrieve file from remote node
      #
      # @param address [String]
      # @param user [String]
      # @param path [String] remote file path
      # @param ssh_opts [Hash]
      # @return [String, NilClass]
      def remote_file_contents(address, user, path, ssh_opts = {})
        if path.to_s.strip.empty?
          raise ArgumentError.new "No file path provided!"
        end
        require "net/ssh"
        content = ""
        ssh_session = Net::SSH.start(address, user, ssh_opts)
        content = ssh_session.exec!("sudo cat #{path}")
        content.empty? ? nil : content
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sfn-3.1.8 lib/sfn/utils/ssher.rb
sfn-3.1.6 lib/sfn/utils/ssher.rb
sfn-3.1.4 lib/sfn/utils/ssher.rb
sfn-3.1.2 lib/sfn/utils/ssher.rb
sfn-3.1.0 lib/sfn/utils/ssher.rb
sfn-3.0.32 lib/sfn/utils/ssher.rb