Class: AppEntitlementsStatistics::MobileProvision

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb

Overview

.mobileprovision file parser

Defined Under Namespace

Classes: DeveloperCertificate

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ MobileProvision

Returns a new instance of MobileProvision.



13
14
15
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 13

def initialize(path)
  @path = path
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



271
272
273
274
275
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 271

def method_missing(method_name, *args, &block)
  mobileprovision.try(:[], method_name.to_s.ai_camelcase) ||
    mobileprovision.send(method_name) ||
    super
end

Instance Method Details

#[](key) ⇒ Object



252
253
254
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 252

def [](key)
  mobileprovision.try(:[], key.to_s)
end

#adhoc?Boolean

Returns:

  • (Boolean)


110
111
112
113
114
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 110

def adhoc?
  return false if platform == :macos # macOS no need adhoc

  !development? && !devices.nil?
end

#app_nameObject



21
22
23
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 21

def app_name
  mobileprovision.try(:[], 'AppIDName')
end

#appstore?Boolean

Detect app store type

related link: developer.apple.com/library/archive/qa/qa1830/_index.html

Returns:

  • (Boolean)


99
100
101
102
103
104
105
106
107
108
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 99

def appstore?
  case platform.downcase.to_sym
  when :ios
    !development? && entitlements.key?('beta-reports-active')
  when :macos
    !development?
  else
    raise Error, "Not implement with platform: #{platform}"
  end
end

#created_dateObject



61
62
63
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 61

def created_date
  mobileprovision.try(:[], 'CreationDate')
end

#developer_certsObject



73
74
75
76
77
78
79
80
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 73

def developer_certs
  certs = mobileprovision.try(:[], 'DeveloperCertificates')
  return if certs.empty?

  certs.each_with_object([]) do |cert, obj|
    obj << DeveloperCertificate.new(cert)
  end
end

#development?Boolean

Detect is development type of mobileprovision

related link: stackoverflow.com/questions/1003066/what-does-get-task-allow-do-in-xcode

Returns:

  • (Boolean)


85
86
87
88
89
90
91
92
93
94
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 85

def development?
  case platform.downcase.to_sym
  when :ios
    entitlements['get-task-allow'] == true
  when :macos
    !devices.nil?
  else
    raise Error, "Not implement with platform: #{platform}"
  end
end

#devicesObject



45
46
47
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 45

def devices
  mobileprovision.try(:[], 'ProvisionedDevices')
end

#empty?Boolean

Returns:

  • (Boolean)


256
257
258
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 256

def empty?
  mobileprovision.nil?
end

#enabled_capabilitiesObject



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 126

