ruby-jss 1.2.0 → 1.2.2

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.

@@ -1,302 +1,229 @@
1
- ### Copyright 2019 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
-
30
-
31
- #####################################
32
- ### Constants
33
- #####################################
34
-
35
- #####################################
36
- ### Module Variables
37
- #####################################
1
+ # Copyright 2019 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.
38
23
 
39
- #####################################
40
- ### Module Methods
41
- #####################################
24
+ module JSS
42
25
 
43
- ####################################
44
- ### Classes
26
+ # Classes
45
27
  #####################################
46
28
 
47
-
48
- ###
49
- ### The definition of a Computer extension attribute in the JSS
50
- ###
51
- ### @see JSS::ExtensionAttribute
52
- ###
53
- ### @see JSS::APIObject
54
- ###
29
+ # The definition of a Computer extension attribute in the JSS
30
+ #
31
+ # @see JSS::ExtensionAttribute
32
+ #
33
+ # @see JSS::APIObject
34
+ #
55
35
  class ComputerExtensionAttribute < JSS::ExtensionAttribute
56
36
 
57
- #####################################
58
- ### Mix-Ins
59
- #####################################
60
-
61
- #####################################
62
- ### Class Methods
63
- #####################################
64
-
65
- #####################################
66
- ### Class Constants
37
+ # Class Constants
67
38
  #####################################
68
39
 
69
- ### The base for REST resources of this class
70
- RSRC_BASE = "computerextensionattributes"
40
+ # The base for REST resources of this class
41
+ RSRC_BASE = 'computerextensionattributes'.freeze
71
42
 
72
- ### the hash key used for the JSON list output of all objects in the JSS
43
+ # the hash key used for the JSON list output of all objects in the JSS
73
44
  RSRC_LIST_KEY = :computer_extension_attributes
74
45
 
75
- ### The hash key used for the JSON object output.
76
- ### It's also used in various error messages
46
+ # The hash key used for the JSON object output.
47
+ # It's also used in various error messages
77
48
  RSRC_OBJECT_KEY = :computer_extension_attribute
78
49
 
79
- ### these ext attribs are related to these kinds of objects
50
+ # these ext attribs are related to these kinds of objects
80
51
  TARGET_CLASS = JSS::Computer
81
52
 
82
- ### A criterion that will return all members of the TARGET_CLASS
83
- ALL_TARGETS_CRITERION = JSS::Criteriable::Criterion.new(:and_or => "and", :name => "Username", :search_type => "like", :value => '')
53
+ # A criterion that will return all members of the TARGET_CLASS
54
+ ALL_TARGETS_CRITERION = JSS::Criteriable::Criterion.new(and_or: 'and', name: 'Username', search_type: 'like', value: '')
84
55
 
85
- ### When the intput type is script, what platforms can they run on?
86
- PLATFORMS = ["Mac","Windows"]
56
+ # When the intput type is script, what platforms can they run on?
57
+ PLATFORM_MAC = 'Mac'.freeze
58
+ PLATFORM_WINDOWS = 'Windows'.freeze
59
+ PLATFORMS = [PLATFORM_MAC, PLATFORM_WINDOWS].freeze
87
60
 
88
- ### When the platform is Windows, what languages can be user?
89
- WINDOWS_SCRIPTING_LANGUAGES = ["VBScript", "Batch File", "PowerShell"]
61
+ # When the platform is Windows, what languages can be user?
62
+ LANGUAGE_VBS = 'VBScript'.freeze
63
+ LANGUAGE_BAT = 'Batch File'.freeze
64
+ LANGUAGE_PSH = 'PowerShell'.freeze
65
+ WINDOWS_SCRIPTING_LANGUAGES = [LANGUAGE_VBS, LANGUAGE_BAT, LANGUAGE_PSH].freeze
90
66
 
91
- ### Where can it be displayed in the Recon App?
67
+ # Where can it be displayed in the Recon App?
92
68
  RECON_DISPLAY_CHOICES = [
93
- "Computer",
94
- "User and Location",
95
- "Purchasing",
96
- "Extension Attributes"
97
- ]
69
+ 'Computer',
70
+ 'User and Location',
71
+ 'Purchasing',
72
+ 'Extension Attributes'
73
+ ].freeze
98
74
 
99
- DEFAULT_RECON_DISPLAY_CHOICE = "Extension Attributes"
75
+ DEFAULT_RECON_DISPLAY_CHOICE = 'Extension Attributes'.freeze
100
76
 
101
77
  # the object type for this object in
102
78
  # the object history table.
103
79
  # See {APIObject#add_object_history_entry}
