fastlane-plugin-airwatch_workspaceone 2.0.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,9 +5,6 @@ module Fastlane
5
5
  module Actions
6
6
  class RetireSpecificVersionAction < Action
7
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
8
  $is_debug = false
12
9
 
13
10
  def self.run(params)
@@ -23,6 +20,7 @@ module Fastlane
23
20
  UI.message(" host_url: #{params[:host_url]}")
24
21
  UI.message(" aw_tenant_code: #{params[:aw_tenant_code]}")
25
22
  UI.message(" b64_encoded_auth: #{params[:b64_encoded_auth]}")
23
+ UI.message(" organization_group_id: #{params[:org_group_id]}")
26
24
  UI.message(" app_identifier: #{params[:app_identifier]}")
27
25
  UI.message(" version_number: #{params[:version_number]}")
28
26
  end
@@ -30,6 +28,7 @@ module Fastlane
30
28
  $host_url = params[:host_url]
31
29
  $aw_tenant_code = params[:aw_tenant_code]
32
30
  $b64_encoded_auth = params[:b64_encoded_auth]
31
+ $org_group_id = params[:org_group_id]
33
32
  app_identifier = params[:app_identifier]
34
33
  version_number = params[:version_number]
35
34
 
@@ -38,7 +37,7 @@ module Fastlane
38
37
  UI.message("1. Finding active app versions")
39
38
  UI.message("------------------------------")
40
39
 
41
- app_versions = find_app(app_identifier)
40
+ app_versions = Helper::AirwatchWorkspaceoneHelper.find_app_versions(app_identifier, 'Active', $host_url, $aw_tenant_code, $b64_encoded_auth, $org_group_id, debug)
42
41
  app_version_numbers = app_versions.map {|app_version| app_version.values[1]}
43
42
  UI.success("Found %d active app version(s)" % [app_versions.count])
44
43
  UI.success("Version number(s): %s" % [app_version_numbers])
@@ -51,7 +50,7 @@ module Fastlane
51
50
  if app_version_numbers.include? version_number
52
51
  version_index = app_version_numbers.index(version_number)
53
52
  app_version_to_retire = app_versions[version_index]
54
- retire_app(app_version_to_retire)
53
+ Helper::AirwatchWorkspaceoneHelper.retire_app(app_version_to_retire, $host_url, $aw_tenant_code, $b64_encoded_auth, debug)
55
54
  else
56
55
  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
56
  end
@@ -59,67 +58,6 @@ module Fastlane
59
58
  UI.success("Version %s successfully retired" % [version_number])
60
59
  end
61
60
 
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
61
  def self.description
124
62
  "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
63
  end
@@ -134,36 +72,45 @@ module Fastlane
134
72
 
135
73
  def self.details
136
74
  # Optional:
137
- "retire_specific_version - To retire specific version of an application on the AirWatch console."
75
+ "retire_specific_version - To retire specific version of an application on the AirWatch/Workspace ONE console."
138
76
  end
139
77
 
140
78
  def self.available_options
