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.
@@ -0,0 +1,212 @@
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?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
+ return active_app_versions
77
+ end
78
+
79
+ def self.list_app_versions(app_identifier)
80
+ require 'rest-client'
81
+ require 'json'
82
+
83
+ response = RestClient.get($host_url + APP_VERSIONS_LIST_SUFFIX % [app_identifier], {accept: :json, 'aw-tenant-code': $aw_tenant_code, 'Authorization': "Basic " + $b64_encoded_auth})
84
+
85
+ if debug
86
+ UI.message("Response code: %d" % [response.code])
87
+ UI.message("Response body:")
88
+ UI.message(response.body)
89
+ end
90
+
91
+ if response.code != 200
92
+ 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.")
93
+ exit
94
+ end
95
+
96
+ json = JSON.parse(response.body)
97
+ return json
98
+ end
99
+
100
+ def self.retire_app(app_version)
101
+ require 'rest-client'
102
+ require 'json'
103
+
104
+ body = {
105
+ "applicationid" => app_version['Id']
106
+ }
107
+
108
+ UI.message("Starting to retire app version: %s" % [app_version['Version']])
109
+ 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})
110
+
111
+ if debug
112
+ UI.message("Response code: %d" % [response.code])
113
+ end
114
+
115
+ if response.code == 202
116
+ UI.message("Successfully retired app version: %s" % [app_version['Version']])
117
+ else
118
+ json = JSON.parse(response.body)
119
+ UI.message("Failed to retire app version: %s" % [app_version['Version']])
120
+ end
121
+ end
122
+
123
+ def self.description
124
+ "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."
125
+ end
126
+
127
+ def self.authors
128
+ ["Ram Awadhesh Sharan"]
129
+ end
130
+
131
+ def self.return_value
132
+ # If your method provides a return value, you can describe here what it does
133
+ end
134
+
135
+ def self.details
136
+ # Optional:
137
+ "retire_specific_version - To retire specific version of an application on the AirWatch console."
138
+ end
139
+
140
+ def self.available_options
141
+ [
142
+ FastlaneCore::ConfigItem.new(key: :host_url,
143
+ env_name: "AIRWATCH_HOST_API_URL",
144
+ description: "Host API URL of the AirWatch instance",
145
+ optional: false,
146
+ type: String,
147
+ verify_block: proc do |value|
148
+ UI.user_error!("No AirWatch Host API URl given.") unless value and !value.empty?
149
+ end),
150
+
151
+ FastlaneCore::ConfigItem.new(key: :aw_tenant_code,
152
+ env_name: "AIRWATCH_API_KEY",
153
+ description: "API key to access AirWatch Rest APIs",
154
+ optional: false,
155
+ type: String,
156
+ verify_block: proc do |value|
157
+ UI.user_error!("Api tenant code header is missing.") unless value and !value.empty?
158
+ end),
159
+
160
+ FastlaneCore::ConfigItem.new(key: :b64_encoded_auth,
161
+ env_name: "AIRWATCH_BASE64_ENCODED_BASIC_AUTH_STRING",
162
+ description: "The base64 encoded Basic Auth string generated by authorizing username and password to the AirWatch instance",
163
+ optional: false,
164
+ type: String,
165
+ verify_block: proc do |value|
166
+ UI.user_error!("The authorization header is empty or the scheme is not basic") unless value and !value.empty?
167
+ end),
168
+
169
+ FastlaneCore::ConfigItem.new(key: :app_identifier,
170
+ env_name: "APP_IDENTIFIER",
171
+ description: "Bundle identifier of your app",
172
+ optional: false,
173
+ type: String,
174
+ verify_block: proc do |value|
175
+ UI.user_error!("No app identifier given, pass using `app_identifier: 'com.example.app'`") unless value and !value.empty?
176
+ end),
177
+
178
+ FastlaneCore::ConfigItem.new(key: :version_number,
179
+ env_name: "AIRWATCH_VERSION_NUMBER",
180
+ description: "Version number of the application to retire",
181
+ optional: false,
182
+ type: String,
183
+ verify_block: proc do |value|
184
+ UI.user_error!("No version number given, pass using `version_number: '1.0'`") unless value and !value.empty?
185
+ end),
186
+
187
+ FastlaneCore::ConfigItem.new(key: :debug,
188
+ env_name: "AIRWATCH_DEBUG",
189
+ description: "Debug flag, set to true to show extended output. default: false",
190
+ optional: true,
191
+ is_string: false,
192
+ default_value: false)
193
+ ]
194
+ end
195
+
196
+ def self.is_supported?(platform)
197
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
198
+ # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
199
+
200
+ [:ios, :android].include?(platform)
201
+ true
202
+ end
203
+
204
+ # helpers
205
+
206
+ def self.debug
207
+ $is_debug
208
+ end
209
+
210
+ end
211
+ end
212
+ end
@@ -0,0 +1,200 @@
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?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
+ return retired_app_versions
74
+ end
75
+
76
+ def self.list_app_versions(app_identifier)
77
+ require 'rest-client'
78
+ require 'json'
79
+
80
+ response = RestClient.get($host_url + APP_VERSIONS_LIST_SUFFIX % [app_identifier], {accept: :json, 'aw-tenant-code': $aw_tenant_code, 'Authorization': "Basic " + $b64_encoded_auth})
81
+
82
+ if debug
83
+ UI.message("Response code: %d" % [response.code])
84
+ UI.message("Response body:")
85
+ UI.message(response.body)
86
+ end
87
+
88
+ if response.code != 200
89
+ 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.")
90
+ exit
91
+ end
92
+
93
+ json = JSON.parse(response.body)
94
+ return json
95
+ end
96
+
97
+ def self.unretire_app(app_version)
98
+ require 'rest-client'
99
+ require 'json'
100
+
101
+ body = {
102
+ "applicationid" => app_version['Id']
103
+ }
104
+
105
+ UI.message("Starting to unretire app version: %s" % [app_version['Version']])
106
+ 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})
107
+
108
+ if debug
109
+ UI.message("Response code: %d" % [response.code])
110
+ end
111
+
112
+ if response.code == 202
113
+ UI.message("Successfully unretired app version: %s" % [app_version['Version']])
114
+ else
115
+ json = JSON.parse(response.body)
116
+ UI.message("Failed to unretire app version: %s" % [app_version['Version']])
117
+ end
118
+ end
119
+
120
+ def self.description
121
+ "The main purpose of this action is to unretire all retired versions of an application."
122
+ end
123
+
124
+ def self.authors
125
+ ["Ram Awadhesh Sharan"]
126
+ end
127
+
128
+ def self.return_value
129
+ # If your method provides a return value, you can describe here what it does
130
+ end
131
+
132
+ def self.details
133
+ # Optional:
134
+ "unretire_all_versions - To unretire all retired versions of an application on the AirWatch console."
135
+ end
136
+
137
+ def self.available_options
138
+ [
139
+ FastlaneCore::ConfigItem.new(key: :host_url,
140
+ env_name: "AIRWATCH_HOST_API_URL",
141
+ description: "Host API URL of the AirWatch instance",
142
+ optional: false,
143
+ type: String,
144
+ verify_block: proc do |value|
145
+ UI.user_error!("No AirWatch Host API URl given.") unless value and !value.empty?
146
+ end),
147
+
148
+ FastlaneCore::ConfigItem.new(key: :aw_tenant_code,
149
+ env_name: "AIRWATCH_API_KEY",
150
+ description: "API key to access AirWatch Rest APIs",
151
+ optional: false,
152
+ type: String,
153
+ verify_block: proc do |value|
154
+ UI.user_error!("Api tenant code header is missing.") unless value and !value.empty?
155
+ end),
156
+
157
+ FastlaneCore::ConfigItem.new(key: :b64_encoded_auth,
158
+ env_name: "AIRWATCH_BASE64_ENCODED_BASIC_AUTH_STRING",
159
+ description: "The base64 encoded Basic Auth string generated by authorizing username and password to the AirWatch instance",
160
+ optional: false,
161
+ type: String,
162
+ verify_block: proc do |value|
163
+ UI.user_error!("The authorization header is empty or the scheme is not basic") unless value and !value.empty?
164
+ end),
165
+
166
+ FastlaneCore::ConfigItem.new(key: :app_identifier,
167
+ env_name: "APP_IDENTIFIER",
168
+ description: "Bundle identifier of your app",
169
+ optional: false,
170
+ type: String,
171
+ verify_block: proc do |value|
172
+ UI.user_error!("No app identifier given, pass using `app_identifier: 'com.example.app'`") unless value and !value.empty?
173
+ end),
174
+
175
+ FastlaneCore::ConfigItem.new(key: :debug,
176
+ env_name: "AIRWATCH_DEBUG",
177
+ description: "Debug flag, set to true to show extended output. default: false",
178
+ optional: true,
179
+ is_string: false,
180
+ default_value: false)
181
+ ]
182
+ end
183
+
184
+ def self.is_supported?(platform)
185
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
186
+ # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
187
+
188
+ [:ios, :android].include?(platform)
189
+ true
190
+ end
191
+
192
+ # helpers
193
+
194
+ def self.debug
195
+ $is_debug
196
+ end
197
+
198
+ end
199
+ end
200
+ end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module AirwatchWorkspaceone
3
- VERSION = "1.0.2"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-airwatch_workspaceone
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ram Awadhesh Sharan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-30 00:00:00.000000000 Z
11
+ date: 2019-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -173,8 +173,13 @@ files:
173
173
  - LICENSE
174
174
  - README.md
175
175
  - lib/fastlane/plugin/airwatch_workspaceone.rb
176
+ - lib/fastlane/plugin/airwatch_workspaceone/actions/add_or_update_assignments_action.rb
177
+ - lib/fastlane/plugin/airwatch_workspaceone/actions/delete_previous_versions_action.rb
178
+ - lib/fastlane/plugin/airwatch_workspaceone/actions/delete_specific_version_action.rb
176
179
  - lib/fastlane/plugin/airwatch_workspaceone/actions/deploy_build_action.rb
177
180
  - lib/fastlane/plugin/airwatch_workspaceone/actions/retire_previous_versions_action.rb
181
+ - lib/fastlane/plugin/airwatch_workspaceone/actions/retire_specific_version_action.rb
182
+ - lib/fastlane/plugin/airwatch_workspaceone/actions/unretire_all_versions.rb
178
183
  - lib/fastlane/plugin/airwatch_workspaceone/helper/airwatch_workspaceone_helper.rb
179
184
  - lib/fastlane/plugin/airwatch_workspaceone/version.rb
180
185
  homepage: https://github.com/letsbondiway/fastlane-plugin-airwatch_workspaceone