fastlane-plugin-airwatch_workspaceone 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -7
- data/lib/fastlane/plugin/airwatch_workspaceone/actions/add_or_update_assignments_action.rb +310 -0
- data/lib/fastlane/plugin/airwatch_workspaceone/actions/delete_previous_versions_action.rb +219 -0
- data/lib/fastlane/plugin/airwatch_workspaceone/actions/delete_specific_version_action.rb +205 -0
- data/lib/fastlane/plugin/airwatch_workspaceone/actions/deploy_build_action.rb +42 -43
- data/lib/fastlane/plugin/airwatch_workspaceone/actions/retire_previous_versions_action.rb +60 -48
- data/lib/fastlane/plugin/airwatch_workspaceone/actions/retire_specific_version_action.rb +212 -0
- data/lib/fastlane/plugin/airwatch_workspaceone/actions/unretire_all_versions.rb +200 -0
- data/lib/fastlane/plugin/airwatch_workspaceone/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24d6f4778a212b4ecd777581295f7455de5d3feb8a6fc664017106b97c4e0455
|
4
|
+
data.tar.gz: f26078ad12791c18fa6bde200e0c5e97633eec8f56f2cbc2868b00387515986c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f03c8eaee4e59ea57e1043164eb728f45294591d87b5d177d43ecaf1adc670c350a79cc8fc481a07ee04c77cfa0b8470bf2ee62742145ea73139ca27d9915c3
|
7
|
+
data.tar.gz: cf7bb83f7658e8eda12cf337ef3345c5fcb0c8de2235e8d8f6b239c50905a45becb1b2bd58588b9878d0c11378eb95a36c5ba263f818a1a56748adecf0d018ab
|
data/README.md
CHANGED
@@ -12,24 +12,42 @@ fastlane add_plugin airwatch_workspaceone
|
|
12
12
|
|
13
13
|
## About airwatch_workspaceone
|
14
14
|
|
15
|
-
The main purpose of this plugin is to upload an IPA or an APK file to an AirWatch or Workspace ONE enterprise instance/console.
|
15
|
+
The main purpose of this plugin is to upload an IPA or an APK file to an AirWatch or Workspace ONE enterprise instance/console. For Android, the plugin works only with legacy AirWatch console and not with Workspace ONE console.
|
16
16
|
|
17
|
-
This plugin features
|
18
|
-
1. deploy_build - To upload an iOS ipa
|
19
|
-
2. retire_previous_versions -
|
17
|
+
This plugin features following actions :-
|
18
|
+
1. deploy_build - To upload an iOS ipa to both legacy AirWatch and Workspace ONE console. Also, to upload an Android APK to legacy AirWatch console.
|
19
|
+
2. retire_previous_versions - The main purpose of this action is to retire previous active versions of an application. This action takes a string parameter where you can specify the number of latest versions to keep if you do not want to retire all the previous active versions.
|
20
|
+
3. delete_previous_versions - The main purpose of this action is to delete versions of an application. This action takes a string parameter where you can specify the number of latest versions to keep if you do not want to delete all the versions.
|
21
|
+
4. retire_specific_version - The main purpose of this action is to retire a specific version of an application. This action takes a string parameter where you can specify the version number to retire.
|
22
|
+
5. delete_specific_version - The main purpose of this action is to delete a specific version of an application. This action takes a string parameter where you can specify the version number to delete.
|
23
|
+
6. add_or_update_assignments_action - The main purpose of this action is to add a new smart group assignment to an application or to update an existing smart group assignment of an application with a given dictionary of deployment/assignment parameters. If a smart group name is provided which does not exist yet on Console, assignment for that smart group is ignored.
|
24
|
+
7. unretire_all_versions - The main purpose of this action is to unretire all retired versions of an application.
|
20
25
|
|
21
26
|
## Available options
|
22
27
|
|
23
28
|
To check for available options, run
|
24
29
|
|
25
30
|
```bash
|
26
|
-
fastlane action
|
31
|
+
fastlane action deploy_build
|
27
32
|
```
|
28
|
-
and
|
29
|
-
|
30
33
|
```bash
|
31
34
|
fastlane action retire_previous_versions
|
32
35
|
```
|
36
|
+
```bash
|
37
|
+
fastlane action delete_previous_versions
|
38
|
+
```
|
39
|
+
```bash
|
40
|
+
fastlane action retire_specific_version
|
41
|
+
```
|
42
|
+
```bash
|
43
|
+
fastlane action delete_specific_version
|
44
|
+
```
|
45
|
+
```bash
|
46
|
+
fastlane action add_or_update_assignments
|
47
|
+
```
|
48
|
+
```bash
|
49
|
+
fastlane action unretire_all_versions
|
50
|
+
```
|
33
51
|
|
34
52
|
## Example
|
35
53
|
|
@@ -0,0 +1,310 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/airwatch_workspaceone_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
class AddOrUpdateAssignmentsAction < Action
|
7
|
+
|
8
|
+
APP_VERSIONS_LIST_SUFFIX = "/API/mam/apps/search?bundleid=%s"
|
9
|
+
ADD_UPDATE_ASSIGNMENT_SUFFIX = "/API/mam/apps/internal/%d/assignments"
|
10
|
+
SEARCH_SMART_GROUP_SUFFIX = "/API/mdm/smartgroups/search?name=%s&organizationgroupid=%d"
|
11
|
+
|
12
|
+
$is_debug = false
|
13
|
+
$app_id_int
|
14
|
+
|
15
|
+
def self.run(params)
|
16
|
+
UI.message("The airwatch_workspaceone plugin is working!")
|
17
|
+
|
18
|
+
# check if debug is enabled
|
19
|
+
$is_debug = params[:debug]
|
20
|
+
|
21
|
+
if debug
|
22
|
+
UI.message("----------------------------------------------")
|
23
|
+
UI.message("AddOrUpdateAssignmentsAction debug information")
|
24
|
+
UI.message("----------------------------------------------")
|
25
|
+
UI.message(" host_url: #{params[:host_url]}")
|
26
|
+
UI.message(" aw_tenant_code: #{params[:aw_tenant_code]}")
|
27
|
+
UI.message(" b64_encoded_auth: #{params[:b64_encoded_auth]}")
|
28
|
+
UI.message(" organization_group_id: #{params[:org_group_id]}")
|
29
|
+
UI.message(" app_identifier: #{params[:app_identifier]}")
|
30
|
+
UI.message(" smart_groups_to_assign: #{params[:smart_groups_to_assign]}")
|
31
|
+
UI.message(" assignment_parameters: #{params[:assignment_parameters]}")
|
32
|
+
end
|
33
|
+
|
34
|
+
$host_url = params[:host_url]
|
35
|
+
$aw_tenant_code = params[:aw_tenant_code]
|
36
|
+
$b64_encoded_auth = params[:b64_encoded_auth]
|
37
|
+
$org_group_id = params[:org_group_id]
|
38
|
+
app_identifier = params[:app_identifier]
|
39
|
+
smart_groups_to_assign = params[:smart_groups_to_assign]
|
40
|
+
assignment_parameters = params[:assignment_parameters]
|
41
|
+
|
42
|
+
# step 1: find app
|
43
|
+
UI.message("-----------------------------")
|
44
|
+
UI.message("1. Finding app's smart groups")
|
45
|
+
UI.message("-----------------------------")
|
46
|
+
|
47
|
+
app_smart_groups = find_app_smart_groups(app_identifier)
|
48
|
+
UI.success("Found %d smart group(s) assigned to the app." % [app_smart_groups.count])
|
49
|
+
UI.success("Smart Group(s): %s" % [app_smart_groups.map {|smart_group| smart_group.values[1]}])
|
50
|
+
|
51
|
+
# step 2: separate smart groups into need to add and need to update
|
52
|
+
UI.message("-----------------------------------------------")
|
53
|
+
UI.message("2. Separating smart groups to add and to update")
|
54
|
+
UI.message("-----------------------------------------------")
|
55
|
+
|
56
|
+
update_smart_group_ids = Array.new
|
57
|
+
update_smart_group_names = Array.new
|
58
|
+
add_smart_group_ids = Array.new
|
59
|
+
add_smart_group_names = Array.new
|
60
|
+
|
61
|
+
smart_groups_to_assign.each do |smart_group|
|
62
|
+
UI.message("Fetching details for %s smart group" % [smart_group])
|
63
|
+
smart_group_id = find_smart_group_id(smart_group)
|
64
|
+
if smart_group_id == -1
|
65
|
+
UI.important("Could not find smart group named %s in the given organization group. Skipping this smart group assignment." % [smart_group])
|
66
|
+
else
|
67
|
+
if app_smart_groups.map {|smart_group| smart_group.values[0]}.include? smart_group_id
|
68
|
+
UI.message("Assignment to the smart group %s needs to be updated" % [smart_group])
|
69
|
+
update_smart_group_ids << smart_group_id
|
70
|
+
update_smart_group_names << smart_group
|
71
|
+
else
|
72
|
+
UI.message("Assignment to the smart group %s needs to be added" % [smart_group])
|
73
|
+
add_smart_group_ids << smart_group_id
|
74
|
+
add_smart_group_names << smart_group
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# step 3: update smart group assignments
|
80
|
+
UI.message("--------------------------------------------")
|
81
|
+
UI.message("3. Updating existing smart group assignments")
|
82
|
+
UI.message("--------------------------------------------")
|
83
|
+
|
84
|
+
if update_smart_group_ids.count <= 0
|
85
|
+
UI.success("No existing smart groups assignment needs to be updated")
|
86
|
+
else
|
87
|
+
add_update_smart_group_assignment(update_smart_group_ids, assignment_parameters, true)
|
88
|
+
UI.success("Assignment for smart group(s): %s successfully updated" % [update_smart_group_names])
|
89
|
+
end
|
90
|
+
|
91
|
+
# step 4: add smart group assignments
|
92
|
+
UI.message("-------------------------------------")
|
93
|
+
UI.message("4. Adding new smart group assignments")
|
94
|
+
UI.message("-------------------------------------")
|
95
|
+
|
96
|
+
if add_smart_group_ids.count <= 0
|
97
|
+
UI.success("No new groups assignment needs to be added")
|
98
|
+
else
|
99
|
+
add_update_smart_group_assignment(add_smart_group_ids, assignment_parameters, false)
|
100
|
+
UI.success("Assignment for smart group(s): %s successfully added" % [add_smart_group_names])
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.find_app_smart_groups(app_identifier)
|
105
|
+
# get the list of apps
|
106
|
+
data = list_app_versions(app_identifier)
|
107
|
+
app_versions = data['Application']
|
108
|
+
|
109
|
+
if app_versions.count <= 0
|
110
|
+
UI.user_error!("No app found on the console having bundle identifier: %s" % [app_identifier])
|
111
|
+
UI.user_error!("Please provide an existing app identifier")
|
112
|
+
exit
|
113
|
+
end
|
114
|
+
|
115
|
+
latest_app_version = app_versions.last
|
116
|
+
$app_id_int = latest_app_version['Id']['Value']
|
117
|
+
app_smart_groups = latest_app_version['SmartGroups']
|
118
|
+
return app_smart_groups
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.list_app_versions(app_identifier)
|
122
|
+
require 'rest-client'
|
123
|
+
require 'json'
|
124
|
+
|
125
|
+
response = RestClient.get($host_url + APP_VERSIONS_LIST_SUFFIX % [app_identifier], {accept: :json, 'aw-tenant-code': $aw_tenant_code, 'Authorization': "Basic " + $b64_encoded_auth})
|
126
|
+
|
127
|
+
if debug
|
128
|
+
UI.message("Response code: %d" % [response.code])
|
129
|
+
UI.message("Response body:")
|
130
|
+
UI.message(response.body)
|
131
|
+
end
|
132
|
+
|
133
|
+
if response.code != 200
|
134
|
+
UI.user_error!("There was an error in finding app versions. One possible reason is that an app with the bundle identifier given does not exist on Console.")
|
135
|
+
exit
|
136
|
+
end
|
137
|
+
|
138
|
+
json = JSON.parse(response.body)
|
139
|
+
return json
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.find_smart_group_id(smart_group_name)
|
143
|
+
data = fetch_smart_group_details(smart_group_name)
|
144
|
+
smart_group_id = -1
|
145
|
+
if data.empty?
|
146
|
+
return smart_group_id
|
147
|
+
end
|
148
|
+
|
149
|
+
data['SmartGroups'].each do |smart_group|
|
150
|
+
smart_group_id = smart_group['SmartGroupID']
|
151
|
+
end
|
152
|
+
|
153
|
+
return smart_group_id
|
154
|
+
end
|
155
|
+
|
156
|
+
def self.fetch_smart_group_details(smart_group_name)
|
157
|
+
require 'rest-client'
|
158
|
+
require 'json'
|
159
|
+
|
160
|
+
response = RestClient.get($host_url + SEARCH_SMART_GROUP_SUFFIX % [smart_group_name, $org_group_id], {accept: :json, 'aw-tenant-code': $aw_tenant_code, 'Authorization': "Basic " + $b64_encoded_auth})
|
161
|
+
|
162
|
+
if debug
|
163
|
+
UI.message("Response code: %d" % [response.code])
|
164
|
+
UI.message("Response body:")
|
165
|
+
UI.message(response.body)
|
166
|
+
end
|
167
|
+
|
168
|
+
if response.code != 200
|
169
|
+
return Hash.new
|
170
|
+
end
|
171
|
+
|
172
|
+
json = JSON.parse(response.body)
|
173
|
+
return json
|
174
|
+
end
|
175
|
+
|
176
|
+
def self.add_update_smart_group_assignment(smart_group_ids, assignment_parameters, update)
|
177
|
+
require 'rest-client'
|
178
|
+
require 'json'
|
179
|
+
|
180
|
+
body = {
|
181
|
+
"SmartGroupIds" => smart_group_ids,
|
182
|
+
"DeploymentParameters" => assignment_parameters
|
183
|
+
}
|
184
|
+
|
185
|
+
if debug
|
186
|
+
UI.message("Deploy Request JSON:")
|
187
|
+
UI.message(body.to_json)
|
188
|
+
end
|
189
|
+
|
190
|
+
if update
|
191
|
+
response = RestClient.put($host_url + ADD_UPDATE_ASSIGNMENT_SUFFIX % [$app_id_int], body.to_json, {content_type: :json, accept: :json, 'aw-tenant-code': $aw_tenant_code, 'Authorization': "Basic " + $b64_encoded_auth})
|
192
|
+
else
|
193
|
+
response = RestClient.post($host_url + ADD_UPDATE_ASSIGNMENT_SUFFIX % [$app_id_int], body.to_json, {content_type: :json, accept: :json, 'aw-tenant-code': $aw_tenant_code, 'Authorization': "Basic " + $b64_encoded_auth})
|
194
|
+
end
|
195
|
+
|
196
|
+
if debug
|
197
|
+
UI.message("Response code: %d" % [response.code])
|
198
|
+
UI.message("Response body:")
|
199
|
+
UI.message(response.body)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def self.description
|
204
|
+
"The main purpose of this action is to add a new smart group assignment to an application or to update an existing smart group assignment of an application with a given dictionary of deployment/assignment parameters. If a smart group name is provided which does not exist yet on Console, assignment for that smart group is ignored."
|
205
|
+
end
|
206
|
+
|
207
|
+
def self.authors
|
208
|
+
["Ram Awadhesh Sharan"]
|
209
|
+
end
|
210
|
+
|
211
|
+
def self.return_value
|
212
|
+
# If your method provides a return value, you can describe here what it does
|
213
|
+
end
|
214
|
+
|
215
|
+
def self.details
|
216
|
+
# Optional:
|
217
|
+
"add_or_update_assignments - To add or update smart group assignments with given deployment parameters."
|
218
|
+
end
|
219
|
+
|
220
|
+
def self.available_options
|
221
|
+
[
|
222
|
+
FastlaneCore::ConfigItem.new(key: :host_url,
|
223
|
+
env_name: "AIRWATCH_HOST_API_URL",
|
224
|
+
description: "Host API URL of the AirWatch instance",
|
225
|
+
optional: false,
|
226
|
+
type: String,
|
227
|
+
verify_block: proc do |value|
|
228
|
+
UI.user_error!("No AirWatch Host API URl given.") unless value and !value.empty?
|
229
|
+
end),
|
230
|
+
|
231
|
+
FastlaneCore::ConfigItem.new(key: :aw_tenant_code,
|
232
|
+
env_name: "AIRWATCH_API_KEY",
|
233
|
+
description: "API key or the tenant code to access AirWatch Rest APIs",
|
234
|
+
optional: false,
|
235
|
+
type: String,
|
236
|
+
verify_block: proc do |value|
|
237
|
+
UI.user_error!("Api tenant code header is missing.") unless value and !value.empty?
|
238
|
+
end),
|
239
|
+
|
240
|
+
FastlaneCore::ConfigItem.new(key: :b64_encoded_auth,
|
241
|
+
env_name: "AIRWATCH_BASE64_ENCODED_BASIC_AUTH_STRING",
|
242
|
+
description: "The base64 encoded Basic Auth string generated by authorizing username and password to the AirWatch instance",
|
243
|
+
optional: false,
|
244
|
+
type: String,
|
245
|
+
verify_block: proc do |value|
|
246
|
+
UI.user_error!("The authorization header is empty or the scheme is not basic") unless value and !value.empty?
|
247
|
+
end),
|
248
|
+
|
249
|
+
FastlaneCore::ConfigItem.new(key: :org_group_id,
|
250
|
+
env_name: "AIRWATCH_ORGANIZATION_GROUP_ID",
|
251
|
+
description: "Organization Group ID integer identifying the customer or container",
|
252
|
+
optional: false,
|
253
|
+
type: String,
|
254
|
+
verify_block: proc do |value|
|
255
|
+
UI.user_error!("No Organization Group ID integer given, pass using `org_group_id: MyOrgGroupId`") unless value and !value.empty?
|
256
|
+
end),
|
257
|
+
|
258
|
+
FastlaneCore::ConfigItem.new(key: :app_identifier,
|
259
|
+
env_name: "APP_IDENTIFIER",
|
260
|
+
description: "Bundle identifier of your app",
|
261
|
+
optional: false,
|
262
|
+
type: String,
|
263
|
+
verify_block: proc do |value|
|
264
|
+
UI.user_error!("No app identifier given, pass using `app_identifier: 'com.example.app'`") unless value and !value.empty?
|
265
|
+
end),
|
266
|
+
|
267
|
+
FastlaneCore::ConfigItem.new(key: :smart_groups_to_assign,
|
268
|
+
env_name: "AIRWATCH_SMART_GROUPS_TO_ASSIGN",
|
269
|
+
description: "Name of the smart group to assign to",
|
270
|
+
optional: false,
|
271
|
+
type: Array,
|
272
|
+
verify_block: proc do |value|
|
273
|
+
UI.user_error!("No smart group given, pass using `smart_group_to_assign: 'MyAppDevTeam'`") unless value and !value.empty?
|
274
|
+
end),
|
275
|
+
|
276
|
+
FastlaneCore::ConfigItem.new(key: :assignment_parameters,
|
277
|
+
env_name: "AIRWATCH_ASSIGNMENT_PARAMETERS",
|
278
|
+
description: "Deployment parameters for the smart group assignment",
|
279
|
+
optional: false,
|
280
|
+
is_string: false,
|
281
|
+
verify_block: proc do |value|
|
282
|
+
UI.user_error!("No deployment parameters given, pass using `assignment_parameters: '{key1: value1, key2: value2}'`") unless value and !value.empty?
|
283
|
+
end),
|
284
|
+
|
285
|
+
FastlaneCore::ConfigItem.new(key: :debug,
|
286
|
+
env_name: "AIRWATCH_DEBUG",
|
287
|
+
description: "Debug flag, set to true to show extended output. default: false",
|
288
|
+
optional: true,
|
289
|
+
is_string: false,
|
290
|
+
default_value: false)
|
291
|
+
]
|
292
|
+
end
|
293
|
+
|
294
|
+
def self.is_supported?(platform)
|
295
|
+
# Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
|
296
|
+
# See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
|
297
|
+
#
|
298
|
+
[:ios, :android].include?(platform)
|
299
|
+
true
|
300
|
+
end
|
301
|
+
|
302
|
+
# helpers
|
303
|
+
|
304
|
+
def self.debug
|
305
|
+
$is_debug
|
306
|
+
end
|
307
|
+
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
@@ -0,0 +1,219 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/airwatch_workspaceone_helper'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
class DeletePreviousVersionsAction < Action
|
7
|
+
|
8
|
+
APP_VERSIONS_LIST_SUFFIX = "/API/mam/apps/search?bundleid=%s"
|
9
|
+
INTERNAL_APP_DELETE_SUFFIX = "/API/mam/apps/internal/%d"
|
10
|
+
|
11
|
+
$is_debug = false
|
12
|
+
|
13
|
+
def self.run(params)
|
14
|
+
UI.message("The airwatch_workspaceone plugin is working!")
|
15
|
+
|
16
|
+
# check if debug is enabled
|
17
|
+
$is_debug = params[:debug]
|
18
|
+
|
19
|
+
if debug
|
20
|
+
UI.message("----------------------------------------------")
|
21
|
+
UI.message("DeletePreviousVersionsAction debug information")
|
22
|
+
UI.message("----------------------------------------------")
|
23
|
+
UI.message(" host_url: #{params[:host_url]}")
|
24
|
+
UI.message(" aw_tenant_code: #{params[:aw_tenant_code]}")
|
25
|
+
UI.message(" b64_encoded_auth: #{params[:b64_encoded_auth]}")
|
26
|
+
UI.message(" app_identifier: #{params[:app_identifier]}")
|
27
|
+
UI.message(" keep_latest_versions_count: #{params[:keep_latest_versions_count]}")
|
28
|
+
end
|
29
|
+
|
30
|
+
$host_url = params[:host_url]
|
31
|
+
$aw_tenant_code = params[:aw_tenant_code]
|
32
|
+
$b64_encoded_auth = params[:b64_encoded_auth]
|
33
|
+
app_identifier = params[:app_identifier]
|
34
|
+
keep_latest_versions_count = params[:keep_latest_versions_count]
|
35
|
+
|
36
|
+
# step 1: find app
|
37
|
+
UI.message("-----------------------")
|
38
|
+
UI.message("1. Finding app versions")
|
39
|
+
UI.message("-----------------------")
|
40
|
+
|
41
|
+
app_versions = find_app(app_identifier)
|
42
|
+
UI.success("Found %d app version(s)" % [app_versions.count])
|
43
|
+
UI.success("Version number(s): %s" % [app_versions.map {|app_version| app_version.values[1]}])
|
44
|
+
|
45
|
+
# step 2: delete versions
|
46
|
+
UI.message("------------------------")
|
47
|
+
UI.message("2. Deleting app versions")
|
48
|
+
UI.message("------------------------")
|
49
|
+
|
50
|
+
keep_latest_versions_count_int = keep_latest_versions_count.to_i
|
51
|
+
if app_versions.count < keep_latest_versions_count_int
|
52
|
+
UI.important("Given number of latest versions to keep is greater than available number of versions on the store.")
|
53
|
+
UI.important("Will not delete any version.")
|
54
|
+
else
|
55
|
+
app_versions.pop(keep_latest_versions_count_int)
|
56
|
+
UI.important("Version number(s) to delete: %s" % [app_versions.map {|app_version| app_version.values[1]}])
|
57
|
+
app_versions.each do |app_version|
|
58
|
+
delete_app(app_version)
|
59
|
+
end
|
60
|
+
UI.success("Version(s) %s successfully deleted." % [app_versions.map {|app_version| app_version.values[1]}])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.find_app(app_identifier)
|
65
|
+
# get the list of apps
|
66
|
+
data = list_app_versions(app_identifier)
|
67
|
+
app_versions = Array.new
|
68
|
+
active_app_versions = Array.new
|
69
|
+
retired_app_versions = Array.new
|
70
|
+
|
71
|
+
data['Application'].each do |app|
|
72
|
+
if app['Status'] == "Active"
|
73
|
+
active_app_version = Hash.new
|
74
|
+
active_app_version['Id'] = app['Id']['Value']
|
75
|
+
active_app_version['Version'] = app['AppVersion']
|
76
|
+
active_app_versions << active_app_version
|
77
|
+
elsif app["Status"] == "Retired"
|
78
|
+
retired_app_version = Hash.new
|
79
|
+
retired_app_version['Id'] = app['Id']['Value']
|
80
|
+
retired_app_version['Version'] = app['AppVersion']
|
81
|
+
retired_app_versions << retired_app_version
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
app_versions.push(*retired_app_versions)
|
86
|
+
app_versions.push(*active_app_versions)
|
87
|
+
return app_versions
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.list_app_versions(app_identifier)
|
91
|
+
require 'rest-client'
|
92
|
+
require 'json'
|
93
|
+
|
94
|
+
response = RestClient.get($host_url + APP_VERSIONS_LIST_SUFFIX % [app_identifier], {accept: :json, 'aw-tenant-code': $aw_tenant_code, 'Authorization': "Basic " + $b64_encoded_auth})
|
95
|
+
|
96
|
+
if debug
|
97
|
+
UI.message("Response code: %d" % [response.code])
|
98
|
+
UI.message("Response body:")
|
99
|
+
UI.message(response.body)
|
100
|
+
end
|
101
|
+
|
102
|
+
if response.code != 200
|
103
|
+
UI.user_error!("There was an error in finding app versions. One possible reason is that an app with the bundle identifier given does not exist on Console.")
|
104
|
+
exit
|
105
|
+
end
|
106
|
+
|
107
|
+
json = JSON.parse(response.body)
|
108
|
+
return json
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.delete_app(app_version)
|
112
|
+
require 'rest-client'
|
113
|
+
require 'json'
|
114
|
+
|
115
|
+
UI.message("Starting to delete app version: %s" % [app_version['Version']])
|
116
|
+
response = RestClient.delete($host_url + INTERNAL_APP_DELETE_SUFFIX % [app_version['Id']], {accept: :json, 'aw-tenant-code': $aw_tenant_code, 'Authorization': "Basic " + $b64_encoded_auth})
|
117
|
+
|
118
|
+
if debug
|
119
|
+
UI.message("Response code: %d" % [response.code])
|
120
|
+
end
|
121
|
+
|
122
|
+
if response.code == 204
|
123
|
+
UI.message("Successfully deleted app version: %s" % [app_version['Version']])
|
124
|
+
else
|
125
|
+
UI.message("Failed to delete app version: %s" % [app_version['Version']])
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.description
|
130
|
+
"The main purpose of this action is to delete versions of an application. This action takes a string parameter where you can specify the number of latest versions to keep if you do not want to delete all the versions."
|
131
|
+
end
|
132
|
+
|
133
|
+
def self.authors
|
134
|
+
["Ram Awadhesh Sharan"]
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.return_value
|
138
|
+
# If your method provides a return value, you can describe here what it does
|
139
|
+
end
|
140
|
+
|
141
|
+
def self.details
|
142
|
+
# Optional:
|
143
|
+
"delete_previous_versions - To delete versions of an application on the AirWatch console."
|
144
|
+
end
|
145
|
+
|
146
|
+
def self.available_options
|
147
|
+
[
|
148
|
+
FastlaneCore::ConfigItem.new(key: :host_url,
|
149
|
+
env_name: "AIRWATCH_HOST_API_URL",
|
150
|
+
description: "Host API URL of the AirWatch instance",
|
151
|
+
optional: false,
|
152
|
+
type: String,
|
153
|
+
verify_block: proc do |value|
|
154
|
+
UI.user_error!("No AirWatch Host API URl given.") unless value and !value.empty?
|
155
|
+
end),
|
156
|
+
|
157
|
+
FastlaneCore::ConfigItem.new(key: :aw_tenant_code,
|
158
|
+
env_name: "AIRWATCH_API_KEY",
|
159
|
+
description: "API key to access AirWatch Rest APIs",
|
160
|
+
optional: false,
|
161
|
+
type: String,
|
162
|
+
verify_block: proc do |value|
|
163
|
+
UI.user_error!("Api tenant code header is missing.") unless value and !value.empty?
|
164
|
+
end),
|
165
|
+
|
166
|
+
FastlaneCore::ConfigItem.new(key: :b64_encoded_auth,
|
167
|
+
env_name: "AIRWATCH_BASE64_ENCODED_BASIC_AUTH_STRING",
|
168
|
+
description: "The base64 encoded Basic Auth string generated by authorizing username and password to the AirWatch instance",
|
169
|
+
optional: false,
|
170
|
+
type: String,
|
171
|
+
verify_block: proc do |value|
|
172
|
+
UI.user_error!("The authorization header is empty or the scheme is not basic") unless value and !value.empty?
|
173
|
+
end),
|
174
|
+
|
175
|
+
FastlaneCore::ConfigItem.new(key: :app_identifier,
|
176
|
+
env_name: "APP_IDENTIFIER",
|
177
|
+
description: "Bundle identifier of your app",
|
178
|
+
optional: false,
|
179
|
+
type: String,
|
180
|
+
verify_block: proc do |value|
|
181
|
+
UI.user_error!("No app identifier given, pass using `app_identifier: 'com.example.app'`") unless value and !value.empty?
|
182
|
+
end),
|
183
|
+
|
184
|
+
FastlaneCore::ConfigItem.new(key: :keep_latest_versions_count,
|
185
|
+
env_name: "AIRWATCH_KEEP_LATEST_VERSIONS_COUNT",
|
186
|
+
description: "Name of the application. default: 0",
|
187
|
+
optional: true,
|
188
|
+
type: String,
|
189
|
+
default_value: "0",
|
190
|
+
verify_block: proc do |value|
|
191
|
+
UI.user_error!("The number of latest versions to keep can not be negative") unless value.to_i >= 0
|
192
|
+
end),
|
193
|
+
|
194
|
+
FastlaneCore::ConfigItem.new(key: :debug,
|
195
|
+
env_name: "AIRWATCH_DEBUG",
|
196
|
+
description: "Debug flag, set to true to show extended output. default: false",
|
197
|
+
optional: true,
|
198
|
+
is_string: false,
|
199
|
+
default_value: false)
|
200
|
+
]
|
201
|
+
end
|
202
|
+
|
203
|
+
def self.is_supported?(platform)
|
204
|
+
# Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
|
205
|
+
# See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
|
206
|
+
|
207
|
+
[:ios, :android].include?(platform)
|
208
|
+
true
|
209
|
+
end
|
210
|
+
|
211
|
+
# helpers
|
212
|
+
|
213
|
+
def self.debug
|
214
|
+
$is_debug
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|