fastlane-plugin-sftp 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc66d85ec195721ab4c6a225cf10ca1f2e3fb17b
4
- data.tar.gz: b6143dde40ce31cd9455793c83c00768aac0b7be
3
+ metadata.gz: ac51bdf322cdc7fd294125577506123707da8e7b
4
+ data.tar.gz: 4a15b34323794f3d2471d7cfec0fd1ae8b8ff04c
5
5
  SHA512:
6
- metadata.gz: c54feaffcef63bc4b86526dca8c741d230ccc5416973541a138f8974284462bffdc6d998d25669a6a7b88fcbe52e1ecb17f9c367b08c96830255fca2049104f4
7
- data.tar.gz: 18ac204189bd30f664976663f02f9cbacf444e6c1bddb58982d904b46c51feda708802584e759662319c8989a978ac6e55151607b07d356de103610d0f9130d1
6
+ metadata.gz: 06a5384854ea56c9fa2ae0164d3eda938bb85967122ade3f3588deb672c5034cd19c42d34d3b8270de0b1fda81f838438193d331e8e76e3bf584580961692289
7
+ data.tar.gz: bce48cc6866ce9e166bd4c7e488280c0a03b75d04c604c76a5c29bb2cc53cc8853b3fc1720fdf970f0b0a61bb5a0ad5231f6f654ff2947b3a1112cf4c62db0c9
@@ -17,6 +17,7 @@ module Fastlane
17
17
  #
18
18
 
19
19
  attr_accessor :host
20
+ attr_accessor :port
20
21
  attr_accessor :user
21
22
  attr_accessor :password
22
23
  attr_accessor :rsa_keypath
@@ -28,6 +29,7 @@ module Fastlane
28
29
  def initialize(options)
29
30
  self.options = options unless options.nil?
30
31
  self.host = options[:server_url]
32
+ self.port = options[:server_port]
31
33
  self.user = options[:server_user]
32
34
  self.password = options[:server_password]
33
35
  self.rsa_keypath = options[:server_key]
@@ -43,12 +45,11 @@ module Fastlane
43
45
  def download
44
46
  # Login & Download all files using RSA key or username/password
45
47
  UI.message('download...')
46
- session = Helper::SftpHelper.login(host, user, password, rsa_keypath, rsa_keypath_passphrase)
48
+ session = Helper::SftpHelper.login(host, port, user, password, rsa_keypath, rsa_keypath_passphrase)
47
49
  UI.message('Downloading files...')
48
50
 
49
51
  session.sftp.connect do |sftp|
50
- source_files = files.map { |entry| Helper::SftpHelper.generate_remote_path(user, entry) }
51
- downloads = sftp_download(sftp, source_files, target_dir)
52
+ downloads = sftp_download(sftp, files, target_dir)
52
53
  downloads.each(&:wait)
53
54
 
54
55
  # Lists the entries in a directory for verification
@@ -6,59 +6,82 @@ module Fastlane
6
6
  class Options
7
7
  def self.general_options
