chook 1.0.0.b1

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.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +174 -0
  3. data/README.md +259 -0
  4. data/bin/chook-server +28 -0
  5. data/data/sample_handlers/RestAPIOperation-executable +91 -0
  6. data/data/sample_handlers/RestAPIOperation.rb +45 -0
  7. data/data/sample_handlers/SmartGroupComputerMembershipChange-executable +47 -0
  8. data/data/sample_handlers/SmartGroupComputerMembershipChange.rb +33 -0
  9. data/data/sample_jsons/ComputerAdded.json +27 -0
  10. data/data/sample_jsons/ComputerCheckIn.json +27 -0
  11. data/data/sample_jsons/ComputerInventoryCompleted.json +27 -0
  12. data/data/sample_jsons/ComputerPolicyFinished.json +27 -0
  13. data/data/sample_jsons/ComputerPushCapabilityChanged.json +27 -0
  14. data/data/sample_jsons/JSSShutdown.json +14 -0
  15. data/data/sample_jsons/JSSStartup.json +14 -0
  16. data/data/sample_jsons/MobileDeviceCheckIn.json +26 -0
  17. data/data/sample_jsons/MobileDeviceCommandCompleted.json +26 -0
  18. data/data/sample_jsons/MobileDeviceEnrolled.json +26 -0
  19. data/data/sample_jsons/MobileDevicePushSent.json +26 -0
  20. data/data/sample_jsons/MobileDeviceUnEnrolled.json +26 -0
  21. data/data/sample_jsons/PatchSoftwareTitleUpdated.json +14 -0
  22. data/data/sample_jsons/PushSent.json +11 -0
  23. data/data/sample_jsons/README +4 -0
  24. data/data/sample_jsons/RestAPIOperation.json +15 -0
  25. data/data/sample_jsons/SCEPChallenge.json +10 -0
  26. data/data/sample_jsons/SmartGroupComputerMembershipChange.json +13 -0
  27. data/data/sample_jsons/SmartGroupMobileDeviceMembershipChange.json +13 -0
  28. data/lib/chook.rb +38 -0
  29. data/lib/chook/configuration.rb +198 -0
  30. data/lib/chook/event.rb +153 -0
  31. data/lib/chook/event/handled_event.rb +154 -0
  32. data/lib/chook/event/handled_event/handlers.rb +206 -0
  33. data/lib/chook/event/test_event.rb +140 -0
  34. data/lib/chook/event_handling.rb +40 -0
  35. data/lib/chook/event_testing.rb +43 -0
  36. data/lib/chook/foundation.rb +33 -0
  37. data/lib/chook/handled_events.rb +33 -0
  38. data/lib/chook/handled_subjects.rb +33 -0
  39. data/lib/chook/procs.rb +46 -0
  40. data/lib/chook/server.rb +121 -0
  41. data/lib/chook/server/routes.rb +27 -0
  42. data/lib/chook/server/routes/handle_webhook_event.rb +39 -0
  43. data/lib/chook/server/routes/home.rb +37 -0
  44. data/lib/chook/subject.rb +143 -0
  45. data/lib/chook/subject/computer.rb +121 -0
  46. data/lib/chook/subject/handled_subject.rb +84 -0
  47. data/lib/chook/subject/jss.rb +56 -0
  48. data/lib/chook/subject/mobile_device.rb +115 -0
  49. data/lib/chook/subject/patch_software_title_update.rb +55 -0
  50. data/lib/chook/subject/push.rb +38 -0
  51. data/lib/chook/subject/randomizers.rb +506 -0
  52. data/lib/chook/subject/rest_api_operation.rb +62 -0
  53. data/lib/chook/subject/samplers.rb +360 -0
  54. data/lib/chook/subject/scep_challenge.rb +32 -0
  55. data/lib/chook/subject/smart_group.rb +50 -0
  56. data/lib/chook/subject/test_subject.rb +195 -0
  57. data/lib/chook/subject/validators.rb +117 -0
  58. data/lib/chook/test_events.rb +33 -0
  59. data/lib/chook/test_subjects.rb +33 -0
  60. data/lib/chook/version.rb +32 -0
  61. metadata +129 -0
