ruby-jss 0.10.0 → 0.10.1a2
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.
Potentially problematic release.
This version of ruby-jss might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/jss/api_object.rb +102 -0
- data/lib/jss/api_object/advanced_search/advanced_computer_search.rb +4 -0
- data/lib/jss/api_object/advanced_search/advanced_mobile_device_search.rb +5 -0
- data/lib/jss/api_object/advanced_search/advanced_user_search.rb +5 -0
- data/lib/jss/api_object/building.rb +5 -0
- data/lib/jss/api_object/category.rb +5 -0
- data/lib/jss/api_object/computer.rb +7 -2
- data/lib/jss/api_object/computer_invitation.rb +5 -0
- data/lib/jss/api_object/department.rb +26 -21
- data/lib/jss/api_object/distribution_point.rb +5 -0
- data/lib/jss/api_object/ebook.rb +5 -0
- data/lib/jss/api_object/extendable.rb +123 -148
- data/lib/jss/api_object/extension_attribute.rb +242 -301
- data/lib/jss/api_object/extension_attribute/computer_extension_attribute.rb +5 -0
- data/lib/jss/api_object/extension_attribute/mobile_device_extension_attribute.rb +14 -9
- data/lib/jss/api_object/extension_attribute/user_extension_attribute.rb +40 -35
- data/lib/jss/api_object/group/computer_group.rb +11 -6
- data/lib/jss/api_object/group/mobile_device_group.rb +11 -6
- data/lib/jss/api_object/group/user_group.rb +16 -11
- data/lib/jss/api_object/ldap_server.rb +5 -0
- data/lib/jss/api_object/mac_application.rb +5 -0
- data/lib/jss/api_object/mobile_device.rb +5 -0
- data/lib/jss/api_object/mobile_device_application.rb +5 -0
- data/lib/jss/api_object/mobile_device_configuration_profile.rb +5 -0
- data/lib/jss/api_object/netboot_server.rb +11 -6
- data/lib/jss/api_object/network_segment.rb +5 -0
- data/lib/jss/api_object/osx_configuration_profile.rb +4 -0
- data/lib/jss/api_object/package.rb +5 -0
- data/lib/jss/api_object/peripheral.rb +4 -0
- data/lib/jss/api_object/peripheral_type.rb +11 -6
- data/lib/jss/api_object/policy.rb +5 -0
- data/lib/jss/api_object/removable_macaddr.rb +28 -23
- data/lib/jss/api_object/restricted_software.rb +5 -0
- data/lib/jss/api_object/script.rb +5 -0
- data/lib/jss/api_object/site.rb +29 -24
- data/lib/jss/api_object/software_update_server.rb +11 -6
- data/lib/jss/api_object/user.rb +5 -0
- data/lib/jss/api_object/webhook.rb +5 -0
- data/lib/jss/version.rb +1 -1
- metadata +4 -4
@@ -1,167 +1,133 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
27
|
module JSS
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
### * A list of target objects with a certain value for the ExtensionAttribute instance.
|
58
|
-
### See the {#all_with_result} method for details
|
59
|
-
### * A list of the most recent value for this ExtensionAttribute in all targets in the JSS
|
60
|
-
###
|
61
|
-
### The {ComputerExtensionAttribute} subclass offers a {ComputerExtensionAttribute#history}
|
62
|
-
### method providing the history of values for the EA for one computer. This requires
|
63
|
-
### MySQL access to the JSS database since that history isn't available via the API.
|
64
|
-
###
|
65
|
-
### Subclasses of ExtensionAttribute must define these constants:
|
66
|
-
### * TARGET_CLASS - the {APIObject} subclass to which the extention attribute applies.
|
67
|
-
### e.g. {JSS::Computer}
|
68
|
-
###
|
69
|
-
### * ALL_TARGETS_CRITERION - a {JSS::Criteriable::Criterion} instance that will be used in
|
70
|
-
### an {AdvancedSearch} to find all of members of the TARGET_CLASS
|
71
|
-
###
|
72
|
-
### @see JSS::APIObject
|
73
|
-
###
|
29
|
+
# Classes
|
30
|
+
###################################
|
31
|
+
|
32
|
+
# The parent class of ExtensionAttribute objects in the JSS.
|
33
|
+
#
|
34
|
+
# The API extension attribute objects work with the definitions of extension
|
35
|
+
# attributes, not the resulting values stored in the JSS with the inventory
|
36
|
+
# reports.
|
37
|
+
#
|
38
|
+
# This superclass, however, uses the {AdvancedSearch} subclasses to provide
|
39
|
+
# access to the reported values in two ways:
|
40
|
+
# * A list of target objects with a certain value for the ExtensionAttribute instance.
|
41
|
+
# See the {#all_with_result} method for details
|
42
|
+
# * A list of the most recent value for this ExtensionAttribute in all targets in the JSS
|
43
|
+
#
|
44
|
+
# The {ComputerExtensionAttribute} subclass offers a {ComputerExtensionAttribute#history}
|
45
|
+
# method providing the history of values for the EA for one computer. This requires
|
46
|
+
# MySQL access to the JSS database since that history isn't available via the API.
|
47
|
+
#
|
48
|
+
# Subclasses of ExtensionAttribute must define these constants:
|
49
|
+
# * TARGET_CLASS - the {APIObject} subclass to which the extention attribute applies.
|
50
|
+
# e.g. {JSS::Computer}
|
51
|
+
#
|
52
|
+
# * ALL_TARGETS_CRITERION - a {JSS::Criteriable::Criterion} instance that will be used in
|
53
|
+
# an {AdvancedSearch} to find all of members of the TARGET_CLASS
|
54
|
+
#
|
55
|
+
# @see JSS::APIObject
|
56
|
+
#
|
74
57
|
class ExtensionAttribute < JSS::APIObject
|
75
58
|
|
76
|
-
|
77
|
-
|
78
|
-
#####################################
|
59
|
+
# Mix-Ins
|
60
|
+
###################################
|
79
61
|
include JSS::Creatable
|
80
62
|
include JSS::Updatable
|
81
63
|
|
82
|
-
|
83
|
-
|
84
|
-
#####################################
|
85
|
-
|
86
|
-
#####################################
|
87
|
-
### Class Constants
|
88
|
-
#####################################
|
89
|
-
|
90
|
-
### What kinds of data can be created by EAs?
|
91
|
-
### Note, Dates must be in the format "YYYY-MM-DD hh:mm:ss"
|
92
|
-
DATA_TYPES = ["String", "Date", "Integer"]
|
93
|
-
DEFAULT_DATA_TYPE = "String"
|
64
|
+
# Class Constants
|
65
|
+
###################################
|
94
66
|
|
95
|
-
|
96
|
-
|
97
|
-
|
67
|
+
# What kinds of data can be created by EAs?
|
68
|
+
# Note, Dates must be in the format "YYYY-MM-DD hh:mm:ss"
|
69
|
+
DATA_TYPES = %w[String Date Integer].freeze
|
70
|
+
DEFAULT_DATA_TYPE = 'String'.freeze
|
98
71
|
|
99
|
-
|
100
|
-
|
72
|
+
# Where does the data come from?
|
73
|
+
INPUT_TYPES = ['Text Field', 'Pop-up Menu', 'script', 'LDAP Attribute Mapping'].freeze
|
74
|
+
DEFAULT_INPUT_TYPE = 'Text Field'.freeze
|
101
75
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
### Where can it be displayed in the WebApp?
|
106
|
-
### subclasses can add to this list
|
76
|
+
# Where can it be displayed in the WebApp?
|
77
|
+
# subclasses can add to this list
|
107
78
|
WEB_DISPLAY_CHOICES = [
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
]
|
115
|
-
DEFAULT_WEB_DISPLAY_CHOICE =
|
116
|
-
|
117
|
-
LAST_RECON_FIELD = 'Last Inventory Update'
|
118
|
-
LAST_RECON_FIELD_SYM = LAST_RECON_FIELD.
|
119
|
-
|
120
|
-
USERNAME_FIELD =
|
79
|
+
'General',
|
80
|
+
'Operating System',
|
81
|
+
'Hardware',
|
82
|
+
'User and Location',
|
83
|
+
'Purchasing',
|
84
|
+
'Extension Attributes'
|
85
|
+
].freeze
|
86
|
+
DEFAULT_WEB_DISPLAY_CHOICE = 'Extension Attributes'.freeze
|
87
|
+
|
88
|
+
LAST_RECON_FIELD = 'Last Inventory Update'.freeze
|
89
|
+
LAST_RECON_FIELD_SYM = LAST_RECON_FIELD.tr(' ', '_').to_sym
|
90
|
+
|
91
|
+
USERNAME_FIELD = 'Username'.freeze
|
121
92
|
USERNAME_FIELD_SYM = USERNAME_FIELD.to_sym
|
122
93
|
|
123
|
-
|
124
|
-
|
125
|
-
######################
|
94
|
+
# Attributes
|
95
|
+
####################
|
126
96
|
|
127
|
-
|
97
|
+
# :id, :name, :in_jss, :need_to_update, and :rest_rsrc come from JSS::APIObject
|
128
98
|
|
129
|
-
|
99
|
+
# @return [String] description of the ext attrib
|
130
100
|
attr_reader :description
|
131
101
|
|
132
|
-
|
102
|
+
# @return [String] the type of data created by the EA. Must be one of DATA_TYPES
|
133
103
|
attr_reader :data_type
|
134
104
|
|
135
|
-
|
105
|
+
# @return [String] where does this data come from? Must be one of the INPUT_TYPES.
|
136
106
|
attr_reader :input_type
|
137
107
|
|
138
|
-
|
108
|
+
# @return [Array<String>] the choices available in the UI when the @input_type is "Pop-up Menu"
|
139
109
|
attr_reader :popup_choices
|
140
110
|
|
141
|
-
|
111
|
+
# @return [String] In which part of the web UI does the data appear?
|
142
112
|
attr_reader :web_display
|
143
113
|
|
144
114
|
|
115
|
+
# Constructor
|
116
|
+
###################################
|
145
117
|
|
146
|
-
#####################################
|
147
|
-
### Constructor
|
148
|
-
#####################################
|
149
118
|
|
150
|
-
|
151
|
-
|
152
|
-
###
|
119
|
+
# @see JSS::APIObject#initialize
|
120
|
+
#
|
153
121
|
def initialize(args = {})
|
154
|
-
|
155
122
|
super args
|
156
123
|
|
157
|
-
|
158
|
-
|
124
|
+
# @init_data now has the raw data
|
125
|
+
# so fill in our attributes or set defaults
|
159
126
|
|
160
127
|
@description = @init_data[:description]
|
161
128
|
@data_type = @init_data[:data_type] || DEFAULT_DATA_TYPE
|
162
129
|
@web_display = @init_data[:inventory_display] || DEFAULT_WEB_DISPLAY_CHOICE
|
163
130
|
|
164
|
-
|
165
131
|
if @init_data[:input_type]
|
166
132
|
@input_type = @init_data[:input_type][:type] || DEFAULT_INPUT_TYPE
|
167
133
|
@popup_choices = @init_data[:input_type][:popup_choices]
|
@@ -171,40 +137,36 @@ module JSS
|
|
171
137
|
@input_type = DEFAULT_INPUT_TYPE
|
172
138
|
end
|
173
139
|
|
174
|
-
|
175
|
-
|
176
|
-
@symbolized_name = @name.gsub(/-| /,'_').to_sym
|
177
|
-
|
140
|
+
# the name of the EA might have spaces and caps, which the will come to us as symbols with the spaces
|
141
|
+
# as underscores, like this.
|
142
|
+
@symbolized_name = @name.gsub(/-| /, '_').to_sym
|
178
143
|
end # init
|
179
144
|
|
180
|
-
#####################################
|
181
|
-
### Public Instance Methods
|
182
|
-
#####################################
|
183
145
|
|
184
|
-
|
185
|
-
|
186
|
-
|
146
|
+
# Public Instance Methods
|
147
|
+
###################################
|
148
|
+
|
149
|
+
|
150
|
+
# @see JSS::Creatable#create
|
151
|
+
#
|
187
152
|
def create
|
188
|
-
if @input_type ==
|
189
|
-
|
153
|
+
if @input_type == 'Pop-up Menu'
|
154
|
+
raise MissingDataError, 'No popup_choices set for Pop-up Menu input_type.' unless @popup_choices.is_a?(Array) && !@popup_choices.empty?
|
190
155
|
end
|
191
156
|
super
|
192
157
|
end
|
193
158
|
|
194
|
-
|
195
|
-
|
196
|
-
###
|
159
|
+
# @see JSS::Updatable#update
|
160
|
+
#
|
197
161
|
def update
|
198
|
-
if @input_type ==
|
199
|
-
|
162
|
+
if @input_type == 'Pop-up Menu'
|
163
|
+
raise MissingDataError, 'No popup_choices set for Pop-up Menu input_type.' unless @popup_choices.is_a?(Array) && !@popup_choices.empty?
|
200
164
|
end
|
201
165
|
super
|
202
166
|
end
|
203
167
|
|
204
|
-
|
205
|
-
|
206
|
-
### @see JSS::APIObject#delete
|
207
|
-
###
|
168
|
+
# @see JSS::APIObject#delete
|
169
|
+
#
|
208
170
|
def delete
|
209
171
|
orig_open_timeout = @api.cnx.options[:open_timeout]
|
210
172
|
orig_timeout = @api.cnx.options[:timeout]
|
@@ -218,178 +180,164 @@ module JSS
|
|
218
180
|
end
|
219
181
|
end
|
220
182
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
def description= (new_val)
|
183
|
+
# Change the description of this EA
|
184
|
+
#
|
185
|
+
# @param new_val[String] the new value
|
186
|
+
#
|
187
|
+
# @return [void]
|
188
|
+
#
|
189
|
+
def description=(new_val)
|
229
190
|
return nil if @description == new_val
|
230
191
|
@description = new_val
|
231
192
|
@need_to_update = true
|
232
193
|
end # name=(newname)
|
233
194
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
def data_type= (new_val)
|
195
|
+
# Change the data type of this EA
|
196
|
+
#
|
197
|
+
# @param new_val[String] the new value, which must be a member of DATA_TYPES
|
198
|
+
#
|
199
|
+
# @return [void]
|
200
|
+
#
|
201
|
+
def data_type=(new_val)
|
242
202
|
return nil if @data_type == new_val
|
243
|
-
raise JSS::InvalidDataError, "data_type must be a string, one of: #{DATA_TYPES.join(
|
203
|
+
raise JSS::InvalidDataError, "data_type must be a string, one of: #{DATA_TYPES.join(', ')}" unless DATA_TYPES.include? new_val
|
244
204
|
@data_type = new_val
|
245
205
|
@need_to_update = true
|
246
206
|
end #
|
247
207
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
###
|
256
|
-
def web_display= (new_val)
|
208
|
+
# Change the inventory_display of this EA
|
209
|
+
#
|
210
|
+
# @param new_val[String] the new value, which must be a member of INVENTORY_DISPLAY_CHOICES
|
211
|
+
#
|
212
|
+
# @return [void]
|
213
|
+
#
|
214
|
+
def web_display=(new_val)
|
257
215
|
return nil if @web_display == new_val
|
258
|
-
raise JSS::InvalidDataError, "inventory_display must be a string, one of: #{INVENTORY_DISPLAY_CHOICES.join(
|
216
|
+
raise JSS::InvalidDataError, "inventory_display must be a string, one of: #{INVENTORY_DISPLAY_CHOICES.join(', ')}" unless WEB_DISPLAY_CHOICES.include? new_val
|
259
217
|
@web_display = new_val
|
260
218
|
@need_to_update = true
|
261
219
|
end #
|
262
220
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
###
|
271
|
-
def input_type= (new_val)
|
221
|
+
# Change the input type of this EA
|
222
|
+
#
|
223
|
+
# @param new_val[String] the new value, which must be a member of INPUT_TYPES
|
224
|
+
#
|
225
|
+
# @return [void]
|
226
|
+
#
|
227
|
+
def input_type=(new_val)
|
272
228
|
return nil if @input_type == new_val
|
273
|
-
raise JSS::InvalidDataError, "input_type must be a string, one of: #{INPUT_TYPES.join(
|
229
|
+
raise JSS::InvalidDataError, "input_type must be a string, one of: #{INPUT_TYPES.join(', ')}" unless INPUT_TYPES.include? new_val
|
274
230
|
@input_type = new_val
|
275
|
-
@popup_choices = nil if @input_type ==
|
231
|
+
@popup_choices = nil if @input_type == 'Text Field'
|
276
232
|
@need_to_update = true
|
277
233
|
end #
|
278
234
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
def popup_choices= (new_val)
|
235
|
+
# Change the Popup Choices of this EA
|
236
|
+
# New value must be an Array, the items will be converted to Strings.
|
237
|
+
#
|
238
|
+
# This automatically sets input_type to "Pop-up Menu"
|
239
|
+
#
|
240
|
+
# Values are checked to ensure they match the @data_type
|
241
|
+
# Note, Dates must be in the format "YYYY-MM-DD hh:mm:ss"
|
242
|
+
#
|
243
|
+
# @param new_val[Array<#to_s>] the new values
|
244
|
+
#
|
245
|
+
# @return [void]
|
246
|
+
#
|
247
|
+
def popup_choices=(new_val)
|
293
248
|
return nil if @popup_choices == new_val
|
294
|
-
raise JSS::InvalidDataError,
|
249
|
+
raise JSS::InvalidDataError, 'popup_choices must be an Array' unless new_val.is_a?(Array)
|
295
250
|
|
296
|
-
|
297
|
-
|
251
|
+
# convert each one to a String,
|
252
|
+
# and check that it matches the @data_type
|
298
253
|
new_val.map! do |v|
|
299
254
|
v = v.to_s.strip
|
300
255
|
case @data_type
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
256
|
+
when 'Date'
|
257
|
+
raise JSS::InvalidDataError, "data_type is Date, but '#{v}' is not formatted 'YYYY-MM-DD hh:mm:ss'" unless v =~ /^\d{4}(-\d\d){2} (\d\d:){2}\d\d$/
|
258
|
+
when 'Integer'
|
259
|
+
raise JSS::InvalidDataError, "data_type is Integer, but '#{v}' is not one" unless v =~ /^\d+$/
|
305
260
|
end
|
306
261
|
v
|
307
262
|
end
|
308
|
-
self.input_type =
|
263
|
+
self.input_type = 'Pop-up Menu'
|
309
264
|
@popup_choices = new_val
|
310
265
|
@need_to_update = true
|
311
266
|
end #
|
312
267
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
### @return [Array<Hash{:id=>Integer,:name=>String,:value=>String,Integer,Time}>] the items that match the result.
|
334
|
-
###
|
268
|
+
# Get an Array of Hashes for all inventory objects
|
269
|
+
# with a desired result in their latest report for this EA.
|
270
|
+
#
|
271
|
+
# Each Hash is one inventory object (computer, mobile device, user), with these keys:
|
272
|
+
# :id - the computer id
|
273
|
+
# :name - the computer name
|
274
|
+
# :value - the matching ext attr value for the objects latest report.
|
275
|
+
#
|
276
|
+
# This is done by creating a temprary {AdvancedSearch} for objects with matching
|
277
|
+
# values in the EA field, then getting the #search_results hash from it.
|
278
|
+
#
|
279
|
+
# The AdvancedSearch is then deleted.
|
280
|
+
#
|
281
|
+
# @param search_type[String] how are we comparing the stored value with the desired value.
|
282
|
+
# must be a member of JSS::Criterion::SEARCH_TYPES
|
283
|
+
#
|
284
|
+
# @param desired_value[String] the value to compare with the stored value to determine a match.
|
285
|
+
#
|
286
|
+
# @return [Array<Hash{:id=>Integer,:name=>String,:value=>String,Integer,Time}>] the items that match the result.
|
287
|
+
#
|
335
288
|
def all_with_result(search_type, desired_value)
|
336
289
|
raise JSS::NoSuchItemError, "EA Not In JSS! Use #create to create this #{self.class::RSRC_OBJECT_KEY}." unless @in_jss
|
337
|
-
raise JSS::InvalidDataError,
|
290
|
+
raise JSS::InvalidDataError, 'Invalid search_type, see JSS::Criteriable::Criterion::SEARCH_TYPES' unless JSS::Criteriable::Criterion::SEARCH_TYPES.include? search_type.to_s
|
338
291
|
begin
|
339
|
-
|
340
292
|
search_class = self.class::TARGET_CLASS::SEARCH_CLASS
|
341
|
-
acs = search_class.new api: @api, :
|
293
|
+
acs = search_class.new api: @api, id: :new, name: "ruby-jss-EA-result-search-#{Time.now.to_jss_epoch}"
|
342
294
|
acs.display_fields = [@name]
|
343
|
-
crit_list = [JSS::Criteriable::Criterion.new(:
|
295
|
+
crit_list = [JSS::Criteriable::Criterion.new(and_or: 'and', name: @name, search_type: search_type.to_s, value: desired_value)]
|
344
296
|
acs.criteria = JSS::Criteriable::Criteria.new crit_list
|
345
297
|
|
346
298
|
acs.create :get_results
|
347
299
|
|
348
300
|
results = []
|
349
301
|
|
350
|
-
acs.search_results.each
|
302
|
+
acs.search_results.each do |i|
|
351
303
|
value = case @data_type
|
352
|
-
|
353
|
-
|
354
|
-
|
304
|
+
when 'Date' then JSS.parse_datetime i[@symbolized_name]
|
305
|
+
when 'Integer' then i[@symbolized_name].to_i
|
306
|
+
else i[@symbolized_name]
|
355
307
|
end # case
|
356
|
-
results << {:
|
357
|
-
|
358
|
-
|
308
|
+
results << { id: i[:id], name: i[:name], value: value }
|
309
|
+
end
|
359
310
|
ensure
|
360
311
|
acs.delete
|
361
312
|
end
|
362
313
|
results
|
363
|
-
end
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
###
|
391
|
-
### @see JSS::AdvancedUserSearch
|
392
|
-
###
|
314
|
+
end # Return an Array of Hashes showing the most recent value
|
315
|
+
|
316
|
+
# for this EA on all inventory objects in the JSS.
|
317
|
+
#
|
318
|
+
# Each Hash is one inventory object (computer, mobile device, user), with these keys:
|
319
|
+
# :id - the jss id
|
320
|
+
# :name - the object (computer, user, mobiledevice) name
|
321
|
+
# :value - the most recent ext attr value for the object.
|
322
|
+
# :as_of - the timestamp of when the value was collected (nil for User EAs)
|
323
|
+
# :username - the username associated with the object
|
324
|
+
#
|
325
|
+
# This is done by creating a temporary {AdvancedSearch}
|
326
|
+
# for all objects, with the EA as a display field. The #search_result
|
327
|
+
# then contains the desired data.
|
328
|
+
#
|
329
|
+
# The AdvancedSearch is then deleted.
|
330
|
+
#
|
331
|
+
# @return [Array<Hash{:id=>Integer,:name=>String,:value=>String,Integer,Time,:as_of=>Time}>]
|
332
|
+
#
|
333
|
+
# @see JSS::AdvancedSearch
|
334
|
+
#
|
335
|
+
# @see JSS::AdvancedComputerSearch
|
336
|
+
#
|
337
|
+
# @see JSS::AdvancedMobileDeviceSearch
|
338
|
+
#
|
339
|
+
# @see JSS::AdvancedUserSearch
|
340
|
+
#
|
393
341
|
def latest_values
|
394
342
|
raise JSS::NoSuchItemError, "EA Not In JSS! Use #create to create this #{self.class::RSRC_OBJECT_KEY}." unless @in_jss
|
395
343
|
tmp_advsrch = "ruby-jss-EA-latest-search-#{Time.now.to_jss_epoch}"
|
@@ -397,10 +345,10 @@ module JSS
|
|
397
345
|
begin
|
398
346
|
search_class = self.class::TARGET_CLASS::SEARCH_CLASS
|
399
347
|
acs = search_class.make name: tmp_advsrch, api: @api
|
400
|
-
acs.display_fields = self.class::TARGET_CLASS == JSS::User ?
|
348
|
+
acs.display_fields = self.class::TARGET_CLASS == JSS::User ? [@name, USERNAME_FIELD] : [@name, USERNAME_FIELD, LAST_RECON_FIELD]
|
401
349
|
|
402
350
|
# search for 'Username like "" ' because all searchable object classes have a "Username" value
|
403
|
-
crit =
|
351
|
+
crit = JSS::Criteriable::Criterion.new(and_or: 'and', name: 'Username', search_type: 'like', value: '')
|
404
352
|
# crit = self.class::ALL_TARGETS_CRITERION
|
405
353
|
acs.criteria = JSS::Criteriable::Criteria.new [crit]
|
406
354
|
acs.create :get_results
|
@@ -409,46 +357,40 @@ module JSS
|
|
409
357
|
|
410
358
|
acs.search_results.each do |i|
|
411
359
|
value = case @data_type
|
412
|
-
|
413
|
-
|
414
|
-
|
360
|
+
when 'Date' then JSS.parse_datetime i[@symbolized_name]
|
361
|
+
when 'Integer' then i[@symbolized_name].to_i
|
362
|
+
else i[@symbolized_name]
|
415
363
|
end # case
|
416
364
|
|
417
365
|
as_of = Time.parse(i[LAST_RECON_FIELD_SYM]) if i[LAST_RECON_FIELD_SYM]
|
418
366
|
|
419
|
-
results << {:
|
420
|
-
end #acs.search_results.each
|
421
|
-
|
367
|
+
results << { id: i[:id], name: i[:name], username: i[USERNAME_FIELD_SYM], value: value, as_of: as_of }
|
368
|
+
end # acs.search_results.each
|
422
369
|
ensure
|
423
370
|
if defined? acs
|
424
371
|
acs.delete if acs
|
425
372
|
else
|
426
|
-
search_class.fetch(:
|
373
|
+
search_class.fetch(name: tmp_advsrch, api: @api).delete if search_class.all_names(:refresh, api: @api).include? tmp_advsrch
|
427
374
|
end
|
428
375
|
end
|
429
376
|
|
430
377
|
results
|
431
|
-
|
432
378
|
end
|
433
379
|
|
434
|
-
|
435
|
-
### aliases
|
380
|
+
# aliases
|
436
381
|
|
437
382
|
alias desc description
|
438
383
|
|
439
|
-
|
440
|
-
|
441
|
-
######################
|
442
|
-
### Private Instance Methods
|
443
|
-
#####################
|
384
|
+
# Private Instance Methods
|
385
|
+
###################
|
444
386
|
|
445
387
|
private
|
446
388
|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
389
|
+
#
|
390
|
+
# Return a REXML object for this ext attr, with the current values.
|
391
|
+
# Subclasses should augment this in their rest_xml methods
|
392
|
+
# then return it .to_s, for saving or updating
|
393
|
+
#
|
452
394
|
def rest_rexml
|
453
395
|
ea = REXML::Element.new self.class::RSRC_OBJECT_KEY.to_s
|
454
396
|
ea.add_element('name').text = @name
|
@@ -458,18 +400,17 @@ module JSS
|
|
458
400
|
|
459
401
|
it = ea.add_element('input_type')
|
460
402
|
it.add_element('type').text = @input_type
|
461
|
-
if @input_type ==
|
403
|
+
if @input_type == 'Pop-up Menu'
|
462
404
|
pcs = it.add_element('popup_choices')
|
463
|
-
@popup_choices.each{|pc| pcs.add_element('choice').text = pc}
|
405
|
+
@popup_choices.each { |pc| pcs.add_element('choice').text = pc }
|
464
406
|
end
|
465
|
-
|
407
|
+
ea
|
466
408
|
end # rest xml
|
467
409
|
|
468
|
-
|
469
410
|
end # class ExtAttrib
|
470
411
|
|
471
412
|
end # module JSS
|
472
413
|
|
473
|
-
require
|
474
|
-
require
|
475
|
-
require
|
414
|
+
require 'jss/api_object/extension_attribute/computer_extension_attribute'
|
415
|
+
require 'jss/api_object/extension_attribute/mobile_device_extension_attribute'
|
416
|
+
require 'jss/api_object/extension_attribute/user_extension_attribute'
|