8
8
  return [
9
- FastlaneCore::ConfigItem.new(key: :server_url,
10
- short_option: '-r',
11
- optional: false,
12
- env_name: 'SERVER_URL',
13
- description: 'URL of your server'),
14
- FastlaneCore::ConfigItem.new(key: :server_user,
15
- short_option: '-u',
16
- optional: false,
17
- env_name: 'SERVER_USER',
18
- description: 'USER of your server'),
19
- FastlaneCore::ConfigItem.new(key: :server_password,
20
- short_option: '-p',
21
- optional: true,
22
- env_name: 'SERVER_PASSWORD',
23
- description: 'PASSWORD for your server (not for production)',
24
- conflicting_options: [:server_key],
25
- conflict_block: proc do |value|
26
- UI.user_error!("You can't use 'server_password' and '#{value.key}' options in one run.")
27
- end),
28
- FastlaneCore::ConfigItem.new(key: :server_key,
29
- short_option: '-k',
30
- optional: true,
31
- env_name: 'SERVER_KEY',
32
- description: 'RSA key for your server',
33
- conflicting_options: [:server_password],
34
- conflict_block: proc do |value|
35
- UI.user_error!("You can't use 'server_key' and '#{value.key}' options in one run.")
36
- end,
37
- verify_block: proc do |value|
38
- UI.user_error!("Key file '#{value}' does not exist") unless File.exist?(value)
39
- end),
40
- FastlaneCore::ConfigItem.new(key: :server_key_passphrase,
41
- short_option: '-v',
42
- optional: true,
43
- env_name: 'SERVER_KEY_PASSPHRASE',
44
- description: 'Optional passphrase for the RSA key for your server. If required but not provided, user will be asked for')
9
+ FastlaneCore::ConfigItem.new(
10
+ key: :server_url,
11
+ short_option: '-r',
12
+ optional: false,
13
+ env_name: 'SERVER_URL',
14
+ description: 'URL of your server'
15
+ ),
16
+ FastlaneCore::ConfigItem.new(
17
+ key: :server_port,
18
+ short_option: '-t',
19
+ optional: true,
20
+ env_name: 'SERVER_PORT',
21
+ type: Integer,
22
+ description: 'PORT used to connect to the server. Defaults to 22',
23
+ default_value: 22
24
+ ),
25
+ FastlaneCore::ConfigItem.new(
26
+ key: :server_user,
27
+ short_option: '-u',
28
+ optional: false,
29
+ env_name: 'SERVER_USER',
30
+ description: 'USER of your server'
31
+ ),
32
+ FastlaneCore::ConfigItem.new(
33
+ key: :server_password,
34
+ short_option: '-p',
35
+ optional: true,
36
+ env_name: 'SERVER_PASSWORD',
37
+ description: 'PASSWORD for your server (not for production)',
38
+ conflicting_options: [:server_key],
39
+ conflict_block: proc do |value|
40
+ UI.user_error!("You can't use 'server_password' and '#{value.key}' options in one run.")
41
+ end
42
+ ),
43
+ FastlaneCore::ConfigItem.new(
44
+ key: :server_key,
45
+ short_option: '-k',
46
+ optional: true,
47
+ env_name: 'SERVER_KEY',
48
+ description: 'RSA key for your server',
49
+ conflicting_options: [:server_password],
50
+ conflict_block: proc do |value|
51
+ UI.user_error!("You can't use 'server_key' and '#{value.key}' options in one run.")
52
+ end,
53
+ verify_block: proc do |value|
54
+ UI.user_error!("Key file '#{value}' does not exist") unless File.exist?(value)
55
+ end
56
+ ),
57
+ FastlaneCore::ConfigItem.new(
58
+ key: :server_key_passphrase,
59
+ short_option: '-v',
60
+ optional: true,
61
+ env_name: 'SERVER_KEY_PASSPHRASE',
62
+ description: 'Optional passphrase for the RSA key for your server. If required but not provided, user will be asked for'
63
+ )
45
64
  ]
46
65
  end
47
66
 
48
67
  def self.available_options_upload
49
68
  return [].concat(general_options).concat(
50
69
  [
51
- FastlaneCore::ConfigItem.new(key: :target_dir,
52
- short_option: '-x',
53
- description: 'target path on the server relative to the home directory of the user'),
54
- FastlaneCore::ConfigItem.new(key: :file_paths,
55
- short_option: '-j',
56
- description: 'List of files/folders to upload',
57
- type: Array,
58
- verify_block: proc do |value|
59
- UI.user_error!("you must provide at least one file to upload") if value.empty?
60
- value.each { |entry| UI.user_error!("file '#{entry}' does not exist") unless File.exist?(entry) }
61
- end)
70
+ FastlaneCore::ConfigItem.new(
71
+ key: :target_dir,
72
+ short_option: '-x',
73
+ description: 'target path on the server'
74
+ ),
75
+ FastlaneCore::ConfigItem.new(
76
+ key: :file_paths,
77
+ short_option: '-j',
78
+ description: 'List of files/folders to upload',
79
+ type: Array,
80
+ verify_block: proc do |value|
81
+ UI.user_error!("you must provide at least one file to upload") if value.empty?
82
+ value.each { |entry| UI.user_error!("file '#{entry}' does not exist") unless File.exist?(entry) }
83
+ end
84
+ )
62
85
  ]
63
86
  )
