Class: Sigh::DownloadAll

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

Instance Method Summary collapse

Instance Method Details

#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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'sigh/lib/sigh/download_all.rb', line 11

def download_all(download_xcode_profiles: false)
  if (api_token = Spaceship::ConnectAPI::Token.from(hash: Sigh.config[:api_key], filepath: Sigh.config[:api_key_path]))
    UI.message("Creating authorization token for App Store Connect API")
    Spaceship::ConnectAPI.token = api_token
  elsif !Spaceship::ConnectAPI.token.nil?
    UI.message("Using existing authorization token for App Store Connect API")
  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
    ]

    # As of 2022-06-25, only available with Apple ID auth
    if Spaceship::ConnectAPI.token
      UI.important("Skipping #{Spaceship::ConnectAPI::Profile::ProfileType::MAC_APP_INHOUSE}... only available with Apple ID auth")
    else
      profile_types << Spaceship::ConnectAPI::Profile::ProfileType::MAC_APP_INHOUSE
    end
  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
    ]

    # As of 2022-06-25, only available with Apple ID auth
    if Spaceship::ConnectAPI.token
      UI.important("Skipping #{Spaceship::ConnectAPI::Profile::ProfileType::MAC_CATALYST_APP_INHOUSE}... only available with Apple ID auth")
    else
      profile_types << Spaceship::ConnectAPI::Profile::ProfileType::MAC_CATALYST_APP_INHOUSE
    end
  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

  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



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'sigh/lib/sigh/download_all.rb', line 95

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



77
78
79
80
81
82
83
84
85
86
87
88
# File 'sigh/lib/sigh/download_all.rb', line 77

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



90
91
92
# File 'sigh/lib/sigh/download_all.rb', line 90

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