Class: IosAndroidToolbox::IosProvisioningProfile
- Inherits:
-
Object
- Object
- IosAndroidToolbox::IosProvisioningProfile
- Defined in:
- lib/ios_android_toolbox/ios_prov_profile.rb
Constant Summary collapse
- PROV_PROFILE_DIR =
ENV['HOME']+'/Library/MobileDevice/Provisioning Profiles'
- UUID_REGEX =
'[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}'
- DEBUG =
false
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
Class Method Summary collapse
- .install(path) ⇒ Object
- .loop_through_profiles_for_app_id(id, &block) ⇒ Object
- .profile_worth_installing?(path_or_profile) ⇒ Boolean
- .remove_stale_equivalent_profiles(path) ⇒ Object
Instance Method Summary collapse
- #app_id ⇒ Object
- #app_id_name ⇒ Object
- #app_id_prefix ⇒ Object
- #aps_environment ⇒ Object
- #creation_date ⇒ Object
- #developer_certificates ⇒ Object
- #get_task_allow ⇒ Object
- #has_provisioned_devices? ⇒ Boolean
-
#initialize(contents) ⇒ IosProvisioningProfile
constructor
A new instance of IosProvisioningProfile.
- #install ⇒ Object
- #is_adhoc? ⇒ Boolean
- #is_development? ⇒ Boolean
- #is_development_aps_environment? ⇒ Boolean
- #is_production? ⇒ Boolean
- #is_production_aps_environment? ⇒ Boolean
- #path ⇒ Object
- #plist ⇒ Object
- #plist_string ⇒ Object
- #provisioned_devices ⇒ Object
- #team_identifier ⇒ Object
- #team_identifiers ⇒ Object
- #team_name ⇒ Object
- #uuid ⇒ Object
Constructor Details
#initialize(contents) ⇒ IosProvisioningProfile
Returns a new instance of IosProvisioningProfile.
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 129 def initialize(contents) # If we specify a path, read it first begin if File.exists? contents and not File.directory? contents contents = File.open(contents).read end rescue end @contents = contents end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
13 14 15 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 13 def contents @contents end |
Class Method Details
.install(path) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 156 def self.install(path) if not File.directory? PROV_PROFILE_DIR FileUtils.mkdir_p PROV_PROFILE_DIR FileUtils.chmod 0755, PROV_PROFILE_DIR end new_profile = IosProvisioningProfile.new(path) new_path = File.join(PROV_PROFILE_DIR, new_profile.uuid+".mobileprovision") if File.(path) != File.(new_path) if profile_worth_installing? new_profile self.remove_stale_equivalent_profiles(path) FileUtils.copy(path, new_path) end else puts "Cannot install new profile over itself!" end end |
.loop_through_profiles_for_app_id(id, &block) ⇒ Object
195 196 197 198 199 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 195 def self.loop_through_profiles_for_app_id(id, &block) self.loop_through_existing_profiles do |p,path| yield p, path if p.app_id == id end end |
.profile_worth_installing?(path_or_profile) ⇒ Boolean
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 175 def self.profile_worth_installing?(path_or_profile) if path_or_profile.is_a? String new_profile = IosProvisioningProfile.new(path_or_profile) elsif path_or_profile.is_a? IosProvisioningProfile new_profile = path_or_profile else raise "Invalid profile or profile path specified" end loop_through_existing_profiles do |installed_profile, path| if installed_profile.app_id == new_profile.app_id and (installed_profile.is_development? and new_profile.is_development? or installed_profile.is_production? and new_profile.is_production? or installed_profile.is_adhoc? and new_profile.is_adhoc?) return false if installed_profile.creation_date >= new_profile.creation_date end end true end |
.remove_stale_equivalent_profiles(path) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 141 def self.remove_stale_equivalent_profiles(path) new_profile = IosProvisioningProfile.new(path) self.loop_through_existing_profiles do |installed_profile, installed_profile_path| if installed_profile.app_id == new_profile.app_id and installed_profile.creation_date < new_profile.creation_date and (installed_profile.is_development? and new_profile.is_development? or installed_profile.is_production? and new_profile.is_production? or installed_profile.is_adhoc? and new_profile.is_adhoc?) puts "Removing stale Prov Profile: #{installed_profile_path}" File.delete installed_profile_path end end end |
Instance Method Details
#app_id ⇒ Object
46 47 48 49 50 51 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 46 def app_id @app_id ||= begin id = plist['Entitlements']['application-identifier'] id.gsub(/^[A-Z0-9]+\./,'') end end |
#app_id_name ⇒ Object
53 54 55 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 53 def app_id_name plist['AppIDName'] end |
#app_id_prefix ⇒ Object
57 58 59 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 57 def app_id_prefix plist['ApplicationIdentifierPrefix'] end |
#aps_environment ⇒ Object
74 75 76 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 74 def aps_environment plist['Entitlements']['aps-environment'] end |
#creation_date ⇒ Object
61 62 63 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 61 def creation_date plist['CreationDate'] end |
#developer_certificates ⇒ Object
90 91 92 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 90 def developer_certificates plist['DeveloperCertificates'] end |
#get_task_allow ⇒ Object
78 79 80 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 78 def get_task_allow plist['Entitlements']['get-task-allow'] end |
#has_provisioned_devices? ⇒ Boolean
65 66 67 68 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 65 def has_provisioned_devices? # <key>ProvisionedDevices</key> !!(/<key>ProvisionedDevices<\/key>/.match(plist_string)) end |
#install ⇒ Object
122 123 124 125 126 127 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 122 def install dst_path = File.join(PROV_PROFILE_DIR,"#{uuid}.mobileprovision") File.open(dst_path, "wb") do |f| f.write(contents) end end |
#is_adhoc? ⇒ Boolean
110 111 112 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 110 def is_adhoc? provisioned_devices.is_a? Array and get_task_allow == false end |
#is_development? ⇒ Boolean
102 103 104 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 102 def is_development? provisioned_devices.is_a? Array and get_task_allow == true end |
#is_development_aps_environment? ⇒ Boolean
114 115 116 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 114 def is_development_aps_environment? aps_environment == 'development' end |
#is_production? ⇒ Boolean
106 107 108 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 106 def is_production? provisioned_devices.nil? and get_task_allow == false end |
#is_production_aps_environment? ⇒ Boolean
118 119 120 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 118 def is_production_aps_environment? aps_environment == 'production' end |
#path ⇒ Object
42 43 44 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 42 def path File.join(PROV_PROFILE_DIR,uuid+".mobileprovision") end |
#plist ⇒ Object
27 28 29 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 27 def plist plist ||= Plist.parse_xml(plist_string) end |
#plist_string ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 15 def plist_string @plist_string ||= begin xml_start = contents.index('<?xml version=') return nil if xml_start.nil? xml_end = contents.index('</plist>', xml_start) return nil if xml_end.nil? contents.slice(xml_start, xml_end - xml_start + 8) end end |
#provisioned_devices ⇒ Object
70 71 72 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 70 def provisioned_devices plist['ProvisionedDevices'] end |
#team_identifier ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 94 def team_identifier if team_identifiers && team_identifiers.size > 0 team_identifiers[0] else nil end end |
#team_identifiers ⇒ Object
86 87 88 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 86 def team_identifiers plist['TeamIdentifier'] end |
#team_name ⇒ Object
82 83 84 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 82 def team_name plist['TeamName'] end |
#uuid ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ios_android_toolbox/ios_prov_profile.rb', line 31 def uuid # <key>UUID</key> # <string>06AF2826-608D-4CE9-99AE-AA917FF1641E</string> if /<key>UUID<\/key>\s*<string>(#{UUID_REGEX})<\/string>/.match(plist_string) puts "Found UUID: #{$1}" if DEBUG uuid = $1 else nil end end |