jss-api 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/lib/jss-api.rb +1 -191
  2. metadata +16 -146
  3. data/.yardopts +0 -7
  4. data/CHANGES.md +0 -88
  5. data/LICENSE.txt +0 -174
  6. data/README.md +0 -396
  7. data/THANKS.md +0 -6
  8. data/bin/cgrouper +0 -485
  9. data/bin/subnet-update +0 -400
  10. data/lib/jss-api/api_connection.rb +0 -400
  11. data/lib/jss-api/api_object.rb +0 -616
  12. data/lib/jss-api/api_object/advanced_search.rb +0 -389
  13. data/lib/jss-api/api_object/advanced_search/advanced_computer_search.rb +0 -95
  14. data/lib/jss-api/api_object/advanced_search/advanced_mobile_device_search.rb +0 -96
  15. data/lib/jss-api/api_object/advanced_search/advanced_user_search.rb +0 -95
  16. data/lib/jss-api/api_object/building.rb +0 -92
  17. data/lib/jss-api/api_object/category.rb +0 -147
  18. data/lib/jss-api/api_object/computer.rb +0 -852
  19. data/lib/jss-api/api_object/creatable.rb +0 -98
  20. data/lib/jss-api/api_object/criteriable.rb +0 -189
  21. data/lib/jss-api/api_object/criteriable/criteria.rb +0 -231
  22. data/lib/jss-api/api_object/criteriable/criterion.rb +0 -228
  23. data/lib/jss-api/api_object/department.rb +0 -93
  24. data/lib/jss-api/api_object/distribution_point.rb +0 -560
  25. data/lib/jss-api/api_object/extendable.rb +0 -221
  26. data/lib/jss-api/api_object/extension_attribute.rb +0 -457
  27. data/lib/jss-api/api_object/extension_attribute/computer_extension_attribute.rb +0 -362
  28. data/lib/jss-api/api_object/extension_attribute/mobile_device_extension_attribute.rb +0 -189
  29. data/lib/jss-api/api_object/extension_attribute/user_extension_attribute.rb +0 -117
  30. data/lib/jss-api/api_object/group.rb +0 -380
  31. data/lib/jss-api/api_object/group/computer_group.rb +0 -124
  32. data/lib/jss-api/api_object/group/mobile_device_group.rb +0 -139
  33. data/lib/jss-api/api_object/group/user_group.rb +0 -139
  34. data/lib/jss-api/api_object/ldap_server.rb +0 -535
  35. data/lib/jss-api/api_object/locatable.rb +0 -286
  36. data/lib/jss-api/api_object/matchable.rb +0 -97
  37. data/lib/jss-api/api_object/mobile_device.rb +0 -556
  38. data/lib/jss-api/api_object/netboot_server.rb +0 -148
  39. data/lib/jss-api/api_object/network_segment.rb +0 -414
  40. data/lib/jss-api/api_object/osx_configuration_profile.rb +0 -261
  41. data/lib/jss-api/api_object/package.rb +0 -812
  42. data/lib/jss-api/api_object/peripheral.rb +0 -335
  43. data/lib/jss-api/api_object/peripheral_type.rb +0 -295
  44. data/lib/jss-api/api_object/policy.rb +0 -898
  45. data/lib/jss-api/api_object/purchasable.rb +0 -316
  46. data/lib/jss-api/api_object/removable_macaddr.rb +0 -98
  47. data/lib/jss-api/api_object/scopable.rb +0 -136
  48. data/lib/jss-api/api_object/scopable/scope.rb +0 -621
  49. data/lib/jss-api/api_object/script.rb +0 -631
  50. data/lib/jss-api/api_object/self_servable.rb +0 -355
  51. data/lib/jss-api/api_object/site.rb +0 -93
  52. data/lib/jss-api/api_object/software_update_server.rb +0 -109
  53. data/lib/jss-api/api_object/updatable.rb +0 -117
  54. data/lib/jss-api/api_object/uploadable.rb +0 -138
  55. data/lib/jss-api/api_object/user.rb +0 -272
  56. data/lib/jss-api/client.rb +0 -504
  57. data/lib/jss-api/compatibility.rb +0 -66
  58. data/lib/jss-api/composer.rb +0 -171
  59. data/lib/jss-api/configuration.rb +0 -306
  60. data/lib/jss-api/db_connection.rb +0 -298
  61. data/lib/jss-api/exceptions.rb +0 -95
  62. data/lib/jss-api/ruby_extensions.rb +0 -35
  63. data/lib/jss-api/ruby_extensions/filetest.rb +0 -43
  64. data/lib/jss-api/ruby_extensions/hash.rb +0 -79
  65. data/lib/jss-api/ruby_extensions/ipaddr.rb +0 -91
  66. data/lib/jss-api/ruby_extensions/pathname.rb +0 -77
  67. data/lib/jss-api/ruby_extensions/string.rb +0 -59
  68. data/lib/jss-api/ruby_extensions/time.rb +0 -63
  69. data/lib/jss-api/server.rb +0 -108
  70. data/lib/jss-api/utility.rb +0 -416
  71. data/lib/jss-api/version.rb +0 -31
@@ -1,117 +0,0 @@
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
@@ -1,138 +0,0 @@
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
@@ -1,272 +0,0 @@
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