Class: Fastlane::Helper::SftpHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/sftp/helper/sftp_helper.rb

Class Method Summary collapse

Class Method Details

.check_file(local_file_path) ⇒ Object

Check file existence locally

Parameters:

  • local_file_path


40
41
42
43
44
45
46
47
48
# File 'lib/fastlane/plugin/sftp/helper/sftp_helper.rb', line 40

def self.check_file(local_file_path)
  if File.exist?(local_file_path)
    UI.verbose('File found at ' + local_file_path)
    return true
  else
    UI.important("File at given path #{local_file_path} does not exist. File will be ignored")
    return false
  end
end

.generate_remote_path(user, target_dir) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/fastlane/plugin/sftp/helper/sftp_helper.rb', line 73

def self.generate_remote_path(user, target_dir)
  path = File.join('/', user, target_dir)
  if user != "root"
    path = File.join('/home', path)
  end
  path
end

.get_target_file_path(source_file_path, target_dir) ⇒ Object



50
51
52
# File 'lib/fastlane/plugin/sftp/helper/sftp_helper.rb', line 50

def self.get_target_file_path(source_file_path, target_dir)
  return File.join(target_dir, File.basename(source_file_path))
end

.load_rsa_key(rsa_keypath) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fastlane/plugin/sftp/helper/sftp_helper.rb', line 61

def self.load_rsa_key(rsa_keypath)
  File.open(rsa_keypath, 'r') do |file|
    rsa_key = [file.read]
    if !rsa_key.nil?
      UI.success('Successfully loaded RSA key...')
    else
      UI.user_error!('Failed to load RSA key...')
    end
    rsa_key
  end
end

.login(host, user, password, rsa_keypath, rsa_keypath_passphrase) ⇒ Object

class methods that you define here become available in your action as ‘Helper::SftpHelper.your_method`



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fastlane/plugin/sftp/helper/sftp_helper.rb', line 14

def self.(host, user, password, rsa_keypath, rsa_keypath_passphrase)
  if host.nil? || user.nil?
    UI.user_error('server_url, server_user and server_password or server_key must be set')
    return nil
  end

  if rsa_keypath
    rsa_key = Helper::SftpHelper.load_rsa_key(rsa_keypath)
    if rsa_key.nil?
      UI.user_error("Failed to load RSA key... #{rsa_keypath}")
    end
  end

  if !rsa_key.nil?
    UI.message('Logging in with RSA key...')
    session = Net::SSH.start(host, user, key_data: rsa_key, keys_only: true, passphrase: rsa_keypath_passphrase)
  else
    UI.message('Logging in with username/password...')
    session = Net::SSH.start(host, user, password: password)
  end
  return session
end

.remote_mkdir(sftp, remote_path) ⇒ Object



54
55
56
57
58
59
# File 'lib/fastlane/plugin/sftp/helper/sftp_helper.rb', line 54

def self.remote_mkdir(sftp, remote_path)
  sftp.mkdir(remote_path)
rescue Net::SFTP::StatusException => e
  raise if e.code != 11
  UI.message("Remote dir #{remote_path} exists.")
end