64
87
  end
@@ -66,17 +89,21 @@ module Fastlane
66
89
  def self.available_options_download
67
90
  return [].concat(general_options).concat(
68
91
  [
69
- FastlaneCore::ConfigItem.new(key: :target_dir,
70
- short_option: '-x',
71
- optional: true,
72
- description: 'local target path to a folder where all downloaded files should be put'),
73
- FastlaneCore::ConfigItem.new(key: :file_paths,
74
- short_option: '-j',
75
- description: 'List of remote files/folders to download relative to the home directory of the user',
76
- type: Array,
77
- verify_block: proc do |value|
78
- UI.user_error!("you must provide at least one file to download") if value.empty?
79
- end)
92
+ FastlaneCore::ConfigItem.new(
93
+ key: :target_dir,
94
+ short_option: '-x',
95
+ optional: true,
96
+ description: 'local target path to a folder where all downloaded files should be put'
97
+ ),
98
+ FastlaneCore::ConfigItem.new(
99
+ key: :file_paths,
100
+ short_option: '-j',
101
+ description: 'List of remote files/folders to download',
102
+ type: Array,
103
+ verify_block: proc do |value|
104
+ UI.user_error!("you must provide at least one file to download") if value.empty?
105
+ end
106
+ )
80
107
  ]
81
108
  )
82
109
  end
@@ -11,7 +11,7 @@ module Fastlane
11
11
  # as `Helper::SftpHelper.your_method`
12
12
  #
13
13
 
14
- def self.login(host, user, password, rsa_keypath, rsa_keypath_passphrase)
14
+ def self.login(host, port, user, password, rsa_keypath, rsa_keypath_passphrase)
15
15
  if host.nil? || user.nil? || (password.nil? && rsa_keypath.nil?)
16
16
  UI.user_error!('server_url, server_user and server_password or server_key must be set')
17
17
  end
@@ -29,6 +29,10 @@ module Fastlane
29
29
  verbose: logging_level,
30
30
  non_interactive: true
31
31
  }
32
+ unless port.nil?
33
+ UI.message("Using custom port #{port}...")
34
+ options[:port] = port
35
+ end
32
36
  if !rsa_key.nil?
33
37
  UI.message('Logging in with RSA key...')
