Class: DeployGate::Builds::Ios::Export
- Inherits:
-
Object
- Object
- DeployGate::Builds::Ios::Export
- Defined in:
- lib/deploygate/builds/ios/export.rb
Constant Summary collapse
- AD_HOC =
'ad-hoc'- ENTERPRISE =
'enterprise'- SUPPORT_EXPORT_METHOD =
[AD_HOC, ENTERPRISE]
- PROFILE_EXTNAME =
'.mobileprovision'
Class Method Summary collapse
- .adhoc?(profile_path) ⇒ Boolean
- .codesigning_identity(profile_path) ⇒ String
- .find_local_data(bundle_identifier, uuid = nil) ⇒ Hash
- .inhouse?(profile_path) ⇒ Boolean
- .installed_certificate?(profile_path) ⇒ Boolean
- .installed_certificates ⇒ Array
- .installed_distribution_certificate_ids ⇒ Array
- .installed_distribution_conflicting_certificates ⇒ Array
- .load_profile_paths ⇒ Object
- .method(profile_path) ⇒ String
- .profile_to_plist(profile_path) ⇒ Hash
- .select_profile(profile_paths) ⇒ String
Class Method Details
.adhoc?(profile_path) ⇒ Boolean
156 157 158 159 |
# File 'lib/deploygate/builds/ios/export.rb', line 156 def adhoc?(profile_path) profile = profile_to_plist(profile_path) !profile['Entitlements']['get-task-allow'] && profile['ProvisionsAllDevices'].nil? end |
.codesigning_identity(profile_path) ⇒ String
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/deploygate/builds/ios/export.rb', line 125 def codesigning_identity(profile_path) profile = profile_to_plist(profile_path) identity = nil profile['DeveloperCertificates'].each do |cert| certificate_str = cert.read certificate = OpenSSL::X509::Certificate.new certificate_str id = OpenSSL::Digest::SHA1.new(certificate.to_der).to_s.upcase! available = `security find-identity -v -p codesigning` available.split("\n").each do |current| next if current.include? "REVOKED" begin search = current.match(/.*\) (.*) \"(.*)\"/) identity = search[2] if id == search[1] rescue end end end identity end |
.find_local_data(bundle_identifier, uuid = nil) ⇒ Hash
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 |
# File 'lib/deploygate/builds/ios/export.rb', line 14 def find_local_data(bundle_identifier, uuid = nil) result_profiles = {} teams = {} profile_paths = load_profile_paths profiles = profile_paths.map{|p| profile_to_plist(p)} profiles.reject! {|profile| profile['UUID'] != uuid} unless uuid.nil? profiles.each do |profile| entities = profile['Entitlements'] unless entities['get-task-allow'] team = entities['com.apple.developer.team-identifier'] application_id = entities['application-identifier'] application_id.slice!(/^#{team}\./) application_id = '.' + application_id if application_id == '*' if bundle_identifier.match(application_id) && DateTime.now < profile['ExpirationDate'] && installed_certificate?(profile['Path']) teams[team] = profile['TeamName'] if teams[team].nil? result_profiles[team] = [] if result_profiles[team].nil? result_profiles[team].push(profile['Path']) end end end { :teams => teams, :profiles => result_profiles } end |
.inhouse?(profile_path) ⇒ Boolean
163 164 165 166 |
# File 'lib/deploygate/builds/ios/export.rb', line 163 def inhouse?(profile_path) profile = profile_to_plist(profile_path) !profile['Entitlements']['get-task-allow'] && !profile['ProvisionsAllDevices'].nil? end |
.installed_certificate?(profile_path) ⇒ Boolean
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/deploygate/builds/ios/export.rb', line 47 def installed_certificate?(profile_path) profile = profile_to_plist(profile_path) certs = profile['DeveloperCertificates'].map do |cert| certificate_str = cert.read certificate = OpenSSL::X509::Certificate.new certificate_str id = OpenSSL::Digest::SHA1.new(certificate.to_der).to_s.upcase! installed_distribution_certificate_ids.include?(id) end certs.include?(true) end |
.installed_certificates ⇒ Array
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/deploygate/builds/ios/export.rb', line 100 def installed_certificates available = `security find-identity -v -p codesigning` certificates = [] available.split("\n").each do |current| next if current.include? "REVOKED" certificates << current end certificates end |
.installed_distribution_certificate_ids ⇒ Array
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/deploygate/builds/ios/export.rb', line 59 def installed_distribution_certificate_ids certificates = installed_certificates() ids = [] certificates.each do |current| next unless current.match(/iPhone Distribution:/) begin (ids << current.match(/.*\) (.*) \".*/)[1]) rescue # the last line does not match end end ids end |
.installed_distribution_conflicting_certificates ⇒ Array
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/deploygate/builds/ios/export.rb', line 75 def installed_distribution_conflicting_certificates certificates = installed_certificates() names = [] certificates.each do |current| begin names << current.match(/(iPhone Distribution:.*)/)[1] rescue end end conflicting_names = names.select{|e| names.index(e) != names.rindex(e)}.uniq conflicting_certificates = [] certificates.each do |current| begin name = current.match(/(iPhone Distribution:.*)/)[1] next unless conflicting_names.include?(name) conflicting_certificates << current rescue end end conflicting_certificates end |
.load_profile_paths ⇒ Object
168 169 170 171 |
# File 'lib/deploygate/builds/ios/export.rb', line 168 def load_profile_paths profiles_path = File.("~") + "/Library/MobileDevice/Provisioning Profiles/*.mobileprovision" Dir[profiles_path] end |
.method(profile_path) ⇒ String
150 151 152 |
# File 'lib/deploygate/builds/ios/export.rb', line 150 def method(profile_path) adhoc?(profile_path) ? AD_HOC : ENTERPRISE end |
.profile_to_plist(profile_path) ⇒ Hash
175 176 177 178 179 180 181 182 183 |
# File 'lib/deploygate/builds/ios/export.rb', line 175 def profile_to_plist(profile_path) File.open(profile_path) do |profile| asn1 = OpenSSL::ASN1.decode(profile.read) plist_str = asn1.value[1].value[0].value[2].value[1].value[0].value plist = Plist.parse_xml plist_str.force_encoding('UTF-8') plist['Path'] = profile_path return plist end end |
.select_profile(profile_paths) ⇒ String
113 114 115 116 117 118 119 120 121 |
# File 'lib/deploygate/builds/ios/export.rb', line 113 def select_profile(profile_paths) select = nil profile_paths.each do |path| select = path if adhoc?(path) && select.nil? select = path if inhouse?(path) end select end |