ruby-jss 0.6.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ruby-jss might be problematic. Click here for more details.

Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +7 -0
  3. data/CHANGES.md +112 -0
  4. data/LICENSE.txt +174 -0
  5. data/README.md +426 -0
  6. data/THANKS.md +6 -0
  7. data/bin/cgrouper +485 -0
  8. data/bin/subnet-update +400 -0
  9. data/lib/jss-api.rb +2 -0
  10. data/lib/jss.rb +190 -0
  11. data/lib/jss/api_connection.rb +410 -0
  12. data/lib/jss/api_object.rb +616 -0
  13. data/lib/jss/api_object/advanced_search.rb +389 -0
  14. data/lib/jss/api_object/advanced_search/advanced_computer_search.rb +95 -0
  15. data/lib/jss/api_object/advanced_search/advanced_mobile_device_search.rb +96 -0
  16. data/lib/jss/api_object/advanced_search/advanced_user_search.rb +95 -0
  17. data/lib/jss/api_object/building.rb +92 -0
  18. data/lib/jss/api_object/category.rb +147 -0
  19. data/lib/jss/api_object/computer.rb +852 -0
  20. data/lib/jss/api_object/creatable.rb +98 -0
  21. data/lib/jss/api_object/criteriable.rb +189 -0
  22. data/lib/jss/api_object/criteriable/criteria.rb +231 -0
  23. data/lib/jss/api_object/criteriable/criterion.rb +228 -0
  24. data/lib/jss/api_object/department.rb +93 -0
  25. data/lib/jss/api_object/distribution_point.rb +560 -0
  26. data/lib/jss/api_object/extendable.rb +221 -0
  27. data/lib/jss/api_object/extension_attribute.rb +466 -0
  28. data/lib/jss/api_object/extension_attribute/computer_extension_attribute.rb +362 -0
  29. data/lib/jss/api_object/extension_attribute/mobile_device_extension_attribute.rb +189 -0
  30. data/lib/jss/api_object/extension_attribute/user_extension_attribute.rb +117 -0
  31. data/lib/jss/api_object/group.rb +380 -0
  32. data/lib/jss/api_object/group/computer_group.rb +124 -0
  33. data/lib/jss/api_object/group/mobile_device_group.rb +139 -0
  34. data/lib/jss/api_object/group/user_group.rb +139 -0
  35. data/lib/jss/api_object/ldap_server.rb +535 -0
  36. data/lib/jss/api_object/locatable.rb +286 -0
  37. data/lib/jss/api_object/matchable.rb +97 -0
  38. data/lib/jss/api_object/mobile_device.rb +556 -0
  39. data/lib/jss/api_object/netboot_server.rb +148 -0
  40. data/lib/jss/api_object/network_segment.rb +414 -0
  41. data/lib/jss/api_object/osx_configuration_profile.rb +262 -0
  42. data/lib/jss/api_object/package.rb +839 -0
  43. data/lib/jss/api_object/peripheral.rb +335 -0
  44. data/lib/jss/api_object/peripheral_type.rb +295 -0
  45. data/lib/jss/api_object/policy.rb +898 -0
  46. data/lib/jss/api_object/purchasable.rb +316 -0
  47. data/lib/jss/api_object/removable_macaddr.rb +98 -0
  48. data/lib/jss/api_object/scopable.rb +136 -0
  49. data/lib/jss/api_object/scopable/scope.rb +621 -0
  50. data/lib/jss/api_object/script.rb +631 -0
  51. data/lib/jss/api_object/self_servable.rb +356 -0
  52. data/lib/jss/api_object/site.rb +93 -0
  53. data/lib/jss/api_object/software_update_server.rb +109 -0
  54. data/lib/jss/api_object/updatable.rb +117 -0
  55. data/lib/jss/api_object/uploadable.rb +138 -0
  56. data/lib/jss/api_object/user.rb +272 -0
  57. data/lib/jss/client.rb +504 -0
  58. data/lib/jss/compatibility.rb +66 -0
  59. data/lib/jss/composer.rb +185 -0
  60. data/lib/jss/configuration.rb +306 -0
  61. data/lib/jss/db_connection.rb +298 -0
  62. data/lib/jss/exceptions.rb +95 -0
  63. data/lib/jss/ruby_extensions.rb +35 -0
  64. data/lib/jss/ruby_extensions/filetest.rb +43 -0
  65. data/lib/jss/ruby_extensions/hash.rb +79 -0
  66. data/lib/jss/ruby_extensions/ipaddr.rb +91 -0
  67. data/lib/jss/ruby_extensions/pathname.rb +77 -0
  68. data/lib/jss/ruby_extensions/string.rb +59 -0
  69. data/lib/jss/ruby_extensions/time.rb +63 -0
  70. data/lib/jss/server.rb +108 -0
  71. data/lib/jss/utility.rb +478 -0
  72. data/lib/jss/version.rb +31 -0
  73. metadata +187 -0
