class Fastlane::Actions::AddOrUpdateAssignmentsAction
Constants
- ADD_UPDATE_ASSIGNMENT_SUFFIX
- SEARCH_SMART_GROUP_SUFFIX
Public Class Methods
add_update_smart_group_assignment(smart_group_ids, assignment_parameters, update)
click to toggle source
# File lib/fastlane/plugin/airwatch_workspaceone/actions/add_or_update_assignments_action.rb, line 155 def self.add_update_smart_group_assignment(smart_group_ids, assignment_parameters, update) require 'rest-client' require 'json' body = { "SmartGroupIds" => smart_group_ids, "DeploymentParameters" => assignment_parameters } if debug UI.message("Deploy Request JSON:") UI.message(body.to_json) end if update 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}) else 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}) end if debug UI.message("Response code: %d" % [response.code]) UI.message("Response body:") UI.message(response.body) end end
available_options()
click to toggle source
# File lib/fastlane/plugin/airwatch_workspaceone/actions/add_or_update_assignments_action.rb, line 199 def self.available_options [ FastlaneCore::ConfigItem.new(key: :host_url, env_name: "AIRWATCH_HOST_API_URL", description: "Host API URL of the AirWatch/Workspace ONE instance without /API/ at the end", optional: false, type: String, verify_block: proc do |value| UI.user_error!("No AirWatch/Workspace ONE Host API URl given, pass using `host_url: 'https://yourhost.com'`") unless value and !value.empty? end), FastlaneCore::ConfigItem.new(key: :aw_tenant_code, env_name: "AIRWATCH_API_KEY", description: "API key or the tenant code to access AirWatch/Workspace ONE Rest APIs", optional: false, type: String, verify_block: proc do |value| UI.user_error!("Api tenant code header is missing, pass using `aw_tenant_code: 'yourapikey'`") unless value and !value.empty? end), FastlaneCore::ConfigItem.new(key: :b64_encoded_auth, env_name: "AIRWATCH_BASE64_ENCODED_BASIC_AUTH_STRING", description: "The base64 encoded Basic Auth string generated by authorizing username and password to the AirWatch/Workspace ONE instance", optional: false, type: String, verify_block: proc do |value| 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? end), FastlaneCore::ConfigItem.new(key: :org_group_id, env_name: "AIRWATCH_ORGANIZATION_GROUP_ID", description: "Organization Group ID integer identifying the customer or container", optional: false, type: String, verify_block: proc do |value| UI.user_error!("No Organization Group ID integer given, pass using `org_group_id: 'yourorggrpintid'`") unless value and !value.empty? end), FastlaneCore::ConfigItem.new(key: :app_identifier, env_name: "APP_IDENTIFIER", description: "Bundle identifier of your app", optional: false, type: String, verify_block: proc do |value| UI.user_error!("No app identifier given, pass using `app_identifier: 'com.example.app'`") unless value and !value.empty? end), FastlaneCore::ConfigItem.new(key: :smart_groups_to_assign, env_name: "AIRWATCH_SMART_GROUPS_TO_ASSIGN", description: "Names of the smart groups to assign the app to", optional: false, type: Array, verify_block: proc do |value| UI.user_error!("No smart group names given, pass using `smart_groups_to_assign: ['yoursmartgrp1', 'yoursmartgroup2']` or `smart_groups_to_assign: 'yoursmartgrp1'`") unless value and !value.empty? end), FastlaneCore::ConfigItem.new(key: :assignment_parameters, env_name: "AIRWATCH_ASSIGNMENT_PARAMETERS", description: "Deployment parameters for the smart group assignment", optional: false, is_string: false, verify_block: proc do |value| UI.user_error!("No smart group assignment parameters given, pass using `assignment_parameters: '{key1: value1, key2: value2}'`") unless value and !value.empty? end), FastlaneCore::ConfigItem.new(key: :debug, env_name: "AIRWATCH_DEBUG", description: "Debug flag, set to true to show extended output. default: false", optional: true, is_string: false, default_value: false) ] end
debug()
click to toggle source
helpers
# File lib/fastlane/plugin/airwatch_workspaceone/actions/add_or_update_assignments_action.rb, line 283 def self.debug $is_debug end
description()
click to toggle source
# File lib/fastlane/plugin/airwatch_workspaceone/actions/add_or_update_assignments_action.rb, line 182 def self.description "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." end
details()
click to toggle source
# File lib/fastlane/plugin/airwatch_workspaceone/actions/add_or_update_assignments_action.rb, line 194 def self.details # Optional: "add_or_update_assignments - To add or update smart group assignments with given deployment parameters." end
fetch_smart_group_details(smart_group_name)
click to toggle source
# File lib/fastlane/plugin/airwatch_workspaceone/actions/add_or_update_assignments_action.rb, line 135 def self.fetch_smart_group_details(smart_group_name) require 'rest-client' require 'json' 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}) if debug UI.message("Response code: %d" % [response.code]) UI.message("Response body:") UI.message(response.body) end if response.code != 200 return Hash.new end json = JSON.parse(response.body) return json end
find_app_smart_groups(app_identifier)
click to toggle source
# File lib/fastlane/plugin/airwatch_workspaceone/actions/add_or_update_assignments_action.rb, line 103 def self.find_app_smart_groups(app_identifier) # get the list of apps apps = Helper::AirwatchWorkspaceoneHelper.list_app_versions(app_identifier, $host_url, $aw_tenant_code, $b64_encoded_auth, $org_group_id, debug) app_versions = apps['Application'] if app_versions.count <= 0 UI.user_error!("No app found on the console having bundle identifier: %s" % [app_identifier]) UI.user_error!("Please provide an existing app identifier") exit end app_versions.sort_by! { |app_version| app_version["Id"]["Value"] } latest_app_version = app_versions.last $app_id_int = latest_app_version['Id']['Value'] app_smart_groups = latest_app_version['SmartGroups'] return app_smart_groups end
find_smart_group_id(smart_group_name)
click to toggle source
# File lib/fastlane/plugin/airwatch_workspaceone/actions/add_or_update_assignments_action.rb, line 121 def self.find_smart_group_id(smart_group_name) smart_groups = fetch_smart_group_details(smart_group_name) smart_group_id = -1 if smart_groups.empty? return smart_group_id end smart_groups['SmartGroups'].each do |smart_group| smart_group_id = smart_group['SmartGroupID'] end return smart_group_id end
is_supported?(platform)
click to toggle source
# File lib/fastlane/plugin/airwatch_workspaceone/actions/add_or_update_assignments_action.rb, line 273 def self.is_supported?(platform) # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example) # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform # [:ios, :android].include?(platform) true end
return_value()
click to toggle source
# File lib/fastlane/plugin/airwatch_workspaceone/actions/add_or_update_assignments_action.rb, line 190 def self.return_value # If your method provides a return value, you can describe here what it does end
run(params)
click to toggle source
# File lib/fastlane/plugin/airwatch_workspaceone/actions/add_or_update_assignments_action.rb, line 14 def self.run(params) UI.message("The airwatch_workspaceone plugin is working!") # check if debug is enabled $is_debug = params[:debug] if debug UI.message("----------------------------------------------") UI.message("AddOrUpdateAssignmentsAction debug information") UI.message("----------------------------------------------") UI.message(" host_url: #{params[:host_url]}") UI.message(" aw_tenant_code: #{params[:aw_tenant_code]}") UI.message(" b64_encoded_auth: #{params[:b64_encoded_auth]}") UI.message(" organization_group_id: #{params[:org_group_id]}") UI.message(" app_identifier: #{params[:app_identifier]}") UI.message(" smart_groups_to_assign: #{params[:smart_groups_to_assign]}") UI.message(" assignment_parameters: #{params[:assignment_parameters]}") end $host_url = params[:host_url] $aw_tenant_code = params[:aw_tenant_code] $b64_encoded_auth = params[:b64_encoded_auth] $org_group_id = params[:org_group_id] app_identifier = params[:app_identifier] smart_groups_to_assign = params[:smart_groups_to_assign] assignment_parameters = params[:assignment_parameters] # step 1: find app UI.message("-----------------------------") UI.message("1. Finding app's smart groups") UI.message("-----------------------------") app_smart_groups = find_app_smart_groups(app_identifier) UI.success("Found %d smart group(s) assigned to the app." % [app_smart_groups.count]) UI.success("Smart Group(s): %s" % [app_smart_groups.map {|smart_group| smart_group.values[1]}]) # step 2: separate smart groups into need to add and need to update UI.message("-----------------------------------------------") UI.message("2. Separating smart groups to add and to update") UI.message("-----------------------------------------------") update_smart_group_ids = Array.new update_smart_group_names = Array.new add_smart_group_ids = Array.new add_smart_group_names = Array.new smart_groups_to_assign.each do |smart_group| UI.message("Fetching details for %s smart group" % [smart_group]) smart_group_id = find_smart_group_id(smart_group) if smart_group_id == -1 UI.important("Could not find smart group named %s in the given organization group. Skipping this smart group assignment." % [smart_group]) else if app_smart_groups.map {|smart_group| smart_group.values[0]}.include? smart_group_id UI.message("Assignment to the smart group %s needs to be updated" % [smart_group]) update_smart_group_ids << smart_group_id update_smart_group_names << smart_group else UI.message("Assignment to the smart group %s needs to be added" % [smart_group]) add_smart_group_ids << smart_group_id add_smart_group_names << smart_group end end end # step 3: update smart group assignments UI.message("--------------------------------------------") UI.message("3. Updating existing smart group assignments") UI.message("--------------------------------------------") if update_smart_group_ids.count <= 0 UI.success("No existing smart groups assignment needs to be updated") else add_update_smart_group_assignment(update_smart_group_ids, assignment_parameters, true) UI.success("Assignment for smart group(s): %s successfully updated" % [update_smart_group_names]) end # step 4: add smart group assignments UI.message("-------------------------------------") UI.message("4. Adding new smart group assignments") UI.message("-------------------------------------") if add_smart_group_ids.count <= 0 UI.success("No new groups assignment needs to be added") else add_update_smart_group_assignment(add_smart_group_ids, assignment_parameters, false) UI.success("Assignment for smart group(s): %s successfully added" % [add_smart_group_names]) end end