View Source BonnyPlug.WebhookPlug (bonny_plug v1.0.3)

Plug that processes incoming admission webhook requests. Valid requests are forwarded to given webhook handlers.

You have to specify the :webhook_type you want to forward to this plug. The :webhook_type has to be be either :validating_webhook or :mutating_webhook.

examples

Examples

compile-time-configuration

Compile time configuration

In a Phoenix router you would forward post requests to this plug:

post "/admission-review/validate", BonnyPlug.WebhookPlug,
  webhook_type: :validating_webhook,
  handlers: [MyApp.WebhookHandlers.FooResourceWebhookHandler]

post "/admission-review/mutate", BonnyPlug.WebhookPlug,
  webhook_type: :mutating_webhook,
  handlers: [MyApp.WebhookHandlers.BarResourceWebhookHandler]

runtime-configuration

Runtime configuration

In the example above, the handlers are defined at compile time. If you need to define the handlers at runtime, you can define them in config/runtime.exs. Note that in this case, handlers are global for all instances of the plug, unless declared at compile time like above.

Your config/runtime.exs:

import Config

config :bonny_plug, BonnyPlug.WebhookPlug
  handlers: [MyApp.WebhookHandlers.FooResourceWebhookHandler]

Your router.ex:

post "/admission-review/validate", BonnyPlug.WebhookPlug,
  webhook_type: :validating_webhook
  # handlers set at compile time according to config

post "/admission-review/mutate", BonnyPlug.WebhookPlug,
  webhook_type: :mutating_webhook,
  handlers: [MyApp.WebhookHandlers.BarResourceWebhookHandler] # NOT overwritten at compile time!

Link to this section Summary

Link to this section Types

@type webhook_type() :: :validating_webhook | :mutating_webhook

Link to this section Functions

Link to this function

process(arg1, webhook_type, handlers)

View Source
@spec process(map(), atom(), Enum.t()) ::
  {:ok, binary()} | {:error, integer(), binary()}