Class: Xolo::Admin::Version

Inherits:
Core::BaseClasses::Version show all
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 …/<version> to get the data for a single version PUT …/<version> to update a version with new data DELETE …/<version> to delete a version from the title

"/titles/#{Xolo::Admin::Title::TARGET_TITLE_PLACEHOLDER}/versions"
UPLOAD_PKG_ROUTE =

Server route for uploading packages

'pkg'

Constants inherited from Core::BaseClasses::Version

Core::BaseClasses::Version::ATTRIBUTES, Core::BaseClasses::Version::DEFAULT_MIN_OS, Core::BaseClasses::Version::STATUS_DEPRECATED, Core::BaseClasses::Version::STATUS_PENDING, Core::BaseClasses::Version::STATUS_PILOT, Core::BaseClasses::Version::STATUS_RELEASED, Core::BaseClasses::Version::STATUS_SKIPPED, Core::BaseClasses::Version::USE_TITLE_FOR_KILLAPP

Instance Attribute Summary collapse

Attributes inherited from Core::BaseClasses::Version

#created_by, #creation_date, #deployed_by, #deprecated_by, #deprecation_date, #dist_pkg, #jamf_pkg, #jamf_pkg_file, #jamf_pkg_id, #jamf_pkg_name, #modification_date, #modified_by, #release_date, #reupload_date, #reuploaded_by, #sha_512, #skipped_by, #skipped_date, #status, #upload_date, #uploaded_by

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::BaseClasses::Version

#deprecated?, #pending?, #pilot?, #released?, #skipped?

Methods inherited from Core::BaseClasses::ServerObject

#initialize, #to_h, #to_json

Methods included from Core::JSONWrappers

extended, included, #parse_json

Constructor Details

This class inherits a constructor from Xolo::Core::BaseClasses::ServerObject

Instance Attribute Details

#cnxObject

the server connection used to fetch this version



129
130
131
# File 'lib/xolo/admin/version.rb', line 129

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.

Returns:



66
67
68
69
# File 'lib/xolo/admin/version.rb', line 66

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.

Returns:

  • (Array<String>)

    The currently known versions of a title on the server



59
60
61
62
# File 'lib/xolo/admin/version.rb', line 59

def self.all_versions(title, cnx)
  resp = cnx.get server_route(title)
  resp.body
end

.cli_optsHash{Symbol: Hash}

Returns The ATTRIBUTES that are available as CLI & walkthru options.

Returns:

  • (Hash{Symbol: Hash})

    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

Parameters:

  • title (String)

    the title

  • version (String)

    the version to delete

  • cnx (Faraday::Connection)

    The connection to use, must be logged in already

Returns:

  • (Hash)

    the response body, parsed JSON



119
120
121
122
# File 'lib/xolo/admin/version.rb', line 119

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

Parameters:

  • cnx (Faraday::Connection)

    The connection to use, must be logged in already

  • groups (Array<String, Integer>) (defaults to: [])

    The groups to deploy to

  • computers (Array<String, Integer>) (defaults to: [])

    The computers to deploy to

Returns:

  • (Hash)

    The response from the server

Raises:

  • (ArgumentError)


104
105
106
107
108
109
110
111
# File 'lib/xolo/admin/version.rb', line 104

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?

Parameters:

  • title (String)

    the title

  • version (String)

    the version

  • cnx (Faraday::Connection)

    The connection to use, must be logged in already

Returns:

  • (Boolean)


77
78
79
# File 'lib/xolo/admin/version.rb', line 77

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

Parameters:

  • title (String)

    the title

  • version (String)

    the version to fetch

  • cnx (Faraday::Connection)

    The connection to use, must be logged in already

Returns:



87
88
89
90
91
92
93
94
# File 'lib/xolo/admin/version.rb', line 87

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

Parameters:

  • title (String)

    the title

  • version (String) (defaults to: nil)

    the version to fetch

  • cnx (Faraday::Connection)

    The connection to use, must be logged in already

Returns:



51
52
53
54
55
# 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 << "/#{version}" if version
  route
end

Instance Method Details

#add(cnx = self.cnx) ⇒ Hash

Add this version to the server

Parameters:

  • cnx (Faraday::Connection) (defaults to: self.cnx)

    The connection to use, must be logged in already

Returns:

  • (Hash)

    the response from the server



163
164
165
166
# File 'lib/xolo/admin/version.rb', line 163

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

Parameters:

  • cnx (Faraday::Connection) (defaults to: self.cnx)

    The connection to use, must be logged in already

Returns:

  • (Hash)

    the response from the server



190
191
192
193
# File 'lib/xolo/admin/version.rb', line 190

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

Parameters:

  • cnx (Faraday::Connection) (defaults to: self.cnx)

    The connection to use, must be logged in already

Returns:

  • (Hash{String => String})

    page_name => url



199
200
201
202
# File 'lib/xolo/admin/version.rb', line 199

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.

Returns:

  • (Boolean)

    whether this version is from a managed title or not



250
251
252
# File 'lib/xolo/admin/version.rb', line 250

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

Parameters:

  • cnx (Faraday::Connection) (defaults to: self.cnx)

    The connection to use, must be logged in already

Returns:

  • (Array<Hash>)

    Data for each computer with this version of this title installed



230
231
232
233
# File 'lib/xolo/admin/version.rb', line 230

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

Parameters:

  • cnx (Faraday::Connection) (defaults to: self.cnx)

    The connection to use, must be logged in already

Returns:

  • (Hash)

    the response body from the server



181
182
183
184
# File 'lib/xolo/admin/version.rb', line 181

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.

Returns:

  • (Boolean)

    whether this version is from a subscribed title or not



244
245
246
# File 'lib/xolo/admin/version.rb', line 244

def subscribed?
  title_object.subscribed?
end

#title_object(cnx = self.cnx, refresh: false) ⇒ Xolo::Admin::Title

Returns the title for this version.

Returns:



237
238
239
240
# File 'lib/xolo/admin/version.rb', line 237

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

Parameters:

  • cnx (Faraday::Connection) (defaults to: self.cnx)

    The connection to use, must be logged in already

Returns:

  • (Hash)

    the response from the server



172
173
174
175
# File 'lib/xolo/admin/version.rb', line 172

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.

Parameters:

Returns:

  • (Faraday::Response)

    The server response



212
213
214
215
216
217
218
219
220
221
222
# File 'lib/xolo/admin/version.rb', line 212

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.expand_path.to_s, 'application/octet-stream')

  content = { file: upfile }
  upload_cnx.post(route) { |req| req.body = content }
end