Class: AppRepo::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/apprepo/uploader.rb

Overview

Responsible for performing the SFTP operation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Uploader

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/apprepo/uploader.rb', line 33

def initialize(options)
  self.options = options unless options.nil?
  self.host = options[:repo_url] # 'repo.teacloud.net'
  self.user = options[:repo_user]
  self.password = options[:repo_password]
  self.rsa_keypath = options[:repo_key] # '../assets/circle.key'
  self.ipa_path = options[:ipa] # '../sampleapp.ipa'
  self.manifest_path = options[:manifest_path] # '../assets/example_manifest.json'
  self.appcode = options[:appcode]

  # AppRepo::Uploader.new.run!
  # FastlaneCore::PrintTable.print_values(config: nil , hide_keys: [:app],
  # mask_keys: ['app_review_information.demo_password'],
  # title: "deliver #{AppRepo::VERSION} Summary") # options
end

Instance Attribute Details

#appcodeObject

Returns the value of attribute appcode.



29
30
31
# File 'lib/apprepo/uploader.rb', line 29

def appcode
  @appcode
end

#hostObject

These want to be an input parameters:



23
24
25
# File 'lib/apprepo/uploader.rb', line 23

def host
  @host
end

#ipa_pathObject

Returns the value of attribute ipa_path.



27
28
29
# File 'lib/apprepo/uploader.rb', line 27

def ipa_path
  @ipa_path
end

#manifest_pathObject

Returns the value of attribute manifest_path.



28
29
30
# File 'lib/apprepo/uploader.rb', line 28

def manifest_path
  @manifest_path
end

#optionsObject

Returns the value of attribute options.



17
18
19
# File 'lib/apprepo/uploader.rb', line 17

def options
  @options
end

#passwordObject

Returns the value of attribute password.



25
26
27
# File 'lib/apprepo/uploader.rb', line 25

def password
  @password
end

#rsa_keypathObject

Returns the value of attribute rsa_keypath.



26
27
28
# File 'lib/apprepo/uploader.rb', line 26

def rsa_keypath
  @rsa_keypath
end

#userObject

Returns the value of attribute user.



24
25
26
# File 'lib/apprepo/uploader.rb', line 24

def user
  @user
end

Instance Method Details

#download_manifest_onlyObject

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/apprepo/uploader.rb', line 94

def download_manifest_only
  FastlaneCore::UI.message('download_manifest_only...')
  rsa_key = load_rsa_key(rsa_keypath)
  success = true
  if !rsa_key.nil?
    FastlaneCore::UI.message('Logging in with RSA key for download...')
    Net::SSH.start(host, user, key_data: rsa_key, keys_only: true) do |ssh|
      FastlaneCore::UI.message('Uploading UPA & Manifest...')
      success = ssh_sftp_download(ssh, manifest_path)
    end
  else
    FastlaneCore::UI.message('Logging in for download...')
    Net::SSH.start(host, user, password: password) do |ssh|
      FastlaneCore::UI.message('Uploading UPA & Manifest...')
      success = ssh_sftp_download(ssh, manifest_path)
    end
  end
  success
end

#uploadObject

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/apprepo/uploader.rb', line 55

def upload
  # Login & Upload IPA with metadata using RSA key or username/password
  FastlaneCore::UI.message('upload...')

  if host.nil? || user.nil?
    FastlaneCore::UI.user_error('repo_url, repo_user and repo_pasdword or repo_key must be set on upload')
    return false
  end

  if rsa_keypath
    rsa_key = load_rsa_key(rsa_keypath)
    if rsa_key.nil?
      FastlaneCore::UI.user_error('Failed to load RSA key... ' + options[:rsa_keypath])
    end
  end

  success = false
  if !rsa_key.nil?
    FastlaneCore::UI.message('Logging in with RSA key...')
    Net::SSH.start(host, user, key_data: rsa_key, keys_only: true) do |ssh|
      FastlaneCore::UI.message('Uploading IPA & Manifest...')
      success = ssh_sftp_upload(ssh, ipa_path, manifest_path)
    end
  else
    FastlaneCore::UI.message('Logging in with username/password...')
    Net::SSH.start(host, user, password: password) do |ssh|
      FastlaneCore::UI.message('Uploading IPA & Manifest...')
      success = ssh_sftp_upload(ssh, ipa_path, manifest_path)
    end
  end
  success
end