@@ -0,0 +1,117 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+ ###
26
+ module JSS
27
+
28
+ ### A mix-in module providing object-updating via the JSS API.
29
+ ###
30
+
31
+
32
+
33
+ #####################################
34
+ ### Module Variables
35
+ #####################################
36
+
37
+ #####################################
38
+ ### Module Methods
39
+ #####################################
40
+
41
+ #####################################
42
+ ### Sub-Modules
43
+ #####################################
44
+
45
+ ###
46
+ ### A mix-in module that allows objects to be updated in the JSS via the API.
47
+ ###
48
+ ### When a JSS::APIObject subclass includes this module, instances of that
49
+ ### subclass can be modified in the JSS using the {#update} or {APIObject#save} methods.
50
+ ###
51
+ ### Such classes should define setter methods for any values that they wish to
52
+ ### modify, such as the {#name=} method defined here. Those setter methods must:
53
+ ### - ensure the correctness of the data they accept.
54
+ ### - set @need_to_update to true, indicating that the local object no longer
55
+ ### matches the JSS, and the changes should be pushed to the server with {#update}
56
+ ###
57
+ ### Classes mixing this module *must* provide a #rest_xml instance method that returns the XML
58
+ ### String to be submitted to the API for object updating.
59
+ ###
60
+ ### @see APIObject#save
61
+ ###
62
+ module Updatable
63
+
64
+ #####################################
65
+ ### Constants
66
+ #####################################
67
+
68
+ UPDATABLE = true
69
+
70
+ #####################################
71
+ ### Attributes
72
+ #####################################
73
+
74
+
75
+ ### @return [Boolean] do we have unsaved changes?
76
+ attr_reader :need_to_update
77
+
78
+
79
+ #####################################
80
+ ### Mixed-in Instance Methods
81
+ #####################################
82
+
83
+ ###
84
+ ### Change the name of this item
85
+ ### Remember to #update to push changes to the server.
86
+ ###
87
+ ### @param newname[String] the new name
88
+ ###
89
+ ### @return [void]
90
+ ###
91
+ def name= (newname)
92
+ raise JSS::UnsupportedError, "Editing #{self.class::RSRC_LIST_KEY} isn't yet supported. Please use other Casper workflows." unless UPDATABLE
93
+ return nil if @name == newname
94
+ raise JSS::InvalidDataError, "Names can't be empty!" if newname.to_s.empty?
95
+ raise JSS::AlreadyExistsError, "A #{self.class::RSRC_OBJECT_KEY} named '#{newname}' already exsists in the JSS" if self.class.all_names(:refresh).include? newname
96
+ @name = newname
97
+ @rest_rsrc = "#{self.class::RSRC_BASE}/name/#{URI.escape @name}" if @rest_rsrc.include? '/name/'
98
+ @need_to_update = true
99
+ end # name=(newname)
100
+
101
+ ###
102
+ ### Save changes to the JSS
103
+ ###
104
+ ### @return [Boolean] success
105
+ ###
106
+ def update
107
+ raise JSS::UnsupportedError, "Editing #{self.class::RSRC_LIST_KEY} isn't yet supported. Please use other Casper workflows." unless UPDATABLE
108
+ return nil unless @need_to_update
109
+ 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
110
+ JSS::API.put_rsrc @rest_rsrc, rest_xml
111
+ @need_to_update = false
112
+ @id
113
+ end # update
114
+
115
+ end # module Creatable
116
+
117
+ end # module
@@ -0,0 +1,138 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+ ###
26
+ module JSS
27
+
28
+ #####################################
29
+ ### Module Variables
30
+ #####################################
31
+
32
+
33
+ #####################################
34
+ ### Module Methods
35
+ #####################################
36
+
37
+ #####################################
38
+ ### Sub-Modules
39
+ #####################################
40
+
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
+ module Uploadable
89
+
90
+ #####################################
91
+ ### Constants
92
+ #####################################
93
+
94
+ UPLOAD_RSRC_PREFIX = "fileuploads"
95
+
96
+ #####################################
97
+ ### Variables
98
+ #####################################
99
+
100
+
101
+ #####################################
102
+ ### Methods
103
+ #####################################
104
+
105
+ ###
106
+ ### Upload a file to the JSS via the REST Resource of the
107
+ ### object to which this module is mixed in.
108
+ ###
109
+ ### @param type[Symbol] the type of upload happening.
110
+ ### Must be one of the keys defined in the class's UPLOAD_TYPES Hash.
111
+ ###
112
+ ### @param local_file[String, Pathname] String or Pathname pointing to the
113
+ ### locally-readable file to be uploaded.
114
+ ###
115
+ ### @return [String] The xml response from the server.
116
+ ###
117
+ def upload(type, local_file)
118
+
119
+ ### the thing's gotta be in the JSS, and have an @id
120
+ raise JSS::NoSuchItemError, 'Create this #{self.class::RSRC_OBJECT_KEY} in the JSS before uploading files to it.' unless @id and @in_jss
121
+
122
+ ### the type has to be defined in the class of self.
123
+ raise JSS::InvalidDataError, "#{self.class::RSRC_LIST_KEY} only take uploads of type: :#{self.class::UPLOAD_TYPES.keys.join(', :')}." unless self.class::UPLOAD_TYPES.keys.include? type
124
+
125
+ ### figure out the resource after the UPLOAD_RSRC_PREFIX
126
+ upload_rsrc = "#{UPLOAD_RSRC_PREFIX}/#{self.class::UPLOAD_TYPES[type]}/id/#{@id}"
127
+
128
+ ### make a File object to hand to REST.
129
+ file = File.new local_file.to_s, 'rb'
130
+
131
+ ### upload it!
132
+ JSS::API.cnx[upload_rsrc].post :name => file
133
+
134
+ end # def upload file
135
+
136
+ end # module FileUpload
137
+
138
+ end # module JSS
@@ -0,0 +1,272 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+ ###
26
+ module JSS
27
+
28
+ #####################################
29
+ ### Module Variables
30
+ #####################################
31
+
32
+ #####################################
33
+ ### Module Methods
34
+ #####################################
35
+
36
+ #####################################
37
+ ### Classes
38
+ #####################################
39
+
40
+ ###
41
+ ### A User in the JSS.
42
+ ###
43
+ ### @see JSS::APIObject
44
+ ###
45
+ class User < JSS::APIObject
46
+
47
+ #####################################
48
+ ### Mix-Ins
49
+ #####################################
50
+ include JSS::Creatable
51
+ include JSS::Updatable
52
+ include JSS::Extendable
53
+
54
+ #####################################
55
+ ### Class Methods
56
+ #####################################
57
+
58
+ #####################################
59
+ ### Class Constants
60
+ #####################################
61
+
62
+ ### The base for REST resources of this class
63
+ RSRC_BASE = "users"
64
+
65
+ ### the hash key used for the JSON list output of all objects in the JSS
66
+ RSRC_LIST_KEY = :users
67
+
68
+ ### The hash key used for the JSON object output.
69
+ ### It's also used in various error messages
70
+ RSRC_OBJECT_KEY = :user
71
+
72
+ ### these keys, as well as :id and :name, are present in valid API JSON data for this class
73
+ VALID_DATA_KEYS = [:position, :full_name, :email]
74
+
75
+ ### This class lets us seach for users
76
+ SEARCH_CLASS = JSS::AdvancedUserSearch
77
+
78
+ ### This is the class for relevant Extension Attributes
79
+ EXT_ATTRIB_CLASS = JSS::UserExtensionAttribute
80
+
81
+ #####################################
82
+ ### Attributes
83
+ #####################################
84
+
85
+ ### @return [String] The user's full name
86
+ attr_reader :full_name
87
+
88
+ ### @return [String] The user's email address
89
+ attr_reader :email
90
+
91
+ ### @return [String] The user's phone number
92
+ attr_reader :phone_number
93
+
94
+ ### @return [String] The user's position / job title
95
+ attr_reader :position
96
+
97
+ ### @return [String] The name of the user's LDAP server
98
+ attr_reader :ldap_server
99
+
100
+
101
+ ### @return [Array<Hash>]
102
+ ###
103
+ ### The sites associated with this user
104
+ ###
105
+ ### Each Hash has then :id and :name for one site
106
+ ###
107
+ attr_reader :sites
108
+
109
+
110
+ ### @return [Array<Hash>]
111
+ ###
112
+ ### The computers associated with this user
113
+ ###
114
+ ### Each Hash has then :id and :name for one computer
115
+ ###
116
+ attr_reader :computers
117
+
118
+
119
+ ### @return [Array<Hash>]
120
+ ###
121
+ ### The peripherals associated with this user
122
+ ###
123
+ ### Each Hash has then :id and :name for one peripheral
124
+ ###
125
+ attr_reader :peripherals
126
+
127
+ ### @return [Array<Hash>]
128
+ ###
129
+ ### The mobile devices associated with this user
130
+ ###
131
+ ### Each Hash has then :id and :name for one device
132
+ ###
133
+ ### @note This data is currently broken - the JSON output of the API only
134
+ ### returns one mobile device, and it isn't formatted in a standard way.
135
+ ###
136
+ attr_reader :mobile_devices
137
+
138
+ ### @return [Array<Hash>]
139
+ ###
140
+ ### The vpp assignments associated with this user
141
+ ###
142
+ ### Each Hash has then :id and :name for one assignment
143
+ ###
144
+ attr_reader :vpp_assignments
145
+
146
+ ### @return [Integer] the total number of vpp codes assigned to this user
147
+ attr_reader :total_vpp_code_count
148
+
149
+ #####################################
150
+ ### Constructor
151
+ #####################################
152
+
153
+ ###
154
+ ### See JSS::APIObject#initialize
155
+ ###
156
+ def initialize (args = {})
157
+ super
158
+
159
+ @full_name = @init_data[:full_name]
160
+ @email = @init_data[:email]
161
+ @phone_number = @init_data[:phone_number]
162
+ @position = @init_data[:position]
163
+ @ldap_server = JSS::APIObject.get_name @init_data[:ldap_server]
164
+ @sites = @init_data[:sites] ? @init_data[:sites] : []
165
+
166
+ if @init_data[:links]
167
+ @computers = @init_data[:links][:computers]
168
+ @peripherals = @init_data[:links][:peripherals]
169
+ @mobile_devices = @init_data[:links][:mobile_devices]
170
+ @vpp_assignments = @init_data[:links][:vpp_assignments]
171
+ @total_vpp_code_count = @init_data[:links][:total_vpp_code_count]
172
+ end
173
+
174
+ parse_ext_attrs
175
+ end
176
+
177
+ #####################################
178
+ ### Public Instance Methods
179
+ #####################################
180
+
181
+
182
+ ###
183
+ ### Simple Setters
184
+ ###
185
+
186
+ ###
187
+ def full_name= (new_val)
188
+ @full_name = new_val
189
+ @need_to_update = true
190
+ end
191
+
192
+ ###
193
+ def email= (new_val)
194
+ @email = new_val
195
+ @need_to_update = true
196
+ end
197
+
198
+ ###
199
+ def phone_number= (new_val)
200
+ @phone_number = new_val
201
+ @need_to_update = true
202
+ end
203
+
204
+ ###
205
+ def position= (new_val)
206
+ @position = new_val
207
+ @need_to_update = true
208
+ end
209
+
210
+ ###
211
+ def ldap_server= (new_val)
212
+ raise JSS::InvalidDataError, "No LDAP server in the JSS named #{new_val}" unless JSS::LDAPServer.all_names.include? new_val
213
+ @ldap_server = new_val
214
+ @need_to_update = true
215
+ end
216
+
217
+ ###
218
+ ### Add this user to a site
219
+ ###
220
+ ### @param site[String] the name of the site
221
+ ###
222
+ ### @return [void]
223
+ ###
224
+ def add_site (site)
225
+ return nil if @sites.map{|s| s[:name]}.include? site
226
+ raise JSS::InvalidDataError, "No site in the JSS named #{site}" unless JSS::Site.all_names.include? site
227
+ @sites << {:name => site}
228
+ @need_to_update = true
229
+ end
230
+
231
+ ###
232
+ ### Remove this user from a site
233
+ ###
234
+ ### @param site[String] the name of the site
235
+ ###
236
+ ### @return [void]
237
+ ###
238
+ def remove_site (site)
239
+ return nil unless @sites.map{|s| s[:name]}.include? site
240
+ @sites.reject!{|s| s[:name] == site}
241
+ @need_to_update = true
242
+ end
243
+
244
+
245
+ #####################################
246
+ ### Private Instance Methods
247
+ #####################################
248
+ private
249
+
250
+ def rest_xml
251
+ doc = REXML::Document.new APIConnection::XML_HEADER
252
+ user = doc.add_element self.class::RSRC_OBJECT_KEY.to_s
253
+
254
+ user.add_element('name').text = @name
255
+ user.add_element('full_name').text = @full_name
256
+ user.add_element('email').text = @email
257
+ user.add_element('phone_number').text = @phone_number
258
+ user.add_element('position').text = @position
259
+
260
+ ldap = user.add_element('ldap_server')
261
+ ldap.add_element('name').text = @ldap_server
262
+
263
+ user << JSS::Site.xml_list(@sites)
264
+
265
+ user << ext_attr_xml
266
+
267
+ return doc.to_s
268
+ end
269
+
270
+ end # class user
271
+
272
+ end # module