Class: Spaceship::Portal::ProvisioningProfile

Inherits:
Spaceship::PortalBase show all
Defined in:
lib/spaceship/portal/provisioning_profile.rb

Overview

Represents a provisioning profile of the Apple Dev Portal

Direct Known Subclasses

AdHoc, AppStore, Development, InHouse

Defined Under Namespace

Classes: AdHoc, AppStore, Development, InHouse

Instance Attribute Summary collapse

Attributes inherited from Base

#raw_data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Spaceship::PortalBase

client

Methods inherited from Base

attr_accessor, attr_mapping, attributes, #attributes, #client, #initialize, #inspect, mapping_module, method_missing, set_client, #setup, #to_s

Constructor Details

This class inherits a constructor from Spaceship::Base

Instance Attribute Details

#appApp

A reference to the app this profile is for. You can then easily access the value directly

Examples:

Example Value

<Spaceship::App
  @app_id="2UMR2S6PAA"
  @name="App Name"
  @platform="ios"
  @prefix="5A997XSAAA"
  @bundle_id="com.krausefx.app"
  @is_wildcard=false
  @dev_push_enabled=false
  @prod_push_enabled=false>

Usage

profile.app.name

Returns:

  • (App)

    The app this profile is for



86
87
88
# File 'lib/spaceship/portal/provisioning_profile.rb', line 86

def app
  @app
end

#certificatesArray

Returns A list of certificates used for this profile.

Examples:

Example Value

[
 <Spaceship::Certificate::Production
   @status=nil
   @id="XC5PH8D4AA"
   @name="iOS Distribution"
   @created=nil
   @expires=#<DateTime: 2015-11-25T22:45:50+00:00 ((2457352j,81950s,0n),+0s,2299161j)>
   @owner_type="team"
   @owner_name=nil
   @owner_id=nil
   @type_display_id="R58UK2EWAA">]
]

Usage

profile.certificates.first.id

Returns:

  • (Array)

    A list of certificates used for this profile



105
106
107
# File 'lib/spaceship/portal/provisioning_profile.rb', line 105

def certificates
  @certificates
end

#devicesArray

Returns A list of devices this profile is enabled for. This will always be [] for AppStore profiles.

Examples:

Example Value

<Spaceship::Device
  @id="WXQ7V239BE"
  @name="Grahams iPhone 4s"
  @udid="ba0ac7d70f7a14c6fa02ef0e02f4fe9c5178e2f7"
  @platform="ios"
  @status="c">]

Usage

profile.devices.first.name

Returns:

  • (Array)

    A list of devices this profile is enabled for. This will always be [] for AppStore profiles



120
121
122
# File 'lib/spaceship/portal/provisioning_profile.rb', line 120

def devices
  @devices
end

#distribution_methodString

Returns The profile distribution type. You probably want to use the class type to detect the profile type instead of this string.

Examples:

AppStore Profile

"store"

AdHoc Profile

"adhoc"

Development Profile

"limited"

Returns:

  • (String)

    The profile distribution type. You probably want to use the class type to detect the profile type instead of this string.



32
33
34
# File 'lib/spaceship/portal/provisioning_profile.rb', line 32

def distribution_method
  @distribution_method
end

#expiresDateTime

Returns The date and time of when the profile expires.

Examples:

#<DateTime: 2015-11-25T22:45:50+00:00 ((2457352j,81950s,0n),+0s,2299161j)>

Returns:

  • (DateTime)

    The date and time of when the profile expires.



22
23
24
# File 'lib/spaceship/portal/provisioning_profile.rb', line 22

def expires
  @expires
end

#idString

Returns The ID generated by the Dev Portal You’ll probably not really need this value.

Examples:

"2MAY7NPHAA"

Returns:

  • (String)

    The ID generated by the Dev Portal You’ll probably not really need this value



9
10
11
# File 'lib/spaceship/portal/provisioning_profile.rb', line 9

def id
  @id
end

#managing_appObject

No information about this attribute



