ruby-jss 0.6.5 → 0.6.6

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 (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +57 -5
  3. data/lib/jss.rb +78 -94
  4. data/lib/jss/api_connection.rb +8 -0
  5. data/lib/jss/api_object.rb +126 -102
  6. data/lib/jss/api_object/creatable.rb +33 -15
  7. data/lib/jss/api_object/distribution_point.rb +4 -1
  8. data/lib/jss/api_object/extension_attribute.rb +1 -1
  9. data/lib/jss/api_object/package.rb +121 -187
  10. data/lib/jss/api_object/policy.rb +590 -251
  11. data/lib/jss/api_object/script.rb +92 -128
  12. data/lib/jss/api_object/self_servable.rb +93 -117
  13. data/lib/jss/api_object/updatable.rb +12 -27
  14. data/lib/jss/api_object/uploadable.rb +12 -15
  15. data/lib/jss/client.rb +178 -156
  16. data/lib/jss/db_connection.rb +34 -49
  17. data/lib/jss/ruby_extensions/string.rb +25 -21
  18. data/lib/jss/version.rb +1 -1
  19. data/lib/jss/webhooks.rb +52 -0
  20. data/lib/jss/webhooks/README.md +269 -0
  21. data/lib/jss/webhooks/configuration.rb +212 -0
  22. data/lib/jss/webhooks/data/sample_handlers/RestAPIOperation-executable +90 -0
  23. data/lib/jss/webhooks/data/sample_handlers/RestAPIOperation.rb +44 -0
  24. data/lib/jss/webhooks/data/sample_jsons/ComputerAdded.json +27 -0
  25. data/lib/jss/webhooks/data/sample_jsons/ComputerCheckIn.json +27 -0
  26. data/lib/jss/webhooks/data/sample_jsons/ComputerInventoryCompleted.json +27 -0
  27. data/lib/jss/webhooks/data/sample_jsons/ComputerPolicyFinished.json +27 -0
  28. data/lib/jss/webhooks/data/sample_jsons/ComputerPushCapabilityChanged.json +27 -0
  29. data/lib/jss/webhooks/data/sample_jsons/JSSShutdown.json +14 -0
  30. data/lib/jss/webhooks/data/sample_jsons/JSSStartup.json +14 -0
  31. data/lib/jss/webhooks/data/sample_jsons/MobileDeviceCheckIn.json +26 -0
  32. data/lib/jss/webhooks/data/sample_jsons/MobileDeviceCommandCompleted.json +26 -0
  33. data/lib/jss/webhooks/data/sample_jsons/MobileDeviceEnrolled.json +26 -0
  34. data/lib/jss/webhooks/data/sample_jsons/MobileDevicePushSent.json +26 -0
  35. data/lib/jss/webhooks/data/sample_jsons/MobileDeviceUnEnrolled.json +26 -0
  36. data/lib/jss/webhooks/data/sample_jsons/PatchSoftwareTitleUpdated.json +14 -0
  37. data/lib/jss/webhooks/data/sample_jsons/PushSent.json +11 -0
  38. data/lib/jss/webhooks/data/sample_jsons/RestAPIOperation.json +15 -0
  39. data/lib/jss/webhooks/data/sample_jsons/SCEPChallenge.json +10 -0
  40. data/lib/jss/webhooks/data/sample_jsons/SmartGroupComputerMembershipChange.json +13 -0
  41. data/lib/jss/webhooks/data/sample_jsons/SmartGroupMobileDeviceMembershipChange.json +13 -0
  42. data/lib/jss/webhooks/event.rb +138 -0
  43. data/lib/jss/webhooks/event/computer_added.rb +37 -0
  44. data/lib/jss/webhooks/event/computer_check_in.rb +37 -0
  45. data/lib/jss/webhooks/event/computer_inventory_completed.rb +37 -0
  46. data/lib/jss/webhooks/event/computer_policy_finished.rb +37 -0
  47. data/lib/jss/webhooks/event/computer_push_capability_changed.rb +37 -0
  48. data/lib/jss/webhooks/event/handlers.rb +191 -0
  49. data/lib/jss/webhooks/event/jss_shutdown.rb +37 -0
  50. data/lib/jss/webhooks/event/jss_startup.rb +37 -0
  51. data/lib/jss/webhooks/event/mobile_device_check_in.rb +37 -0
  52. data/lib/jss/webhooks/event/mobile_device_command_completed.rb +37 -0
  53. data/lib/jss/webhooks/event/mobile_device_enrolled.rb +37 -0
  54. data/lib/jss/webhooks/event/mobile_device_push_sent.rb +37 -0
  55. data/lib/jss/webhooks/event/mobile_device_unenrolled.rb +37 -0
  56. data/lib/jss/webhooks/event/patch_software_title_updated.rb +37 -0
  57. data/lib/jss/webhooks/event/push_sent.rb +37 -0
  58. data/lib/jss/webhooks/event/rest_api_operation.rb +37 -0
  59. data/lib/jss/webhooks/event/scep_challenge.rb +37 -0
  60. data/lib/jss/webhooks/event/smart_group_computer_membership_change.rb +37 -0
  61. data/lib/jss/webhooks/event/smart_group_mobile_device_membership_change.rb +37 -0
  62. data/lib/jss/webhooks/event/webhook.rb +39 -0
  63. data/lib/jss/webhooks/event_objects.rb +111 -0
  64. data/lib/jss/webhooks/event_objects/computer.rb +48 -0
  65. data/lib/jss/webhooks/event_objects/jss.rb +35 -0
  66. data/lib/jss/webhooks/event_objects/mobile_device.rb +47 -0
  67. data/lib/jss/webhooks/event_objects/patch_software_title_update.rb +37 -0
  68. data/lib/jss/webhooks/event_objects/push.rb +32 -0
  69. data/lib/jss/webhooks/event_objects/rest_api_operation.rb +36 -0
  70. data/lib/jss/webhooks/event_objects/scep_challenge.rb +31 -0
  71. data/lib/jss/webhooks/event_objects/smart_group.rb +34 -0
  72. data/lib/jss/webhooks/server_app.rb +36 -0
  73. data/lib/jss/webhooks/server_app/routes.rb +26 -0
  74. data/lib/jss/webhooks/server_app/routes/handle_webhook_event.rb +38 -0
  75. data/lib/jss/webhooks/server_app/routes/home.rb +36 -0
  76. data/lib/jss/webhooks/server_app/self_signed_cert.rb +64 -0
  77. data/lib/jss/webhooks/server_app/server.rb +59 -0
  78. data/lib/jss/webhooks/version.rb +31 -0
  79. metadata +63 -4
@@ -0,0 +1,27 @@
1
+ {
2
+ "webhook": {
3
+ "id": 5,
4
+ "name": "ComputerPushCapabilityChanged Webhook",
5
+ "webhookEvent": "ComputerPushCapabilityChanged"
6
+ },
7
+ "event": {
8
+ "udid": "99848AF0-xxxx-XXXX-xxxx-B79B9F65D7F8",
9
+ "deviceName": "wanderer",
10
+ "model": "MacBookPro10,1",
11
+ "macAddress": "yy:E0:yy:16:yy:E9",
12
+ "alternateMacAddress": "32:xx:1A:xx:xx:60",
13
+ "serialNumber": "VM87S764H831",
14
+ "osVersion": "10.15.2",
15
+ "osBuild": "48673",
16
+ "userDirectoryID": "-1",
17
+ "username": "username",
18
+ "realName": "User Name",
19
+ "emailAddress": "user@school.edu",
20
+ "phone": "x3369",
21
+ "position": "Apple Peeler",
22
+ "department": "MacBack",
23
+ "building": "Soho",
24
+ "room": "s167",
25
+ "jssID": 1322
26
+ }
27
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "webhook": {
3
+ "id": 7,
4
+ "name": "JSSShutdown Webhook",
5
+ "webhookEvent": "JSSShutdown"
6
+ },
7
+ "event": {
8
+ "institution": "MyCoolSchool",
9
+ "hostAddress": "casper.mycoolschool.edu",
10
+ "webApplicationPath": "/path/to/web/app",
11
+ "isClusterMaster": true,
12
+ "jssUrl": "https://casper.mycoolschool.edu:8443/"
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "webhook": {
3
+ "id": 8,
4
+ "name": "JSSStartup Webhook",
5
+ "webhookEvent": "JSSStartup"
6
+ },
7
+ "event": {
8
+ "institution": "MyCoolSchool",
9
+ "hostAddress": "casper.mycoolschool.edu",
10
+ "webApplicationPath": "/path/to/web/app",
11
+ "isClusterMaster": true,
12
+ "jssUrl": "https://casper.mycoolschool.edu:8443/"
13
+ }
14
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "webhook": {
3
+ "id": 9,
4
+ "name": "MobileCheckin Webhook",
5
+ "webhookEvent": "MobileDeviceCheckIn"
6
+ },
7
+ "event": {
8
+ "udid": "0d12c74062dxyxyxb4b234f4ac1yxyxyx1efccd0",
9
+ "deviceName": "tipple",
10
+ "version": "4.71.00",
11
+ "model": "iPhone7,2",
12
+ "bluetoothMacAddress": "xx:xx:37:yy:78:xx",
13
+ "wifiMacAddress": "yy:yy:37:xx:78:yy",
14
+ "imei": "xx yyyyyy zzzzzz 0",
15
+ "icciID": "aaaa bbbb cccc dddd eeee",
16
+ "product": null,
17
+ "serialNumber": "C8EM25KSG5PT",
18
+ "userDirectoryID": "-1",
19
+ "room": "s167",
20
+ "osVersion": "9.3.4",
21
+ "osBuild": "13G35",
22
+ "modelDisplay": "iPhone 6",
23
+ "username": "username",
24
+ "jssID": 158
25
+ }
26
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "webhook": {
3
+ "id": 10,
4
+ "name": "MobileCommandComplete Webhook",
5
+ "webhookEvent": "MobileDeviceCommandCompleted"
6
+ },
7
+ "event": {
8
+ "udid": "0d12c74062dxyxyxb4b234f4ac1yxyxyx1efccd0",
9
+ "deviceName": "tipple",
10
+ "version": "4.71.00",
11
+ "model": "iPhone7,2",
12
+ "bluetoothMacAddress": "xx:xx:37:yy:78:xx",
13
+ "wifiMacAddress": "yy:yy:37:xx:78:yy",
14
+ "imei": "xx yyyyyy zzzzzz 0",
15
+ "icciID": "aaaa bbbb cccc dddd eeee",
16
+ "product": null,
17
+ "serialNumber": "C8EM25KSG5PT",
18
+ "userDirectoryID": "-1",
19
+ "room": "s167",
20
+ "osVersion": "9.3.4",
21
+ "osBuild": "13G35",
22
+ "modelDisplay": "iPhone 6",
23
+ "username": "username",
24
+ "jssID": 158
25
+ }
26
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "webhook": {
3
+ "id": 11,
4
+ "name": "MobileEnrolled Webhook",
5
+ "webhookEvent": "MobileDeviceEnrolled"
6
+ },
7
+ "event": {
8
+ "udid": "0d12c74062dxyxyxb4b234f4ac1yxyxyx1efccd0",
9
+ "deviceName": "tipple",
10
+ "version": "4.71.00",
11
+ "model": "iPhone7,2",
12
+ "bluetoothMacAddress": "xx:xx:37:yy:78:xx",
13
+ "wifiMacAddress": "yy:yy:37:xx:78:yy",
14
+ "imei": "xx yyyyyy zzzzzz 0",
15
+ "icciID": "aaaa bbbb cccc dddd eeee",
16
+ "product": null,
17
+ "serialNumber": "C8EM25KSG5PT",
18
+ "userDirectoryID": "-1",
19
+ "room": "s167",
20
+ "osVersion": "9.3.4",
21
+ "osBuild": "13G35",
22
+ "modelDisplay": "iPhone 6",
23
+ "username": "username",
24
+ "jssID": 158
25
+ }
26
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "webhook": {
3
+ "id": 12,
4
+ "name": "MobilePush Webhook",
5
+ "webhookEvent": "MobileDevicePushSent"
6
+ },
7
+ "event": {
8
+ "udid": "0d12c74062dxyxyxb4b234f4ac1yxyxyx1efccd0",
9
+ "deviceName": "tipple",
10
+ "version": "4.71.00",
11
+ "model": "iPhone7,2",
12
+ "bluetoothMacAddress": "xx:xx:37:yy:78:xx",
13
+ "wifiMacAddress": "yy:yy:37:xx:78:yy",
14
+ "imei": "xx yyyyyy zzzzzz 0",
15
+ "icciID": "aaaa bbbb cccc dddd eeee",
16
+ "product": null,
17
+ "serialNumber": "C8EM25KSG5PT",
18
+ "userDirectoryID": "-1",
19
+ "room": "s167",
20
+ "osVersion": "9.3.4",
21
+ "osBuild": "13G35",
22
+ "modelDisplay": "iPhone 6",
23
+ "username": "username",
24
+ "jssID": 158
25
+ }
26
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "webhook": {
3
+ "id": 13,
4
+ "name": "MobileUnEnrolled Webhook",
5
+ "webhookEvent": "MobileDeviceUnEnrolled"
6
+ },
7
+ "event": {
8
+ "udid": "0d12c74062dxyxyxb4b234f4ac1yxyxyx1efccd0",
9
+ "deviceName": "tipple",
10
+ "version": "4.71.00",
11
+ "model": "iPhone7,2",
12
+ "bluetoothMacAddress": "xx:xx:37:yy:78:xx",
13
+ "wifiMacAddress": "yy:yy:37:xx:78:yy",
14
+ "imei": "xx yyyyyy zzzzzz 0",
15
+ "icciID": "aaaa bbbb cccc dddd eeee",
16
+ "product": null,
17
+ "serialNumber": "C8EM25KSG5PT",
18
+ "userDirectoryID": "-1",
19
+ "room": "s167",
20
+ "osVersion": "9.3.4",
21
+ "osBuild": "13G35",
22
+ "modelDisplay": "iPhone 6",
23
+ "username": "username",
24
+ "jssID": 158
25
+ }
26
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "webhook": {
3
+ "id": 14,
4
+ "name": "PatchSoftwareTitleUpdated Webhook",
5
+ "webhookEvent": "PatchSoftwareTitleUpdated"
6
+ },
7
+ "event": {
8
+ "name": "CoolApp",
9
+ "latestVersion": "12.4.3",
10
+ "lastUpdate": 1463054400000,
11
+ "reportUrl": "http://CoolApp.com/downloads/latest",
12
+ "jssID": 1
13
+ }
14
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "webhook": {
3
+ "id": 15,
4
+ "name": "PushSent Webhook",
5
+ "webhookEvent": "PushSent"
6
+ },
7
+ "event": {
8
+ "type": "blank",
9
+ "jssID": 1322
10
+ }
11
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "webhook": {
3
+ "id": 16,
4
+ "name": "RestAPIOperation Webhook",
5
+ "webhookEvent": "RestAPIOperation"
6
+ },
7
+ "event": {
8
+ "operationSuccessful": true,
9
+ "objectID": 1233,
10
+ "objectName": "wanderer",
11
+ "objectTypeName": "computer",
12
+ "authorizedUsername": "username",
13
+ "restAPIOperationType": "POST"
14
+ }
15
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "webhook": {
3
+ "id": 17,
4
+ "name": "SCEPChallenge Webhook",
5
+ "webhookEvent": "SCEPChallenge"
6
+ },
7
+ "event": {
8
+ "targetDevice": "computer"
9
+ }
10
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "webhook": {
3
+ "id": 18,
4
+ "name": "SmartGroupComputerMembershipChange Webhook",
5
+ "webhookEvent": "SmartGroupComputerMembershipChange"
6
+ },
7
+ "event": {
8
+ "name": "OddComputers",
9
+ "smartGroup": true,
10
+ "jssid": 95,
11
+ "computer": true
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "webhook": {
3
+ "id": 19,
4
+ "name": "SmartGroupMobileDeviceMembershipChange Webhook",
5
+ "webhookEvent": "SmartGroupMobileDeviceMembershipChange"
6
+ },
7
+ "event": {
8
+ "name": "OddMobileDevs",
9
+ "smartGroup": true,
10
+ "jssid": 99,
11
+ "computer": false
12
+ }
13
+ }
@@ -0,0 +1,138 @@
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
+ module JSSWebHooks
26
+
27
+ # The superclass of all webhook events.
28
+ #
29
+ # Almost all processing happens here in the Superclass. The Subclasses
30
+ # define specfic-event-related details.
31
+ # As such, the Subclasses must define these constants:
32
+ #
33
+ # HANDLER_KEY = The JSSWebHooks::Configuration key pointing to the handler
34
+ # file for this event. See Event#handle for details.
35
+ #
36
+ # OBJECT_CLASS = the JSSWebHooks::EventObjects (q.v.) class representing the
37
+ # event object with this event
38
+ #
39
+ class Event
40
+
41
+ #########################
42
+ # Class Instance Variables
43
+
44
+ # Holds a mapping of Event names as they come from the JSS to the
45
+ # Event subclasses that represent them. Will be populated
46
+ # as the event subclasses are required.
47
+ @event_to_class_names ||= {}
48
+
49
+ # Getter for @event_to_class_names
50
+ #
51
+ # @return [Hash{String => Class} a mapping of Event names as they come from
52
+ # the JSS to the JSSWebHooks::Event subclasses that represent them
53
+ #
54
+ def self.event_to_class_names
55
+ @event_to_class_names
56
+ end
57
+
58
+ # Given the raw json from the JSS webhook,
59
+ # create an object of the correct Event subclass
60
+ #
61
+ # @param [String] raw_event_json The JSON http POST content from the JSS
62
+ #
63
+ # @return [JSSWebHooks::Event subclass] the Event subclass matching the event
64
+ #
65
+ def self.parse_event(raw_event_json)
66
+ event_json = JSON.parse(raw_event_json, symbolize_names: true)
67
+ event_name = event_json[:webhook][:webhookEvent]
68
+ JSSWebHooks::Event.event_to_class_names[event_name].new event_json, raw_event_json
69
+ end
70
+
71
+ # @return [String] the raw JSON recieved from the JSS
72
+ attr_reader :raw_json
73
+
74
+ # @return [Hash] The parsed JSON recieved from the JSS
75
+ attr_reader :event_json
76
+
77
+ # @return [JSSWebHooks::WebHook] The webhook in the JSS that caused this event
78
+ attr_reader :webhook
79
+
80
+ # @return [JSSWebHooks::EventObjects class] The event object sent with the event
81
+ attr_reader :event_object
82
+
83
+ # @return [Array<Proc,Pathname>] the handlers defined for this event
84
+ attr_reader :handlers
85
+
86
+ def initialize(event_json, raw_json)
87
+ @event_json = event_json
88
+ @raw_json = raw_json
89
+
90
+ # make a WebHook instance out of the webhook data for the event
91
+ @webhook = WebHook.new(event_json[:webhook])
92
+
93
+ # make an Event Objects class instance for the event object that
94
+ # came with this event.
95
+ @event_object = self.class::OBJECT_CLASS.new(event_json[:event])
96
+
97
+ # An array of handlers for this event type.
98
+ @handlers = JSSWebHooks::Event::Handlers.event_handlers[self.class::EVENT_NAME]
99
+ @handlers ||= []
100
+ end # init
101
+
102
+ def handle
103
+ @handlers.each do |handler|
104
+ case handler
105
+ when Pathname
106
+ pipe_to_executable handler
107
+ when Proc
108
+ handle_with_proc handler
109
+ end # case
110
+ end # @handlers.each do |handler|
111
+
112
+ # the handle method should return a string, since
113
+ # it's what gets called by the Post processor
114
+ # and it's output it returned as the HTTP Result
115
+ # body.
116
+ "Processed by #{@handlers.count} handlers"
117
+ end # def handle
118
+
119
+ # TODO: have something here that
120
+ # cleans up old threads and forks
121
+ def pipe_to_executable(handler)
122
+ thread = Thread.new do
123
+ IO.popen([handler.to_s], 'w') { |h| h.puts @raw_json }
124
+ end
125
+ end
126
+
127
+ def handle_with_proc(handler)
128
+ thread = Thread.new { handler.call self }
129
+ end
130
+
131
+ end # class event
132
+
133
+ end # module
134
+
135
+ # load in the subclass definitions
136
+ Pathname.new(__FILE__).parent.+('event').children.each do |file|
137
+ require file.to_s if file.extname == '.rb'
138
+ end
@@ -0,0 +1,37 @@
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
+ module JSSWebHooks
26
+
27
+ class ComputerAddedEvent < Event
28
+
29
+ EVENT_NAME = 'ComputerAdded'.freeze
30
+ OBJECT_CLASS = JSSWebHooks::EventObjects::Computer
31
+
32
+ end # class
33
+
34
+ # map the EVENT_NAME (which comes from the JSS) with this class
35
+ JSSWebHooks::Event.event_to_class_names[ComputerAddedEvent::EVENT_NAME] = ComputerAddedEvent
36
+
37
+ end # module