Module: Jamf::Uploadable

Included in:
Computer, MobileDevice, MobileDeviceApplication, Peripheral, Policy, SelfServable
Defined in:
lib/jamf/api/classic/api_objects/uploadable.rb

Overview

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

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

UPLOADABLE =

Constants

true
UPLOAD_RSRC_PREFIX =
'fileuploads'.freeze
FORCE_IPA_UPLOAD_PARAM =
'FORCE_IPA_UPLOAD'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

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



148
149
150
# File 'lib/jamf/api/classic/api_objects/uploadable.rb', line 148

def self.included(klass)
  klass.extend(ClassMethods)
end

Instance Method Details

#upload(type, local_file, force_ipa_upload: false) ⇒ Boolean

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

Parameters:

  • type (Symbol)

    the type of upload happening. Must be one of the keys defined in the class’s UPLOAD_TYPES Hash.

  • local_file (String, Pathname)

    String or Pathname pointing to the locally-readable file to be uploaded.

  • force_ipa_upload (Boolean) (defaults to: false)

    Should the server upload the .ipa file to JCDS or AWS if such are confgured for use?

Returns:

  • (Boolean)

    was the upload successful?

Raises:



171
172
173
174
175
176
# File 'lib/jamf/api/classic/api_objects/uploadable.rb', line 171

def upload(type, local_file, force_ipa_upload: false)
  # the thing's gotta be in the JSS, and have an @id
  raise Jamf::NoSuchItemError, "Create this #{self.class::RSRC_OBJECT_KEY} in the JSS before uploading files to it." unless @id && @in_jss

  self.class.upload @id, type, local_file, force_ipa_upload: force_ipa_upload, cnx: @cnx
end