67
68
69
# File 'lib/spaceship/portal/provisioning_profile.rb', line 67

def managing_app
  @managing_app
end

#nameString

Returns The name of this profile.

Examples:

"com.krausefx.app AppStore"

Returns:

  • (String)

    The name of this profile



37
38
39
# File 'lib/spaceship/portal/provisioning_profile.rb', line 37

def name
  @name
end

#platformString

Returns The supported platform for this profile.

Examples:

"ios"

Returns:

  • (String)

    The supported platform for this profile



64
65
66
# File 'lib/spaceship/portal/provisioning_profile.rb', line 64

def platform
  @platform
end

#statusString

Returns The status of this profile.

Examples:

Active (profile is fine)

"Active"

Expired (time ran out)

"Expired"

Invalid (e.g. code signing identity not available any more)

"Invalid"

Returns:

  • (String)

    The status of this profile



46
47
48
# File 'lib/spaceship/portal/provisioning_profile.rb', line 46

def status
  @status
end

#typeString

Returns The type of the profile (development or distribution). You’ll probably not need this value.

Examples:

Distribution

"iOS Distribution"

Development

"iOS Development"

Returns:

  • (String)

    The type of the profile (development or distribution). You’ll probably not need this value



54
55
56
# File 'lib/spaceship/portal/provisioning_profile.rb', line 54

def type
  @type
end

#uuidString

Returns The UDID of this provisioning profile This value is used for example for code signing It is also contained in the actual profile.

Examples:

"23d7df3b-9767-4e85-a1ea-1df4d8f32fec"

Returns:

  • (String)

    The UDID of this provisioning profile This value is used for example for code signing It is also contained in the actual profile



16
17
18
# File 'lib/spaceship/portal/provisioning_profile.rb', line 16

def uuid
  @uuid
end

#versionString

Returns This will always be “2”.

Examples:

"2"

Returns:

  • (String)

    This will always be “2”



59
60
61
# File 'lib/spaceship/portal/provisioning_profile.rb', line 59

def version
  @version
end

Class Method Details

.allArray

Returns all profiles registered for this account If you’re calling this from a subclass (like AdHoc), this will only return the profiles that are of this type

Returns:

  • (Array)

    Returns all profiles registered for this account If you’re calling this from a subclass (like AdHoc), this will only return the profiles that are of this type



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/spaceship/portal/provisioning_profile.rb', line 244

def all
  profiles = client.provisioning_profiles.map do |profile|
    self.factory(profile)
  end

  # filter out the profiles managed by xcode
  profiles.delete_if do |profile|
    profile.managed_by_xcode?
  end

  return profiles if self == ProvisioningProfile

  # only return the profiles that match the class
  profiles.select do |profile|
    profile.class == self
  end
end

.create!(name: nil, bundle_id: nil, certificate: nil, devices: []) ⇒ ProvisioningProfile

Create a new provisioning profile

Parameters:

  • name (String) (defaults to: nil)

    : The name of the provisioning profile on the Dev Portal

  • bundle_id (String) (defaults to: nil)

    : The app identifier, this paramter is required

  • certificate (Certificate) (defaults to: nil)

    : The certificate that should be used with this provisioning profile. You can also pass an array of certificates to this method. This will only work for development profiles

  • devices (Array) (defaults to: [])

    (optional): An array of Device objects that should be used in this profile. It is recommend to not pass devices as spaceship will automatically add all devices for AdHoc and Development profiles and add none for AppStore and Enterprise Profiles

Returns:



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
# File 'lib/spaceship/portal/provisioning_profile.rb', line 195