141
79
  [
142
80
  FastlaneCore::ConfigItem.new(key: :host_url,
143
81
  env_name: "AIRWATCH_HOST_API_URL",
144
- description: "Host API URL of the AirWatch instance",
82
+ description: "Host API URL of the AirWatch/Workspace ONE instance without /API/ at the end",
145
83
  optional: false,
146
84
  type: String,
147
85
  verify_block: proc do |value|
148
- UI.user_error!("No AirWatch Host API URl given.") unless value and !value.empty?
86
+ UI.user_error!("No AirWatch/Workspace ONE Host API URl given, pass using `host_url: 'https://yourhost.com'`") unless value and !value.empty?
149
87
  end),
150
88
 
151
89
  FastlaneCore::ConfigItem.new(key: :aw_tenant_code,
152
90
  env_name: "AIRWATCH_API_KEY",
153
- description: "API key to access AirWatch Rest APIs",
91
+ description: "API key or the tenant code to access AirWatch/Workspace ONE Rest APIs",
154
92
  optional: false,
155
93
  type: String,
156
94
  verify_block: proc do |value|
157
- UI.user_error!("Api tenant code header is missing.") unless value and !value.empty?
95
+ UI.user_error!("Api tenant code header is missing, pass using `aw_tenant_code: 'yourapikey'`") unless value and !value.empty?
158
96
  end),
159
97
 
160
98
  FastlaneCore::ConfigItem.new(key: :b64_encoded_auth,
161
99
  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",
100
+ description: "The base64 encoded Basic Auth string generated by authorizing username and password to the AirWatch/Workspace ONE instance",
101
+ optional: false,
102
+ type: String,
103
+ verify_block: proc do |value|
104
+ 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?
105
+ end),
106
+
107
+ FastlaneCore::ConfigItem.new(key: :org_group_id,
108
+ env_name: "AIRWATCH_ORGANIZATION_GROUP_ID",
109
+ description: "Organization Group ID integer identifying the customer or container",
163
110
  optional: false,
164
111
  type: String,
165
112
  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?
113
+ UI.user_error!("No Organization Group ID integer given, pass using `org_group_id: 'yourorggrpintid'`") unless value and !value.empty?
167
114
  end),
168
115
 
169
116
  FastlaneCore::ConfigItem.new(key: :app_identifier,
@@ -5,9 +5,6 @@ module Fastlane
5
5
  module Actions
6
6
  class UnretireAllVersionsAction < Action
7
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
8
  $is_debug = false
12
9
 
13
10
  def self.run(params)
@@ -23,12 +20,14 @@ module Fastlane
23
20
  UI.message(" host_url: #{params[:host_url]}")
24
21
  UI.message(" aw_tenant_code: #{params[:aw_tenant_code]}")
25
22
  UI.message(" b64_encoded_auth: #{params[:b64_encoded_auth]}")
23
+ UI.message(" organization_group_id: #{params[:org_group_id]}")
26
24
  UI.message(" app_identifier: #{params[:app_identifier]}")
27
25
  end
28
26
 
29
27
  $host_url = params[:host_url]
30
28
  $aw_tenant_code = params[:aw_tenant_code]
31
29
  $b64_encoded_auth = params[:b64_encoded_auth]
30
+ $org_group_id = params[:org_group_id]
32
31
  app_identifier = params[:app_identifier]
33
32
 
34
33
  # step 1: find app
@@ -36,7 +35,7 @@ module Fastlane
36
35
  UI.message("1. Finding retired app versions")
37
36
  UI.message("-------------------------------")
38
37
 
39
- retired_app_versions = find_app(app_identifier)
38
+ retired_app_versions = Helper::AirwatchWorkspaceoneHelper.find_app_versions(app_identifier, 'Retired', $host_url, $aw_tenant_code, $b64_encoded_auth, $org_group_id, debug)
40
39
  if retired_app_versions.count <= 0
41
40
  UI.important("No retired app versions found for application with bundle identifier given: %s" % [app_identifier])
42
41
  return
@@ -51,72 +50,11 @@ module Fastlane
51
50
  UI.message("----------------------------------")
52
51
 
53
52
  retired_app_versions.each do |retired_app_version|
54
- unretire_app(retired_app_version)
53
+ Helper::AirwatchWorkspaceoneHelper.unretire_app(retired_app_version, $host_url, $aw_tenant_code, $b64_encoded_auth, debug)
55
54
  end
56
55
  UI.success("Version(s) %s successfully unretired." % [retired_app_versions.map {|retired_app_version| retired_app_version.values[1]}])
57
56
  end
58
57
 
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
58
  def self.description
121
59
  "The main purpose of this action is to unretire all retired versions of an application."
122
60
  end
@@ -131,36 +69,45 @@ module Fastlane
131
69
 
132
70
  def self.details
133
71
  # Optional:
134
- "unretire_all_versions - To unretire all retired versions of an application on the AirWatch console."
72
+ "unretire_all_versions - To unretire all retired versions of an application on the AirWatch/Workspace ONE console."
135
73
  end
136
74
 
137
75
  def self.available_options
138
76
  [
139
77
  FastlaneCore::ConfigItem.new(key: :host_url,
140
78
  env_name: "AIRWATCH_HOST_API_URL",
141
- description: "Host API URL of the AirWatch instance",
79
+ description: "Host API URL of the AirWatch/Workspace ONE instance without /API/ at the end",
142
80
  optional: false,
143
81
  type: String,
144
82
  verify_block: proc do |value|
145
- UI.user_error!("No AirWatch Host API URl given.") unless value and !value.empty?
83
+ UI.user_error!("No AirWatch/Workspace ONE Host API URl given, pass using `host_url: 'https://yourhost.com'`") unless value and !value.empty?
146
84
  end),
147
85
 
148
86
  FastlaneCore::ConfigItem.new(key: :aw_tenant_code,
149
87
  env_name: "AIRWATCH_API_KEY",
150
- description: "API key to access AirWatch Rest APIs",
88
+ description: "API key or the tenant code to access AirWatch/Workspace ONE Rest APIs",
151
89
  optional: false,
152
90
  type: String,
153
91
  verify_block: proc do |value|
154
- UI.user_error!("Api tenant code header is missing.") unless value and !value.empty?
92
+ UI.user_error!("Api tenant code header is missing, pass using `aw_tenant_code: 'yourapikey'`") unless value and !value.empty?
155
93
  end),
156
94
 
157
95
  FastlaneCore::ConfigItem.new(key: :b64_encoded_auth,
158
96
  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",
97
+ description: "The base64 encoded Basic Auth string generated by authorizing username and password to the AirWatch/Workspace ONE instance",
98
+ optional: false,
99
+ type: String,
100
+ verify_block: proc do |value|
101
+ 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?
102
+ end),
103
+
104
+ FastlaneCore::ConfigItem.new(key: :org_group_id,
105
+ env_name: "AIRWATCH_ORGANIZATION_GROUP_ID",
106
+ description: "Organization Group ID integer identifying the customer or container",
160
107
  optional: false,
161
108
  type: String,
162
109
  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?
110
+ UI.user_error!("No Organization Group ID integer given, pass using `org_group_id: 'yourorggrpintid'`") unless value and !value.empty?
164
111
  end),
165
112
 
166
113
  FastlaneCore::ConfigItem.new(key: :app_identifier,
@@ -0,0 +1,164 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/airwatch_workspaceone_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class UnretireSpecificVersionAction < Action
7
+
8
+ $is_debug = false
9
+
10
+ def self.run(params)
11
+ UI.message("The airwatch_workspaceone plugin is working!")
12
+
13
+ # check if debug is enabled
14
+ $is_debug = params[:debug]
15
+
16
+ if debug
17
+ UI.message("-----------------------------------------------")
18
+ UI.message("UnretireSpecificVersionAction debug information")
19
+ UI.message("-----------------------------------------------")
20
+ UI.message(" host_url: #{params[:host_url]}")
21
+ UI.message(" aw_tenant_code: #{params[:aw_tenant_code]}")
22
+ UI.message(" b64_encoded_auth: #{params[:b64_encoded_auth]}")
23
+ UI.message(" organization_group_id: #{params[:org_group_id]}")
24
+ UI.message(" app_identifier: #{params[:app_identifier]}")
25
+ UI.message(" version_number: #{params[:version_number]}")
26
+ end
27
+
28
+ $host_url = params[:host_url]
29
+ $aw_tenant_code = params[:aw_tenant_code]
30
+ $b64_encoded_auth = params[:b64_encoded_auth]
31
+ $org_group_id = params[:org_group_id]
32
+ app_identifier = params[:app_identifier]
33
+ version_number = params[:version_number]
34
+
35
+ # step 1: find app
36
+ UI.message("-------------------------------")
37
+ UI.message("1. Finding retired app versions")
38
+ UI.message("-------------------------------")
39
+
40
+ retired_app_versions = Helper::AirwatchWorkspaceoneHelper.find_app_versions(app_identifier, 'Retired', $host_url, $aw_tenant_code, $b64_encoded_auth, $org_group_id, debug)
41
+ if retired_app_versions.count <= 0
42
+ UI.important("No retired app versions found for application with bundle identifier given: %s" % [app_identifier])
43
+ return
44
+ end
45
+
46
+ retired_version_numbers = retired_app_versions.map {|retired_app_version| retired_app_version.values[1]}
47
+ UI.success("Found %d retired app version(s)" % [retired_app_versions.count])
48
+ UI.success("Version number(s): %s" % [retired_version_numbers])
49
+
50
+ # step 2: retire specific version
51
+ UI.message("----------------------------------")
52
+ UI.message("2. UnRetiring specific app version")
53
+ UI.message("----------------------------------")
54
+
55
+ if retired_version_numbers.include? version_number
56
+ version_index = retired_version_numbers.index(version_number)
57
+ app_version_to_unretire = retired_app_versions[version_index]
58
+ Helper::AirwatchWorkspaceoneHelper.unretire_app(app_version_to_unretire, $host_url, $aw_tenant_code, $b64_encoded_auth, debug)
59
+ else
60
+ UI.user_error!("A version with the given version number: %s does not exist on the console for this application or is already Active." % [version_number])
61
+ end
62
+
63
+ UI.success("Version %s successfully unretired" % [version_number])
64
+ end
65
+
66
+ def self.description
67
+ "The main purpose of this action is to unretire a specific version of an application. This action takes a string parameter where you can specify the version number to unretire."
68
+ end
69
+
70
+ def self.authors
71
+ ["Ram Awadhesh Sharan"]
72
+ end
73
+
74
+ def self.return_value
75
+ # If your method provides a return value, you can describe here what it does
76
+ end
77
+
78
+ def self.details
79
+ # Optional:
80
+ "unretire_specific_version - To unretire specific version of an application on the AirWatch/Workspace ONE console."
81
+ end
82
+
83
+ def self.available_options
84
+ [
85
+ FastlaneCore::ConfigItem.new(key: :host_url,
86
+ env_name: "AIRWATCH_HOST_API_URL",
87
+ description: "Host API URL of the AirWatch/Workspace ONE instance without /API/ at the end",
88
+ optional: false,
89
+ type: String,
90
+ verify_block: proc do |value|
91
+ UI.user_error!("No AirWatch/Workspace ONE Host API URl given, pass using `host_url: 'https://yourhost.com'`") unless value and !value.empty?
92
+ end),
93
+
94
+ FastlaneCore::ConfigItem.new(key: :aw_tenant_code,
95
+ env_name: "AIRWATCH_API_KEY",
96
+ description: "API key or the tenant code to access AirWatch/Workspace ONE Rest APIs",
97
+ optional: false,
98
+ type: String,
99
+ verify_block: proc do |value|
100
+ UI.user_error!("Api tenant code header is missing, pass using `aw_tenant_code: 'yourapikey'`") unless value and !value.empty?
101
+ end),
102
+
103
+ FastlaneCore::ConfigItem.new(key: :b64_encoded_auth,
104
+ env_name: "AIRWATCH_BASE64_ENCODED_BASIC_AUTH_STRING",
105
+ description: "The base64 encoded Basic Auth string generated by authorizing username and password to the AirWatch/Workspace ONE instance",
106
+ optional: false,
107
+ type: String,
108
+ verify_block: proc do |value|
109
+ 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?
110
+ end),
111
+
112
+ FastlaneCore::ConfigItem.new(key: :org_group_id,
113
+ env_name: "AIRWATCH_ORGANIZATION_GROUP_ID",
114
+ description: "Organization Group ID integer identifying the customer or container",
115
+ optional: false,
116
+ type: String,
117
+ verify_block: proc do |value|
118
+ UI.user_error!("No Organization Group ID integer given, pass using `org_group_id: 'yourorggrpintid'`") unless value and !value.empty?
119
+ end),
120
+
121
+ FastlaneCore::ConfigItem.new(key: :app_identifier,
122
+ env_name: "APP_IDENTIFIER",
123
+ description: "Bundle identifier of your app",
124
+ optional: false,
125
+ type: String,
126
+ verify_block: proc do |value|
127
+ UI.user_error!("No app identifier given, pass using `app_identifier: 'com.example.app'`") unless value and !value.empty?
128
+ end),
129
+
130
+ FastlaneCore::ConfigItem.new(key: :version_number,
131
+ env_name: "AIRWATCH_VERSION_NUMBER",
132
+ description: "Version number of the application to unretire",
133
+ optional: false,
134
+ type: String,
135
+ verify_block: proc do |value|
136
+ UI.user_error!("No version number given, pass using `version_number: '1.0'`") unless value and !value.empty?
137
+ end),
138
+
139
+ FastlaneCore::ConfigItem.new(key: :debug,
140
+ env_name: "AIRWATCH_DEBUG",
141
+ description: "Debug flag, set to true to show extended output. default: false",
142
+ optional: true,
143
+ is_string: false,
144
+ default_value: false)
145
+ ]
146
+ end
147
+
148
+ def self.is_supported?(platform)
149
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
150
+ # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
151
+
152
+ [:ios, :android].include?(platform)
153
+ true
154
+ end
155
+
156
+ # helpers
157
+
158
+ def self.debug
159
+ $is_debug
160
+ end
161
+
162
+ end
163
+ end
164
+ end