104
80
  OBJECT_HISTORY_OBJECT_TYPE = 73
105
81
 
106
- ######################
107
- ### Attributes
82
+ # Attributes
108
83
  ######################
109
84
 
110
- ### When the @input_type is "script", The platform on which a script will run.
111
- ###
112
- ### NOTE: The web app seems to let you have both Mac and Windows
113
- ### scripts defined when the type is "script",
114
- ### however the API will only return the Mac script info if both are defined.
115
- ###
116
- ### @return [String]
117
- attr_reader :platform
118
-
119
- ### @return [String] the script code that will be executed when the @input_type is "script",
85
+ # @return [String] the script code that will be executed when the @input_type is "script",
120
86
  attr_reader :script
87
+ alias code script
121
88
 
89
+ # @return [Boolean] if the input type is 'script', is this EA enabled?
90
+ attr_reader :enabled
91
+ alias enabled? enabled
92
+
93
+ # When the @input_type is "script", The platform on which a script will run.
94
+ #
95
+ # NOTE: The web app seems to let you have both Mac and Windows
96
+ # scripts defined when the type is "script",
97
+ # however the API will only return the Mac script info if both are defined.
98
+ # DEPRECATED: windows EAs are no longer supported
99
+ #
100
+ # @return [String]
101
+ attr_reader :platform
122
102
 
123
- ### The scripting language of the @script when @input_type is "script",
124
- ### and the @platform is "Windows"
125
- ###
126
- ### @return [String]
103
+ # The scripting language of the @script when @input_type is "script",
104
+ # and the @platform is "Windows"
105
+ #
106
+ # DEPRECATED: windows EAs are no longer supported
107
+ # @return [String]
127
108
  attr_reader :scripting_language
128
109
 
129
- ### @return [String] In which part of the Recon App does the data appear?
110
+ # DEPRECATED: this is no longer separate from the web_display.
111
+ # @return [String] In which part of the Recon App does the data appear?
130
112
  attr_reader :recon_display
131
113
 
132
- #####################################
133
- ### Constructor
114
+ # Public Instance Methods
134
115
  #####################################
135
116
 
136
- ###
137
- ### @see JSS::APIObject#initialize
138
- ###
139
- def initialize(args = {})
117
+ # Change the recon_display of this EA
118
+ # DEPRECATED, no longer separate from web_display in jamf pro.
119
+ #
120
+ def recon_display=(new_val)
121
+ return if @recon_display == new_val
122
+ raise JSS::InvalidDataError, "recon_display must be a string, one of: #{RECON_DISPLAY_CHOICES.join(', ')}" unless RECON_DISPLAY_CHOICES.include? new_val
140
123
 
141
- super args
142
-
143
- @recon_display = @init_data[:recon_display] || DEFAULT_RECON_DISPLAY_CHOICE
124
+ @recon_display = new_val
125
+ @need_to_update = true
126
+ end
144
127
 
145
- if @init_data[:input_type]
146
- @platform = @init_data[:input_type][:platform]
147
- @script = @init_data[:input_type][:script]
148
- @scripting_language = @init_data[:input_type][:scripting_language]
149
- end
150
- end # init
128
+ # enable this script ea
129
+ #
130
+ # @return [void]
131
+ #
132
+ def enable
133
+ return if enabled?
151
134
 
135
+ @enabled = true
136
+ @need_to_update = true
137
+ end
152
138
 
153
- #####################################
154
- ### Public Instance Methods
155
- #####################################
139
+ # disable this script ea
140
+ #
141
+ # @return [void]
142
+ #
143
+ def disable
144
+ return unless enabled?
156
145
 
157
- ###
158
- ### @see JSS::Creatable#create
159
- ###
160
- ### @return [Integer] the JSS id of the newly created object
161
- ###
162
- def create
163
- if @input_type == "script"
164
- raise MissingDataError, "No platform set for script input_type." unless @platform
165
- raise MissingDataError, "No script set for script input_type." unless @script
166
- if @platform == "Windows"
167
- raise MissingDataError, "No scripting_language set for Windows script input_type." unless @scripting_language
168
- end
169
- end # case
170
-
171
- super
146
+ @enabled = false
147
+ @need_to_update = true
172
148
  end
173
149
 
