Class: Xolo::Admin::Version
- Inherits:
-
Core::BaseClasses::Version
- Object
- Core::BaseClasses::Version
- Xolo::Admin::Version
- Defined in:
- lib/xolo/admin/version.rb
Overview
A version/patch as used by xadm. This adds cli and walkthru UI, as well as an interface to the Xolo Server for Title objects.
Constant Summary collapse
- SERVER_ROUTE =
This is the server path for dealing with titles POST to add a new one GET to get a list of versions for a title GET .../
to get the data for a single version PUT .../ to update a version with new data DELETE .../ to delete a version from the title "/titles/#{Xolo::Admin::Title::TARGET_TITLE_PLACEHOLDER}/versions"- UPLOAD_PKG_ROUTE =
Server route for uploading packages
'pkg'
Instance Attribute Summary collapse
-
#cnx ⇒ Object
the server connection used to fetch this version.
Class Method Summary collapse
-
.all_version_objects(title, cnx) ⇒ Array<Xolo::Admin::Version>
The currently known versions of a title on the server.
-
.all_versions(title, cnx) ⇒ Array<String>
The currently known versions of a title on the server.
-
.cli_opts ⇒ Hash{Symbol: Hash}
The ATTRIBUTES that are available as CLI & walkthru options.
-
.delete(title, version, cnx) ⇒ Hash
Delete a version of a title from the server.
-
.deploy(title, version, cnx, groups: [], computers: []) ⇒ Hash
Deploy a version to desired computers and groups via MDM.
-
.exist?(title, version, cnx) ⇒ Boolean
Does a version of a title exist on the server?.
-
.fetch(title, version, cnx) ⇒ Xolo::Admin::Title
Fetch a version of a title from the server.
-
.server_route(title, version = nil) ⇒ Xolo::Admin::Title
get the server route to a specific version (or the version list) for a title.
Instance Method Summary collapse
-
#add(cnx = self.cnx) ⇒ Hash
Add this version to the server.
-
#delete(cnx = self.cnx) ⇒ Hash
Delete this title from the server.
-
#gui_urls(cnx = self.cnx) ⇒ Hash{String => String}
Fetch a hash of URLs for the GUI pages for this title.
-
#managed? ⇒ Boolean
Whether this version is from a managed title or not.
-
#patch_report_data(cnx = self.cnx) ⇒ Array<Hash>
Get the Patch Report data for this version It's the JPAPI report data with each hash having a frozen: key added.
-
#repair(cnx = self.cnx) ⇒ Hash
Repair this version.
-
#subscribed? ⇒ Boolean
Whether this version is from a subscribed title or not.
-
#title_object(cnx = self.cnx, refresh: false) ⇒ Xolo::Admin::Title
The title for this version.
-
#update(cnx = self.cnx) ⇒ Hash
Update this version to the server.
-
#upload_pkg(upload_cnx) ⇒ Faraday::Response
Upload a .pkg for this version At this point, the pkg_to_upload attribute will contain the local file path.
Instance Attribute Details
#cnx ⇒ Object
the server connection used to fetch this version
131 132 133 |
# File 'lib/xolo/admin/version.rb', line 131 def cnx @cnx end |
Class Method Details
.all_version_objects(title, cnx) ⇒ Array<Xolo::Admin::Version>
Returns The currently known versions of a title on the server.
68 69 70 71 |
# File 'lib/xolo/admin/version.rb', line 68 def self.all_version_objects(title, cnx) resp = cnx.get server_route(title) resp.body.map { |vd| Xolo::Admin::Version.new vd } end |
.all_versions(title, cnx) ⇒ Array<String>
Returns The currently known versions of a title on the server.
61 62 63 64 |
# File 'lib/xolo/admin/version.rb', line 61 def self.all_versions(title, cnx) resp = cnx.get server_route(title) resp.body end |
.cli_opts ⇒ Hash{Symbol: Hash}
Returns The ATTRIBUTES that are available as CLI & walkthru options.
41 42 43 |
# File 'lib/xolo/admin/version.rb', line 41 def self.cli_opts @cli_opts ||= ATTRIBUTES.select { |_k, v| v[:cli] } end |
.delete(title, version, cnx) ⇒ Hash
Delete a version of a title from the server
121 122 123 124 |
# File 'lib/xolo/admin/version.rb', line 121 def self.delete(title, version, cnx) resp = cnx.delete server_route(title, version) resp.body end |
.deploy(title, version, cnx, groups: [], computers: []) ⇒ Hash
Deploy a version to desired computers and groups via MDM
106 107 108 109 110 111 112 113 |
# File 'lib/xolo/admin/version.rb', line 106 def self.deploy(title, version, cnx, groups: [], computers: []) raise ArgumentError, 'Must provide at least one group or computer' if groups.pix_empty? && computers.pix_empty? route = "#{server_route(title, version)}/deploy" content = { groups: groups, computers: computers } resp = cnx.post(route) { |req| req.body = content } resp.body end |
.exist?(title, version, cnx) ⇒ Boolean
Does a version of a title exist on the server?
79 80 81 |
# File 'lib/xolo/admin/version.rb', line 79 def self.exist?(title, version, cnx) all_versions(title, cnx).include? version end |
.fetch(title, version, cnx) ⇒ Xolo::Admin::Title
Fetch a version of a title from the server
89 90 91 92 93 94 95 96 |
# File 'lib/xolo/admin/version.rb', line 89 def self.fetch(title, version, cnx) resp = cnx.get server_route(title, version) vers_obj = new resp.body vers_obj.cnx = cnx vers_obj rescue Faraday::ResourceNotFound raise Xolo::NoSuchItemError, "No such version '#{version}'" end |
.server_route(title, version = nil) ⇒ Xolo::Admin::Title
get the server route to a specific version (or the version list) for a title
51 52 53 54 55 56 57 |
# File 'lib/xolo/admin/version.rb', line 51 def self.server_route(title, version = nil) route = SERVER_ROUTE.sub(Xolo::Admin::Title::TARGET_TITLE_PLACEHOLDER, title) route << "/#{URI::Parser.new.escape(version)}" if version ### the CGI escape one doesn't seem to work with, e.g. "7.1.5 (84650)" # route << "/#{CGI.escape(version)}" if version route end |
Instance Method Details
#add(cnx = self.cnx) ⇒ Hash
Add this version to the server
165 166 167 168 |
# File 'lib/xolo/admin/version.rb', line 165 def add(cnx = self.cnx) resp = cnx.post self.class.server_route(title), to_h resp.body end |
#delete(cnx = self.cnx) ⇒ Hash
Delete this title from the server
192 193 194 195 |
# File 'lib/xolo/admin/version.rb', line 192 def delete(cnx = self.cnx) self.class.delete title, version, cnx # already returns resp.body end |
#gui_urls(cnx = self.cnx) ⇒ Hash{String => String}
Fetch a hash of URLs for the GUI pages for this title
201 202 203 204 |
# File 'lib/xolo/admin/version.rb', line 201 def gui_urls(cnx = self.cnx) resp = cnx.get "#{self.class.server_route(title, version)}/urls" resp.body end |
#managed? ⇒ Boolean
Returns whether this version is from a managed title or not.
252 253 254 |
# File 'lib/xolo/admin/version.rb', line 252 def managed? title_object.managed? end |
#patch_report_data(cnx = self.cnx) ⇒ Array<Hash>
Get the Patch Report data for this version It's the JPAPI report data with each hash having a frozen: key added
232 233 234 235 |
# File 'lib/xolo/admin/version.rb', line 232 def patch_report_data(cnx = self.cnx) resp = cnx.get "#{self.class.server_route(title, version)}/patch_report" resp.body end |
#repair(cnx = self.cnx) ⇒ Hash
Repair this version
183 184 185 186 |
# File 'lib/xolo/admin/version.rb', line 183 def repair(cnx = self.cnx) resp = cnx.post "#{self.class.server_route(title, version)}/repair" resp.body end |
#subscribed? ⇒ Boolean
Returns whether this version is from a subscribed title or not.
246 247 248 |
# File 'lib/xolo/admin/version.rb', line 246 def subscribed? title_object.subscribed? end |
#title_object(cnx = self.cnx, refresh: false) ⇒ Xolo::Admin::Title
Returns the title for this version.
239 240 241 242 |
# File 'lib/xolo/admin/version.rb', line 239 def title_object(cnx = self.cnx, refresh: false) @title_object = nil if refresh @title_object ||= Xolo::Admin::Title.fetch(title, cnx) end |
#update(cnx = self.cnx) ⇒ Hash
Update this version to the server
174 175 176 177 |
# File 'lib/xolo/admin/version.rb', line 174 def update(cnx = self.cnx) resp = cnx.put self.class.server_route(title, version), to_h resp.body end |
#upload_pkg(upload_cnx) ⇒ Faraday::Response
Upload a .pkg for this version At this point, the pkg_to_upload attribute will contain the local file path.
214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/xolo/admin/version.rb', line 214 def upload_pkg(upload_cnx) return unless pkg_to_upload.is_a? Pathname # route = "#{UPLOAD_PKG_ROUTE}/#{title}/#{version}" route = "#{self.class.server_route(title, version)}/#{UPLOAD_PKG_ROUTE}" upfile = Faraday::Multipart::FilePart.new(pkg_to_upload..to_s, 'application/octet-stream') content = { file: upfile } upload_cnx.post(route) { |req| req.body = content } end |