Class: Sigh::DownloadAll

Inherits:
Object
  • Object
show all
Defined in:
sigh/lib/sigh/download_all.rb

Instance Method Summary collapse

Instance Method Details

#api_tokenObject



62
63
64
65
66
# File 'sigh/lib/sigh/download_all.rb', line 62

def api_token
  api_token ||= Spaceship::ConnectAPI::Token.create(Sigh.config[:api_key]) if Sigh.config[:api_key]
  api_token ||= Spaceship::ConnectAPI::Token.from_json_file(Sigh.config[:api_key_path]) if Sigh.config[:api_key_path]
  return api_token
end

#download_all(download_xcode_profiles: false) ⇒ Object

Download all valid provisioning profiles



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'sigh/lib/sigh/download_all.rb', line 11

def download_all(download_xcode_profiles: false)
  if (token = api_token)
    UI.message("Creating authorization token for App Store Connect API")
    Spaceship::ConnectAPI.token = token
  else
    # Team selection passed though FASTLANE_ITC_TEAM_ID and FASTLANE_ITC_TEAM_NAME environment variables
    # Prompts select team if multiple teams and none specified
    UI.message("Starting login with user '#{Sigh.config[:username]}'")
    Spaceship::ConnectAPI.(Sigh.config[:username], nil, use_portal: true, use_tunes: false)
    UI.message("Successfully logged in")
  end

  if download_xcode_profiles
    UI.deprecated("The App Store Connect API does not support querying for Xcode managed profiles: --download_code_profiles is deprecated")
  end

  case Sigh.config[:platform].to_s
  when 'ios'
    profile_types = [
      Spaceship::ConnectAPI::Profile::ProfileType::IOS_APP_STORE,
      Spaceship::ConnectAPI::Profile::ProfileType::IOS_APP_INHOUSE,
      Spaceship::ConnectAPI::Profile::ProfileType::IOS_APP_ADHOC,
      Spaceship::ConnectAPI::Profile::ProfileType::IOS_APP_DEVELOPMENT
    ]
  when 'macos'
    profile_types = [
      Spaceship::ConnectAPI::Profile::ProfileType::MAC_APP_STORE,
      Spaceship::ConnectAPI::Profile::ProfileType::MAC_APP_DEVELOPMENT,
      Spaceship::ConnectAPI::Profile::ProfileType::MAC_APP_DIRECT
    ]
  when 'catalyst'
    profile_types = [
      Spaceship::ConnectAPI::Profile::ProfileType::MAC_CATALYST_APP_STORE,
      Spaceship::ConnectAPI::Profile::ProfileType::MAC_CATALYST_APP_DEVELOPMENT,
      Spaceship::ConnectAPI::Profile::ProfileType::MAC_CATALYST_APP_DIRECT
    ]
  when 'tvos'
    profile_types = [
      Spaceship::ConnectAPI::Profile::ProfileType::TVOS_APP_STORE,
      Spaceship::ConnectAPI::Profile::ProfileType::TVOS_APP_INHOUSE,
      Spaceship::ConnectAPI::Profile::ProfileType::TVOS_APP_ADHOC,
      Spaceship::ConnectAPI::Profile::ProfileType::TVOS_APP_DEVELOPMENT
    ]
  end

  # Filtering on 'profileType' seems to be undocumented as of 2020-07-30
  # but works on both web session and official API
  profiles = Spaceship::ConnectAPI::Profile.all(filter: { profileType: profile_types.join(",") }, includes: "bundleId")
  download_profiles(profiles)
end

#download_profile(profile) ⇒ Object

Parameters:

  • profile (ProvisioningProfile)

    A profile we plan to download and store



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'sigh/lib/sigh/download_all.rb', line 87

def download_profile(profile)
  FileUtils.mkdir_p(Sigh.config[:output_path])

  type_name = pretty_type(profile.profile_type)
  profile_name = "#{type_name}_#{profile.uuid}_#{profile.bundle_id.identifier}"

  if Sigh.config[:platform].to_s == 'tvos'
    profile_name += "_tvos"
  end

  if ['macos', 'catalyst'].include?(Sigh.config[:platform].to_s)
    profile_name += '.provisionprofile'
  else
    profile_name += '.mobileprovision'
  end

  output_path = File.join(Sigh.config[:output_path], profile_name)
  File.open(output_path, "wb") do |f|
    content = Base64.decode64(profile.profile_content)
    f.write(content)
  end

  Manager.install_profile(output_path) unless Sigh.config[:skip_install]
end

#download_profiles(profiles) ⇒ Object

Parameters:

  • profiles (Array)

    Array of all the provisioning profiles we want to download



69
70
71
72
73
74
75
76
77
78
79
80
# File 'sigh/lib/sigh/download_all.rb', line 69

def download_profiles(profiles)
  UI.important("No profiles available for download") if profiles.empty?

  profiles.each do |profile|
    if profile.valid?
      UI.message("Downloading profile '#{profile.name}'...")
      download_profile(profile)
    else
      UI.important("Skipping invalid/expired profile '#{profile.name}'")
    end
  end
end

#pretty_type(profile_type) ⇒ Object



82
83
84
# File 'sigh/lib/sigh/download_all.rb', line 82

def pretty_type(profile_type)
  return Sigh.profile_pretty_type(profile_type)
end