fastlane-plugin-airwatch_workspaceone 1.0.2 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,8 +5,9 @@ module Fastlane
5
5
  module Actions
6
6
  class RetirePreviousVersionsAction < Action
7
7
 
8
- APPS_LIST_SUFFIX = "/API/mam/apps/search?bundleid=%s"
9
- INTERNAL_APP_RETIRE_SUFFIX = "/API/mam/apps/internal/%d/retire"
8
+ APP_VERSIONS_LIST_SUFFIX = "/API/mam/apps/search?applicationtype=Internal&bundleid=%s"
9
+ INTERNAL_APP_RETIRE_SUFFIX = "/API/mam/apps/internal/%d/retire"
10
+
10
11
  $is_debug = false
11
12
 
12
13
  def self.run(params)
@@ -16,103 +17,115 @@ module Fastlane
16
17
  $is_debug = params[:debug]
17
18
 
18
19
  if debug
19
- UI.message("---------------------------------")
20
- UI.message("AirWatch plugin debug information")
21
- UI.message("---------------------------------")
20
+ UI.message("----------------------------------------------")
21
+ UI.message("RetirePreviousVersionsAction debug information")
22
+ UI.message("----------------------------------------------")
22
23
  UI.message(" host_url: #{params[:host_url]}")
23
24
  UI.message(" aw_tenant_code: #{params[:aw_tenant_code]}")
24
25
  UI.message(" b64_encoded_auth: #{params[:b64_encoded_auth]}")
25
26
  UI.message(" app_identifier: #{params[:app_identifier]}")
26
- UI.message(" app_name: #{params[:app_name]}")
27
- UI.message("---------------------------------")
27
+ UI.message(" keep_latest_versions_count: #{params[:keep_latest_versions_count]}")
28
28
  end
29
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
- app_name = params[:app_name]
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
+ UI.message(APP_VERSIONS_LIST_SUFFIX % [app_identifier])
35
36
 
36
37
  # step 1: find app
37
38
  UI.message("------------------------------")
38
39
  UI.message("1. Finding active app versions")
39
40
  UI.message("------------------------------")
40
41
 
41
- appIDs = find_app(app_identifier, host_url, aw_tenant_code, b64_encoded_auth)
42
- UI.success("Found %d active app versions" % [appIDs.count])
43
- if debug
44
- UI.success("Integer app ids:")
45
- UI.success(appIDs)
46
- end
42
+ app_versions = find_app(app_identifier)
43
+ UI.success("Found %d active app version(s)" % [app_versions.count])
44
+ UI.success("Version number(s): %s" % [app_versions.map {|app_version| app_version.values[1]}])
47
45
 
48
46
  # step 2: retire previous versions
49
- UI.message("-------------------------------")
50
- UI.message("2. Retiring active app versions")
51
- UI.message("-------------------------------")
52
-
53
- appIDs.each do |appID|
54
- retire_app(host_url, aw_tenant_code, b64_encoded_auth, appID)
47
+ UI.message("-----------------------------------------")
48
+ UI.message("2. Retiring requested active app versions")
49
+ UI.message("-----------------------------------------")
50
+
51
+ keep_latest_versions_count_int = keep_latest_versions_count.to_i
52
+ if app_versions.count < keep_latest_versions_count_int
53
+ UI.important("Given number of latest versions to keep is greater than available number of versions on the store.")
54
+ UI.important("Will not retire any version.")
55
+ else
56
+ app_versions.pop(keep_latest_versions_count_int)
57
+ UI.important("Version number(s) to retire: %s" % [app_versions.map {|app_version| app_version.values[1]}])
58
+ app_versions.each do |app_version|
59
+ retire_app(app_version)
60
+ end
61
+ UI.success("Version(s) %s successfully retired." % [app_versions.map {|app_version| app_version.values[1]}])
55
62
  end
56
-
57
- UI.success("All active app versions successfully retired")
58
63
  end
59
64
 
60
- def self.find_app(app_identifier, host_url, aw_tenant_code, b64_encoded_auth)
65
+ def self.find_app(app_identifier)
61
66
  # get the list of apps
62
- data = list_apps(host_url, aw_tenant_code, b64_encoded_auth, app_identifier)
63
- active_app_version_ids = Array.new
67
+ data = list_app_versions(app_identifier)
68
+ active_app_versions = Array.new
64
69
 
65
70
  data['Application'].each do |app|
66
71
  if app['Status'] == "Active"
