Class: Fastlane::Actions::FirebaseAppDistributionRemoveTestersAction

Inherits:
Action
  • Object
show all
Extended by:
Fastlane::Auth::FirebaseAppDistributionAuthClient, Helper::FirebaseAppDistributionHelper
Defined in:
lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_remove_testers_action.rb

Constant Summary

Constants included from Fastlane::Auth::FirebaseAppDistributionAuthClient

Fastlane::Auth::FirebaseAppDistributionAuthClient::CLIENT_ID, Fastlane::Auth::FirebaseAppDistributionAuthClient::CLIENT_SECRET, Fastlane::Auth::FirebaseAppDistributionAuthClient::REDACTION_CHARACTER, Fastlane::Auth::FirebaseAppDistributionAuthClient::REDACTION_EXPOSED_LENGTH, Fastlane::Auth::FirebaseAppDistributionAuthClient::SCOPE, Fastlane::Auth::FirebaseAppDistributionAuthClient::TOKEN_CREDENTIAL_URI

Class Method Summary collapse

Methods included from Fastlane::Auth::FirebaseAppDistributionAuthClient

get_authorization

Methods included from Helper::FirebaseAppDistributionHelper

app_id_from_params, app_name_from_app_id, binary_type_from_path, blank?, deep_symbolize_keys, get_ios_app_id_from_archive_plist, get_ios_app_id_from_plist, get_value_from_value_or_file, group_name, init_google_api_client, lane_platform, parse_plist, present?, project_name, project_number_from_app_id, string_to_array, xcode_archive_path

Class Method Details

.authorsObject



45
46
47
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_remove_testers_action.rb', line 45

def self.authors
  ["Tunde Agboola"]
end

.available_optionsObject



54
55
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
86
87
88
89
90
91
92
93
94
95
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_remove_testers_action.rb', line 54

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :project_number,
                                env_name: "FIREBASEAPPDISTRO_PROJECT_NUMBER",
                                description: "Your Firebase project number. You can find the project number in the Firebase console, on the General Settings page",
                                type: Integer,
                                 optional: false),
    FastlaneCore::ConfigItem.new(key: :emails,
                                env_name: "FIREBASEAPPDISTRO_REMOVE_TESTERS_EMAILS",
                                description: "Comma separated list of tester emails to be deleted (or removed from a group if a group alias is specified). A maximum of 1000 testers can be deleted/removed at a time",
                                optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :file,
                                env_name: "FIREBASEAPPDISTRO_REMOVE_TESTERS_FILE",
                                description: "Path to a file containing a comma separated list of tester emails to be deleted (or removed from a group if a group alias is specified). A maximum of 1000 testers can be deleted/removed at a time",
                                optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :group_alias,
                                 env_name: "FIREBASEAPPDISTRO_REMOVE_TESTERS_GROUP_ALIAS",
                                 description: "Alias of the group to remove the specified testers from. Testers will not be deleted from the project",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :service_credentials_file,
                                description: "Path to Google service credentials file",
                                optional: true,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :service_credentials_json_data,
                                 description: "Google service account json file content",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :firebase_cli_token,
                                 description: "Auth token generated using the Firebase CLI's login:ci command",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :debug,
                                 description: "Print verbose debug output",
                                 optional: true,
                                 default_value: false,
                                 is_string: false)

  ]
end

.descriptionObject



41
42
43
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_remove_testers_action.rb', line 41

def self.description
  "Delete testers in bulk from a comma-separated list or a file"
end

.detailsObject

supports markdown.



50
51
52
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_remove_testers_action.rb', line 50

def self.details
  "Delete testers in bulk from a comma-separated list or a file"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_remove_testers_action.rb', line 97

def self.is_supported?(platform)
  true
end

.remove_testers_from_group(client, project_number, group_alias, emails) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_remove_testers_action.rb', line 121

def self.remove_testers_from_group(client, project_number, group_alias, emails)
  UI.message("⏳ Removing #{emails.count} testers from group #group_alias}...")
  request = Google::Apis::FirebaseappdistributionV1::GoogleFirebaseAppdistroV1BatchLeaveGroupRequest.new(
    emails: emails
  )

  begin
    client.batch_project_group_leave(group_name(project_number, group_alias), request)
  rescue Google::Apis::Error => err
    case err.status_code.to_i
    when 400
      UI.user_error!(ErrorMessage::INVALID_EMAIL_ADDRESS)
    when 404
      UI.user_error!(ErrorMessage::INVALID_TESTER_GROUP)
    else
      UI.crash!(err)
    end
  end

  UI.success("✅ Tester(s) removed successfully.")
end

.remove_testers_from_project(client, project_number, emails) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/fastlane/plugin/firebase_app_distribution/actions/firebase_app_distribution_remove_testers_action.rb', line 101

def self.remove_testers_from_project(client, project_number, emails)
  UI.message("⏳ Removing #{emails.count} testers from project #{project_number}...")
  request = Google::Apis::FirebaseappdistributionV1::GoogleFirebaseAppdistroV1BatchRemoveTestersRequest.new(
    emails: emails
  )

  begin
    response = client.batch_project_tester_remove(project_name(project_number), request)
  rescue Google::Apis::Error => err
    case err.status_code.to_i
    when 404
      UI.user_error!(ErrorMessage::INVALID_PROJECT)
    else
      UI.crash!(err)
    end
  end

  UI.success("✅ #{response.emails.count} tester(s) removed successfully.")
end

.run(params) ⇒ Object



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/firebase_app_distribution/actions/firebase_app_distribution_remove_testers_action.rb', line 15

def self.run(params)
  init_google_api_client(params[:debug])
  client = Google::Apis::FirebaseappdistributionV1::FirebaseAppDistributionService.new
  client.authorization = get_authorization(params[:service_credentials_file], params[:firebase_cli_token], params[:service_credentials_json_data], params[:debug])

  if blank?(params[:emails]) && blank?(params[:file])
    UI.user_error!("Must specify `emails` or `file`.")
  end

  emails = string_to_array(get_value_from_value_or_file(params[:emails], params[:file]))
  project_number = params[:project_number]
  group_alias = params[:group_alias]

  UI.user_error!("Must pass at least one email") if blank?(emails)

  if emails.count > 1000
    UI.user_error!("A maximum of 1000 testers can be removed at a time.")
  end

  if present?(group_alias)
    remove_testers_from_group(client, project_number, group_alias, emails)
  else
    remove_testers_from_project(client, project_number, emails)
  end
end