174
- ###
175
- ### Change the recon_display of this EA
176
- ###
177
- def recon_display= (new_val)
178
- return nil if @recon_display == new_val
179
- raise JSS::InvalidDataError, "recon_display must be a string, one of: #{RECON_DISPLAY_CHOICES.join(", ")}" unless RECON_DISPLAY_CHOICES.include? new_val
180
- @recon_display = new_val
181
- @need_to_update = true
182
- end #
183
-
184
-
185
- ###
186
- ### Change the input type of this EA
187
- ###
188
- ### @see JSS::ExtensionAttribute#input_type=
189
- ###
190
- ### @return [void]
191
- ###
192
- def input_type= (new_val)
193
- raise JSS::InvalidDataError, "ComputerExtensionAttribute input_types cannot be 'LDAP Attribute Mapping'" if new_val == 'LDAP Attribute Mapping'
194
-
195
- super
196
-
197
- case @input_type
198
- when *["Text Field","Pop-up Menu"]
199
- @script = nil
200
- @scripting_language = nil
201
- @platform = nil
202
- when "script"
203
- @popup_choices = nil
204
- end # case
205
- end #
206
-
207
- ###
208
- ### This unsets any script-related attributes
209
- ###
210
- ### @param (see JSS::ExtensionAttribute#popup_choices=)
211
- ###
212
- ### @return [void]
213
- ###
214
- def popup_choices= (new_val)
215
- super
216
- @script = nil
217
- @scripting_language = nil
218
- @platform = nil
219
- end #
220
-
221
- ###
222
- ### Change the platform of this EA.
223
- ### Setting this automatically sets input_type to script
224
- ###
225
- ### @param new_val[String] the new value, which must be a member of PLATFORMS
226
- ###
227
- ### @return [void]
228
- ###
229
- def platform= (new_val)
230
- return nil if @platform == new_val
231
- raise JSS::InvalidDataError, "platform must be a string, one of: #{PLATFORMS.join(", ")}" unless PLATFORMS.include? new_val
232
- self.input_type = "script"
233
- @platform = new_val
234
- @need_to_update = true
235
- end #
236
-
237
- ###
238
- ### Change the script of this EA.
239
- ### Setting this automatically sets input_type to script
240
- ###
241
- ### @param new_val[String] the new value
242
- ###
243
- ### @return [void]
244
- ###
245
- def script= (new_val)
246
- return nil if @script == new_val
247
- self.input_type = "script"
150
+ # Change the script of this EA.
151
+ # Setting this automatically sets input_type to script
152
+ #
153
+ # @param new_val[String] the new value
154
+ #
155
+ # @return [void]
156
+ #
157
+ def script=(new_val)
158
+ return if @script == new_val
159
+
160
+ JSS::Validate.non_empty_string new_val
161
+
162
+ self.input_type = INPUT_TYPE_SCRIPT
248
163
  @script = new_val
249
164
  @need_to_update = true
250
- end #
251
-
252
-
253
- ###
254
- ### Change the scripting_language of this EA.
255
- ### Setting this automatically sets input_type to 'script'
256
- ### and the platform to "Windows"
257
- ###
258
- ### @param new_val[String] the new value, which must be one of {WINDOWS_SCRIPTING_LANGUAGES}
259
- ###
260
- ### @return [void]
261
- ###
262
- def scripting_language= (new_val)
263
- return nil if @scripting_language == new_val
264
- raise JSS::InvalidDataError, "Scripting language must be a string, one of: #{WINDOWS_SCRIPTING_LANGUAGES.join(", ")}" unless WINDOWS_SCRIPTING_LANGUAGES.include? new_val
265
- self.input_type = "script"
266
- self.platform = "Windows"
267
- @scripting_language = new_val
268
- @need_to_update = true
269
- end #
165
+ end
166
+ alias code= script=
270
167
 
168
+ # DEPRECATED: windows EAs are no longer supported
169
+ #
170
+ # Change the platform of this EA.
171
+ # Setting this automatically sets input_type to script
172
+ #
173
+ # @param new_val[String] the new value, which must be a member of PLATFORMS
174
+ #
175
+ # @return [void]
176
+ #
177
+ def platform=(new_val)
178
+ return if @platform == new_val
179
+ raise JSS::InvalidDataError, "platform must be a string, one of: #{PLATFORMS.join(', ')}" unless PLATFORMS.include? new_val
180
+
181
+ self.input_type = INPUT_TYPE_SCRIPT
182
+ @platform = new_val
183
+ @need_to_update = true
184
+ end
271
185
 