def enabled_capabilities
  capabilities = Hash.new
  entitlements.each do |key, value|
      case key
      when 'com.apple.developer.game-center'
          capabilities['Game Center'] = {
              key => value
          }
      when 'keychain-access-groups' 
          capabilities['Keychain sharing'] =   {
              key => value
          }
      when 'aps-environment'
          capabilities['Push Notifications'] = {
              key => value
          }
      when 'com.apple.developer.applesignin'
          capabilities['Sign In with Apple'] = {
              key => value
          }
      when 'com.apple.developer.siri'
          capabilities['SiriKit'] = {
              key => value
          }
      when 'com.apple.security.application-groups'
          capabilities['App Groups'] = {
              key => value
          }
      when 'com.apple.developer.associated-domains'
          capabilities['Associated Domains']  =  {
              key => value
          }
      when 'com.apple.developer.default-data-protection'
          capabilities['Data Protection'] = {
              key => value
          }
      when 'com.apple.developer.networking.networkextension'
          capabilities ['Network Extensions'] = {
              key => value
          }
      when 'com.apple.developer.networking.vpn.api'
          capabilities ['Personal VPN'] =  {
              key => value
          }
      when 'com.apple.developer.healthkit',
          'com.apple.developer.healthkit.access'
          capabilities['HealthKit']  = {
              'com.apple.developer.healthkit' => entitlements['com.apple.developer.healthkit'],
              'com.apple.developer.healthkit.access' => entitlements['com.apple.developer.healthkit.access'],
          } unless capabilities.include?('HealthKit')
      when 'com.apple.developer.icloud-services',
          'com.apple.developer.icloud-container-identifiers'
          capabilities['iCloud']  = {
              'com.apple.developer.icloud-services' => entitlements['com.apple.developer.icloud-services'],
              'com.apple.developer.icloud-container-identifiers' => entitlements['com.apple.developer.icloud-container-identifiers'],
          } unless capabilities.include?('iCloud')
      when 'com.apple.developer.in-app-payments'
          capabilities['Apple Pay'] = {
              key => value
          }
      when 'com.apple.developer.homekit'
          capabilities['HomeKit'] =  {
              key => value
          }
      when 'com.apple.developer.user-fonts'
          capabilities['Fonts'] = {
              key => value
          }
      when 'com.apple.developer.pass-type-identifiers'
          capabilities['Wallet'] =  {
              key => value
          }
      when 'inter-app-audio'
          capabilities['Inter-App Audio'] =  {
              key => value
          }
      when 'com.apple.developer.networking.multipath'
          capabilities['Multipath'] = {
              key => value
          }
      when 'com.apple.developer.authentication-services.autofill-credential-provider'
          capabilities['AutoFill Credential Provider'] = {
              key => value
          }
      when 'com.apple.developer.networking.wifi-info'
          capabilities['Access WiFi Information'] = {
              key => value
          }
      when 'com.apple.external-accessory.wireless-configuration'
          capabilities['Wireless Accessory Configuration'] = {
              key => value
          }
      when 'com.apple.developer.kernel.extended-virtual-addressing'
          capabilities['Extended Virtual Address Space'] = {
              key => value
          }
      when 'com.apple.developer.nfc.readersession.formats'
          capabilities['NFC Tag Reading'] =  {
              key => value
          }
      when 'com.apple.developer.ClassKit-environment'
          capabilities['ClassKit'] =  {
              key => value
          }
      when 'com.apple.developer.networking.HotspotConfiguration'
          capabilities['Hotspot'] =  {
              key => value
          }
      when 'com.apple.developer.devicecheck.appattest-environment'
          capabilities['App Attest'] =  {
              key => value
          }
      when 'com.apple.developer.coremedia.hls.low-latency'
          capabilities['Low Latency HLS'] =  {
              key => value
          }
      when 'com.apple.developer.associated-domains.mdm-managed'
          capabilities['MDM Managed Associated Domains'] =  {
              key => value
          }
      end
  end
  capabilities
end

#enterprise?Boolean Also known as: inhouse?

Returns:

  • (Boolean)


116
117
118
119
120
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 116

def enterprise?
  return false if platform == :macos # macOS no need adhoc

  !development? && !adhoc? && !appstore?
end

#entitlementsObject



69
70
71
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 69

def entitlements
  mobileprovision.try(:[], 'Entitlements')
end

#expired_dateObject



65
66
67
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 65

def expired_date
  mobileprovision.try(:[], 'ExpirationDate')
end

#mobileprovisionObject



260
261
262
263
264
265
266
267
268
269
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 260

def mobileprovision
  return @mobileprovision = nil unless File.exist?(@path)

  data = File.read(@path)
  data = strip_plist_wrapper(data) unless bplist?(data)
  list = CFPropertyList::List.new(data: data).value
  @mobileprovision = CFPropertyList.native_types(list)
rescue CFFormatError
  @mobileprovision = nil
end

#nameObject



17
18
19
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 17

def name
  mobileprovision.try(:[], 'Name')
end

#platformObject



41
42
43
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 41

def platform
  platforms[0]
end

#platformsObject



32
33
34
35
36
37
38
39
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 32

def platforms
  return unless platforms = mobileprovision.try(:[], 'Platform')

  platforms.map do |v|
    v = 'macOS' if v == 'OSX'
    v.downcase.to_sym
  end
end

#profile_nameObject



57
58
59
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 57

def profile_name
  mobileprovision.try(:[], 'Name')
end

#respond_to_missing?(method_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


277
278
279
280
281
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 277

def respond_to_missing?(method_name, *args)
  mobileprovision.key?(method_name.to_s.ai_camelcase) ||
    mobileprovision.respond_to?(method_name) ||
    super
end

#team_identifierObject



49
50
51
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 49

def team_identifier
  mobileprovision.try(:[], 'TeamIdentifier')
end

#team_nameObject



53
54
55
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 53

def team_name
  mobileprovision.try(:[], 'TeamName')
end

#typeObject



25
26
27
28
29
30
# File 'lib/cocoapods-entitlements-statistics/app_entitlements_statistics/mobile_provision.rb', line 25

def type
  return :development if development?
  return :adhoc if adhoc?
  return :appstore if appstore?
  return :enterprise if enterprise?
end