@@ -0,0 +1,62 @@
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
+ Chook::Subject.classes[Chook::Subject::REST_API_OPERATION] = {
26
+ operationSuccessful: {
27
+ validation: :boolean,
28
+ randomizer: :bool
29
+ # sampler: ,
30
+ # api_object_attribute: :operationSuccessful
31
+ },
32
+ objectID: {
33
+ validation: Integer,
34
+ randomizer: :int,
35
+ # sampler: ,
36
+ # api_object_attribute: :objectID
37
+ },
38
+ objectName: { # This can be "" if the object doesn't have a name attribute.
39
+ validation: String,
40
+ randomizer: :word,
41
+ # sampler: ,
42
+ # api_object_attribute: :objectName
43
+ },
44
+ objectTypeName: {
45
+ validation: String,
46
+ randomizer: :word,
47
+ # sampler: ,
48
+ # api_object_attribute: :objectTypeName
49
+ },
50
+ authorizedUsername: {
51
+ validation: String,
52
+ randomizer: :word,
53
+ # sampler: :username,
54
+ # api_object_attribute: :authorizedUsername
55
+ },
56
+ restAPIOperationType: {
57
+ validation: String,
58
+ randomizer: :rest_operation,
59
+ # sampler: ,
60
+ # api_object_attribute: :restAPIOperationType
61
+ }
62
+ }
@@ -0,0 +1,360 @@
1
+ require 'jss'
2
+
3
+ module Chook
4
+
5
+ # A namespace for holding Constants and methods for
6
+ # pulling sample data from a JSS for use with Test events and test subjects
7
+ module Samplers
8
+
9
+ # Institution Sampler
10
+ #
11
+ # @param [JSS::APIConnection] API Connection object
12
+ # @return [String] The name of the JSS's Organization Name
13
+ #
14
+ def self.institution(api: JSS.api)
15
+ api.get_rsrc('activationcode')[:activation_code][:organization_name]
16
+ end # end institution
17
+
18
+ # Serial Number
19
+ #
20
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
21
+ # @return [Type] Sampled Computer or Mobile Device Serial Number
22
+ #
23
+ def self.serial_number(device_object)
24
+ device_object.serial_number
25
+ end # end serial_number
26
+
27
+ # MAC Address Sampler
28
+ #
29
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
30
+ # @return [String] A MAC Address sampled from a MobileDevice or Computer in the JSS
31
+ #
32
+ def self.mac_address(device_object)
33
+ if device_object.is_a? JSS::Computer
34
+ device_object.mac_address
35
+ else
36
+ device_object.wifi_mac_address
37
+ end
38
+ end # end mac_address
39
+
40
+ # UDID Sampler
41
+ #
42
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
43
+ # @return [String] A UDID sampled from a MobileDevice or Computer in the JSS
44
+ #
45
+ def self.udid(device_object)
46
+ if device_object.is_a? JSS::Computer
47
+ device_object.udid
48
+ else
49
+ device_object.uuid
50
+ end
51
+ end # end udid
52
+
53
+ # IMEI Sampler
54
+ #
55
+ # @param [JSS:MobileDevice] device_object JSS Mobile Device Object
56
+ # @return [String] An IMEI sampled from a MobileDevice in the JSS
57
+ #
58
+ def self.imei(mobile_device_object)
59
+ mobile_device_object.network[:imei]
60
+ end # end imei
61
+
62
+ # ICCID Sampler
63
+ #
64
+ # @param [JSS:MobileDevice] device_object JSS Mobile Device Object
65
+ # @return [String] An ICCID sampled from a MobileDevice in the JSS
66
+ #
67
+ def self.iccid(mobile_device_object)
68
+ mobile_device_object.network[:iccid]
69
+ end # end iccid
70
+
71
+ # Version
72
+ #
73
+ # @param [JSS::APIConnection] API Connection object
74
+ # @return [String] Carrier Version String
75
+ #
76
+ def self.version(mobile_device_object)
77
+ mobile_device_object.network[:carrier_settings_version]
78
+ end # end version
79
+
80
+ # Product
81
+ # is always nil in the sample JSONs... And there isn't anything labeled "product" in api.get_rsrc("mobiledevices/id/#{id}")
82
+ #
83
+ # @return [NilClass] nil
84
+ #
85
+ def self.product
86
+ nil
87
+ end # end product
88
+
89
+ # Model Display
90
+ # @param [JSS:MobileDevice] device_object JSS Mobile Device Object
91
+ # @return [String] Mobile Device Model String
92
+ #
93
+ def self.model_display(mobile_device_object)
94
+ mobile_device_object.model_display
95
+ end # end model_display
96
+
97
+ # JSS ID Sampler
98
+ #
99
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
100
+ # @return [Integer] A JSS ID sampled from a MobileDevice or Computer in the JSS
101
+ #
102
+ def self.jssid(device_object)
103
+ device_object.id
104
+ end # end jssid
105
+
106
+ # OS Build Sampler
107
+ #
108
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
109
+ # @return [String] Operating System Build from a MobileDevice or Computer in the JSS
110
+ #
111
+ def self.os_build(device_object)
112
+ if device_object.is_a? JSS::Computer
113
+ device_object.hardware[:os_build]
114
+ else
115
+ device_object.os_build
116
+ end
117
+ end # end os_build
118
+
119
+ # OS Version Sampler
120
+ #
121
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
122
+ # @return [String] Operating System Version from a MobileDevice or Computer in the JSS
123
+ #
124
+ def self.os_version(device_object)
125
+ if device_object.is_a? JSS::Computer
126
+ device_object.hardware[:os_version]
127
+ else
128
+ device_object.os_version
129
+ end
130
+ end # end os_version
131
+
132
+ # Device Name Sampler
133
+ #
134
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
135
+ # @return [String] A name sampled from a MobileDevice or Computer in the JSS
136
+ #
137
+ def self.device_name(device_object)
138
+ device_object.name
139
+ end # end device_name
140
+
141
+ # Model Sampler
142
+ #
143
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
144
+ # @return [String] A model sampled from a MobileDevice or Computer in the JSS
145
+ #
146
+ def self.model(device_object)
147
+ if device_object.is_a? JSS::Computer
148
+ device_object.hardware[:model]
149
+ else
150
+ device_object.model
151
+ end
152
+ end # end model
153
+
154
+ # Username Sampler
155
+ #
156
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
157
+ # @return [String] A username sampled from a MobileDevice or Computer in the JSS
158
+ #
159
+ def self.username(device_object)
160
+ device_object.username
161
+ end # end username
162
+
163
+ # User Directory ID Sampler
164
+ #
165
+ # @param [JSS::Computer] computer_object JSS Computer Object
166
+ # @return [Integer] A randomly sampled uid from a Computer in the JSS
167
+ #
168
+ def self.user_directory_id(computer_object)
169
+ an_account = computer_object.groups_accounts[:local_accounts].sample
170
+ return '-1' if an_account.empty?
171
+ an_account[:uid]
172
+ end # end user_directory_id
173
+
174
+ # Real Name Sampler
175
+ #
176
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
177
+ # @return [String] A real name from a Computer or MobileDevice in the JSS
178
+ #
179
+ def self.real_name(device_object)
180
+ device_object.real_name
181
+ end # end real_name
182
+
183
+ # Email Address Sampler
184
+ #
185
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
186
+ # @return [String] An email address from a Computer or MobileDevice in the JSS
187
+ #
188
+ def self.email_address(device_object)
189
+ device_object.email_address
190
+ end # end email_address
191
+
192
+ # Phone Sampler
193
+ #
194
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
195
+ # @return [String] A phone number from a Computer or MobileDevice in the JSS
196
+ #
197
+ def self.phone(device_object)
198
+ device_object.phone
199
+ end # end phone
200
+
201
+ # Position Sampler
202
+ #
203
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
204
+ # @return [String] A position from a Computer or MobileDevice in the JSS
205
+ #
206
+ def self.position(device_object)
207
+ device_object.position
208
+ end # end position
209
+
210
+ # Department Sampler
211
+ #
212
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
213
+ # @return [String] A department from a Computer or MobileDevice in the JSS
214
+ #
215
+ def self.department(device_object)
216
+ device_object.department
217
+ end # end department
218
+
219
+ # Building Sampler
220
+ #
221
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
222
+ # @return [String] A building from a Computer or MobileDevice in the JSS
223
+ #
224
+ def self.building(device_object)
225
+ if device_object.is_a? JSS::Computer
226
+ device_object.building
227
+ else
228
+ device_object.location[:building]
229
+ end
230
+ end # end building
231
+
232
+ # Room Sampler
233
+ #
234
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
235
+ # @return [String] A room from a Computer or MobileDevice in the JSS
236
+ #
237
+ def self.room(device_object)
238
+ device_object.room
239
+ end # end room
240
+
241
+ #### SmartGroup
242
+
243
+ # Smart Group Sampler
244
+ #
245
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
246
+ # @return [String] A Smart Group name from the JSS
247
+ #
248
+ # def self.smart_group(device_object)
249
+ # if device_object.is_a? JSS::Computer
250
+ # device_object.smart_groups[:smart_groups].sample[:name]
251
+ # elsif device_object.is_a? JSS::MobileDevice
252
+ # device_object.mobile_device_groups.sample[:name]
253
+ # else
254
+ # ''
255
+ # end # if device_object.is_a? JSS::Computer
256
+ # end # end smart_group
257
+
258
+ # Smart Group ID Sampler
259
+ #
260
+ # @param [JSS:MobileDevice or JSS::Computer] device_object JSS Mobile Device or Computer Object
261
+ # @return [Integer] The ID # of a MobileDevice or Computer Smart Group from JSS
262
+ #
263
+ # def self.smart_group_jssid(device_object)
264
+ # if device_object.is_a? JSS::Computer
265
+ # device_object.smart_groups[:smart_groups].sample[:id]
266
+ # elsif device_object.is_a? JSS::MobileDevice
267
+ # device_object.mobile_device_groups.sample[:id]
268
+ # else
269
+ # 0
270
+ # end # if device_object.is_a? JSS::Computer
271
+ # end # end group_jssid
272
+
273
+ def self.smart_group_type(device_object)
274
+ if device_object.is_a? JSS::Computer
275
+ true
276
+ elsif device_object.is_a? JSS::MobileDevice
277
+ false
278
+ end # if device_object.is_a? JSS::Computer
279
+ end
280
+
281
+ # Any Smart Group ID (wrapper)
282
+ #
283
+ # @return [Integer] The ID # of a MobileDevice or Computer Smart Group from JSS
284
+ #
285
+ # def self.any_smart_group_jssid
286
+ # [computer_smart_group_jssid, mobile_smart_group_jssid].sample
287
+ # end # end any_smart_group_id
288
+
289
+ #### PatchSoftwareTitleUpdated
290
+
291
+ # Patch ID Sampler
292
+ #
293
+ # @param [JSS::APIConnection] API Connection object
294
+ # @return [Integer] An enabled Patch Reporting Software ID from the JSS
295
+ #
296
+ def self.patch_id(_patch_hash, api: JSS.api)
297
+ all_patch_ids(api).sample.to_i
298
+ end # end patch_id
299
+
300
+ # All Patch IDs
301
+ #
302
+ # @param [JSS::APIConnection] API Connection object
303
+ # @return [Array<Integer>] An Array of enabled Patch Reporting Software IDs from the JSS
304
+ #
305
+ def self.all_patch_ids(_patch_hash, api: JSS.api)
306
+ all_patches = api.get_rsrc('patches')[:patch_reporting_software_titles]
307
+ all_ids = []
308
+ all_patches.each { |patch| all_ids << patch[:id] }
309
+ raise 'No Patch Reporting Software Titles found' if all_ids.empty?
310
+ all_ids
311
+ end # end all_patch_ids
312
+
313
+ # Patch Last Update Sampler
314
+ #
315
+ # @return [Time] A Time for a Patch, since they can't be sampled via the API.
316
+ #
317
+ def self.patch_last_update(_patch_hash)
318
+ Time.now
319
+ end # end patch_last_update
320
+
321
+ # Patch Report URL
322
+ #
323
+ # @param [JSS::APIConnection] API Connection object
324
+ # @return [String] description of returned object
325
+ #
326
+ def self.patch_report_url(_patch_hash, api: JSS.api)
327
+ api.rest_url.chomp('/JSSResource')
328
+ end # end patch_report_url
329
+
330
+ # All Patches
331
+ #
332
+ # @param [JSS::APIConnection] API Connection object
333
+ # @return [Array<Hash>] Array of Hashes containing ids and names of enabled Patches
334
+ #
335
+ def self.all_patches(api: JSS.api)
336
+ api.get_rsrc('patches')[:patch_reporting_software_titles]
337
+ end # end all_patches
338
+
339
+ # Patch Name Sampler
340
+ #
341
+ # @param [Hash] raw_patch Hash of output from API query like get_rsrc("patches/id/#{id}")
342
+ # @return [String] A Patch Reporting Software Title Name
343
+ #
344
+ def self.patch_name(raw_patch) # , api: JSS.api)
345
+ raw_patch[:software_title][:name]
346
+ end # end patch_name
347
+
348
+ # Patch Latest Version
349
+ #
350
+ # @param [Hash] raw_patch Hash of output from API query like get_rsrc("patches/id/#{id}")
351
+ # @return [String] The lastest version of a patch software title
352
+ #
353
+ def self.patch_latest_version(raw_patch, api: JSS.api)
354
+ patch = api.get_rsrc("patches/id/#{raw_patch[:id]}")
355
+ patch[:software_title][:versions].select { |i| i.is_a? String }.first
356
+ end # end patch_latest_version
357
+
358
+ end # module samplers
359
+
360
+ end # module Chook
@@ -0,0 +1,32 @@
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
+ Chook::Subject.classes[Chook::Subject::SCEP_CHALLENGE] = {
26
+ targetDevice: {
27
+ # validation: ,
28
+ # randomizer: ,
29
+ # sampler: ,
30
+ # api_object_attribute:
31
+ }
32
+ }