def create!(name: nil, bundle_id: nil, certificate: nil, devices: [])
  raise "Missing required parameter 'bundle_id'" if bundle_id.to_s.empty?
  raise "Missing required parameter 'certificate'. e.g. use `Spaceship::Certificate::Production.all.first`" if certificate.to_s.empty?

  app = Spaceship::App.find(bundle_id)
  raise "Could not find app with bundle id '#{bundle_id}'" unless app

  # Fill in sensible default values
  name ||= [bundle_id, self.pretty_type].join(' ')

  devices = [] if (self == AppStore or self == InHouse) # App Store Profiles MUST NOT have devices

  certificate_parameter = certificate.collect { |c| c.id } if certificate.kind_of?Array
  certificate_parameter ||= [certificate.id]

  # Fix https://github.com/KrauseFx/fastlane/issues/349
  certificate_parameter = certificate_parameter.first if certificate_parameter.count == 1

  if devices.nil? or devices.count == 0
    if self == Development or self == AdHoc
      # For Development and AdHoc we usually want all devices by default
      devices = Spaceship::Device.all
    end
  end

  def send_create_request(name, type, app_id, certificate_parameter, devices)
    tries ||= 5
    client.create_provisioning_profile!(name, type, app_id, certificate_parameter, devices)
  rescue => ex 
    unless (tries -= 1).zero?
      sleep 3
      retry
    end

    raise ex # re-raise the exception
  end

  profile = send_create_request(name,
                                self.type,
                                app.app_id,
                                certificate_parameter,
                                devices.map {|d| d.id} )
  
  self.new(profile)
end

.factory(attrs) ⇒ Object

Create a new object based on a hash. This is used to create a new object based on the server response.



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
# File 'lib/spaceship/portal/provisioning_profile.rb', line 149

def factory(attrs)
  # Ad Hoc Profiles look exactly like App Store profiles, but usually include devices
  attrs['distributionMethod'] = 'adhoc' if attrs['distributionMethod'] == 'store' && attrs['devices'].size > 0
  # available values of `distributionMethod` at this point: ['adhoc', 'store', 'limited']

  klass = case attrs['distributionMethod']
  when 'limited'
    Development
  when 'store'
    AppStore
  when 'adhoc'
    AdHoc
  when 'inhouse'
    InHouse
  else
    raise "Can't find class '#{attrs['distributionMethod']}'"
  end

  attrs['appId'] = App.factory(attrs['appId'])
  attrs['devices'].map! { |device| Device.factory(device) }
  attrs['certificates'].map! { |cert| Certificate.factory(cert) }

  klass.client = @client
  klass.new(attrs)
end

.find_by_bundle_id(bundle_id) ⇒ Array

Returns an array of provisioning profiles matching the bundle identifier Returns [] if no profiles were found This may also contain invalid or expired profiles

Returns:

  • (Array)

    Returns an array of provisioning profiles matching the bundle identifier Returns [] if no profiles were found This may also contain invalid or expired profiles



266
267
268
269
270
# File 'lib/spaceship/portal/provisioning_profile.rb', line 266

def find_by_bundle_id(bundle_id)
  all.find_all do |profile|
    profile.app.bundle_id == bundle_id
  end
end

.pretty_typeString

Returns The human readable name of this profile type.

Examples:

"AppStore"
"AdHoc"
"Development"
"InHouse"

Returns:

  • (String)

    The human readable name of this profile type.



181
182
183
# File 'lib/spaceship/portal/provisioning_profile.rb', line 181

def pretty_type
  name.split('::').last
end

.typeString

Returns The profile type used for web requests to the Dev Portal.

Examples:

"limited"
"store"
"adhoc"
"inhouse"

Returns:

  • (String)

    The profile type used for web requests to the Dev Portal



143
144
145
# File 'lib/spaceship/portal/provisioning_profile.rb', line 143

def type
  raise "You cannot create a ProvisioningProfile without a type. Use a subclass."
end

Instance Method Details

#certificate_valid?Bool

Is the certificate of this profile available?

Returns:

  • (Bool)

    is the certificate valid?



379
380
381
382
383
384
385
386
387
# File 'lib/spaceship/portal/provisioning_profile.rb', line 379

def certificate_valid?
  return false if (certificates || []).count == 0
  certificates.each do |c|
    if Spaceship::Certificate.all.collect { |s| s.id }.include?(c.id)
      return true
    end
  end
  return false
end

#delete!Object

