Class: ModeScp
- Inherits:
-
Object
- Object
- ModeScp
- Defined in:
- lib/punt/mode/mode_scp.rb
Instance Method Summary collapse
- #download(local_path, remote_path, mode_opts: nil, dry_run: false, verbose: false) ⇒ Object
- #download_versionfile(deploystage, mode_opts: nil, verbose: false) ⇒ Object
- #mode_opts(environment) ⇒ Object
- #mode_start(mode_opts: nil, dry_run: false, verbose: true) ⇒ Object
- #transfer(local_path, remote_path, mode_opts: nil, dry_run: false, verbose: false) ⇒ Object
- #transfer_complete(mode_opts: nil, dry_run: false, verbose: true) ⇒ Object
- #transfer_start(mode_opts: nil, dry_run: false, verbose: true) ⇒ Object
- #upload_versionfile(version, deploystage, mode_opts: nil, verbose: false) ⇒ Object
Instance Method Details
#download(local_path, remote_path, mode_opts: nil, dry_run: false, verbose: false) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/punt/mode/mode_scp.rb', line 46 def download(local_path, remote_path, mode_opts: nil, dry_run: false, verbose: false) scp_args = ["scp"] (mode_opts, verbose, scp_args) if (File.directory?(local_path)) scp_args << "-r" end scp_args << scp_remote_file(remote_path, mode_opts) scp_args << local_path scp_command = scp_args.join(" ") puts scp_command if verbose `#{scp_command}` unless dry_run end |
#download_versionfile(deploystage, mode_opts: nil, verbose: false) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/punt/mode/mode_scp.rb', line 76 def download_versionfile(deploystage, mode_opts: nil, verbose: false) filename = ".punt_#{deploystage}" versionfile = Tempfile.new(filename) download(versionfile.path, filename, mode_opts: mode_opts, verbose: verbose) version = versionfile.read versionfile.unlink return version end |
#mode_opts(environment) ⇒ Object
3 4 5 |
# File 'lib/punt/mode/mode_scp.rb', line 3 def mode_opts(environment) return environment["scp"] end |
#mode_start(mode_opts: nil, dry_run: false, verbose: true) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/punt/mode/mode_scp.rb', line 7 def mode_start(mode_opts: nil, dry_run: false, verbose: true) @has_sshpass = feature_detect_sshpass if @has_sshpass && !mode_opts['ssh_key'] print "(using sshpass) enter the ssh password: " @ssh_password = gets.chomp elsif !mode_opts['ssh_key'] puts "sshpass is not installed. You will need to enter your password for every scp action that is generated. To avoid entering your password for every scp action, you can switch to key-based authentication by setting ssh_key. If key based authentication is not possible, try installing sshpass (https://gist.github.com/arunoda/7790979)" puts "" end end |
#transfer(local_path, remote_path, mode_opts: nil, dry_run: false, verbose: false) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/punt/mode/mode_scp.rb', line 25 def transfer(local_path, remote_path, mode_opts: nil, dry_run: false, verbose: false) scp_args = ["scp"] (mode_opts, verbose, scp_args) if (File.directory?(local_path)) scp_args << "-r" end if (@has_sshpass && @ssh_password) scp_args.unshift(@ssh_password).unshift("-p").unshift("sshpass") end scp_args << local_path scp_args << scp_remote_file(remote_path, mode_opts) scp_command = scp_args.join(" ") puts scp_command `#{scp_command}` unless dry_run end |
#transfer_complete(mode_opts: nil, dry_run: false, verbose: true) ⇒ Object
22 23 |
# File 'lib/punt/mode/mode_scp.rb', line 22 def transfer_complete(mode_opts: nil, dry_run: false, verbose: true) end |
#transfer_start(mode_opts: nil, dry_run: false, verbose: true) ⇒ Object
19 20 |
# File 'lib/punt/mode/mode_scp.rb', line 19 def transfer_start(mode_opts: nil, dry_run: false, verbose: true) end |
#upload_versionfile(version, deploystage, mode_opts: nil, verbose: false) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/punt/mode/mode_scp.rb', line 63 def upload_versionfile(version, deploystage, mode_opts: nil, verbose: false) filename = ".punt_#{deploystage}" versionfile = Tempfile.new(filename) versionfile.write("#{version}") versionfile.close() transfer(versionfile.path, filename, mode_opts: mode_opts) versionfile.unlink end |