ruby-jss 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +29 -22
- data/README.md +66 -86
- data/bin/jamfHelperBackgrounder +148 -0
- data/bin/netseg-update +0 -1
- data/lib/jss.rb +20 -9
- data/lib/jss/api_connection.rb +369 -295
- data/lib/jss/api_object.rb +651 -418
- data/lib/jss/api_object/account.rb +69 -77
- data/lib/jss/api_object/advanced_search.rb +201 -236
- data/lib/jss/api_object/advanced_search/advanced_computer_search.rb +42 -42
- data/lib/jss/api_object/advanced_search/advanced_mobile_device_search.rb +33 -43
- data/lib/jss/api_object/advanced_search/advanced_user_search.rb +33 -43
- data/lib/jss/api_object/building.rb +39 -52
- data/lib/jss/api_object/categorizable.rb +221 -0
- data/lib/jss/api_object/category.rb +81 -89
- data/lib/jss/api_object/computer.rb +486 -525
- data/lib/jss/api_object/computer_invitation.rb +73 -86
- data/lib/jss/api_object/criteriable.rb +6 -7
- data/lib/jss/api_object/ebook.rb +21 -0
- data/lib/jss/api_object/extendable.rb +6 -8
- data/lib/jss/api_object/group.rb +0 -3
- data/lib/jss/api_object/locatable.rb +19 -20
- data/lib/jss/api_object/mac_application.rb +21 -0
- data/lib/jss/api_object/mobile_device.rb +30 -21
- data/lib/jss/api_object/mobile_device_application.rb +447 -0
- data/lib/jss/api_object/mobile_device_configuration_profile.rb +21 -0
- data/lib/jss/api_object/osx_configuration_profile.rb +0 -3
- data/lib/jss/api_object/package.rb +21 -34
- data/lib/jss/api_object/peripheral.rb +16 -18
- data/lib/jss/api_object/policy.rb +5 -83
- data/lib/jss/api_object/purchasable.rb +11 -13
- data/lib/jss/api_object/scopable.rb +11 -12
- data/lib/jss/api_object/script.rb +3 -17
- data/lib/jss/api_object/self_servable.rb +419 -205
- data/lib/jss/api_object/self_servable/icon.rb +179 -0
- data/lib/jss/api_object/updatable.rb +35 -34
- data/lib/jss/api_object/uploadable.rb +72 -70
- data/lib/jss/api_object/user.rb +6 -7
- data/lib/jss/api_object/vppable.rb +117 -0
- data/lib/jss/client.rb +264 -225
- data/lib/jss/db_connection.rb +7 -5
- data/lib/jss/exceptions.rb +50 -42
- data/lib/jss/ruby_extensions.rb +8 -7
- data/lib/jss/ruby_extensions/object.rb +19 -0
- data/lib/jss/utility.rb +82 -40
- data/lib/jss/version.rb +1 -1
- metadata +37 -68
- data/bin/jss-webhook-server +0 -3
- data/lib/jss/webhooks.rb +0 -53
- data/lib/jss/webhooks/README.md +0 -269
- data/lib/jss/webhooks/configuration.rb +0 -213
- data/lib/jss/webhooks/data/sample_handlers/RestAPIOperation-executable +0 -91
- data/lib/jss/webhooks/data/sample_handlers/RestAPIOperation.rb +0 -45
- data/lib/jss/webhooks/data/sample_jsons/ComputerAdded.json +0 -27
- data/lib/jss/webhooks/data/sample_jsons/ComputerCheckIn.json +0 -27
- data/lib/jss/webhooks/data/sample_jsons/ComputerInventoryCompleted.json +0 -27
- data/lib/jss/webhooks/data/sample_jsons/ComputerPolicyFinished.json +0 -27
- data/lib/jss/webhooks/data/sample_jsons/ComputerPushCapabilityChanged.json +0 -27
- data/lib/jss/webhooks/data/sample_jsons/JSSShutdown.json +0 -14
- data/lib/jss/webhooks/data/sample_jsons/JSSStartup.json +0 -14
- data/lib/jss/webhooks/data/sample_jsons/MobileDeviceCheckIn.json +0 -26
- data/lib/jss/webhooks/data/sample_jsons/MobileDeviceCommandCompleted.json +0 -26
- data/lib/jss/webhooks/data/sample_jsons/MobileDeviceEnrolled.json +0 -26
- data/lib/jss/webhooks/data/sample_jsons/MobileDevicePushSent.json +0 -26
- data/lib/jss/webhooks/data/sample_jsons/MobileDeviceUnEnrolled.json +0 -26
- data/lib/jss/webhooks/data/sample_jsons/PatchSoftwareTitleUpdated.json +0 -14
- data/lib/jss/webhooks/data/sample_jsons/PushSent.json +0 -11
- data/lib/jss/webhooks/data/sample_jsons/RestAPIOperation.json +0 -15
- data/lib/jss/webhooks/data/sample_jsons/SCEPChallenge.json +0 -10
- data/lib/jss/webhooks/data/sample_jsons/SmartGroupComputerMembershipChange.json +0 -13
- data/lib/jss/webhooks/data/sample_jsons/SmartGroupMobileDeviceMembershipChange.json +0 -13
- data/lib/jss/webhooks/event.rb +0 -139
- data/lib/jss/webhooks/event/computer_added.rb +0 -38
- data/lib/jss/webhooks/event/computer_check_in.rb +0 -38
- data/lib/jss/webhooks/event/computer_inventory_completed.rb +0 -38
- data/lib/jss/webhooks/event/computer_policy_finished.rb +0 -38
- data/lib/jss/webhooks/event/computer_push_capability_changed.rb +0 -38
- data/lib/jss/webhooks/event/handlers.rb +0 -192
- data/lib/jss/webhooks/event/jss_shutdown.rb +0 -38
- data/lib/jss/webhooks/event/jss_startup.rb +0 -38
- data/lib/jss/webhooks/event/mobile_device_check_in.rb +0 -38
- data/lib/jss/webhooks/event/mobile_device_command_completed.rb +0 -38
- data/lib/jss/webhooks/event/mobile_device_enrolled.rb +0 -38
- data/lib/jss/webhooks/event/mobile_device_push_sent.rb +0 -38
- data/lib/jss/webhooks/event/mobile_device_unenrolled.rb +0 -38
- data/lib/jss/webhooks/event/patch_software_title_updated.rb +0 -38
- data/lib/jss/webhooks/event/push_sent.rb +0 -38
- data/lib/jss/webhooks/event/rest_api_operation.rb +0 -38
- data/lib/jss/webhooks/event/scep_challenge.rb +0 -38
- data/lib/jss/webhooks/event/smart_group_computer_membership_change.rb +0 -38
- data/lib/jss/webhooks/event/smart_group_mobile_device_membership_change.rb +0 -38
- data/lib/jss/webhooks/event/webhook.rb +0 -40
- data/lib/jss/webhooks/event_objects.rb +0 -112
- data/lib/jss/webhooks/event_objects/computer.rb +0 -49
- data/lib/jss/webhooks/event_objects/jss.rb +0 -36
- data/lib/jss/webhooks/event_objects/mobile_device.rb +0 -48
- data/lib/jss/webhooks/event_objects/patch_software_title_update.rb +0 -38
- data/lib/jss/webhooks/event_objects/push.rb +0 -33
- data/lib/jss/webhooks/event_objects/rest_api_operation.rb +0 -37
- data/lib/jss/webhooks/event_objects/scep_challenge.rb +0 -32
- data/lib/jss/webhooks/event_objects/smart_group.rb +0 -35
- data/lib/jss/webhooks/server_app.rb +0 -37
- data/lib/jss/webhooks/server_app/routes.rb +0 -27
- data/lib/jss/webhooks/server_app/routes/handle_webhook_event.rb +0 -39
- data/lib/jss/webhooks/server_app/routes/home.rb +0 -37
- data/lib/jss/webhooks/server_app/self_signed_cert.rb +0 -65
- data/lib/jss/webhooks/server_app/server.rb +0 -60
- data/lib/jss/webhooks/version.rb +0 -32
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
### Copyright 2017 Pixar
|
|
2
|
+
|
|
3
|
+
###
|
|
4
|
+
### Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
5
|
+
### with the following modification; you may not use this file except in
|
|
6
|
+
### compliance with the Apache License and the following modification to it:
|
|
7
|
+
### Section 6. Trademarks. is deleted and replaced with:
|
|
8
|
+
###
|
|
9
|
+
### 6. Trademarks. This License does not grant permission to use the trade
|
|
10
|
+
### names, trademarks, service marks, or product names of the Licensor
|
|
11
|
+
### and its affiliates, except as required to comply with Section 4(c) of
|
|
12
|
+
### the License and to reproduce the content of the NOTICE file.
|
|
13
|
+
###
|
|
14
|
+
### You may obtain a copy of the Apache License at
|
|
15
|
+
###
|
|
16
|
+
### http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
###
|
|
18
|
+
### Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
### distributed under the Apache License with the above modification is
|
|
20
|
+
### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
21
|
+
### KIND, either express or implied. See the Apache License for the specific
|
|
22
|
+
### language governing permissions and limitations under the Apache License.
|
|
23
|
+
###
|
|
24
|
+
###
|
|
25
|
+
|
|
26
|
+
###
|
|
27
|
+
module JSS
|
|
28
|
+
|
|
29
|
+
# An Icon in the JSS, used in Self Service.
|
|
30
|
+
#
|
|
31
|
+
# At the moment, icons are not API objects, they are collections of data
|
|
32
|
+
# stored in the JSS that might be included in some API object's Self Service data.
|
|
33
|
+
#
|
|
34
|
+
# The data available for an icon are:
|
|
35
|
+
#
|
|
36
|
+
# - id: the icon's id in the JSS
|
|
37
|
+
# - name: the icon's non-unique name in the JSS
|
|
38
|
+
# - uri: the uri to download or preview the icon
|
|
39
|
+
# - data: the icon file itself, base-64 encoded.
|
|
40
|
+
#
|
|
41
|
+
# Icon instances are read-only. To change the icon for an self-servable object,
|
|
42
|
+
# see {SelfServable#icon=}.
|
|
43
|
+
#
|
|
44
|
+
# NOTE: Since icons are not APIObjects, there's no way to see a list of them
|
|
45
|
+
# via the API. The JSS::Icon class methods .all, .all_ids, and .all_names
|
|
46
|
+
# require MySQL database access. See {JSS::DBConnection}.
|
|
47
|
+
#
|
|
48
|
+
class Icon
|
|
49
|
+
|
|
50
|
+
# Class Methods
|
|
51
|
+
#####################################
|
|
52
|
+
|
|
53
|
+
# Return an Array of { id:, name: } Hashes for all icons known to the JSS
|
|
54
|
+
# Since Icon lists aren't accessible via the API, this method must
|
|
55
|
+
# query the SQL database directly, and will raise an exception if you
|
|
56
|
+
# aren't connected to the database.
|
|
57
|
+
#
|
|
58
|
+
# @param refresh[Boolean] re-read the data from the server?
|
|
59
|
+
#
|
|
60
|
+
# @return [Array<Hash>] The names and ids of all icons known to the JSS
|
|
61
|
+
#
|
|
62
|
+
def self.all(refresh = false)
|
|
63
|
+
@all_icons = nil if refresh
|
|
64
|
+
return @all_icons if @all_icons
|
|
65
|
+
@all_icons = []
|
|
66
|
+
qry = 'SELECT icon_id, filename FROM icons'
|
|
67
|
+
res = JSS::DB_CNX.db.query qry
|
|
68
|
+
res.each_hash { |icon| @all_icons << { id: icon['icon_id'].to_i, name: icon['filename'] } }
|
|
69
|
+
@all_icons
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# An Array of all icon ids known to the JSS.
|
|
73
|
+
# See {Icon.all}.
|
|
74
|
+
#
|
|
75
|
+
# @param refresh[Boolean] re-read the data from the server?
|
|
76
|
+
#
|
|
77
|
+
# @return [Array<Integer>] The ids of all icons known to the JSS
|
|
78
|
+
#
|
|
79
|
+
def self.all_ids(refresh = false)
|
|
80
|
+
all(refresh).map { |i| i[:id] }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# An Array of all icon names known to the JSS.
|
|
84
|
+
# See {Icon.all}.
|
|
85
|
+
# NOTE: Icon names are not unique
|
|
86
|
+
#
|
|
87
|
+
# @param refresh[Boolean] re-read the data from the server?
|
|
88
|
+
#
|
|
89
|
+
# @return [Array<Integer>] The names of all icons known to the JSS
|
|
90
|
+
#
|
|
91
|
+
def self.all_names(refresh = false)
|
|
92
|
+
all(refresh).map { |i| i[:name] }
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Attributes
|
|
96
|
+
#####################################
|
|
97
|
+
|
|
98
|
+
# @return [Integer] the icon's id in the JSS
|
|
99
|
+
attr_reader :id
|
|
100
|
+
|
|
101
|
+
# @return [String] the icon's name in the JSS
|
|
102
|
+
# NOTE: these are not unique
|
|
103
|
+
attr_reader :name
|
|
104
|
+
alias filename name
|
|
105
|
+
|
|
106
|
+
# @return [String] The URI for downloading or previewing the icon from the JSS
|
|
107
|
+
attr_reader :uri
|
|
108
|
+
|
|
109
|
+
# @return [String] The raw icon file.
|
|
110
|
+
attr_reader :data
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
# Constructor
|
|
114
|
+
#####################################
|
|
115
|
+
|
|
116
|
+
# Set up a new JSS::Icon instance
|
|
117
|
+
#
|
|
118
|
+
# @param icon_data[Hash] The :self_service_icon Hash from the :self_service
|
|
119
|
+
# Hash of an object's API @init_data
|
|
120
|
+
#
|
|
121
|
+
# @return [JSS::Icon] The new object
|
|
122
|
+
#
|
|
123
|
+
def initialize(icon_data)
|
|
124
|
+
return unless icon_data.is_a? Hash
|
|
125
|
+
@id = icon_data[:id]
|
|
126
|
+
@name = icon_data[:filename]
|
|
127
|
+
@uri = icon_data[:uri]
|
|
128
|
+
@data = icon_data[:data]
|
|
129
|
+
|
|
130
|
+
# if no :filename, its called :name
|
|
131
|
+
@name ||= icon_data[:name]
|
|
132
|
+
|
|
133
|
+
# if there's no id, as with MobileDeviceConfigurationProfile
|
|
134
|
+
# get it from the end of the uri if possible
|
|
135
|
+
if @uri && !@id
|
|
136
|
+
@id = Regexp.last_match(1).to_i if @uri =~ /(\d+)$/
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# decode the icon data, or grab from
|
|
140
|
+
# the URI if needed
|
|
141
|
+
@data = Base64.decode64(@data) if @data
|
|
142
|
+
@data ||= open(@uri).read if @uri
|
|
143
|
+
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Instance Methods
|
|
147
|
+
#####################################
|
|
148
|
+
|
|
149
|
+
# Open the icon's URL in the current user's browser
|
|
150
|
+
#
|
|
151
|
+
# @return [void]
|
|
152
|
+
#
|
|
153
|
+
def show_in_browser
|
|
154
|
+
return nil unless @uri
|
|
155
|
+
system "/usr/bin/open '#{@uri}'"
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# Save the icon to a file.
|
|
159
|
+
#
|
|
160
|
+
# @param path[Pathname, String] The path to which the file should be saved.
|
|
161
|
+
# If the path given is an existing directory, the icon's current filename will
|
|
162
|
+
# be used, if known.
|
|
163
|
+
#
|
|
164
|
+
# @param overwrite[Boolean] Overwrite the file if it exists? Defaults to false
|
|
165
|
+
#
|
|
166
|
+
# @return [void]
|
|
167
|
+
#
|
|
168
|
+
def save(path, overwrite = false)
|
|
169
|
+
path = Pathname.new path
|
|
170
|
+
path = path + @name if path.directory? && @name
|
|
171
|
+
|
|
172
|
+
raise JSS::AlreadyExistsError, "The file #{path} already exists" if path.exist? unless overwrite
|
|
173
|
+
path.delete if path.exist?
|
|
174
|
+
path.jss_save @data
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
end # class icon
|
|
178
|
+
|
|
179
|
+
end # module
|
|
@@ -26,54 +26,54 @@
|
|
|
26
26
|
### A mix-in module providing object-updating via the JSS API.
|
|
27
27
|
module JSS
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
# Module Variables
|
|
30
30
|
#####################################
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
# Module Methods
|
|
33
33
|
#####################################
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
# Sub-Modules
|
|
36
36
|
#####################################
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
# A mix-in module that allows objects to be updated in the JSS via the API.
|
|
39
|
+
#
|
|
40
|
+
# When a JSS::APIObject subclass includes this module, instances of that
|
|
41
|
+
# subclass can be modified in the JSS using the {#update} or {APIObject#save} methods.
|
|
42
|
+
#
|
|
43
|
+
# Such classes should define setter methods for any values that they wish to
|
|
44
|
+
# modify, such as the {#name=} method defined here. Those setter methods must:
|
|
45
|
+
# - ensure the validity of the data they accept.
|
|
46
|
+
# - set @need_to_update to true, indicating that the local object no longer
|
|
47
|
+
# matches the JSS, and the changes should be pushed to the server with {#update}
|
|
48
|
+
#
|
|
49
|
+
# Classes mixing this module *must* provide a #rest_xml instance method that returns the XML
|
|
50
|
+
# String to be submitted to the API for object updating.
|
|
51
|
+
#
|
|
52
|
+
# @see_also APIObject#save
|
|
53
|
+
#
|
|
54
54
|
module Updatable
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
# Constants
|
|
57
57
|
#####################################
|
|
58
58
|
|
|
59
59
|
UPDATABLE = true
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
# Attributes
|
|
62
62
|
#####################################
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
# @return [Boolean] do we have unsaved changes?
|
|
65
65
|
attr_reader :need_to_update
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
# Mixed-in Instance Methods
|
|
68
68
|
#####################################
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
# Change the name of this item
|
|
71
|
+
# Remember to #update to push changes to the server.
|
|
72
|
+
#
|
|
73
|
+
# @param newname[String] the new name
|
|
74
|
+
#
|
|
75
|
+
# @return [void]
|
|
76
|
+
#
|
|
77
77
|
def name=(newname)
|
|
78
78
|
return nil if @name == newname
|
|
79
79
|
raise JSS::UnsupportedError, "Editing #{self.class::RSRC_LIST_KEY} isn't yet supported. Please use other Casper workflows." unless UPDATABLE
|
|
@@ -85,16 +85,17 @@ module JSS
|
|
|
85
85
|
@need_to_update = true
|
|
86
86
|
end # name=(newname)
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
# Save changes to the JSS
|
|
89
|
+
#
|
|
90
|
+
# @return [Boolean] success
|
|
91
|
+
#
|
|
92
92
|
def update
|
|
93
93
|
return nil unless @need_to_update
|
|
94
94
|
raise JSS::UnsupportedError, "Editing #{self.class::RSRC_LIST_KEY} isn't yet supported. Please use other Casper workflows." unless UPDATABLE
|
|
95
95
|
raise JSS::NoSuchItemError, "Not In JSS! Use #create to create this #{self.class::RSRC_OBJECT_KEY} in the JSS before updating it." unless @in_jss
|
|
96
96
|
JSS::API.put_rsrc @rest_rsrc, rest_xml
|
|
97
97
|
@need_to_update = false
|
|
98
|
+
refresh_icon if self_servable?
|
|
98
99
|
@id
|
|
99
100
|
end # update
|
|
100
101
|
|
|
@@ -27,107 +27,109 @@
|
|
|
27
27
|
module JSS
|
|
28
28
|
|
|
29
29
|
#####################################
|
|
30
|
-
|
|
30
|
+
# Module Variables
|
|
31
31
|
#####################################
|
|
32
32
|
|
|
33
33
|
#####################################
|
|
34
|
-
|
|
34
|
+
# Module Methods
|
|
35
35
|
#####################################
|
|
36
36
|
|
|
37
37
|
#####################################
|
|
38
|
-
|
|
38
|
+
# Sub-Modules
|
|
39
39
|
#####################################
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
41
|
+
#
|
|
42
|
+
# A mixin module providing file-upload capabilities to JSSAPIObject subclasses.
|
|
43
|
+
#
|
|
44
|
+
# Classes mixing in this module are required to define a constant UPLOAD_TYPES
|
|
45
|
+
# which is a Hash of :type => :resource pairs, like this:
|
|
46
|
+
#
|
|
47
|
+
# UPLOAD_TYPES = {
|
|
48
|
+
# :icon => :mobiledeviceapplicationsicon
|
|
49
|
+
# :app => mobiledeviceapplicationsipa
|
|
50
|
+
# :attachment => mobiledeviceapplications
|
|
51
|
+
# }
|
|
52
|
+
#
|
|
53
|
+
# with one pair for each type of upload that the class can handle.
|
|
54
|
+
# (most of them only handle one, usually :attachment)
|
|
55
|
+
#
|
|
56
|
+
# When the #upload method is called, one of the keys from that Hash must be specified
|
|
57
|
+
#
|
|
58
|
+
# Classes with only one upload type may want to redefine #upload to always call super with
|
|
59
|
+
# that one type.
|
|
60
|
+
#
|
|
61
|
+
# ----
|
|
62
|
+
#
|
|
63
|
+
# Implementation Notes from
|
|
64
|
+
# https://casperserver:8443/api/index.htm#!/fileuploads/uploadFiles_post
|
|
65
|
+
#
|
|
66
|
+
# POST ...JSSResource/fileuploads/<resource>/<idType>/<id>
|
|
67
|
+
#
|
|
68
|
+
# You can POST different types of files by entering parameters for <resource>, <idType>, and <id>.
|
|
69
|
+
# For example /JSSResource/fileuploads/computers/id/2.
|
|
70
|
+
#
|
|
71
|
+
# Attachments can be uploaded by specifying computers, mobiledevices, enrollmentprofiles, or
|
|
72
|
+
# peripherals as the resource.
|
|
73
|
+
#
|
|
74
|
+
# Icons can be uploaded by specifying policies, ebooks, or mobiledeviceapplicationsicon as the resource.
|
|
75
|
+
#
|
|
76
|
+
# A mobile device application can be uploaded by using mobiledeviceapplicationsipa as the resource.
|
|
77
|
+
#
|
|
78
|
+
# A disk encryption can be uploaded by specifying diskencryptionconfigurations as the resource.
|
|
79
|
+
#
|
|
80
|
+
# idTypes supported are "id" and "name", although peripheral names are not supported.
|
|
81
|
+
#
|
|
82
|
+
# A sample command is:
|
|
83
|
+
# curl -k -u user:password https://my.jss:8443/JSSResource/fileuploads/computers/id/2 -F name=@/Users/admin/Documents/Sample.doc -X POST
|
|
84
|
+
#
|
|
85
|
+
#
|
|
86
|
+
#
|
|
87
|
+
#
|
|
88
88
|
module Uploadable
|
|
89
89
|
|
|
90
90
|
#####################################
|
|
91
|
-
|
|
91
|
+
# Constants
|
|
92
92
|
#####################################
|
|
93
93
|
|
|
94
|
+
UPLOADABLE = true
|
|
95
|
+
|
|
94
96
|
UPLOAD_RSRC_PREFIX = 'fileuploads'.freeze
|
|
95
97
|
|
|
96
98
|
#####################################
|
|
97
|
-
|
|
99
|
+
# Variables
|
|
98
100
|
#####################################
|
|
99
101
|
|
|
100
102
|
#####################################
|
|
101
|
-
|
|
103
|
+
# Methods
|
|
102
104
|
#####################################
|
|
103
105
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
106
|
+
#
|
|
107
|
+
# Upload a file to the JSS via the REST Resource of the
|
|
108
|
+
# object to which this module is mixed in.
|
|
109
|
+
#
|
|
110
|
+
# @param type[Symbol] the type of upload happening.
|
|
111
|
+
# Must be one of the keys defined in the class's UPLOAD_TYPES Hash.
|
|
112
|
+
#
|
|
113
|
+
# @param local_file[String, Pathname] String or Pathname pointing to the
|
|
114
|
+
# locally-readable file to be uploaded.
|
|
115
|
+
#
|
|
116
|
+
# @return [String] The xml response from the server.
|
|
117
|
+
#
|
|
116
118
|
def upload(type, local_file)
|
|
117
|
-
|
|
119
|
+
# the thing's gotta be in the JSS, and have an @id
|
|
118
120
|
raise JSS::NoSuchItemError, 'Create this #{self.class::RSRC_OBJECT_KEY} in the JSS before uploading files to it.' unless @id && @in_jss
|
|
119
121
|
|
|
120
|
-
|
|
122
|
+
# the type has to be defined in the class of self.
|
|
121
123
|
raise JSS::InvalidDataError, "#{self.class::RSRC_LIST_KEY} only take uploads of type: :#{self.class::UPLOAD_TYPES.keys.join(', :')}." \
|
|
122
124
|
unless self.class::UPLOAD_TYPES.keys.include? type
|
|
123
125
|
|
|
124
|
-
|
|
126
|
+
# figure out the resource after the UPLOAD_RSRC_PREFIX
|
|
125
127
|
upload_rsrc = "#{UPLOAD_RSRC_PREFIX}/#{self.class::UPLOAD_TYPES[type]}/id/#{@id}"
|
|
126
128
|
|
|
127
|
-
|
|
129
|
+
# make a File object to hand to REST. 'rb' = read,binary
|
|
128
130
|
file = File.new local_file.to_s, 'rb'
|
|
129
131
|
|
|
130
|
-
|
|
132
|
+
# upload it!
|
|
131
133
|
JSS::API.cnx[upload_rsrc].post name: file
|
|
132
134
|
end # def upload file
|
|
133
135
|
|