Skip to content

Commit 6a0aa60

Browse files
committed
docs
1 parent 52fb87f commit 6a0aa60

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

README.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,22 @@ This example will assume the following directory structure:
153153

154154
```text
155155
├── config/
156-
│ ├── hooks.yml # global hooks config
157-
│ ├── puma.rb # puma config
156+
│ ├── hooks.yml # global hooks config
157+
│ ├── puma.rb # puma config
158158
│ └── endpoints/
159159
│ ├── hello.yml
160160
│ └── goodbye.yml
161161
└── plugins/
162-
├── handlers/ # custom handler plugins
162+
├── handlers/ # custom handler plugins
163163
│ ├── hello_handler.rb
164164
│ └── goodbye_handler.rb
165+
├── lifecycle/ # custom lifecycle plugins (optional)
166+
│ └── my_lifecycle_plugin.rb # custom lifecycle plugin (optional)
167+
├── instruments/ # custom instrument plugins (optional)
168+
│ ├── stats.rb # a custom stats instrument plugin (optional)
169+
│ └── failbot.rb # a custom error notifier instrument plugin (optional)
165170
└── auth/
166-
└── goodbye_auth.rb # custom auth plugin (optional)
171+
└── goodbye_auth.rb # custom auth plugin (optional)
167172
```
168173

169174
Let's go through each step in detail.
@@ -174,8 +179,10 @@ First, create a `hooks.yml` file in the `config` directory. This file will defin
174179

175180
```yaml
176181
# file: config/hooks.yml
177-
handler_plugin_dir: ./plugins/handlers
178-
auth_plugin_dir: ./plugins/auth
182+
handler_plugin_dir: ./plugins/handlers # Directory for handler plugins
183+
auth_plugin_dir: ./plugins/auth # Directory for authentication plugins (optional)
184+
lifecycle_plugin_dir: ./plugins/lifecycle # Directory for lifecycle plugins (optional)
185+
instruments_plugin_dir: ./plugins/instruments # Directory for instrument plugins (optional)
179186
180187
# Available endpoints
181188
# Each endpoint configuration file should be placed in the endpoints directory
@@ -213,6 +220,10 @@ auth:
213220
type: Goodbye # This is a custom authentication plugin you would define in the plugins/auth
214221
secret_env_key: GOODBYE_API_KEY # the name of the environment variable containing the secret
215222
header: Authorization
223+
224+
# Optional additional options for the endpoint (can be anything you want)
225+
opts:
226+
foo: bar
216227
```
217228

218229
#### 3. Implement your handler plugins
@@ -251,6 +262,8 @@ class GoodbyeHandler < Hooks::Plugins::Handlers::Base
251262
end
252263
```
253264

265+
See the [Handler Plugins](docs/handler_plugins.md) documentation for more information on how to create your own custom handler plugins and what the values of `payload`, `headers`, and `config` are when the `call` method is invoked.
266+
254267
#### 4. Implement authentication plugins (optional)
255268

256269
If you want to secure your webhook endpoints, you can create custom authentication plugins in the `plugins/auth` directory. Here is an example of a simple authentication plugin for the `/goodbye` endpoint:
@@ -268,7 +281,7 @@ module Hooks
268281
secret = fetch_secret(config, secret_env_key_name: :secret_env_key)
269282
270283
# check if the Authorization header matches the secret
271-
auth_header = headers[config[:header]]
284+
auth_header = headers[config[:auth][:header]]
272285
return false unless auth_header
273286
274287
# compare the Authorization header with the secret
@@ -280,6 +293,8 @@ module Hooks
280293
end
281294
```
282295

296+
To learn more about how you can create your own custom authentication plugins, see the [Auth Plugins](docs/auth_plugins.md) documentation.
297+
283298
#### Summary
284299

285300
What these steps have done is set up a Hooks server that listens for incoming webhook requests at `/webhooks/hello` and `/webhooks/goodbye`. The `/hello` endpoint will respond with a success message without any authentication, while the `/goodbye` endpoint will require a valid `Authorization` header that matches the secret defined in the environment variable `GOODBYE_API_KEY`. Before the `/goodbye` endpoint enters the defined handler, it will first check the authentication plugin to ensure the request is valid.

0 commit comments

Comments
 (0)