lib/spaceship/portal/provisioning_profile.rb in spaceship-0.32.4 vs lib/spaceship/portal/provisioning_profile.rb in spaceship-0.33.0
- old
+ new
@@ -150,26 +150,16 @@
end
# Create a new object based on a hash.
# This is used to create a new object based on the server response.
def factory(attrs)
- # Ad Hoc Profiles look exactly like App Store profiles, but usually include devices
- profile_details = client.provisioning_profile_details(provisioning_profile_id: attrs["provisioningProfileId"])
-
- # The only difference between App Store and Ad Hoc provisioniong profile is the devices that are attached
- if attrs['distributionMethod'] == 'store' && (profile_details['devices'] || []).size > 0
- attrs['distributionMethod'] = 'adhoc'
- end
# 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
@@ -178,27 +168,10 @@
attrs['appId'] = App.set_client(@client).factory(attrs['appId'])
klass.client = @client
obj = klass.new(attrs)
- # Set the response of the details request, in case we want to access it later on
- obj.profile_details = profile_details
-
- # Since 15th September 2016 certificates and devices are hidden behind another request
- # see https://github.com/fastlane/fastlane/issues/6137 for more information
- # That's why we set it here
-
- # Parse all the devices from the details request
- obj.devices = (profile_details["devices"] || []).collect do |device|
- Device.set_client(client).factory(device)
- end
-
- # Parse all the certificates from the details request
- obj.certificates = (profile_details["certificates"] || []).collect do |cert|
- Certificate.set_client(client).factory(cert)
- end
-
return obj
end
# @return (String) The human readable name of this profile type.
# @example
@@ -277,13 +250,24 @@
# filter out the profiles managed by xcode
profiles.delete_if(&:managed_by_xcode?)
return profiles if self == ProvisioningProfile
+ # To distinguish between AppStore and AdHoc profiles, we need to send
+ # a details request (see `fetch_details`). This is an expensive operation
+ # which we can't do for every single provisioning profile
+ # Instead we'll treat App Store profiles the same way as Ad Hoc profiles
+ # Spaceship::ProvisioningProfile::AdHoc.all will return the same array as
+ # Spaceship::ProvisioningProfile::AppStore.all, containing only AppStore
+ # profiles. To determine if it's an Ad Hoc profile, you can use the
+ # is_adhoc? method on the profile.
+ klass = self
+ klass = AppStore if self == AdHoc
+
# only return the profiles that match the class
- profiles.select do |profile|
- profile.class == self
+ return profiles.select do |profile|
+ profile.class == klass
end
end
# @return (Array) Returns an array of provisioning
# profiles matching the bundle identifier
@@ -352,10 +336,13 @@
# e.g. after you added new devices to the profile
# This will also update the code signing identity if necessary
# @return (ProvisioningProfile) A new provisioning profile, as
# the repair method will generate a profile with a new ID
def update!
+ # sigh handles more specific filtering and validation steps that make this logic OK
+ #
+ # This is the minimum protection needed for people using spaceship directly
unless certificate_valid?
if mac?
if self.kind_of? Development
self.certificates = [Spaceship::Certificate::MacDevelopment.all.first]
else
@@ -403,21 +390,58 @@
end
return false
end
# @return (Bool) Is the current provisioning profile valid?
+ # To also verify the certificate call certificate_valid?
def valid?
- return (status == 'Active' and certificate_valid?)
+ return status == 'Active'
end
# @return (Bool) Is this profile managed by Xcode?
def managed_by_xcode?
managing_app == 'Xcode'
end
# @return (Bool) Is this a Mac provisioning profile?
def mac?
platform == 'mac'
+ end
+
+ def devices
+ fetch_details
+
+ @devices = (self.profile_details["devices"] || []).collect do |device|
+ Device.set_client(client).factory(device)
+ end if (@devices || []).empty?
+
+ @devices
+ end
+
+ def certificates
+ fetch_details
+
+ @certificates = (profile_details["certificates"] || []).collect do |cert|
+ Certificate.set_client(client).factory(cert)
+ end if (@certificates || []).empty?
+
+ return @certificates
+ end
+
+ # @return (Bool) Is this current provisioning profile adhoc?
+ # AppStore and AdHoc profiles are the same except that AdHoc has devices
+ def is_adhoc?
+ return false unless self.kind_of?(AppStore) || self.kind_of?(AdHoc)
+
+ return devices.count > 0
+ end
+
+ private
+
+ def fetch_details
+ # Since 15th September 2016 certificates and devices are hidden behind another request
+ # see https://github.com/fastlane/fastlane/issues/6137 for more information
+ self.profile_details ||= client.provisioning_profile_details(provisioning_profile_id: self.id)
end
end
end
end