186
+ # Change the scripting_language of this EA.
187
+ # Setting this automatically sets input_type to 'script'
188
+ # and the platform to "Windows"
189
+ #
190
+ # DEPRECATED: windows EAs are no longer supported
191
+ #
192
+ # @param new_val[String] the new value, which must be one of {WINDOWS_SCRIPTING_LANGUAGES}
193
+ #
194
+ # @return [void]
195
+ #
196
+ def scripting_language=(new_val)
197
+ return if @scripting_language == new_val
198
+ unless WINDOWS_SCRIPTING_LANGUAGES.include? new_val
199
+ raise JSS::InvalidDataError, "Scripting language must be a string, one of: #{WINDOWS_SCRIPTING_LANGUAGES.join(', ')}"
200
+ end
272
201
 
202
+ self.input_type = INPUT_TYPE_SCRIPT
203
+ self.platform = 'Windows'
204
+ @scripting_language = new_val
205
+ @need_to_update = true
206
+ end
273
207
 
274
- ### Return an Array of Hashes showing the history of reported values for this EA on one computer.
275
- ###
276
- ### Each hash contains these 2 keys:
277
- ### * :value - String, Integer, or Time, depending on @data_type
278
- ### * :timestamp - Time
279
- ###
280
- ### This method requires a MySQL database connection established via JSS::DB_CNX.connect
281
- ###
282
- ### @see JSS::DBConnection
283
- ###
284
- ### @param computer[Integer,String] the id or name of the Computer.
285
- ###
286
- ### @return [Array<Hash{:timestamp=>Time,:value=>String,Integer,Time}>]
287
- ###
208
+ # Return an Array of Hashes showing the history of reported values for this EA on one computer.
209
+ #
210
+ # Each hash contains these 2 keys:
211
+ # * :value - String, Integer, or Time, depending on @data_type
212
+ # * :timestamp - Time
213
+ #
214
+ # This method requires a MySQL database connection established via JSS::DB_CNX.connect
215
+ #
216
+ # @see JSS::DBConnection
217
+ #
218
+ # @param computer[Integer,String] the id or name of the Computer.
219
+ #
220
+ # @return [Array<Hash{:timestamp=>Time,:value=>String,Integer,Time}>]
221
+ #
288
222
  def history(computer)
289
223
  raise JSS::NoSuchItemError, "EA Not In JSS! Use #create to create this #{RSRC_OBJECT_KEY}." unless @in_jss
290
224
  raise JSS::InvalidConnectionError, "Database connection required for 'history' query." unless JSS::DB_CNX.connected?
291
225
 
292
- computer_id = case computer
293
- when *JSS::Computer.all_ids(api: @api)
294
- computer
295
- when *JSS::Computer.all_names(api: @api)
296
- JSS::Computer.map_all_ids_to(:name, api: @api).invert[computer]
297
- else nil
298
- end # case
299
-
226
+ computer_id = JSS::Computer.valid_id computer, api: @api
300
227
  raise JSS::NoSuchItemError, "No computer found matching '#{computer}'" unless computer_id
301
228
 
302
229
  the_query = <<-END_Q
@@ -311,52 +238,19 @@ module JSS
311
238
  history = []
312
239
 
313
240
  qrez.each_hash do |entry|
314
- value = case @data_type
241
+ value =
242
+ case @data_type
315
243
  when 'String' then entry['value']
316
244
  when 'Integer' then entry['value'].to_i
317
245
  when 'Date' then JSS.parse_datetime(entry['value'])
318
- end # case
319
- newhash = {:value => value, :timestamp => JSS.epoch_to_time(entry['timestamp_epoch']) }
246
+ end # case
247
+ newhash = { value: value, timestamp: JSS.epoch_to_time(entry['timestamp_epoch']) }
320
248
  history << newhash
321
249
  end # each hash
322
250
 
323
251
  history
324
252
  end # history
325
253
 
326
-
327
- ### Aliases here, since YARD seems to have issues with them above
328
- alias code script
329
- alias code= script=
330
-
331
- ######################
332
- ### Private Instance Methods
333
- #####################
334
-
335
- private
336
-
337
- ###
338
- ### Return the REST XML for this pkg, with the current values,
339
- ### for saving or updating
340
- ###
341
- def rest_xml
342
-
343
- cea = rest_rexml # See parent class
344
- cea.add_element('recon_display').text = @recon_display
345
-
346
- if @input_type == 'script'
347
- it = cea.elements["input_type"]
348
- it.add_element('script').text = @script
349
- it.add_element('platform').text = @platform
350
- it.add_element('scripting_language').text = @scripting_language if @scripting_language
351
- end
352
-
353
- doc = REXML::Document.new APIConnection::XML_HEADER
354
- doc << cea
355
-
356
- return doc.to_s
357
- end # rest xml
358
-
359
254
  end # class ExtAttrib
360
255
 
361
-
362
256
  end # module