Class: Fastlane::Helper::SftpHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::SftpHelper
- Defined in:
- lib/fastlane/plugin/sftp/helper/sftp_helper.rb
Class Method Summary collapse
-
.check_file(local_file_path) ⇒ Object
Check file existence locally.
- .generate_remote_path(user, target_dir) ⇒ Object
- .get_target_file_path(source_file_path, target_dir) ⇒ Object
- .load_rsa_key(rsa_keypath) ⇒ Object
-
.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`.
- .remote_mkdir(sftp, remote_path) ⇒ Object
Class Method Details
.check_file(local_file_path) ⇒ Object
Check file existence locally
53 54 55 56 57 58 59 60 61 |
# File 'lib/fastlane/plugin/sftp/helper/sftp_helper.rb', line 53 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
89 90 91 92 93 94 95 |
# File 'lib/fastlane/plugin/sftp/helper/sftp_helper.rb', line 89 def self.generate_remote_path(user, target_dir) path = File.join('/', user, target_dir) if user != "root" path = File.join('/home', path) end return path end |
.get_target_file_path(source_file_path, target_dir) ⇒ Object
63 64 65 |
# File 'lib/fastlane/plugin/sftp/helper/sftp_helper.rb', line 63 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
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/fastlane/plugin/sftp/helper/sftp_helper.rb', line 77 def self.load_rsa_key(rsa_keypath) UI.user_error!("RSA key file #{rsa_keypath} does not exist") unless check_file(rsa_keypath) rsa_key = IO.read(rsa_keypath) if !rsa_key.to_s.empty? UI.success('Successfully loaded RSA key...') else UI.user_error!("Failed to load RSA key... #{rsa_keypath}") end return rsa_key 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 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fastlane/plugin/sftp/helper/sftp_helper.rb', line 14 def self.login(host, user, password, rsa_keypath, rsa_keypath_passphrase) if host.nil? || user.nil? || (password.nil? && rsa_keypath.nil?) UI.user_error!('server_url, server_user and server_password or server_key must be set') end if rsa_keypath # will raise an excetion if file is empty rsa_key = Helper::SftpHelper.load_rsa_key(rsa_keypath) end logging_level = :warn if ENV["DEBUG"] == "1" logging_level = :debug end = { verbose: logging_level, non_interactive: true } if !rsa_key.nil? UI.('Logging in with RSA key...') = .merge({ key_data: rsa_key, keys_only: true, passphrase: rsa_keypath_passphrase, auth_methods: ["publickey"] }) else UI.('Logging in with username/password...') = .merge({ password: password, auth_methods: ["password"] }) end return Net::SSH.start(host, user, ) end |
.remote_mkdir(sftp, remote_path) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/fastlane/plugin/sftp/helper/sftp_helper.rb', line 67 def self.remote_mkdir(sftp, remote_path) sftp.mkdir!(remote_path) rescue Net::SFTP::StatusException => e # the returned code depends on the implementation of the SFTP server # we handle code FX_FILE_ALREADY_EXISTS and FX_FAILURE the same codes = Net::SFTP::Constants::StatusCodes raise if e.code != codes::FX_FAILURE && e.code != codes::FX_FILE_ALREADY_EXISTS UI.("Remote dir #{remote_path} exists.") end |