34
38
  options = options.merge({
@@ -65,13 +69,38 @@ module Fastlane
65
69
  end
66
70
 
67
71
  def self.remote_mkdir(sftp, remote_path)
68
- sftp.mkdir!(remote_path)
72
+ return if remote_dir_exists?(sftp, remote_path)
73
+
74
+ path_parts = Pathname(remote_path).each_filename.to_a
75
+ UI.message("Pathparts = #{path_parts}")
76
+ path_value = remote_path.start_with?("/") ? "" : "."
77
+ path_parts.each do |path|
78
+ begin
79
+ path_value = path_value + File::SEPARATOR + path
80
+ UI.message("creating #{path_value}")
81
+ sftp.mkdir!(path_value)
82
+ rescue Net::SFTP::StatusException => e
83
+ # ignoring all errors while creating sub paths
84
+ UI.message("operation failed: #{e.message}")
85
+ end
86
+ end
87
+
88
+ # check for existence again
89
+ folder_exists = remote_dir_exists?(sftp, remote_path)
90
+ UI.user_error!("remote folder #{remote_path} does not exist and could not be created") unless folder_exists
91
+ end
92
+
93
+ def self.remote_dir_exists?(sftp, remote_path)
94
+ UI.message("Checking remote directory #{remote_path}")
95
+ attrs = sftp.stat!(remote_path)
96
+ UI.user_error!("Path #{remote_path} is not a directory") unless attrs.directory?
97
+ return true
69
98
  rescue Net::SFTP::StatusException => e
70
- # the returned code depends on the implementation of the SFTP server
71
- # we handle code FX_FILE_ALREADY_EXISTS and FX_FAILURE the same
99
+ # directory does not exist, we have to create it
72
100
  codes = Net::SFTP::Constants::StatusCodes
73
- raise if e.code != codes::FX_FAILURE && e.code != codes::FX_FILE_ALREADY_EXISTS
74
- UI.message("Remote dir #{remote_path} exists.")
101
+ raise if e.code != codes::FX_NO_SUCH_FILE && e.code != codes::FX_NO_SUCH_PATH
102
+ UI.message("Remote directory #{remote_path} does not exist")
103
+ return false
75
104
  end
76
105
 
77
106
  def self.load_rsa_key(rsa_keypath)
@@ -85,14 +114,6 @@ module Fastlane
85
114
  end
86
115
  return rsa_key
87
116
  end
88
-
89
- def self.generate_remote_path(user, target_dir)
90
- path = File.join('/', user, target_dir)
91
- if user != "root"
92
- path = File.join('/home', path)
93
- end
94
- return path
95
- end
96
117
  end
97
118
  end
98
119
  end
@@ -17,6 +17,7 @@ module Fastlane
17
17
  #
18
18
 
19
19
  attr_accessor :host
20
+ attr_accessor :port
20
21
  attr_accessor :user
21
22
  attr_accessor :password
22
23
  attr_accessor :rsa_keypath
@@ -28,6 +29,7 @@ module Fastlane
28
29
  def initialize(options)
29
30
  self.options = options unless options.nil?
30
31
  self.host = options[:server_url]
32
+ self.port = options[:server_port]
31
33
  self.user = options[:server_user]
32
34
  self.password = options[:server_password]
33
35
  self.rsa_keypath = options[:server_key]
@@ -44,13 +46,11 @@ module Fastlane
44
46
  # Login & Upload all files using RSA key or username/password
45
47
  UI.message('upload...')
46
48
 
47
- session = Helper::SftpHelper.login(host, user, password, rsa_keypath, rsa_keypath_passphrase)
49
+ session = Helper::SftpHelper.login(host, port, user, password, rsa_keypath, rsa_keypath_passphrase)
48
50
  UI.message('Uploading files...')
49
51
 
50
52
  session.sftp.connect do |sftp|
51
- Helper::SftpHelper.remote_mkdir(sftp, Helper::SftpHelper.generate_remote_path(user, target_dir))
52
- path = target_dir
53
-
53
+ Helper::SftpHelper.remote_mkdir(sftp, target_dir)
54
54
  uploads = []
55
55
  files.each do |file|
56
56
  next unless Helper::SftpHelper.check_file(file)
@@ -64,7 +64,7 @@ module Fastlane
64
64
  uploads.each(&:wait)
65
65
 
66
66
  # Lists the entries in a directory for verification
67
- sftp.dir.foreach(path) do |entry|
67
+ sftp.dir.foreach(target_dir) do |entry|
68
68
  UI.message(entry.longname)
69
69
  end
70
70
  end
@@ -1,6 +1,6 @@
1
1
  module Fastlane
2
2
  module Sftp
3
- VERSION = "1.0.0".freeze
3
+ VERSION = "1.1.0".freeze
4
4
  SUMMARY = 'Fastlane plugin to upload or dowload files/folders via SFTP'.freeze
5
5
  DESCRIPTION = 'Fastlane plugin SFTP'.freeze
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-sftp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Limberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-13 00:00:00.000000000 Z
11
+ date: 2019-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh