Class: Consyncful::WebhookController

Inherits:
ActionController::API
  • Object
show all
Includes:
ActionController::HttpAuthentication::Basic::ControllerMethods
Defined in:
app/controllers/consyncful/webhook_controller.rb

Overview

The Consyncful::WebhookController is responsible for handling incoming webhook requests that can trigger synchronization jobs within Consyncful.

Features:

  • Only responds to requests if ‘sync_mode` is configured as `:webhook`.

  • Optionally requires HTTP Basic authentication if ‘webhook_authentication_required` is enabled in configuration.

  • Exposes a single endpoint (‘trigger_sync`) that signals a sync process through `Consyncful::Sync.signal_webhook!`.

Security:

  • Uses ‘ActionController::HttpAuthentication::Basic` to enforce authentication when enabled.

  • Compares provided credentials with configured values using ‘ActiveSupport::SecurityUtils.secure_compare` to prevent timing attacks.

Responses:

  • Returns ‘404 Not Found` if webhooks are not enabled.

  • Returns ‘202 Accepted` after signaling a sync.

Instance Method Summary collapse

Instance Method Details

#trigger_syncObject



27
28
29
30
31
32
# File 'app/controllers/consyncful/webhook_controller.rb', line 27

def trigger_sync
  return head :not_found unless use_webhooks?

  Consyncful::Sync.signal_webhook!
  head :accepted
end