Permalink
Browse files

Update free team requests to work with Fastlane 2.

  • Loading branch information...
andrewhavens committed Mar 21, 2018
1 parent beba15c commit e508e7c7d666e2b4182fe32b7822700364d66efe
View
@@ -9,7 +9,7 @@ GIT
PATH
remote: .
specs:
motion-provisioning (0.0.7)
motion-provisioning (1.0.0)
fastlane (~> 2.85)
highline (>= 1.7.2, < 2.0.0)
@@ -36,7 +36,7 @@ GEM
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.2.1)
excon (0.60.0)
excon (0.61.0)
faraday (0.14.0)
multipart-post (>= 1.2, < 3)
faraday-cookie_jar (0.0.6)
@@ -45,7 +45,7 @@ GEM
faraday_middleware (0.12.2)
faraday (>= 0.7.4, < 1.0)
fastimage (2.1.1)
fastlane (2.85.0)
fastlane (2.86.1)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.3, < 3.0.0)
babosa (>= 1.0.2, < 2.0.0)
@@ -70,6 +70,7 @@ GEM
public_suffix (~> 2.0.0)
rubyzip (>= 1.1.0, < 2.0.0)
security (= 0.1.3)
simctl (~> 1.6)
slack-notifier (>= 2.0.0, < 3.0.0)
terminal-notifier (>= 1.6.2, < 2.0.0)
terminal-table (>= 1.4.5, < 2.0.0)
@@ -115,6 +116,7 @@ GEM
multi_xml (0.6.0)
multipart-post (2.0.0)
nanaimo (0.2.3)
naturally (2.1.0)
os (0.9.6)
plist (3.4.0)
public_suffix (2.0.5)
@@ -150,6 +152,9 @@ GEM
faraday (~> 0.9)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
simctl (1.6.2)
CFPropertyList
naturally
simplecov (0.12.0)
docile (~> 1.1.0)
json (>= 1.8, < 3)
View
@@ -96,7 +96,7 @@ def self.client
end
if client.team_id.nil?
raise "could not find free team"
raise "The current user does not belong to a free team."
end
else
if team_id = MotionProvisioning.config['team_id'] || ENV['MOTION_PROVISIONING_TEAM_ID']
@@ -113,22 +113,20 @@ def self.client
raise "The current user does not belong to team with ID '#{team_id}' selected in config.yml."
end
else
team_id = client.select_team
self.team = client.teams.detect { |team| team['teamId'] == team_id }
if File.exist?(config_path) && ENV['MOTION_PROVISIONING_TEAM_ID'].nil?
answer = Utils.ask("Info", "Do you want to save the team \"#{team['name']}\" (#{team_id}) in the config file ('#{MotionProvisioning.output_path}/config.yaml') so you dont have to select it again? (Y/n):")
if answer.yes?
config = YAML.load(File.read(config_path))
config['team_id'] = team_id
File.write(config_path, config.to_yaml)
end
end
end
end
Utils.log("Info", "Selected team \"#{self.team['name']}\" (#{self.team['teamId']}).")
Utils.log("Info", "Selected team \"#{team['name']}\" (#{team['teamId']}).")
if File.exist?(config_path) && ENV['MOTION_PROVISIONING_TEAM_ID'].nil? && MotionProvisioning.config['team_id'].nil?
answer = Utils.ask("Info", "Do you want to save the team \"#{team['name']}\" (#{team['teamId']}) in the config file ('#{MotionProvisioning.output_path}/config.yaml') so you dont have to select it again? (Y/n):")
if answer.yes?
config = YAML.load(File.read(config_path))
config['team_id'] = team['teamId']
File.write(config_path, config.to_yaml)
end
end
Spaceship::App.set_client(client)
Spaceship::AppGroup.set_client(client)
@@ -1,5 +1,46 @@
module Spaceship
class FreePortalClient < Spaceship::PortalClient
XCODE_VERSION = '9.2 (9C40b)'
def teams
return @teams if @teams
req = request(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/listTeams.action", nil, {
'X-Xcode-Version' => XCODE_VERSION # necessary in order to work with Xcode free team
})
@teams = parse_response(req, 'teams').sort_by do |team|
[
team['name'],
team['teamId']
]
end
end
def development_certificates(mac: false)
paging do |page_number|
r = request(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(mac)}/listAllDevelopmentCerts.action?clientId=XABBG36SBA&teamId=#{team_id}", nil, {
'X-Xcode-Version' => XCODE_VERSION # necessary in order to work with Xcode free team
})
parse_response(r, 'certificates')
end
end
def provisioning_profiles_via_xcode_api(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
}
r.headers['X-Xcode-Version'] = XCODE_VERSION # necessary in order to work with Xcode free team
end
result = parse_response(req, 'provisioningProfiles')
csrf_cache[Spaceship::Portal::ProvisioningProfile] = self.csrf_tokens
result
end
def create_provisioning_profile!(name, distribution_method, app_id, certificate_ids, device_ids, mac: false, sub_platform: nil, template_name: nil)
ensure_csrf(Spaceship::App)
@@ -67,12 +108,36 @@ def details_for_app(app)
parse_response(r, 'appId')
end
def create_app!(type, name, bundle_id, mac: false)
def create_app!(type, name, bundle_id, mac: false, enable_services: {})
# We moved the ensure_csrf to the top of this method
# as we got some users with issues around creating new apps
# https://github.com/fastlane/fastlane/issues/5813
ensure_csrf(Spaceship::Portal::App)
ident_params = case type.to_sym
when :explicit
{
type: 'explicit',
# push: 'on', # Not available to free teams
# inAppPurchase: 'on', # Not available to free teams
gameCenter: 'on'
}
when :wildcard
{
type: 'wildcard',
}
end
params = {
identifier: bundle_id,
name: name,
teamId: team_id
}
params.merge!(ident_params)
enable_services.each do |k, v|
params[v.service_id.to_sym] = v.value
end
ensure_csrf(Spaceship::App)
@@ -102,12 +167,15 @@ def create_development_certificate(csr, mac: false)
private
def request_plist(method, url_or_path = nil, params = nil, headers = {}, &block)
headers['X-Xcode-Version'] = '7.3.1 (7D1014)'
headers['Content-Type'] = 'text/x-xml-plist'
headers['X-Xcode-Version'] = XCODE_VERSION
headers['Accept'] = 'text/x-xml-plist'
headers['User-Agent'] = USER_AGENT
headers.merge!(csrf_tokens)
params = params.to_plist if params
if params
headers['Content-Type'] = 'text/x-xml-plist'
params = params.to_plist
end
send_request(method, url_or_path, params, headers, &block)
end
@@ -1,16 +1,15 @@
module Spaceship
class PortalClient < Spaceship::Client
def distribution_certificates(mac: false)
def development_certificates(mac: false)
paging do |page_number|
r = request(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(mac)}/downloadDistributionCerts.action?clientId=XABBG36SBA&teamId=#{team_id}")
r = request(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(mac)}/listAllDevelopmentCerts.action?clientId=XABBG36SBA&teamId=#{team_id}")
parse_response(r, 'certificates')
end
end
def development_certificates(mac: false)
def distribution_certificates(mac: false)
paging do |page_number|
r = request(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(mac)}/listAllDevelopmentCerts.action?clientId=XABBG36SBA&teamId=#{team_id}")
r = request(:post, "https://developerservices2.apple.com/services/#{PROTOCOL_VERSION}/#{platform_slug(mac)}/downloadDistributionCerts.action?clientId=XABBG36SBA&teamId=#{team_id}")
parse_response(r, 'certificates')
end
end
View
@@ -39,9 +39,14 @@ def stub_login
with(body: { "accountName" => "bad-username", "password" => "bad-password", "rememberMe" => true }.to_json).
to_return(status: 401, body: '{}', headers: { 'Set-Cookie' => 'session=invalid' })
# Portal login
# List paid teams
stub_request(:post, 'https://developer.apple.com/services-account/QH65B2/account/listTeams.action').
to_return(status: 200, body: adp_read_fixture_file('listTeams.action.json'), headers: { 'Content-Type' => 'application/json' })
# List free teams
stub_request(:post, "https://developerservices2.apple.com/services/QH65B2/listTeams.action").
with(:headers => {'X-Xcode-Version'=>'9.2 (9C40b)'}).
to_return(status: 200, body: adp_read_fixture_file('listTeams.action.json'), headers: { 'Content-Type' => 'application/json' })
end
def stub_create_profile(type, platform)

2 comments on commit e508e7c

@wndxlori

This comment has been minimized.

Show comment
Hide comment
@wndxlori

wndxlori Mar 21, 2018

We’re gonna need some very specific documentation on how this needs to be updated, when the Xcode version changes. Such that whoever first runs into a problem with it could make the change and submit a PR.

wndxlori replied Mar 21, 2018

We’re gonna need some very specific documentation on how this needs to be updated, when the Xcode version changes. Such that whoever first runs into a problem with it could make the change and submit a PR.

@andrewhavens

This comment has been minimized.

Show comment
Hide comment
@andrewhavens

andrewhavens Mar 21, 2018

Contributor

@wndxlori I don't think the version matters. Just that the header is present in the request.

Contributor

andrewhavens replied Mar 21, 2018

@wndxlori I don't think the version matters. Just that the header is present in the request.

Please sign in to comment.