chook 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +12 -0
- data/README.md +24 -25
- data/lib/chook/event/handled_event.rb +7 -2
- data/lib/chook/server.rb +5 -1
- data/lib/chook/server/routes/handle_webhook_event.rb +7 -2
- data/lib/chook/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c4ec862f7ad2fdbbc49daeb67862dd096a7524be67a5d5901e1d948a7857ae2
|
4
|
+
data.tar.gz: 3da70bf1d76edbf10371abc819b645e3620bd259a7973d9bdc39e71be74f95b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a81f5307c33b300e307a28fa59bfd008f1513d1b135c46855a4f0a41b8033269b346790d65f3c168423bb5c363cb17e04062b780ef73b3190b05e59b3e48339
|
7
|
+
data.tar.gz: 81fb57becdf2dc470be52fc287b955ccf6cbbb72dd5cab955924b925ff2cfc66d1d2c2dad35cfd7bdbdbc9f4cf0c7eb410100f939b2ffdad78a47a82e8b1bad2
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Chook Change Log
|
2
2
|
|
3
|
+
## v 1.1.2, 2019-01-24
|
4
|
+
|
5
|
+
- code cleanup & bugfixes
|
6
|
+
|
7
|
+
- thread ids show up in debug logging
|
8
|
+
|
9
|
+
- go back to calling Thread.new explicitly, so that the JSS gets immediate acknowlegment of reciept of the POST
|
10
|
+
|
11
|
+
- don't use sessions for the event-handling route
|
12
|
+
|
13
|
+
- update README.md to be more server focused, since thats the primary use of Chook
|
14
|
+
|
3
15
|
## v 1.1.1, 2018-10-18
|
4
16
|
|
5
17
|
- Admin web page authentication is now separated from Webhooks HTTP Basic Auth.
|
data/README.md
CHANGED
@@ -29,10 +29,9 @@ Chook also provides a simple [sinatra](http://sinatrarb.com/)-based HTTP server
|
|
29
29
|
|
30
30
|
**You do not need to be a Ruby developer to use Chook!**
|
31
31
|
|
32
|
-
The Chook webhook handling server can use "Event Handlers" written in
|
33
|
-
any language. See below for more information.
|
32
|
+
The Chook webhook handling server can use "Event Handlers" written in any language. See below for more information.
|
34
33
|
|
35
|
-
Although Chook integrates well with [ruby-jss](http://pixaranimationstudios.github.io/ruby-jss/index.html), especially for processing
|
34
|
+
Although Chook integrates well with [ruby-jss](http://pixaranimationstudios.github.io/ruby-jss/index.html), especially for processing webhook events,
|
36
35
|
it's a separate tool. However, ruby-jss is required when using Jamf-based admin page authentication, or using sampling features to generate TestEvents.
|
37
36
|
|
38
37
|
For more detail about the Jamf Pro Webhooks API and the JSON data it passes, please see
|
@@ -387,33 +386,31 @@ Watch the Chook log, with the level at info or debug, to see events come in.
|
|
387
386
|
|
388
387
|
## The Framework
|
389
388
|
|
390
|
-
|
391
|
-
classes. When the JSON payload of a JSS webhook POST request is passed into the
|
392
|
-
`Chook::Event.parse_event` method, an instance of the appropriate subclass of
|
393
|
-
`Chook::Event` is returned, for example
|
394
|
-
`Chook::Event::ComputerInventoryCompletedEvent`
|
389
|
+
While most folks will get along fine using the chook server and writing handlers, the server is built upon a framework implemented in the `Chook` ruby module, available after doing`require 'chook'`. For those with very specific needs, this framework can be used to implement your own webhook handling service, or to simulate a JamfPro server sending webhook events to some handling service.
|
395
390
|
|
396
|
-
|
391
|
+
The Chook framework abstracts webhook Events and their components as Ruby classes, grouped in two namespaces: HandledEvents, and TestEvents.
|
397
392
|
|
398
|
-
|
393
|
+
When the JSON payload of a JSS webhook POST request is passed into the `Chook::Event.parse_event` method, an instance of the appropriate subclass of `Chook::Event` is returned, for example, given the JSON for a ComputerInventoryCompleted webhook event, a `Chook::Event::ComputerInventoryCompletedEvent` instance is returned by `Chook::Event.parse_event`.
|
394
|
+
|
395
|
+
Each such event instance contains these important attributes:
|
396
|
+
|
397
|
+
* **webhook_id:** The webhook ID stored in the JSS
|
399
398
|
which caused the POST request. This attribute matches the "webhook[:id]"
|
400
|
-
|
399
|
+
value of the POSTed JSON.
|
401
400
|
|
402
401
|
* **webhook_name:** A read-only instance of the webhook name stored in the JSS
|
403
402
|
which caused the POST request. This attribute matches the "webhook[:name]"
|
404
|
-
|
403
|
+
value of the POSTed JSON.
|
405
404
|
|
406
405
|
* **subject:** A read-only instance of a `Chook::Subject::<Class>`
|
407
406
|
representing the "subject" that accompanies the event that triggered the
|
408
|
-
webhook. It comes from the "event"
|
407
|
+
webhook. It comes from the "event" object of the POSTed JSON, and
|
409
408
|
different events come with different subjects attached. For example, the
|
410
409
|
ComputerInventoryCompleted event comes with a "computer" subject containing
|
411
410
|
data about the JSS computer that completed inventory.
|
412
411
|
|
413
|
-
This is not
|
414
|
-
of named attributes about that computer.
|
415
|
-
module attempts to look up subject data from the API, but any
|
416
|
-
Handlers written for the event could easily do a similar operation.
|
412
|
+
This is not a ruby-jss `JSS::Computer` object from the REST API, but rather a group
|
413
|
+
of named attributes about that computer.
|
417
414
|
|
418
415
|
* **event_json:** The JSON content from the POST request, parsed into
|
419
416
|
a Ruby hash with symbolized keys (meaning the JSON key "deviceName" becomes
|
@@ -422,17 +419,19 @@ Each Event instance contains these important attributes:
|
|
422
419
|
* **raw_json:** A String containing the raw JSON from the POST
|
423
420
|
request.
|
424
421
|
|
425
|
-
* **handlers:** An Array of custom plug-ins for working with the
|
426
|
-
event. See _Event Handlers_, below.
|
427
|
-
|
428
|
-
|
429
|
-
|
430
422
|
### Events and Subjects
|
431
423
|
|
432
424
|
Here are the Event classes supported by the framework and the Subject classes
|
433
425
|
they contain.
|
434
|
-
|
435
|
-
|
426
|
+
|
427
|
+
For details about the attributes of each Subject, see [the Jamf Developer documentation](https://developer.jamf.com/webhooks).
|
428
|
+
|
429
|
+
**A special note about Subjects**
|
430
|
+
|
431
|
+
In Jamf's documentation, what Chook refers to as a 'Subject' is
|
432
|
+
called an 'event object' because it is a JSON 'object' (a.k.a. dictionary, hash, associative array)
|
433
|
+
labeled 'event'. We've chosen the word 'subject' to make talking about this thing a
|
434
|
+
bit more clear in the context of object-oriented programming.
|
436
435
|
|
437
436
|
Each Event class is a subclass of `Chook::Event`, where all of their
|
438
437
|
functionality is defined.
|
@@ -504,4 +503,4 @@ Ruby code.
|
|
504
503
|
## TODOs
|
505
504
|
|
506
505
|
- Better YARD docs
|
507
|
-
-
|
506
|
+
- more documentation beyond this README
|
@@ -138,14 +138,19 @@ module Chook
|
|
138
138
|
"Processed by #{handlers.count} handlers"
|
139
139
|
end # def handle
|
140
140
|
|
141
|
+
# TODO: these threads will die midstream when the server stops.
|
142
|
+
# Find a way to .join them or otherwise clean them up.
|
143
|
+
|
141
144
|
def pipe_to_executable(handler)
|
142
145
|
logger.debug "EXTERNAL: Sending JSON to stdin of '#{handler.basename}'"
|
143
|
-
|
146
|
+
_thread = Thread.new do
|
147
|
+
IO.popen([handler.to_s], 'w') { |h| h.puts @raw_json }
|
148
|
+
end
|
144
149
|
end
|
145
150
|
|
146
151
|
def handle_with_proc(handler)
|
147
152
|
logger.debug "INTERNAL: Running Handler defined in #{handler.handler_file}"
|
148
|
-
handler.handle self
|
153
|
+
_thread = Thread.new { handler.handle self }
|
149
154
|
end
|
150
155
|
|
151
156
|
def logger
|
data/lib/chook/server.rb
CHANGED
@@ -84,7 +84,11 @@ module Chook
|
|
84
84
|
enable :static
|
85
85
|
enable :sessions
|
86
86
|
set :sessions, expire_after: Chook.config.admin_session_expires if Chook.config.admin_user
|
87
|
-
|
87
|
+
if Chook.config.concurrency
|
88
|
+
set :threaded, true
|
89
|
+
else
|
90
|
+
enable :lock
|
91
|
+
end
|
88
92
|
end # configure
|
89
93
|
|
90
94
|
Chook::HandledEvent::Handlers.load_handlers
|
@@ -43,13 +43,18 @@ module Chook
|
|
43
43
|
else
|
44
44
|
|
45
45
|
event.logger.info "START From #{request.ip}, WebHook '#{event.webhook_name}' (id: #{event.webhook_id})"
|
46
|
-
|
47
|
-
event.logger.debug "JSON: #{raw_json}"
|
46
|
+
event.logger.debug "Thread id: #{Thread.current.object_id}; JSON: #{raw_json}"
|
48
47
|
|
49
48
|
result = event.handle
|
50
49
|
|
51
50
|
event.logger.info "END #{result}"
|
52
51
|
end
|
52
|
+
|
53
|
+
# this route shouldn't have a session expiration
|
54
|
+
# And when it does, the date format is wrong, and the
|
55
|
+
# JAMFSoftwareServerLog complains about it for every
|
56
|
+
# webhook sent.
|
57
|
+
env['rack.session.options'].delete :expire_after
|
53
58
|
result
|
54
59
|
end # post
|
55
60
|
|
data/lib/chook/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Lasell
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-01-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
180
|
version: '0'
|
181
181
|
requirements: []
|
182
182
|
rubyforge_project:
|
183
|
-
rubygems_version: 2.7.
|
183
|
+
rubygems_version: 2.7.8
|
184
184
|
signing_key:
|
185
185
|
specification_version: 4
|
186
186
|
summary: A Ruby framework for simulating and processing Jamf Pro Webhook Events
|