Class: Fastlane::Actions::RetrieveDevicesAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/retrieve_devices/actions/retrieve_devices_action.rb

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



96
97
98
# File 'lib/fastlane/plugin/retrieve_devices/actions/retrieve_devices_action.rb', line 96

def self.authors
  ["builtbyproxy"]
end

.available_optionsObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/fastlane/plugin/retrieve_devices/actions/retrieve_devices_action.rb', line 56

def self.available_options
  user = CredentialsManager::AppfileConfig.try_fetch_value(:apple_dev_portal_id)
  user ||= CredentialsManager::AppfileConfig.try_fetch_value(:apple_id)

  [
    FastlaneCore::ConfigItem.new(key: :api_key_path,
                                 env_names: ["FL_RETRIEVE_DEVICES_API_KEY_PATH", "APP_STORE_CONNECT_API_KEY_PATH"],
                                 description: "Path to your App Store Connect API Key JSON file (https://docs.fastlane.tools/app-store-connect-api/#using-fastlane-api-key-json-file)",
                                 optional: true,
                                 conflicting_options: [:api_key],
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find API key JSON file at path '#{value}'") unless File.exist?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :api_key,
                                 env_names: ["FL_RETRIEVE_DEVICES_API_KEY", "APP_STORE_CONNECT_API_KEY"],
                                 description: "Your App Store Connect API Key information (https://docs.fastlane.tools/app-store-connect-api/#use-return-value-and-pass-in-as-an-option)",
                                 type: Hash,
                                 default_value: Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::APP_STORE_CONNECT_API_KEY],
                                 default_value_dynamic: true,
                                 optional: true,
                                 sensitive: true,
                                 conflicting_options: [:api_key_path]),
    FastlaneCore::ConfigItem.new(key: :username,
                                 env_name: "DELIVER_USER",
                                 description: "Optional: Your Apple ID",
                                 optional: true,
                                 default_value: user,
                                 default_value_dynamic: true)
  ]
end

.categoryObject



104
105
106
# File 'lib/fastlane/plugin/retrieve_devices/actions/retrieve_devices_action.rb', line 104

def self.category
  :misc
end

.descriptionObject



45
46
47
# File 'lib/fastlane/plugin/retrieve_devices/actions/retrieve_devices_action.rb', line 45

def self.description
  "This action will retrieve a list of each device registered with Apple"
end

.detailsObject



49
50
51
52
53
54
# File 'lib/fastlane/plugin/retrieve_devices/actions/retrieve_devices_action.rb', line 49

def self.details
  [
    "This action will retrieve a list of names and UDIDs of each device registered with your Apple Certificate.",
    "This list is exactly the same as the list used to compare against what is/isn't registered in the `register_device/s` action."
  ].join("\n")
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/fastlane/plugin/retrieve_devices/actions/retrieve_devices_action.rb', line 100

def self.is_supported?(platform)
  [:ios, :mac].include?(platform)
end

.outputObject



87
88
89
90
91
# File 'lib/fastlane/plugin/retrieve_devices/actions/retrieve_devices_action.rb', line 87

def self.output
  [
    ['DEVICES_FOR_APPLE_CERTIFICATE', 'A hash with the Name and UDID of each device registered with Apple']
  ]
end

.return_valueObject



93
94
# File 'lib/fastlane/plugin/retrieve_devices/actions/retrieve_devices_action.rb', line 93

def self.return_value
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/retrieve_devices/actions/retrieve_devices_action.rb', line 11

def self.run(params)
  require 'spaceship'

  UI.message("The retrieve_devices plugin is working!")

  if (api_token = Spaceship::ConnectAPI::Token.from(hash: params[:api_key], filepath: params[: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
    UI.message("Login to App Store Connect (#{params[:username]})")
    UI.message("\033[0;35mConsider using https://onetomany.dev/ to share the mobile MFA from your apple account if you are sharing an apple account\033[0m")
    credentials = CredentialsManager::AccountManager.new(user: params[:username])
    Spaceship::ConnectAPI.(credentials.user, credentials.password, use_portal: true, use_tunes: false)
    UI.message("Login successful")
  end

  UI.message("Fetching list of currently registered devices...")
  existing_devices = Spaceship::ConnectAPI::Device.all.map { |ed| { name: ed.name, udid: ed.udid } }

  UI.success("Successfully retrieved the following devices")

  existing_devices.each do |ed|
    UI.message("UDID: #{ed[:udid]} | NAME: #{ed[:name]}")
  end

  Actions.lane_context[SharedValues::DEVICES_FOR_APPLE_CERTIFICATE] = existing_devices
end