ruby-jss 0.7.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of ruby-jss might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGES.md +29 -22
- data/README.md +66 -86
- data/bin/jamfHelperBackgrounder +148 -0
- data/bin/netseg-update +0 -1
- data/lib/jss.rb +20 -9
- data/lib/jss/api_connection.rb +369 -295
- data/lib/jss/api_object.rb +651 -418
- data/lib/jss/api_object/account.rb +69 -77
- data/lib/jss/api_object/advanced_search.rb +201 -236
- data/lib/jss/api_object/advanced_search/advanced_computer_search.rb +42 -42
- data/lib/jss/api_object/advanced_search/advanced_mobile_device_search.rb +33 -43
- data/lib/jss/api_object/advanced_search/advanced_user_search.rb +33 -43
- data/lib/jss/api_object/building.rb +39 -52
- data/lib/jss/api_object/categorizable.rb +221 -0
- data/lib/jss/api_object/category.rb +81 -89
- data/lib/jss/api_object/computer.rb +486 -525
- data/lib/jss/api_object/computer_invitation.rb +73 -86
- data/lib/jss/api_object/criteriable.rb +6 -7
- data/lib/jss/api_object/ebook.rb +21 -0
- data/lib/jss/api_object/extendable.rb +6 -8
- data/lib/jss/api_object/group.rb +0 -3
- data/lib/jss/api_object/locatable.rb +19 -20
- data/lib/jss/api_object/mac_application.rb +21 -0
- data/lib/jss/api_object/mobile_device.rb +30 -21
- data/lib/jss/api_object/mobile_device_application.rb +447 -0
- data/lib/jss/api_object/mobile_device_configuration_profile.rb +21 -0
- data/lib/jss/api_object/osx_configuration_profile.rb +0 -3
- data/lib/jss/api_object/package.rb +21 -34
- data/lib/jss/api_object/peripheral.rb +16 -18
- data/lib/jss/api_object/policy.rb +5 -83
- data/lib/jss/api_object/purchasable.rb +11 -13
- data/lib/jss/api_object/scopable.rb +11 -12
- data/lib/jss/api_object/script.rb +3 -17
- data/lib/jss/api_object/self_servable.rb +419 -205
- data/lib/jss/api_object/self_servable/icon.rb +179 -0
- data/lib/jss/api_object/updatable.rb +35 -34
- data/lib/jss/api_object/uploadable.rb +72 -70
- data/lib/jss/api_object/user.rb +6 -7
- data/lib/jss/api_object/vppable.rb +117 -0
- data/lib/jss/client.rb +264 -225
- data/lib/jss/db_connection.rb +7 -5
- data/lib/jss/exceptions.rb +50 -42
- data/lib/jss/ruby_extensions.rb +8 -7
- data/lib/jss/ruby_extensions/object.rb +19 -0
- data/lib/jss/utility.rb +82 -40
- data/lib/jss/version.rb +1 -1
- metadata +37 -68
- data/bin/jss-webhook-server +0 -3
- data/lib/jss/webhooks.rb +0 -53
- data/lib/jss/webhooks/README.md +0 -269
- data/lib/jss/webhooks/configuration.rb +0 -213
- data/lib/jss/webhooks/data/sample_handlers/RestAPIOperation-executable +0 -91
- data/lib/jss/webhooks/data/sample_handlers/RestAPIOperation.rb +0 -45
- data/lib/jss/webhooks/data/sample_jsons/ComputerAdded.json +0 -27
- data/lib/jss/webhooks/data/sample_jsons/ComputerCheckIn.json +0 -27
- data/lib/jss/webhooks/data/sample_jsons/ComputerInventoryCompleted.json +0 -27
- data/lib/jss/webhooks/data/sample_jsons/ComputerPolicyFinished.json +0 -27
- data/lib/jss/webhooks/data/sample_jsons/ComputerPushCapabilityChanged.json +0 -27
- data/lib/jss/webhooks/data/sample_jsons/JSSShutdown.json +0 -14
- data/lib/jss/webhooks/data/sample_jsons/JSSStartup.json +0 -14
- data/lib/jss/webhooks/data/sample_jsons/MobileDeviceCheckIn.json +0 -26
- data/lib/jss/webhooks/data/sample_jsons/MobileDeviceCommandCompleted.json +0 -26
- data/lib/jss/webhooks/data/sample_jsons/MobileDeviceEnrolled.json +0 -26
- data/lib/jss/webhooks/data/sample_jsons/MobileDevicePushSent.json +0 -26
- data/lib/jss/webhooks/data/sample_jsons/MobileDeviceUnEnrolled.json +0 -26
- data/lib/jss/webhooks/data/sample_jsons/PatchSoftwareTitleUpdated.json +0 -14
- data/lib/jss/webhooks/data/sample_jsons/PushSent.json +0 -11
- data/lib/jss/webhooks/data/sample_jsons/RestAPIOperation.json +0 -15
- data/lib/jss/webhooks/data/sample_jsons/SCEPChallenge.json +0 -10
- data/lib/jss/webhooks/data/sample_jsons/SmartGroupComputerMembershipChange.json +0 -13
- data/lib/jss/webhooks/data/sample_jsons/SmartGroupMobileDeviceMembershipChange.json +0 -13
- data/lib/jss/webhooks/event.rb +0 -139
- data/lib/jss/webhooks/event/computer_added.rb +0 -38
- data/lib/jss/webhooks/event/computer_check_in.rb +0 -38
- data/lib/jss/webhooks/event/computer_inventory_completed.rb +0 -38
- data/lib/jss/webhooks/event/computer_policy_finished.rb +0 -38
- data/lib/jss/webhooks/event/computer_push_capability_changed.rb +0 -38
- data/lib/jss/webhooks/event/handlers.rb +0 -192
- data/lib/jss/webhooks/event/jss_shutdown.rb +0 -38
- data/lib/jss/webhooks/event/jss_startup.rb +0 -38
- data/lib/jss/webhooks/event/mobile_device_check_in.rb +0 -38
- data/lib/jss/webhooks/event/mobile_device_command_completed.rb +0 -38
- data/lib/jss/webhooks/event/mobile_device_enrolled.rb +0 -38
- data/lib/jss/webhooks/event/mobile_device_push_sent.rb +0 -38
- data/lib/jss/webhooks/event/mobile_device_unenrolled.rb +0 -38
- data/lib/jss/webhooks/event/patch_software_title_updated.rb +0 -38
- data/lib/jss/webhooks/event/push_sent.rb +0 -38
- data/lib/jss/webhooks/event/rest_api_operation.rb +0 -38
- data/lib/jss/webhooks/event/scep_challenge.rb +0 -38
- data/lib/jss/webhooks/event/smart_group_computer_membership_change.rb +0 -38
- data/lib/jss/webhooks/event/smart_group_mobile_device_membership_change.rb +0 -38
- data/lib/jss/webhooks/event/webhook.rb +0 -40
- data/lib/jss/webhooks/event_objects.rb +0 -112
- data/lib/jss/webhooks/event_objects/computer.rb +0 -49
- data/lib/jss/webhooks/event_objects/jss.rb +0 -36
- data/lib/jss/webhooks/event_objects/mobile_device.rb +0 -48
- data/lib/jss/webhooks/event_objects/patch_software_title_update.rb +0 -38
- data/lib/jss/webhooks/event_objects/push.rb +0 -33
- data/lib/jss/webhooks/event_objects/rest_api_operation.rb +0 -37
- data/lib/jss/webhooks/event_objects/scep_challenge.rb +0 -32
- data/lib/jss/webhooks/event_objects/smart_group.rb +0 -35
- data/lib/jss/webhooks/server_app.rb +0 -37
- data/lib/jss/webhooks/server_app/routes.rb +0 -27
- data/lib/jss/webhooks/server_app/routes/handle_webhook_event.rb +0 -39
- data/lib/jss/webhooks/server_app/routes/home.rb +0 -37
- data/lib/jss/webhooks/server_app/self_signed_cert.rb +0 -65
- data/lib/jss/webhooks/server_app/server.rb +0 -60
- data/lib/jss/webhooks/version.rb +0 -32
@@ -1,14 +0,0 @@
|
|
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
|
-
}
|
@@ -1,15 +0,0 @@
|
|
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
|
-
}
|
@@ -1,13 +0,0 @@
|
|
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
|
-
}
|
data/lib/jss/webhooks/event.rb
DELETED
@@ -1,139 +0,0 @@
|
|
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
|
-
module JSSWebHooks
|
27
|
-
|
28
|
-
# The superclass of all webhook events.
|
29
|
-
#
|
30
|
-
# Almost all processing happens here in the Superclass. The Subclasses
|
31
|
-
# define specfic-event-related details.
|
32
|
-
# As such, the Subclasses must define these constants:
|
33
|
-
#
|
34
|
-
# HANDLER_KEY = The JSSWebHooks::Configuration key pointing to the handler
|
35
|
-
# file for this event. See Event#handle for details.
|
36
|
-
#
|
37
|
-
# OBJECT_CLASS = the JSSWebHooks::EventObjects (q.v.) class representing the
|
38
|
-
# event object with this event
|
39
|
-
#
|
40
|
-
class Event
|
41
|
-
|
42
|
-
#########################
|
43
|
-
# Class Instance Variables
|
44
|
-
|
45
|
-
# Holds a mapping of Event names as they come from the JSS to the
|
46
|
-
# Event subclasses that represent them. Will be populated
|
47
|
-
# as the event subclasses are required.
|
48
|
-
@event_to_class_names ||= {}
|
49
|
-
|
50
|
-
# Getter for @event_to_class_names
|
51
|
-
#
|
52
|
-
# @return [Hash{String => Class} a mapping of Event names as they come from
|
53
|
-
# the JSS to the JSSWebHooks::Event subclasses that represent them
|
54
|
-
#
|
55
|
-
def self.event_to_class_names
|
56
|
-
@event_to_class_names
|
57
|
-
end
|
58
|
-
|
59
|
-
# Given the raw json from the JSS webhook,
|
60
|
-
# create an object of the correct Event subclass
|
61
|
-
#
|
62
|
-
# @param [String] raw_event_json The JSON http POST content from the JSS
|
63
|
-
#
|
64
|
-
# @return [JSSWebHooks::Event subclass] the Event subclass matching the event
|
65
|
-
#
|
66
|
-
def self.parse_event(raw_event_json)
|
67
|
-
event_json = JSON.parse(raw_event_json, symbolize_names: true)
|
68
|
-
event_name = event_json[:webhook][:webhookEvent]
|
69
|
-
JSSWebHooks::Event.event_to_class_names[event_name].new event_json, raw_event_json
|
70
|
-
end
|
71
|
-
|
72
|
-
# @return [String] the raw JSON recieved from the JSS
|
73
|
-
attr_reader :raw_json
|
74
|
-
|
75
|
-
# @return [Hash] The parsed JSON recieved from the JSS
|
76
|
-
attr_reader :event_json
|
77
|
-
|
78
|
-
# @return [JSSWebHooks::WebHook] The webhook in the JSS that caused this event
|
79
|
-
attr_reader :webhook
|
80
|
-
|
81
|
-
# @return [JSSWebHooks::EventObjects class] The event object sent with the event
|
82
|
-
attr_reader :event_object
|
83
|
-
|
84
|
-
# @return [Array<Proc,Pathname>] the handlers defined for this event
|
85
|
-
attr_reader :handlers
|
86
|
-
|
87
|
-
def initialize(event_json, raw_json)
|
88
|
-
@event_json = event_json
|
89
|
-
@raw_json = raw_json
|
90
|
-
|
91
|
-
# make a WebHook instance out of the webhook data for the event
|
92
|
-
@webhook = WebHook.new(event_json[:webhook])
|
93
|
-
|
94
|
-
# make an Event Objects class instance for the event object that
|
95
|
-
# came with this event.
|
96
|
-
@event_object = self.class::OBJECT_CLASS.new(event_json[:event])
|
97
|
-
|
98
|
-
# An array of handlers for this event type.
|
99
|
-
@handlers = JSSWebHooks::Event::Handlers.event_handlers[self.class::EVENT_NAME]
|
100
|
-
@handlers ||= []
|
101
|
-
end # init
|
102
|
-
|
103
|
-
def handle
|
104
|
-
@handlers.each do |handler|
|
105
|
-
case handler
|
106
|
-
when Pathname
|
107
|
-
pipe_to_executable handler
|
108
|
-
when Proc
|
109
|
-
handle_with_proc handler
|
110
|
-
end # case
|
111
|
-
end # @handlers.each do |handler|
|
112
|
-
|
113
|
-
# the handle method should return a string, since
|
114
|
-
# it's what gets called by the Post processor
|
115
|
-
# and it's output it returned as the HTTP Result
|
116
|
-
# body.
|
117
|
-
"Processed by #{@handlers.count} handlers"
|
118
|
-
end # def handle
|
119
|
-
|
120
|
-
# TODO: have something here that
|
121
|
-
# cleans up old threads and forks
|
122
|
-
def pipe_to_executable(handler)
|
123
|
-
thread = Thread.new do
|
124
|
-
IO.popen([handler.to_s], 'w') { |h| h.puts @raw_json }
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def handle_with_proc(handler)
|
129
|
-
thread = Thread.new { handler.call self }
|
130
|
-
end
|
131
|
-
|
132
|
-
end # class event
|
133
|
-
|
134
|
-
end # module
|
135
|
-
|
136
|
-
# load in the subclass definitions
|
137
|
-
Pathname.new(__FILE__).parent.+('event').children.each do |file|
|
138
|
-
require file.to_s if file.extname == '.rb'
|
139
|
-
end
|
@@ -1,38 +0,0 @@
|
|
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
|
-
module JSSWebHooks
|
27
|
-
|
28
|
-
class ComputerAddedEvent < Event
|
29
|
-
|
30
|
-
EVENT_NAME = 'ComputerAdded'.freeze
|
31
|
-
OBJECT_CLASS = JSSWebHooks::EventObjects::Computer
|
32
|
-
|
33
|
-
end # class
|
34
|
-
|
35
|
-
# map the EVENT_NAME (which comes from the JSS) with this class
|
36
|
-
JSSWebHooks::Event.event_to_class_names[ComputerAddedEvent::EVENT_NAME] = ComputerAddedEvent
|
37
|
-
|
38
|
-
end # module
|
@@ -1,38 +0,0 @@
|
|
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
|
-
module JSSWebHooks
|
27
|
-
|
28
|
-
class ComputerCheckInEvent < Event
|
29
|
-
|
30
|
-
EVENT_NAME = 'ComputerCheckIn'.freeze
|
31
|
-
OBJECT_CLASS = JSSWebHooks::EventObjects::Computer
|
32
|
-
|
33
|
-
end # class
|
34
|
-
|
35
|
-
# map the EVENT_NAME (which comes from the JSS) with this class
|
36
|
-
JSSWebHooks::Event.event_to_class_names[ComputerCheckInEvent::EVENT_NAME] = ComputerCheckInEvent
|
37
|
-
|
38
|
-
end # module
|
@@ -1,38 +0,0 @@
|
|
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
|
-
module JSSWebHooks
|
27
|
-
|
28
|
-
class ComputerInventoryCompletedEvent < Event
|
29
|
-
|
30
|
-
EVENT_NAME = 'ComputerInventoryCompleted'.freeze
|
31
|
-
OBJECT_CLASS = JSSWebHooks::EventObjects::Computer
|
32
|
-
|
33
|
-
end # class
|
34
|
-
|
35
|
-
# map the EVENT_NAME (which comes from the JSS) with this class
|
36
|
-
JSSWebHooks::Event.event_to_class_names[ComputerInventoryCompletedEvent::EVENT_NAME] = ComputerInventoryCompletedEvent
|
37
|
-
|
38
|
-
end # module
|
@@ -1,38 +0,0 @@
|
|
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
|
-
module JSSWebHooks
|
27
|
-
|
28
|
-
class ComputerPolicyFinishedEvent < Event
|
29
|
-
|
30
|
-
EVENT_NAME = 'ComputerPolicyFinished'.freeze
|
31
|
-
OBJECT_CLASS = JSSWebHooks::EventObjects::Computer
|
32
|
-
|
33
|
-
end # class
|
34
|
-
|
35
|
-
# map the EVENT_NAME (which comes from the JSS) with this class
|
36
|
-
JSSWebHooks::Event.event_to_class_names[ComputerPolicyFinishedEvent::EVENT_NAME] = ComputerPolicyFinishedEvent
|
37
|
-
|
38
|
-
end # module
|
@@ -1,38 +0,0 @@
|
|
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
|
-
module JSSWebHooks
|
27
|
-
|
28
|
-
class ComputerPushCapabilityChangedEvent < Event
|
29
|
-
|
30
|
-
EVENT_NAME = 'ComputerPushCapabilityChanged'.freeze
|
31
|
-
OBJECT_CLASS = JSSWebHooks::EventObjects::Computer
|
32
|
-
|
33
|
-
end # class
|
34
|
-
|
35
|
-
# map the EVENT_NAME (which comes from the JSS) with this class
|
36
|
-
JSSWebHooks::Event.event_to_class_names[ComputerPushCapabilityChangedEvent::EVENT_NAME] = ComputerPushCapabilityChangedEvent
|
37
|
-
|
38
|
-
end # module
|
@@ -1,192 +0,0 @@
|
|
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
|
-
module JSSWebHooks
|
27
|
-
|
28
|
-
# This method is used by the Ruby event-handler files.
|
29
|
-
#
|
30
|
-
# Loading them should call this method and pass in a block
|
31
|
-
# with one parameter: a JSS::WebHooks::Event subclass object.
|
32
|
-
#
|
33
|
-
# The block is then converted to a Proc instance in @loaded_event_handler
|
34
|
-
# and from there can be stored for use by the event identified by the filename.
|
35
|
-
#
|
36
|
-
# NOTE: the files should be read with 'load' not 'require', so that they can
|
37
|
-
# be re-loaded as needed
|
38
|
-
#
|
39
|
-
# @see_also JSSWebHooks::load_handlers
|
40
|
-
#
|
41
|
-
# @param [Block] block the block to be used as an event handler
|
42
|
-
#
|
43
|
-
# @yieldparam [JSS::WebHooks::Event subclass] The event to be handled
|
44
|
-
#
|
45
|
-
# @return [Proc] the block converted to a Proc
|
46
|
-
#
|
47
|
-
def self.event_handler(&block)
|
48
|
-
Event::Handlers.loaded_event_handler = Proc.new(&block)
|
49
|
-
end
|
50
|
-
|
51
|
-
class Event
|
52
|
-
|
53
|
-
module Handlers
|
54
|
-
|
55
|
-
############################
|
56
|
-
# Module constants
|
57
|
-
|
58
|
-
DEFAULT_HANDLER_DIR = '/Library/Application Support/JSSWebHooks'.freeze
|
59
|
-
|
60
|
-
############################
|
61
|
-
# Module Instance Variables, & accessors
|
62
|
-
|
63
|
-
@loaded_event_handler = nil
|
64
|
-
|
65
|
-
# Getter for @loaded_event_handler
|
66
|
-
#
|
67
|
-
# @return [Proc,nil] the most recent Proc loaded from a handler file.
|
68
|
-
# destined for storage in @event_handlers
|
69
|
-
#
|
70
|
-
def self.loaded_event_handler
|
71
|
-
@loaded_event_handler
|
72
|
-
end
|
73
|
-
|
74
|
-
# Setter for @loaded_event_handler
|
75
|
-
#
|
76
|
-
# @param [Proc] a_proc the most recent Proc loaded from a handler file.
|
77
|
-
# destined for storage in @event_handlers
|
78
|
-
#
|
79
|
-
def self.loaded_event_handler=(a_proc)
|
80
|
-
@loaded_event_handler = a_proc
|
81
|
-
end
|
82
|
-
|
83
|
-
@event_handlers = {}
|
84
|
-
|
85
|
-
# Getter for @event_handlers
|
86
|
-
#
|
87
|
-
# @return [Hash{String => Array}] a mapping of Event Names as the come from
|
88
|
-
# the JSS to an Array of handlers for the event. The handlers are either
|
89
|
-
# Proc objects to call from within ruby, or Pathnames to executable files
|
90
|
-
# which will take raw JSON on stdin.
|
91
|
-
def self.event_handlers
|
92
|
-
@event_handlers
|
93
|
-
end
|
94
|
-
|
95
|
-
############################
|
96
|
-
# Module Methods
|
97
|
-
|
98
|
-
# Load all the event handlers from the handler_dir or an arbitrary dir.
|
99
|
-
#
|
100
|
-
# @param [String, Pathname] from_dir directory from which to
|
101
|
-
# load the handlers
|
102
|
-
# @param [Boolean] reload should we reload handlers if they've already
|
103
|
-
# been loaded?
|
104
|
-
#
|
105
|
-
# @return [void]
|
106
|
-
#
|
107
|
-
def self.load_handlers(from_dir = CONFIG.handler_dir, reload = false)
|
108
|
-
from_dir ||= DEFAULT_HANDLER_DIR
|
109
|
-
|
110
|
-
if reload
|
111
|
-
@handlers_loaded_from = nil
|
112
|
-
@event_handlers = {}
|
113
|
-
@loaded_event_handler = nil
|
114
|
-
end
|
115
|
-
|
116
|
-
handler_dir = Pathname.new(from_dir)
|
117
|
-
return unless handler_dir.directory? && handler_dir.readable?
|
118
|
-
|
119
|
-
handler_dir.children.each do |handler_file|
|
120
|
-
load_handler(handler_file) if handler_file.file? && handler_file.readable?
|
121
|
-
end
|
122
|
-
|
123
|
-
@handlers_loaded_from = handler_dir
|
124
|
-
end # load handlers
|
125
|
-
|
126
|
-
# Load an even handler from a file.
|
127
|
-
# Handler files must begin with the name of the event they handle,
|
128
|
-
# e.g. ComputerAdded, followed by: nothing, a dot, a dash, or
|
129
|
-
# and underscore. Case doesn't matter.
|
130
|
-
# So all of these are OK:
|
131
|
-
# ComputerAdded
|
132
|
-
# computeradded.sh
|
133
|
-
# COMPUTERAdded_notify_team
|
134
|
-
# Computeradded-update-ldap
|
135
|
-
# There can be as many as desired for each event.
|
136
|
-
#
|
137
|
-
# Each must be either:
|
138
|
-
# - An executable file, which will have the raw JSON from the JSS piped
|
139
|
-
# to it's stdin when executed
|
140
|
-
# or
|
141
|
-
# - A non-executable file of ruby code like this:
|
142
|
-
# JSSWebHooks.event_handler do |event|
|
143
|
-
# # your code goes here.
|
144
|
-
# end
|
145
|
-
#
|
146
|
-
# (see HERE for details about writing the ruby handlers)
|
147
|
-
#
|
148
|
-
# @param [Pathname] from_file the file from which to
|
149
|
-
#
|
150
|
-
# @return [Type] description of returned object
|
151
|
-
#
|
152
|
-
def self.load_handler(from_file)
|
153
|
-
handler_file = Pathname.new from_file
|
154
|
-
event_name = event_name_from_handler_filename(handler_file)
|
155
|
-
return unless event_name
|
156
|
-
|
157
|
-
# create an array for this event's handlers, if needed
|
158
|
-
@event_handlers[event_name] ||= []
|
159
|
-
|
160
|
-
if handler_file.executable?
|
161
|
-
# store as a Pathname, we'll pipe JSON to it
|
162
|
-
@event_handlers[event_name] << handler_file unless \
|
163
|
-
@event_handlers[event_name].include? handler_file
|
164
|
-
else
|
165
|
-
# load the file. If written correctly, it will
|
166
|
-
# put a Proc into @loaded_event_handler
|
167
|
-
load handler_file.to_s
|
168
|
-
# store as a Proc, to be called when the event is handled.
|
169
|
-
@event_handlers[event_name] << @loaded_event_handler unless \
|
170
|
-
@event_handlers[event_name].include? @loaded_event_handler
|
171
|
-
|
172
|
-
end # if handler_file.executable?
|
173
|
-
end # self.load_handler(handler_file)
|
174
|
-
|
175
|
-
# Given a handler filename, return the event name it wants to handle
|
176
|
-
#
|
177
|
-
# @param [Pathname] filename The filename from which to glean the
|
178
|
-
# event name.
|
179
|
-
#
|
180
|
-
# @return [String,nil] The matching event name or nil if no match
|
181
|
-
#
|
182
|
-
def self.event_name_from_handler_filename(filename)
|
183
|
-
@event_names ||= JSSWebHooks::Event.event_to_class_names.keys
|
184
|
-
desired_event_name = filename.basename.to_s.split(/\.|-|_/).first
|
185
|
-
@event_names.select { |n| desired_event_name.casecmp(n).zero? }.first
|
186
|
-
end
|
187
|
-
|
188
|
-
end # module Handler
|
189
|
-
|
190
|
-
end # class event
|
191
|
-
|
192
|
-
end # module
|