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,389 +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 Parent class for Advanced Computer, MobileDevice, and User searchs
42
- ###
43
- ### Subclasses must define:
44
- ### * the constant RESULT_CLASS which is the JSS Module class of
45
- ### the item returned by the search, e.g. JSS::Computer
46
- ### * the constant RESULT_ID_FIELDS, which is an Array of Symbols
47
- ### that come from the API in the search_results along with the
48
- ### symbolized display fields.
49
- ### E.g. for AdvancedComputerSearches, :id, :name, and :udid are present along with
50
- ### whatever display fields have been defined.
51
- ###
52
- ###
53
- ### @see JSS::AdvancedComputerSearch
54
- ### @see JSS::AdvancedMobileDeviceSearch
55
- ### @see JSS::AdvancedUserSearch
56
- ### @see JSS::APIObject
57
- ###
58
- class AdvancedSearch < JSS::APIObject
59
-
60
- #####################################
61
- ### Mix-Ins
62
- #####################################
63
- include JSS::Creatable
64
- include JSS::Updatable
65
- include JSS::Criteriable
66
-
67
- #####################################
68
- ### Class Constants
69
- #####################################
70
-
71
- EXPORT_FORMATS = [:csv, :tab, :xml]
72
-
73
- #####################################
74
- ### Attributes
75
- #####################################
76
-
77
-
78
- ###
79
- ### @return [Array<Hash>] the results of the search
80
- ###
81
- ### Each Hash is one object that matches the criteria.
82
- ### Within each hash there are variable keys, but always at least
83
- ### the keys defined in each subclasses RESULT_ID_FIELDS
84
- ###
85
- ### The other keys correspond to the {AdvancedSearch#display_fields} defined for this
86
- ### Advanced Search.
87
- ###
88
- attr_reader :search_results
89
-
90
- ### @return [Array<Symbol>]
91
- ###
92
- ### The search result Hash keys for the {#display_fields} of the search
93
- ###
94
- ### The field names in {#display_fields} are strings matching how the field is labeled
95
- ### in the web UI (including the names of Extension Attributes). They have to be that way
96
- ### when submitting them to the API, and thats mostly what {#display_fields} and related
97
- ### methods are for.
98
- ###
99
- ### However, when those names come back as the Hash Keys of the {#search_results}
100
- ### they (inconsistently) have spaces and/or dashes converted to underscores, and,
101
- ### the JSON module converts the keys to Symbols, so they don't match the {#display_fields}.
102
- ###
103
- ### For example, the display field "Last Check-in" might come back as any of these Symbols:
104
- ### - :"Last Check-in"
105
- ### - :Last_Check_in
106
- ### - :"Last_Check-in"
107
- ###
108
- ### Also, the data returned in the {#search_results} contains more keys than just the
109
- ### {#display_fields} - namely it comes with some standard identifiers for each found item.
110
- ### such as JSS id number and name.
111
- ###
112
- ### {#result_display_keys} will hold just the Hash keys corresponding to the
113
- ### {#display_fields} by taking the keys from the first result Hash, and removing the
114
- ### identifier keys as listed in each subclass's RESULT_ID_FIELDS constant.
115
- ###
116
- attr_reader :result_display_keys
117
-
118
- ### @return [String] the name of the site for this search
119
- attr_reader :site
120
-
121
- ### @return [String] the SQL query generated by the JSS based on the critera
122
- attr_reader :sql_text
123
-
124
- #####################################
125
- ### Constructor
126
- #####################################
127
-
128
- ###
129
- ### @see APIObject#initialize
130
- ###
131
- def initialize(args = {})
132
-
133
- super args
134
-
135
- ### @init_data now has the raw data
136
- ### so fill in our attributes or set defaults
137
-
138
- @sql_text = @init_data[:sql_text]
139
- @site = JSS::APIObject.get_name(@init_data[:site])
140
-
141
-
142
-
143
- @display_fields = @init_data[:display_fields] ? @init_data[:display_fields].map{|f| f[:name]} : []
144
-
145
- @search_results = @init_data[self.class::RESULT_CLASS::RSRC_LIST_KEY]
146
- @search_results ||= []
147
- if @search_results.empty?
148
- @result_display_keys =[]
149
- else
150
- @result_display_keys = @search_results[0].keys - self.class::RESULT_ID_FIELDS
151
- end
152
-
153
- # make sure each hash of the search results
154
- # has a key matching a standard key.
155
- #
156
- @search_results.each do |hash|
157
- hash.keys.each do |key|
158
- std_key = key.to_s.gsub(/ |-/,"_").to_sym
159
- next if hash[std_key]
160
- hash[std_key] = hash[key]
161
- end
162
- end
163
-
164
- parse_criteria
165
-
166
-
167
- end # init
168
-
169
- #####################################
170
- ### Public Instance Methods
171
- #####################################
172
-
173
- ###
174
- ### Create in the JSS
175
- ###
176
- ### If get_results is true, they'll be available in {#search_results}. This might be slow.
177
- ###
178
- ### @param get_results[Boolean] should the results of the search be queried immediately?
179
- ###
180
- ### @return [Integer] the id of the newly created search
181
- ###
182
- def create(get_results = false)
183
- raise JSS::InvalidDataError, "JSS::Criteriable::Criteria instance required" unless @criteria.kind_of? JSS::Criteriable::Criteria
184
- raise JSS::InvalidDataError, "display_fields must be an Array." unless @display_fields.kind_of? Array
185
-
186
- orig_timeout = JSS::API.cnx.options[:timeout]
187
- JSS::API.timeout = 1800
188
- super()
189
- requery_search_results if get_results
190
- JSS::API.timeout = orig_timeout
191
-
192
- @id # remember to return the id
193
-
194
- end
195
-
196
- ###
197
- ### Save any changes
198
- ###
199
- ### If get_results is true, they'll be available in {#search_results}. This might be slow.
200
- ###
201
- ### @param get_results[Boolean] should the results of the search be queried immediately?
202
- ###
203
- ### @return [Integer] the id of the updated search
204
- ###
205
- def update(get_results = false)
206
- orig_timeout = JSS::API.cnx.options[:timeout]
207
- JSS::API.timeout = 1800
208
- super()
209
- requery_search_results if get_results
210
- JSS::API.timeout = orig_timeout
211
-
212
- @id # remember to return the id
213
- end
214
-
215
-
216
- ###
217
- ### Requery the API for the search results.
218
- ###
219
- ### This can be very slow, so temporarily reset the API timeout to 30 minutes
220
- ###
221
- ### @return [Array<Hash>] the new search results
222
- ###
223
- def requery_search_results
224
- orig_open_timeout = JSS::API.cnx.options[:open_timeout]
225
- orig_timeout = JSS::API.cnx.options[:timeout]
226
- JSS::API.timeout = 1800
227
- JSS::API.open_timeout = 1800
228
- begin
229
- requery = self.class.new(:id => @id)
230
- @search_results = requery.search_results
231
- @result_display_keys = requery.result_display_keys
232
- ensure
233
- JSS::API.timeout = orig_timeout
234
- JSS::API.open_timeout = orig_open_timeout
235
- end
236
- end
237
-
238
- ###
239
- ### @return [Array<String>] the fields to be returned with the search results
240
- ###
241
- ### The API delivers these as an array of Hashes,
242
- ### where each hash has only one key, :name => the name of the fields/ExtAttrib
243
- ### to display. It should probably not have the underlying Hashes, and just
244
- ### be an array of names. This class converts it to just an Array of field names
245
- ### (Strings) for internal use.
246
- ###
247
- ### These fields are returned in the @search_results
248
- ### data along with :id, :name, and other unique identifiers
249
- ### for each found item. In that data, their names have
250
- ### spaces and dashes converted to underscores, and they are
251
- ### symbolized.
252
- ###
253
- ###
254
- def display_fields
255
- @display_fields
256
- end
257
-
258
- ###
259
- ### Set the list of fields to be retrieved with the
260
- ### search results.
261
- ###
262
- ### @param new_val[Array<String>] the new field names
263
- ###
264
- def display_fields= (new_val)
265
- raise JSS::InvalidDataError, "display_fields must be an Array." unless new_val.kind_of? Array
266
- return if new_val.sort == @display_fields.sort
267
- @display_fields = new_val
268
- @need_to_update = true
269
- end
270
-
271
-
272
-
273
- ###
274
- ### @return [Integer] the number of items found by the search
275
- ###
276
- def count
277
- @search_results.count
278
- end
279
-
280
- ###
281
- ### Export the display fields of the search results to a file.
282
- ###
283
- ### @param output_file[String,Pathname] The file in which to store the exported results
284
- ###
285
- ### @param format[Symbol] one of :csv, :tab, or :xml, defaults to :csv
286
- ###
287
- ### @param overwrite[Boolean] should the output_file be overwrite if it exists? Defaults to false
288
- ###
289
- ### @return [Pathname] the path to the output file
290
- ###
291
- ### @note This method only exports the display fields defined in this advanced search for
292
- ### the search_result members (computers, mobile_devices, or users)
293
- ### It doesn't currently provide the ability to export subsets of info about those objects, as the
294
- ### Web UI does (e.g. group memberships, applications, receipts, etc)
295
- ###
296
- def export(output_file, format = :csv, overwrite = false)
297
-
298
- raise JSS::InvalidDataError, "Export format must be one of: :#{EXPORT_FORMATS.join ', :'}" unless EXPORT_FORMATS.include? format
299
-
300
- out = Pathname.new output_file
301
-
302
- unless overwrite
303
- raise JSS::AlreadyExistsError, "The output file already exists: #{out}" if out.exist?
304
- end
305
-
306
-
307
- case format
308
- when :csv
309
- require 'csv'
310
- CSV.open(out.to_s, 'wb') do |csv|
311
- csv << @result_display_keys
312
- @search_results.each do |row|
313
- csv << @result_display_keys.map {|key| row[key]}
314
- end # each do row
315
- end #CSV.open
316
-
317
- when :tab
318
- tabbed = @result_display_keys.join("\t") + "\n"
319
- @search_results.each do |row|
320
- tabbed << @result_display_keys.map {|key| row[key]}.join("\t") + "\n"
321
- end # each do row
322
- out.jss_save tabbed.chomp
323
-
324
- else # :xml
325
- doc = REXML::Document.new '<?xml version="1.0" encoding="ISO-8859-1"?>'
326
- members = doc.add_element self.class::RESULT_CLASS::RSRC_LIST_KEY.to_s
327
- @search_results.each do |row|
328
- member = members.add_element self.class::RESULT_CLASS::RSRC_OBJECT_KEY.to_s
329
- @result_display_keys.each do |field|
330
- member.add_element(field.to_s.gsub(' ',"_")).text = row[field].empty? ? nil : row[field]
331
- end # ech do field
332
- end #each do row
333
- out.jss_save doc.to_s.gsub('><', ">\n<")
334
- end # case
335
-
336
- return out
337
- end
338
-
339
-
340
- #####################################
341
- ### Private Instance Methods
342
- #####################################
343
- private
344
-
345
- ###
346
- ### Clean up the inconsistent "Display Field" keys in the search results.
347
- ###
348
- ### Sometimes spaces have been converted to underscores, sometimes not, sometimes both.
349
- ### Same for dashes.
350
- ### E.g :"Last Check-in"/:Last_Check_in/:"Last_Check-in", :Computer_Name, and :"Display Name"/:Display_Name
351
- ###
352
- ### This ensures there's always the fully underscored version.
353
- ###
354
- ### Update an internally used array of the display field names, symbolized, with
355
- ### spaces and dashes converted to underscores. We use these
356
- ### to overcome inconsistencies in how the names come from the API
357
- ###
358
- ### @return [void]
359
- ###
360
- def standardize_display_field_keys
361
- spdash=
362
- us =
363
- @display_field_std_keys = @display_fields.map{|f| f.gsub(/ |-/,"_").to_sym }
364
- end
365
-
366
- def rest_xml
367
- doc = REXML::Document.new APIConnection::XML_HEADER
368
- acs = doc.add_element self.class::RSRC_OBJECT_KEY.to_s
369
- acs.add_element('name').text = @name
370
- acs.add_element('sort_1').text = @sort_1 if @sort_1
371
- acs.add_element('sort_2').text = @sort_2 if @sort_2
372
- acs.add_element('sort_3').text = @sort_3 if @sort_3
373
-
374
- acs << @criteria.rest_xml
375
-
376
- df = acs.add_element('display_fields')
377
- @display_fields.each{|f| df.add_element('display_field').add_element('name').text = f }
378
-
379
- return doc.to_s
380
- end # rest xml
381
-
382
- end # class AdvancedSearch
383
-
384
- end # module JSS
385
-
386
- require "jss-api/api_object/advanced_search/advanced_computer_search"
387
- require "jss-api/api_object/advanced_search/advanced_mobile_device_search"
388
- require "jss-api/api_object/advanced_search/advanced_user_search"
389
-
@@ -1,95 +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
- ### An AdvancedComputerSearch in the JSS
42
- ###
43
- ### @see JSS::AdvancedSearch
44
- ###
45
- ### @see JSS::APIObject
46
- ###
47
- class AdvancedComputerSearch < JSS::AdvancedSearch
48
-
49
- #####################################
50
- ### Mix-Ins
51
- #####################################
52
-
53
- #####################################
54
- ### Class Constants
55
- #####################################
56
-
57
- ### The base for REST resources of this class
58
- RSRC_BASE = "advancedcomputersearches"
59
-
60
- ### the hash key used for the JSON list output of all objects in the JSS
61
- RSRC_LIST_KEY = :advanced_computer_searches
62
-
63
- ### The hash key used for the JSON object output.
64
- ### It's also used in various error messages
65
- RSRC_OBJECT_KEY = :advanced_computer_search
66
-
67
- ### these keys, as well as :id and :name, are present in valid API JSON data for this class
68
- VALID_DATA_KEYS = [:sql_text, :display_fields, :computers]
69
-
70
- ### what kind of thing is returned by this search?
71
- RESULT_CLASS = JSS::Computer
72
-
73
- ### what data fields come back along with the display fields
74
- ### for each computer?
75
- RESULT_ID_FIELDS = [:id, :name, :udid]
76
-
77
- #####################################
78
- ### Attributes
79
- #####################################
80
-
81
- #####################################
82
- ### Constructor
83
- #####################################
84
-
85
- #####################################
86
- ### Public Instance Methods
87
- #####################################
88
-
89
- #####################################
90
- ### Private Instance Methods
91
- #####################################
92
-
93
- end # class
94
-
95
- end # module