Class: Spaceship::PortalClient
- Inherits:
-
Client
- Object
- Client
- Spaceship::PortalClient
show all
- Defined in:
- lib/spaceship/portal/portal_client.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary
Constants inherited
from Client
Client::PROTOCOL_VERSION, Client::USER_AGENT
Instance Attribute Summary
Attributes inherited from Client
#client, #csrf_tokens, #logger, #user
Provisioning Profiles
collapse
-
#create_provisioning_profile!(name, distribution_method, app_id, certificate_ids, device_ids, mac: false, sub_platform: nil) ⇒ Object
-
#delete_provisioning_profile!(profile_id, mac: false) ⇒ Object
-
#download_provisioning_profile(profile_id, mac: false) ⇒ Object
-
#fetch_csrf_token_for_provisioning(mac: false) ⇒ Object
We need a custom way to fetch the csrf token for the provisioning profile requests, since we use a separate API endpoint (host of Xcode API) to fetch the provisioning profiles All we do is fetch one profile (if exists) to get a valid csrf token with its time stamp This method is being called from all requests that modify, create or downloading provisioning profiles.
-
#provisioning_profile_details(provisioning_profile_id: nil, mac: false) ⇒ Object
-
#provisioning_profiles(mac: false) ⇒ Object
-
#repair_provisioning_profile!(profile_id, name, distribution_method, app_id, certificate_ids, device_ids, mac: false) ⇒ Object
Methods inherited from Client
#UI, #cookie, #handle_two_factor, #handle_two_step, #initialize, #itc_service_key, #load_session_from_env, #load_session_from_file, login, #login, #page_size, #paging, #parse_response, #persistent_cookie_path, #request, #select_device, #send_shared_login_request, #store_cookie, #store_session, #with_retry
Class Method Details
.hostname ⇒ Object
8
9
10
|
# File 'lib/spaceship/portal/portal_client.rb', line 8
def self.hostname
"https://developer.apple.com/services-account/#{PROTOCOL_VERSION}/"
end
|
Instance Method Details
#app_groups ⇒ Object
182
183
184
185
186
187
188
189
190
191
192
|
# File 'lib/spaceship/portal/portal_client.rb', line 182
def app_groups
paging do |page_number|
r = request(:post, 'account/ios/identifiers/listApplicationGroups.action', {
teamId: team_id,
pageNumber: page_number,
pageSize: page_size,
sort: 'name=asc'
})
parse_response(r, 'applicationGroupList')
end
end
|
#apps(mac: false) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/spaceship/portal/portal_client.rb', line 89
def apps(mac: false)
paging do |page_number|
r = request(:post, "account/#{platform_slug(mac)}/identifiers/listAppIds.action", {
teamId: team_id,
pageNumber: page_number,
pageSize: page_size,
sort: 'name=asc'
})
parse_response(r, 'appIds')
end
end
|
#associate_groups_with_app(app, groups) ⇒ Object
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/spaceship/portal/portal_client.rb', line 122
def associate_groups_with_app(app, groups)
ensure_csrf(Spaceship::AppGroup)
request(:post, 'account/ios/identifiers/assignApplicationGroupToAppId.action', {
teamId: team_id,
appIdId: app.app_id,
displayId: app.app_id,
applicationGroups: groups.map(&:app_group_id)
})
details_for_app(app)
end
|
#certificates(types, mac: false) ⇒ Object
263
264
265
266
267
268
269
270
271
272
273
274
|
# File 'lib/spaceship/portal/portal_client.rb', line 263
def certificates(types, mac: false)
paging do |page_number|
r = request(:post, "account/#{platform_slug(mac)}/certificate/listCertRequests.action", {
teamId: team_id,
types: types.join(','),
pageNumber: page_number,
pageSize: page_size,
sort: 'certRequestStatusCode=asc'
})
parse_response(r, 'certRequests')
end
end
|
#create_app!(type, name, bundle_id, mac: false) ⇒ Object
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
|
# File 'lib/spaceship/portal/portal_client.rb', line 135
def create_app!(type, name, bundle_id, mac: false)
ensure_csrf(Spaceship::App)
ident_params = case type.to_sym
when :explicit
{
type: 'explicit',
identifier: bundle_id,
push: 'on',
inAppPurchase: 'on',
gameCenter: 'on'
}
when :wildcard
{
type: 'wildcard',
identifier: bundle_id
}
end
params = {
name: name,
teamId: team_id
}
params.merge!(ident_params)
r = request(:post, "account/#{platform_slug(mac)}/identifiers/addAppId.action", params)
parse_response(r, 'appId')
end
|
#create_app_group!(name, group_id) ⇒ Object
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/spaceship/portal/portal_client.rb', line 194
def create_app_group!(name, group_id)
ensure_csrf(Spaceship::AppGroup)
r = request(:post, 'account/ios/identifiers/addApplicationGroup.action', {
name: name,
identifier: group_id,
teamId: team_id
})
parse_response(r, 'applicationGroup')
end
|
#create_certificate!(type, csr, app_id = nil) ⇒ Object
276
277
278
279
280
281
282
283
284
285
286
|
# File 'lib/spaceship/portal/portal_client.rb', line 276
def create_certificate!(type, csr, app_id = nil)
ensure_csrf(Spaceship::Certificate)
r = request(:post, 'account/ios/certificate/submitCertificateRequest.action', {
teamId: team_id,
type: type,
csrContent: csr,
appIdId: app_id })
parse_response(r, 'certRequest')
end
|
#create_device!(device_name, device_id, mac: false) ⇒ Object
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
# File 'lib/spaceship/portal/portal_client.rb', line 244
def create_device!(device_name, device_id, mac: false)
ensure_csrf(Spaceship::Device)
req = request(:post) do |r|
r.url "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(mac)}/addDevice.action"
r.params = {
teamId: team_id,
deviceNumber: device_id,
name: device_name
}
end
parse_response(req, 'device')
end
|
#create_provisioning_profile!(name, distribution_method, app_id, certificate_ids, device_ids, mac: false, sub_platform: nil) ⇒ Object
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
|
# File 'lib/spaceship/portal/portal_client.rb', line 340
def create_provisioning_profile!(name, distribution_method, app_id, certificate_ids, device_ids, mac: false, sub_platform: nil)
ensure_csrf(Spaceship::ProvisioningProfile) do
fetch_csrf_token_for_provisioning
end
params = {
teamId: team_id,
provisioningProfileName: name,
appIdId: app_id,
distributionType: distribution_method,
certificateIds: certificate_ids,
deviceIds: device_ids
}
params[:subPlatform] = sub_platform if sub_platform
r = request(:post, "account/#{platform_slug(mac)}/profile/createProvisioningProfile.action", params)
parse_response(r, 'provisioningProfile')
end
|
#delete_app!(app_id, mac: false) ⇒ Object
168
169
170
171
172
173
174
175
176
|
# File 'lib/spaceship/portal/portal_client.rb', line 168
def delete_app!(app_id, mac: false)
ensure_csrf(Spaceship::App)
r = request(:post, "account/#{platform_slug(mac)}/identifiers/deleteAppId.action", {
teamId: team_id,
appIdId: app_id
})
parse_response(r)
end
|
#delete_app_group!(app_group_id) ⇒ Object
205
206
207
208
209
210
211
212
213
|
# File 'lib/spaceship/portal/portal_client.rb', line 205
def delete_app_group!(app_group_id)
ensure_csrf(Spaceship::AppGroup)
r = request(:post, 'account/ios/identifiers/deleteApplicationGroup.action', {
teamId: team_id,
applicationGroup: app_group_id
})
parse_response(r)
end
|
#delete_provisioning_profile!(profile_id, mac: false) ⇒ Object
376
377
378
379
380
381
382
383
384
385
386
|
# File 'lib/spaceship/portal/portal_client.rb', line 376
def delete_provisioning_profile!(profile_id, mac: false)
ensure_csrf(Spaceship::ProvisioningProfile) do
fetch_csrf_token_for_provisioning
end
r = request(:post, "account/#{platform_slug(mac)}/profile/deleteProvisioningProfile.action", {
teamId: team_id,
provisioningProfileId: profile_id
})
parse_response(r)
end
|
#details_for_app(app) ⇒ Object
101
102
103
104
105
106
107
|
# File 'lib/spaceship/portal/portal_client.rb', line 101
def details_for_app(app)
r = request(:post, "account/#{platform_slug(app.mac?)}/identifiers/getAppIdDetail.action", {
teamId: team_id,
appIdId: app.app_id
})
parse_response(r, 'appId')
end
|
#devices(mac: false) ⇒ Object
219
220
221
222
223
224
225
226
227
228
229
|
# File 'lib/spaceship/portal/portal_client.rb', line 219
def devices(mac: false)
paging do |page_number|
r = request(:post, "account/#{platform_slug(mac)}/device/listDevices.action", {
teamId: team_id,
pageNumber: page_number,
pageSize: page_size,
sort: 'name=asc'
})
parse_response(r, 'devices')
end
end
|
#devices_by_class(device_class) ⇒ Object
231
232
233
234
235
236
237
238
239
240
241
242
|
# File 'lib/spaceship/portal/portal_client.rb', line 231
def devices_by_class(device_class)
paging do |page_number|
r = request(:post, 'account/ios/device/listDevices.action', {
teamId: team_id,
pageNumber: page_number,
pageSize: page_size,
sort: 'name=asc',
deviceClasses: device_class
})
parse_response(r, 'devices')
end
end
|
#download_certificate(certificate_id, type, mac: false) ⇒ Object
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
# File 'lib/spaceship/portal/portal_client.rb', line 288
def download_certificate(certificate_id, type, mac: false)
{ type: type, certificate_id: certificate_id }.each { |k, v| raise "#{k} must not be nil" if v.nil? }
r = request(:get, "account/#{platform_slug(mac)}/certificate/downloadCertificateContent.action", {
teamId: team_id,
certificateId: certificate_id,
type: type
})
a = parse_response(r)
if r.success? && a.include?("Apple Inc")
return a
else
raise UnexpectedResponse.new, "Couldn't download certificate, got this instead: #{a}"
end
end
|
#download_provisioning_profile(profile_id, mac: false) ⇒ Object
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
# File 'lib/spaceship/portal/portal_client.rb', line 359
def download_provisioning_profile(profile_id, mac: false)
ensure_csrf(Spaceship::ProvisioningProfile) do
fetch_csrf_token_for_provisioning
end
r = request(:get, "account/#{platform_slug(mac)}/profile/downloadProfileContent", {
teamId: team_id,
provisioningProfileId: profile_id
})
a = parse_response(r)
if r.success? && a.include?("DOCTYPE plist PUBLIC")
return a
else
raise UnexpectedResponse.new, "Couldn't download provisioning profile, got this instead: #{a}"
end
end
|
#fetch_csrf_token_for_provisioning(mac: false) ⇒ Object
We need a custom way to fetch the csrf token for the provisioning profile requests, since we use a separate API endpoint (host of Xcode API) to fetch the provisioning profiles All we do is fetch one profile (if exists) to get a valid csrf token with its time stamp This method is being called from all requests that modify, create or downloading provisioning profiles. Source github.com/fastlane/fastlane/issues/5903
412
413
414
415
416
417
418
419
420
421
422
423
424
425
|
# File 'lib/spaceship/portal/portal_client.rb', line 412
def fetch_csrf_token_for_provisioning(mac: false)
req = request(:post) do |r|
r.url "https://developer.apple.com/services-account/#{PROTOCOL_VERSION}/account/#{platform_slug(mac)}/profile/listProvisioningProfiles.action"
r.params = {
teamId: team_id,
pageSize: 1,
pageNumber: 1,
sort: "name=asc"
}
end
parse_response(req, 'provisioningProfiles')
return nil
end
|
#in_house? ⇒ Boolean
Is the current session from an Enterprise In House account?
71
72
73
74
|
# File 'lib/spaceship/portal/portal_client.rb', line 71
def in_house?
return @in_house unless @in_house.nil?
@in_house = (team_information['type'] == 'In-House')
end
|
#provisioning_profile_details(provisioning_profile_id: nil, mac: false) ⇒ Object
332
333
334
335
336
337
338
|
# File 'lib/spaceship/portal/portal_client.rb', line 332
def provisioning_profile_details(provisioning_profile_id: nil, mac: false)
r = request(:post, "account/#{platform_slug(mac)}/profile/getProvisioningProfile.action", {
teamId: team_id,
provisioningProfileId: provisioning_profile_id
})
parse_response(r, 'provisioningProfile')
end
|
#provisioning_profiles(mac: false) ⇒ Object
319
320
321
322
323
324
325
326
327
328
329
330
|
# File 'lib/spaceship/portal/portal_client.rb', line 319
def provisioning_profiles(mac: false)
req = request(:post) do |r|
r.url "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(mac)}/listProvisioningProfiles.action"
r.params = {
teamId: team_id,
includeInactiveProfiles: true,
onlyCountLists: true
}
end
parse_response(req, 'provisioningProfiles')
end
|
#repair_provisioning_profile!(profile_id, name, distribution_method, app_id, certificate_ids, device_ids, mac: false) ⇒ Object
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
# File 'lib/spaceship/portal/portal_client.rb', line 388
def repair_provisioning_profile!(profile_id, name, distribution_method, app_id, certificate_ids, device_ids, mac: false)
ensure_csrf(Spaceship::ProvisioningProfile) do
fetch_csrf_token_for_provisioning
end
r = request(:post, "account/#{platform_slug(mac)}/profile/regenProvisioningProfile.action", {
teamId: team_id,
provisioningProfileId: profile_id,
provisioningProfileName: name,
appIdId: app_id,
distributionType: distribution_method,
certificateIds: certificate_ids.join(','),
deviceIds: device_ids
})
parse_response(r, 'provisioningProfile')
end
|
#revoke_certificate!(certificate_id, type, mac: false) ⇒ Object
304
305
306
307
308
309
310
311
312
313
|
# File 'lib/spaceship/portal/portal_client.rb', line 304
def revoke_certificate!(certificate_id, type, mac: false)
ensure_csrf(Spaceship::Certificate)
r = request(:post, "account/#{platform_slug(mac)}/certificate/revokeCertificate.action", {
teamId: team_id,
certificateId: certificate_id,
type: type
})
parse_response(r, 'certRequests')
end
|
#select_team ⇒ Object
Shows a team selection for the user in the terminal. This should not be called on CI systems
54
55
56
|
# File 'lib/spaceship/portal/portal_client.rb', line 54
def select_team
@current_team_id = self.UI.select_team
end
|
#send_login_request(user, password) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/spaceship/portal/portal_client.rb', line 12
def send_login_request(user, password)
response = send_shared_login_request(user, password)
return response if self.cookie.include?("myacinfo")
return send_shared_login_request(user, password)
end
|
Returns The currently selected Team ID.
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/spaceship/portal/portal_client.rb', line 39
def team_id
return @current_team_id if @current_team_id
if teams.count > 1
puts "The current user is in #{teams.count} teams. Pass a team ID or call `select_team` to choose a team. Using the first one for now."
end
if teams.count == 0
raise "User '#{user}' does not have access to any teams with an active membership"
end
@current_team_id ||= teams[0]['teamId']
end
|
#team_id=(team_id) ⇒ Object
Set a new team ID which will be used from now on
59
60
61
|
# File 'lib/spaceship/portal/portal_client.rb', line 59
def team_id=(team_id)
@current_team_id = team_id
end
|
Returns Fetches all information of the currently used team.
64
65
66
67
68
|
# File 'lib/spaceship/portal/portal_client.rb', line 64
def team_information
teams.find do |t|
t['teamId'] == team_id
end
end
|
#teams ⇒ Array
Returns A list of all available teams.
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/spaceship/portal/portal_client.rb', line 27
def teams
return @teams if @teams
req = request(:post, "https://developerservices2.apple.com/services/QH65B2/listTeams.action")
@teams = parse_response(req, 'teams').sort_by do |team|
[
team['name'],
team['teamId']
]
end
end
|
#update_service_for_app(app, service) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/spaceship/portal/portal_client.rb', line 109
def update_service_for_app(app, service)
ensure_csrf(Spaceship::App)
request(:post, service.service_uri, {
teamId: team_id,
displayId: app.app_id,
featureType: service.service_id,
featureValue: service.value
})
details_for_app(app)
end
|