Module: Xolo::Server::Helpers::JamfPro
Overview
constants and methods for accessing the Jamf Pro server from the Xolo server
This is used both as a ‘helper’ in the Sinatra server, and an included mixin for the Xolo::Server::Title and Xolo::Server::Version classes.
This means methods here are available in instances of those classes, and in all routes, views, and helpers in Sinatra.
Constant Summary collapse
- PATCH_REPORT_UNKNOWN_VERSION =
Constants
'UNKNOWN_VERSION'- PATCH_REPORT_JPAPI_PAGE_SIZE =
500
Class Method Summary collapse
-
.extended(extender) ⇒ Object
when this module is extended.
-
.included(includer) ⇒ Object
when this module is included.
Instance Method Summary collapse
-
#jamf_cnx(refresh: false) ⇒ Jamf::Connection
A connection to Jamf Pro via ruby-jss.
-
#jamf_gui_url ⇒ String
The start of the Jamf Pro URL for GUI/WebApp access.
-
#jamf_xolo_category_id ⇒ Object
The id of the ‘xolo’ category in Jamf Pro.s.
-
#valid_forced_exclusion_group_name ⇒ String
if there’s a forced_exclusion group defined in the server config return it’s name, but only if it exists in jamf.
Class Method Details
.extended(extender) ⇒ Object
when this module is extended
53 54 55 |
# File 'lib/xolo/server/helpers/jamf_pro.rb', line 53 def self.extended(extender) Xolo.verbose_extend extender, self end |
.included(includer) ⇒ Object
when this module is included
48 49 50 |
# File 'lib/xolo/server/helpers/jamf_pro.rb', line 48 def self.included(includer) Xolo.verbose_include includer, self end |
Instance Method Details
#jamf_cnx(refresh: false) ⇒ Jamf::Connection
A connection to Jamf Pro via ruby-jss.
We don’t use the default connection but use this method to create standalone ones as needed and ensure they are disconnected, (or will timeout) when we are done.
TODO: allow using APIClients
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/xolo/server/helpers/jamf_pro.rb', line 88 def jamf_cnx(refresh: false) if refresh @jamf_cnx = nil log_debug 'Jamf: Refreshing Jamf connection' end return @jamf_cnx if @jamf_cnx @jamf_cnx = Jamf::Connection.new( name: "jamf-pro-cnx-#{Time.now.strftime('%F-%T')}", host: Xolo::Server.config.jamf_hostname, port: Xolo::Server.config.jamf_port, verify_cert: Xolo::Server.config.jamf_verify_cert, ssl_version: Xolo::Server.config.jamf_ssl_version, open_timeout: Xolo::Server.config.jamf_open_timeout, timeout: Xolo::Server.config.jamf_timeout, user: Xolo::Server.config.jamf_api_user, pw: Xolo::Server.config.jamf_api_pw, keep_alive: false ) log_debug "Jamf: Connected to Jamf Pro at #{@jamf_cnx.base_url} as user '#{Xolo::Server.config.jamf_api_user}'. KeepAlive: #{@jamf_cnx.keep_alive?}, Expires: #{@jamf_cnx.token.expires}. cnx ID: #{@jamf_cnx.object_id}" @jamf_cnx end |
#jamf_gui_url ⇒ String
Returns The start of the Jamf Pro URL for GUI/WebApp access.
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/xolo/server/helpers/jamf_pro.rb', line 66 def jamf_gui_url return @jamf_gui_url if @jamf_gui_url host = Xolo::Server.config.jamf_gui_hostname host ||= Xolo::Server.config.jamf_hostname port = Xolo::Server.config.jamf_gui_port port ||= Xolo::Server.config.jamf_port @jamf_gui_url = "https://#{host}:#{port}" end |
#jamf_xolo_category_id ⇒ Object
The id of the ‘xolo’ category in Jamf Pro.s
115 116 117 118 119 120 121 122 |
# File 'lib/xolo/server/helpers/jamf_pro.rb', line 115 def jamf_xolo_category_id @jamf_xolo_category_id ||= if Jamf::Category.all_names(cnx: jamf_cnx).include? Xolo::Server::JAMF_XOLO_CATEGORY Jamf::Category.valid_id(Xolo::Server::JAMF_XOLO_CATEGORY, cnx: jamf_cnx).to_s else Jamf::Category.create(name: Xolo::Server::JAMF_XOLO_CATEGORY, cnx: jamf_cnx).save end end |
#valid_forced_exclusion_group_name ⇒ String
if there’s a forced_exclusion group defined in the server config return it’s name, but only if it exists in jamf. If it doesn’t return nil and alert someone
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/xolo/server/helpers/jamf_pro.rb', line 130 def valid_forced_exclusion_group_name return @valid_forced_exclusion_group_name if defined?(@valid_forced_exclusion_group_name) the_grp_name = Xolo::Server.config.forced_exclusion if the_grp_name if Jamf::ComputerGroup.all_names(cnx: jamf_cnx).include? the_grp_name @valid_forced_exclusion_group_name = the_grp_name else msg = "ERROR: The forced_exclusion group '#{Xolo::Server.config.forced_exclusion}' in xolo server config does not exist in Jamf" log_error msg, alert: true @valid_forced_exclusion_group_name = nil end # not in config else @valid_forced_exclusion_group_name = nil end end |