Delete the provisioning profile



314
315
316
# File 'lib/spaceship/portal/provisioning_profile.rb', line 314

def delete!
  client.delete_provisioning_profile!(self.id)
end

#downloadString

Download the current provisioning profile. This will not store the provisioning profile on the file system. Instead this method will return the content of the profile.

Examples:

File.write("path.mobileprovision", profile.download)

Returns:

  • (String)

    The content of the provisioning profile You’ll probably want to store it on the file system



309
310
311
# File 'lib/spaceship/portal/provisioning_profile.rb', line 309

def download
  client.download_provisioning_profile(self.id)
end

#managed_by_xcode?Bool

Returns Is this profile managed by Xcode?.

Returns:

  • (Bool)

    Is this profile managed by Xcode?



395
396
397
# File 'lib/spaceship/portal/provisioning_profile.rb', line 395

def managed_by_xcode?
  managing_app == 'Xcode'
end

#repair!ProvisioningProfile

Repair an existing provisioning profile alias to update!

Returns:

  • (ProvisioningProfile)

    A new provisioning profile, as the repair method will generate a profile with a new ID



322
323
324
# File 'lib/spaceship/portal/provisioning_profile.rb', line 322

def repair!
  update!
end

#send_create_request(name, type, app_id, certificate_parameter, devices) ⇒ Object



220
221
222
223
224
225
226
227
228
229
230
# File 'lib/spaceship/portal/provisioning_profile.rb', line 220

def send_create_request(name, type, app_id, certificate_parameter, devices)
  tries ||= 5
  client.create_provisioning_profile!(name, type, app_id, certificate_parameter, devices)
rescue => ex 
  unless (tries -= 1).zero?
    sleep 3
    retry
  end

  raise ex # re-raise the exception
end

#send_update_request(id, name, distribution_method, app_id, certificates, devices) ⇒ Object



342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/spaceship/portal/provisioning_profile.rb', line 342

def send_update_request(id, name, distribution_method, app_id, certificates, devices)
  tries ||= 5
  client.repair_provisioning_profile!(
    id,
    name,
    distribution_method,
    app_id,
    certificates,
    devices
  )
rescue => ex 
  unless (tries -= 1).zero?
    sleep 3
    retry
  end
  raise ex # re-raise the exception
end

#update!ProvisioningProfile

Updates the provisioning profile from the local data e.g. after you added new devices to the profile This will also update the code signing identity if necessary

Returns:

  • (ProvisioningProfile)

    A new provisioning profile, as the repair method will generate a profile with a new ID



331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/spaceship/portal/provisioning_profile.rb', line 331

def update!
  unless certificate_valid?
    if self.kind_of?Development
      self.certificates = [Spaceship::Certificate::Development.all.first]
    elsif self.kind_of?InHouse
      self.certificates = [Spaceship::Certificate::InHouse.all.first]
    else
      self.certificates = [Spaceship::Certificate::Production.all.first]  
    end
  end

  def send_update_request(id, name, distribution_method, app_id, certificates, devices)
    tries ||= 5
    client.repair_provisioning_profile!(
      id,
      name,
      distribution_method,
      app_id,
      certificates,
      devices
    )
  rescue => ex 
    unless (tries -= 1).zero?
      sleep 3
      retry
    end
    raise ex # re-raise the exception
  end

  send_update_request(
    self.id,
    self.name,
    self.distribution_method,
    self.app.app_id,
    self.certificates.map { |c| c.id },
    self.devices.map { |d| d.id }
  )

  # We need to fetch the provisioning profile again, as the ID changes
  profile = Spaceship::ProvisioningProfile.all.find do |profile|
    profile.name == self.name # we can use the name as it's valid
  end

  return profile
end

#valid?Bool

Returns Is the current provisioning profile valid?.

Returns:

  • (Bool)

    Is the current provisioning profile valid?



390
391
392
# File 'lib/spaceship/portal/provisioning_profile.rb', line 390

def valid?
  return (status == 'Active' and certificate_valid?)
end