67
- active_app_version_ids << app['Id']['Value']
72
+ active_app_version = Hash.new
73
+ active_app_version['Id'] = app['Id']['Value']
74
+ active_app_version['Version'] = app['AppVersion']
75
+ active_app_versions << active_app_version
68
76
  end
69
77
  end
70
78
 
71
- active_app_version_ids.pop
72
- return active_app_version_ids
79
+ active_app_versions.sort_by! { |app_version| app_version["Id"] }
80
+ return active_app_versions
73
81
  end
74
82
 
75
- def self.list_apps(host_url, aw_tenant_code, b64_encoded_auth, app_identifier)
83
+ def self.list_app_versions(app_identifier)
76
84
  require 'rest-client'
77
85
  require 'json'
78
86
 
79
- response = RestClient.get(host_url + APPS_LIST_SUFFIX % [app_identifier], {accept: :json, 'aw-tenant-code': aw_tenant_code, 'Authorization': "Basic " + b64_encoded_auth})
87
+ response = RestClient.get($host_url + APP_VERSIONS_LIST_SUFFIX % [app_identifier], {accept: :json, 'aw-tenant-code': $aw_tenant_code, 'Authorization': "Basic " + $b64_encoded_auth})
80
88
 
81
89
  if debug
82
90
  UI.message("Response code: %d" % [response.code])
83
91
  UI.message("Response body:")
84
- UI.message(response.body)
92
+ UI.message(JSON.pretty_generate(response.body))
93
+ end
94
+
95
+ if response.code != 200
96
+ 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.")
97
+ exit
85
98
  end
86
99
 
87
100
  json = JSON.parse(response.body)
88
101
  return json
89
102
  end
90
103
 
91
- def self.retire_app(host_url, aw_tenant_code, b64_encoded_auth, app_id)
104
+ def self.retire_app(app_version)
92
105
  require 'rest-client'
93
106
  require 'json'
94
107
 
95
108
  body = {
96
- "applicationid" => app_id
109
+ "applicationid" => app_version['Id']
97
110
  }
98
111
 
99
- UI.message("Starting to retire app version having integer identifier: %d" % [app_id])
100
- response = RestClient.post(host_url + INTERNAL_APP_RETIRE_SUFFIX % [app_id], body.to_json, {accept: :json, 'aw-tenant-code': aw_tenant_code, 'Authorization': "Basic " + b64_encoded_auth})
112
+ UI.message("Starting to retire app version: %s" % [app_version['Version']])
113
+ response = RestClient.post($host_url + INTERNAL_APP_RETIRE_SUFFIX % [app_version['Id']], body.to_json, {accept: :json, 'aw-tenant-code': $aw_tenant_code, 'Authorization': "Basic " + $b64_encoded_auth})
101
114
 
102
115
  if debug
103
116
  UI.message("Response code: %d" % [response.code])
104
117
  end
105
118
 
106
119
  if response.code == 202
107
- UI.message("Successfully retired app version having integer identifier: %d" % [app_id])
120
+ UI.message("Successfully retired app version: %s" % [app_version['Version']])
108
121
  else
109
122
  json = JSON.parse(response.body)
110
- UI.message("Failed to retire app version having integer identifier: %d" % [app_id])
123
+ UI.message("Failed to retire app version: %s" % [app_version['Version']])
111
124
  end
112
125
  end
113
126
 
114
127
  def self.description
115
- "The main purpose of this action is to retire previous versions of the application"
128
+ "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."
116
129
  end
117
130
 
118
131
  def self.authors
@@ -125,36 +138,36 @@ module Fastlane
125
138
 
126
139
  def self.details
127
140
  # Optional:
128
- "retire_previous_versions - To retire all active versions of the application on the AirWatch console except the latest version."
141
+ "retire_previous_versions - To retire previous active versions of an application on the AirWatch/Workspace ONE console except the latest version."
129
142
  end
130
143
 
131
144
  def self.available_options
