module Jamf::Uploadable

A mixin module providing file-upload capabilities to JSSAPIObject subclasses.

Classes mixing in this module are required to define a constant UPLOAD_TYPES which is a Hash of :type => :resource pairs, like this:

UPLOAD_TYPES = {
   :icon => :mobiledeviceapplicationsicon
   :app => :mobiledeviceapplicationsipa
   :attachment => :mobiledeviceapplications
 }

with one pair for each type of upload that the class can handle. (most of them only handle one, usually :attachment)

When the upload method is called, one of the keys from that Hash must be specified

Classes with only one upload type may want to redefine upload to always call super with that one type.


Implementation Notes from casperserver:8443/api/index.htm#!/fileuploads/uploadFiles_post

POST ...JSSResource/fileuploads/<resource>/<idType>/<id>

You can POST different types of files by entering parameters for <resource>, <idType>, and <id>. For example /JSSResource/fileuploads/computers/id/2.

Attachments can be uploaded by specifying computers, mobiledevices, enrollmentprofiles, or peripherals as the resource.

Icons can be uploaded by specifying policies, ebooks, or mobiledeviceapplicationsicon as the resource.

A mobile device application can be uploaded by using mobiledeviceapplicationsipa as the resource.

A disk encryption can be uploaded by specifying diskencryptionconfigurations as the resource.

idTypes supported are “id” and “name”, although peripheral names are not supported.

A sample command is:

curl -k -u user:password https://my.jss:8443/JSSResource/fileuploads/computers/id/2 -F name=@/Users/admin/Documents/Sample.doc -X POST

Constants

FORCE_IPA_UPLOAD_PARAM
UPLOADABLE

Constants

UPLOAD_RSRC_PREFIX

Public Class Methods

included(klass) click to toggle source

this loads the class methods (via ‘extend’) when the instanace methods are included

    # File lib/jamf/api/classic/api_objects/uploadable.rb
148 def self.included(klass)
149   klass.extend(ClassMethods)
150 end

Public Instance Methods

upload(type, local_file, force_ipa_upload: false) click to toggle source

instance method wrapper for class method

Upload a file to the JSS to be stored with this instance of the class mixing in the Uploadable module

@param type the type of upload happening.

Must be one of the keys defined in the class's UPLOAD_TYPES Hash.

@param local_file[String, Pathname] String or Pathname pointing to the

locally-readable file to be uploaded.

@param force_ipa_upload Should the server upload the .ipa file to

JCDS or AWS if such are confgured for use?

@return [Boolean] was the upload successful?

    # File lib/jamf/api/classic/api_objects/uploadable.rb
171 def upload(type, local_file, force_ipa_upload: false)
172   # the thing's gotta be in the JSS, and have an @id
173   raise Jamf::NoSuchItemError, "Create this #{self.class::RSRC_OBJECT_KEY} in the JSS before uploading files to it." unless @id && @in_jss
174 
175   self.class.upload @id, type, local_file, force_ipa_upload: force_ipa_upload, cnx: @cnx
176 end