132
145
  [
133
146
  FastlaneCore::ConfigItem.new(key: :host_url,
134
147
  env_name: "AIRWATCH_HOST_API_URL",
135
- description: "Host API URL of the AirWatch instance",
148
+ description: "Host API URL of the AirWatch/Workspace ONE instance without /API/ at the end",
136
149
  optional: false,
137
150
  type: String,
138
151
  verify_block: proc do |value|
139
- UI.user_error!("No AirWatch Host API URl given.") unless value and !value.empty?
152
+ UI.user_error!("No AirWatch/Workspace ONE Host API URl given, pass using `host_url: 'https://yourhost.com'`") unless value and !value.empty?
140
153
  end),
141
154
 
142
155
  FastlaneCore::ConfigItem.new(key: :aw_tenant_code,
143
156
  env_name: "AIRWATCH_API_KEY",
144
- description: "API key to access AirWatch Rest APIs",
157
+ description: "API key or the tenant code to access AirWatch/Workspace ONE Rest APIs",
145
158
  optional: false,
146
159
  type: String,
147
160
  verify_block: proc do |value|
148
- UI.user_error!("Api tenant code header is missing.") unless value and !value.empty?
161
+ UI.user_error!("Api tenant code header is missing, pass using `aw_tenant_code: 'yourapikey'`") unless value and !value.empty?
149
162
  end),
150
163
 
151
164
  FastlaneCore::ConfigItem.new(key: :b64_encoded_auth,
152
165
  env_name: "AIRWATCH_BASE64_ENCODED_BASIC_AUTH_STRING",
153
- description: "The base64 encoded Basic Auth string generated by authorizing username and password to the AirWatch instance",
166
+ description: "The base64 encoded Basic Auth string generated by authorizing username and password to the AirWatch/Workspace ONE instance",
154
167
  optional: false,
155
168
  type: String,
156
169
  verify_block: proc do |value|
157
- UI.user_error!("The authorization header is empty or the scheme is not basic") unless value and !value.empty?
170
+ UI.user_error!("The authorization header is empty or the scheme is not basic, pass using `b64_encoded_auth: 'yourb64encodedauthstring'`") unless value and !value.empty?
158
171
  end),
159
172
 
160
173
  FastlaneCore::ConfigItem.new(key: :app_identifier,
@@ -166,13 +179,14 @@ module Fastlane
166
179
  UI.user_error!("No app identifier given, pass using `app_identifier: 'com.example.app'`") unless value and !value.empty?
167
180
  end),
168
181
 
169
- FastlaneCore::ConfigItem.new(key: :app_name,
170
- env_name: "AIRWATCH_APPLICATION_NAME",
171
- description: "Name of the application",
172
- optional: false,
182
+ FastlaneCore::ConfigItem.new(key: :keep_latest_versions_count,
183
+ env_name: "AIRWATCH_KEEP_LATEST_VERSIONS_COUNT",
184
+ description: "Name of the application. default: 1",
185
+ optional: true,
173
186
  type: String,
187
+ default_value: "1",
174
188
  verify_block: proc do |value|
175
- UI.user_error!("No app name given, pass using `app_name: 'My sample app'`") unless value and !value.empty?
189
+ UI.user_error!("The number of latest versions to keep can not be negative, pass using `keep_latest_versions_count: 'count'`") unless value.to_i > 0
176
190
  end),
177
191
 
178
192
  FastlaneCore::ConfigItem.new(key: :debug,
@@ -200,4 +214,4 @@ module Fastlane
200
214
 
201
215
  end
202
216
  end
203
- end
217
+ end
@@ -0,0 +1,213 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/airwatch_workspaceone_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class RetireSpecificVersionAction < Action
7
+
8
+ APP_VERSIONS_LIST_SUFFIX = "/API/mam/apps/search?applicationtype=Internal&bundleid=%s"
9
+ INTERNAL_APP_RETIRE_SUFFIX = "/API/mam/apps/internal/%d/retire"
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("RetireSpecificVersionAction 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(" version_number: #{params[:version_number]}")
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
+ version_number = params[:version_number]
35
+
36
+ # step 1: find app
37
+ UI.message("------------------------------")
38
+ UI.message("1. Finding active app versions")
39
+ UI.message("------------------------------")
40
+
41
+ app_versions = find_app(app_identifier)
42
+ app_version_numbers = app_versions.map {|app_version| app_version.values[1]}
43
+ UI.success("Found %d active app version(s)" % [app_versions.count])
44
+ UI.success("Version number(s): %s" % [app_version_numbers])
45
+
46
+ # step 2: retire specific version
47
+ UI.message("--------------------------------")
48
+ UI.message("2. Retiring specific app version")
49
+ UI.message("--------------------------------")
50
+
51
+ if app_version_numbers.include? version_number
52
+ version_index = app_version_numbers.index(version_number)
53
+ app_version_to_retire = app_versions[version_index]
54
+ retire_app(app_version_to_retire)
55
+ else
56
+ UI.user_error!("A version with the given version number: %s does not exist on the console for this application or is already retired." % [version_number])
57
+ end
58
+
59
+ UI.success("Version %s successfully retired" % [version_number])
60
+ end
61
+
62
+ def self.find_app(app_identifier)
63
+ # get the list of apps
64
+ data = list_app_versions(app_identifier)
65
+ active_app_versions = Array.new
66
+
67
+ data['Application'].each do |app|
68
+ if app['Status'] == "Active"
69
+ active_app_version = Hash.new
70
+ active_app_version['Id'] = app['Id']['Value']
71
+ active_app_version['Version'] = app['AppVersion']
72
+ active_app_versions << active_app_version
73
+ end
74
+ end
75
+
76
+ active_app_versions.sort_by! { |app_version| app_version["Id"] }
77
+ return active_app_versions
78
+ end
79
+
80
+ def self.list_app_versions(app_identifier)
81
+ require 'rest-client'
82
+ require 'json'
83
+
84
+ response = RestClient.get($host_url + APP_VERSIONS_LIST_SUFFIX % [app_identifier], {accept: :json, 'aw-tenant-code': $aw_tenant_code, 'Authorization': "Basic " + $b64_encoded_auth})
85
+
86
+ if debug
87
+ UI.message("Response code: %d" % [response.code])
88
+ UI.message("Response body:")
89
+ UI.message(response.body)
90
+ end
91
+
92
+ if response.code != 200
93
+ 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.")
94
+ exit
95
+ end
96
+
97
+ json = JSON.parse(response.body)
98
+ return json
99
+ end
100
+
101
+ def self.retire_app(app_version)
102
+ require 'rest-client'
103
+ require 'json'
104
+
105
+ body = {
106
+ "applicationid" => app_version['Id']
107
+ }
108
+
109
+ UI.message("Starting to retire app version: %s" % [app_version['Version']])
110
+ response = RestClient.post($host_url + INTERNAL_APP_RETIRE_SUFFIX % [app_version['Id']], body.to_json, {accept: :json, 'aw-tenant-code': $aw_tenant_code, 'Authorization': "Basic " + $b64_encoded_auth})
111
+
112
+ if debug
113
+ UI.message("Response code: %d" % [response.code])
114
+ end
115
+
116
+ if response.code == 202
117
+ UI.message("Successfully retired app version: %s" % [app_version['Version']])
118
+ else
119
+ json = JSON.parse(response.body)
120
+ UI.message("Failed to retire app version: %s" % [app_version['Version']])
121
+ end
122
+ end
123
+
124
+ def self.description
125
+ "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."
126
+ end
127
+
128
+ def self.authors
129
+ ["Ram Awadhesh Sharan"]
130
+ end
131
+
132
+ def self.return_value
133
+ # If your method provides a return value, you can describe here what it does
134
+ end
135
+
136
+ def self.details
137
+ # Optional:
138
+ "retire_specific_version - To retire specific version of an application on the AirWatch/Workspace ONE console."
139
+ end
140
+
141
+ def self.available_options
142
+ [
143
+ FastlaneCore::ConfigItem.new(key: :host_url,
144
+ env_name: "AIRWATCH_HOST_API_URL",
145
+ description: "Host API URL of the AirWatch/Workspace ONE instance without /API/ at the end",
146
+ optional: false,
147
+ type: String,
148
+ verify_block: proc do |value|
149
+ UI.user_error!("No AirWatch/Workspace ONE Host API URl given, pass using `host_url: 'https://yourhost.com'`") unless value and !value.empty?
150
+ end),
151
+
152
+ FastlaneCore::ConfigItem.new(key: :aw_tenant_code,
153
+ env_name: "AIRWATCH_API_KEY",
154
+ description: "API key or the tenant code to access AirWatch/Workspace ONE Rest APIs",
155
+ optional: false,
156
+ type: String,
157
+ verify_block: proc do |value|
158
+ UI.user_error!("Api tenant code header is missing, pass using `aw_tenant_code: 'yourapikey'`") unless value and !value.empty?
159
+ end),
160
+
161
+ FastlaneCore::ConfigItem.new(key: :b64_encoded_auth,
162
+ env_name: "AIRWATCH_BASE64_ENCODED_BASIC_AUTH_STRING",
163
+ description: "The base64 encoded Basic Auth string generated by authorizing username and password to the AirWatch/Workspace ONE instance",
164
+ optional: false,
165
+ type: String,
166
+ verify_block: proc do |value|
167
+ UI.user_error!("The authorization header is empty or the scheme is not basic, pass using `b64_encoded_auth: 'yourb64encodedauthstring'`") unless value and !value.empty?
168
+ end),
169
+
170
+ FastlaneCore::ConfigItem.new(key: :app_identifier,
171
+ env_name: "APP_IDENTIFIER",
172
+ description: "Bundle identifier of your app",
173
+ optional: false,
174
+ type: String,
175
+ verify_block: proc do |value|
176
+ UI.user_error!("No app identifier given, pass using `app_identifier: 'com.example.app'`") unless value and !value.empty?
177
+ end),
178
+
179
+ FastlaneCore::ConfigItem.new(key: :version_number,
180
+ env_name: "AIRWATCH_VERSION_NUMBER",
181
+ description: "Version number of the application to retire",
182
+ optional: false,
183
+ type: String,
184
+ verify_block: proc do |value|
185
+ UI.user_error!("No version number given, pass using `version_number: '1.0'`") unless value and !value.empty?
186
+ end),
187
+
188
+ FastlaneCore::ConfigItem.new(key: :debug,
189
+ env_name: "AIRWATCH_DEBUG",
190
+ description: "Debug flag, set to true to show extended output. default: false",
191
+ optional: true,
192
+ is_string: false,
193
+ default_value: false)
194
+ ]
195
+ end
196
+
197
+ def self.is_supported?(platform)
198
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
199
+ # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
200
+
201
+ [:ios, :android].include?(platform)
202
+ true
203
+ end
204
+
205
+ # helpers
206
+
207
+ def self.debug
208
+ $is_debug
209
+ end
210
+
211
+ end
212
+ end
213
+ end
@@ -0,0 +1,201 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/airwatch_workspaceone_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class UnretireAllVersionsAction < Action
7
+
8
+ APP_VERSIONS_LIST_SUFFIX = "/API/mam/apps/search?applicationtype=Internal&bundleid=%s"
9
+ INTERNAL_APP_UNRETIRE_SUFFIX = "/API/mam/apps/internal/%d/unretire"
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("UnretireAllVersionsAction 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
+ end
28
+
29
+ $host_url = params[:host_url]
30
+ $aw_tenant_code = params[:aw_tenant_code]
31
+ $b64_encoded_auth = params[:b64_encoded_auth]
32
+ app_identifier = params[:app_identifier]
33
+
34
+ # step 1: find app
35
+ UI.message("-------------------------------")
36
+ UI.message("1. Finding retired app versions")
37
+ UI.message("-------------------------------")
38
+
39
+ retired_app_versions = find_app(app_identifier)
40
+ if retired_app_versions.count <= 0
41
+ UI.important("No retired app versions found for application with bundle identifier given: %s" % [app_identifier])
42
+ return
43
+ end
44
+
45
+ UI.success("Found %d retired app version(s)" % [retired_app_versions.count])
46
+ UI.success("Version number(s): %s" % [retired_app_versions.map {|retired_app_version| retired_app_version.values[1]}])
47
+
48
+ # step 2: retire previous versions
49
+ UI.message("----------------------------------")
50
+ UI.message("2. UnRetiring retired app versions")
51
+ UI.message("----------------------------------")
52
+
53
+ retired_app_versions.each do |retired_app_version|
54
+ unretire_app(retired_app_version)
55
+ end
56
+ UI.success("Version(s) %s successfully unretired." % [retired_app_versions.map {|retired_app_version| retired_app_version.values[1]}])
57
+ end
58
+
59
+ def self.find_app(app_identifier)
60
+ # get the list of apps
61
+ data = list_app_versions(app_identifier)
62
+ retired_app_versions = Array.new
63
+
64
+ data['Application'].each do |app|
65
+ if app['Status'] == "Retired"
66
+ retired_app_version = Hash.new
67
+ retired_app_version['Id'] = app['Id']['Value']
68
+ retired_app_version['Version'] = app['AppVersion']
69
+ retired_app_versions << retired_app_version
70
+ end
71
+ end
72
+
73
+ retired_app_versions.sort_by! { |app_version| app_version["Id"] }
74
+ return retired_app_versions
75
+ end
76
+
77
+ def self.list_app_versions(app_identifier)
78
+ require 'rest-client'
79
+ require 'json'
80
+
81
+ response = RestClient.get($host_url + APP_VERSIONS_LIST_SUFFIX % [app_identifier], {accept: :json, 'aw-tenant-code': $aw_tenant_code, 'Authorization': "Basic " + $b64_encoded_auth})
82
+
83
+ if debug
84
+ UI.message("Response code: %d" % [response.code])
85
+ UI.message("Response body:")
86
+ UI.message(response.body)
87
+ end
88
+
89
+ if response.code != 200
90
+ 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.")
91
+ exit
92
+ end
93
+
94
+ json = JSON.parse(response.body)
95
+ return json
96
+ end
97
+
98
+ def self.unretire_app(app_version)
99
+ require 'rest-client'
100
+ require 'json'
101
+
102
+ body = {
103
+ "applicationid" => app_version['Id']
104
+ }
105
+
106
+ UI.message("Starting to unretire app version: %s" % [app_version['Version']])
107
+ response = RestClient.post($host_url + INTERNAL_APP_UNRETIRE_SUFFIX % [app_version['Id']], body.to_json, {accept: :json, 'aw-tenant-code': $aw_tenant_code, 'Authorization': "Basic " + $b64_encoded_auth})
108
+
109
+ if debug
110
+ UI.message("Response code: %d" % [response.code])
111
+ end
112
+
113
+ if response.code == 202
114
+ UI.message("Successfully unretired app version: %s" % [app_version['Version']])
115
+ else
116
+ json = JSON.parse(response.body)
117
+ UI.message("Failed to unretire app version: %s" % [app_version['Version']])
118
+ end
119
+ end
120
+
121
+ def self.description
122
+ "The main purpose of this action is to unretire all retired versions of an application."
123
+ end
124
+
125
+ def self.authors
126
+ ["Ram Awadhesh Sharan"]
127
+ end
128
+
129
+ def self.return_value
130
+ # If your method provides a return value, you can describe here what it does
131
+ end
132
+
133
+ def self.details
134
+ # Optional:
135
+ "unretire_all_versions - To unretire all retired versions of an application on the AirWatch/Workspace ONE console."
136
+ end
137
+
138
+ def self.available_options
139
+ [
140
+ FastlaneCore::ConfigItem.new(key: :host_url,
141
+ env_name: "AIRWATCH_HOST_API_URL",
142
+ description: "Host API URL of the AirWatch/Workspace ONE instance without /API/ at the end",
143
+ optional: false,
144
+ type: String,
145
+ verify_block: proc do |value|
146
+ UI.user_error!("No AirWatch/Workspace ONE Host API URl given, pass using `host_url: 'https://yourhost.com'`") unless value and !value.empty?
147
+ end),
148
+
149
+ FastlaneCore::ConfigItem.new(key: :aw_tenant_code,
150
+ env_name: "AIRWATCH_API_KEY",
151
+ description: "API key or the tenant code to access AirWatch/Workspace ONE Rest APIs",
152
+ optional: false,
153
+ type: String,
154
+ verify_block: proc do |value|
155
+ UI.user_error!("Api tenant code header is missing, pass using `aw_tenant_code: 'yourapikey'`") unless value and !value.empty?
156
+ end),
157
+
158
+ FastlaneCore::ConfigItem.new(key: :b64_encoded_auth,
159
+ env_name: "AIRWATCH_BASE64_ENCODED_BASIC_AUTH_STRING",
160
+ description: "The base64 encoded Basic Auth string generated by authorizing username and password to the AirWatch/Workspace ONE instance",
161
+ optional: false,
162
+ type: String,
163
+ verify_block: proc do |value|
164
+ UI.user_error!("The authorization header is empty or the scheme is not basic, pass using `b64_encoded_auth: 'yourb64encodedauthstring'`") unless value and !value.empty?
165
+ end),
166
+
167
+ FastlaneCore::ConfigItem.new(key: :app_identifier,
168
+ env_name: "APP_IDENTIFIER",
169
+ description: "Bundle identifier of your app",
170
+ optional: false,
171
+ type: String,
172
+ verify_block: proc do |value|
173
+ UI.user_error!("No app identifier given, pass using `app_identifier: 'com.example.app'`") unless value and !value.empty?
174
+ end),
175
+
176
+ FastlaneCore::ConfigItem.new(key: :debug,
177
+ env_name: "AIRWATCH_DEBUG",
178
+ description: "Debug flag, set to true to show extended output. default: false",
179
+ optional: true,
180
+ is_string: false,
181
+ default_value: false)
182
+ ]
183
+ end
184
+
185
+ def self.is_supported?(platform)
186
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
187
+ # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
188
+
189
+ [:ios, :android].include?(platform)
190
+ true
191
+ end
192
+
193
+ # helpers
194
+
195
+ def self.debug
196
+ $is_debug
197
+ end
198
+
199
+ end
200
+ end
201
+ end