Class: Legate::Configuration::Webhooks
- Inherits:
-
Object
- Object
- Legate::Configuration::Webhooks
- Defined in:
- lib/legate/configuration/webhooks.rb
Overview
Configuration settings for the inbound webhook listener and processing.
Defined Under Namespace
Classes: RouteConfig
Instance Attribute Summary collapse
-
#base_path ⇒ String
The base path for all webhook routes.
-
#default_session_service ⇒ Legate::SessionService::Base?
The default session service instance to use in the webhook worker.
-
#dynamic_agent_route_pattern ⇒ String
The path pattern for the dynamic agent handler.
-
#enable_dynamic_agent_handler ⇒ Boolean
Whether the dynamic agent handler route is enabled.
-
#global_secret ⇒ String?
The secret key used by the global validator (e.g., for HMAC).
-
#global_validator ⇒ Symbol, ...
A global validator to apply if an agent doesn’t specify one.
-
#listen_address ⇒ String
The IP address the listener should bind to.
-
#listen_port ⇒ Integer
The port the listener should bind to.
-
#listener_enabled ⇒ Boolean
Whether the webhook listener is enabled.
Instance Method Summary collapse
-
#find_validator(name) ⇒ Proc?
Finds a registered validator by name.
-
#initialize ⇒ Webhooks
constructor
A new instance of Webhooks.
-
#register_route(path) {|route_config| ... } ⇒ Object
Registers a static webhook route.
-
#register_validator(name) {|request, secret| ... } ⇒ Object
Registers a named validator proc/lambda.
-
#static_routes ⇒ Hash{String => RouteConfig}
Retrieves the configurations for all registered static routes.
Constructor Details
#initialize ⇒ Webhooks
Returns a new instance of Webhooks.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/legate/configuration/webhooks.rb', line 36 def initialize @listener_enabled = true # Enable listener by default for easier testing/use @listen_address = '127.0.0.1' # Default to loopback for security @listen_port = 9292 @base_path = '/webhooks' @enable_dynamic_agent_handler = true # Enable dynamic handler by default for easier testing @dynamic_agent_route_pattern = '/agents/:agent_name/trigger' @global_validator = nil @global_secret = nil @default_session_service = nil @validators = {} @static_routes = {} # Store static routes: path -> RouteConfig end |
Instance Attribute Details
#base_path ⇒ String
Returns The base path for all webhook routes. Defaults to ‘/webhooks’.
19 20 21 |
# File 'lib/legate/configuration/webhooks.rb', line 19 def base_path @base_path end |
#default_session_service ⇒ Legate::SessionService::Base?
Returns The default session service instance to use in the webhook worker.
34 35 36 |
# File 'lib/legate/configuration/webhooks.rb', line 34 def default_session_service @default_session_service end |
#dynamic_agent_route_pattern ⇒ String
Returns The path pattern for the dynamic agent handler. Defaults to ‘/agents/:agent_name/trigger’.
25 26 27 |
# File 'lib/legate/configuration/webhooks.rb', line 25 def dynamic_agent_route_pattern @dynamic_agent_route_pattern end |
#enable_dynamic_agent_handler ⇒ Boolean
Returns Whether the dynamic agent handler route is enabled. Defaults to false.
22 23 24 |
# File 'lib/legate/configuration/webhooks.rb', line 22 def enable_dynamic_agent_handler @enable_dynamic_agent_handler end |
#global_secret ⇒ String?
Returns The secret key used by the global validator (e.g., for HMAC).
31 32 33 |
# File 'lib/legate/configuration/webhooks.rb', line 31 def global_secret @global_secret end |
#global_validator ⇒ Symbol, ...
Returns A global validator to apply if an agent doesn’t specify one.
28 29 30 |
# File 'lib/legate/configuration/webhooks.rb', line 28 def global_validator @global_validator end |
#listen_address ⇒ String
Returns The IP address the listener should bind to. Defaults to ‘127.0.0.1’.
13 14 15 |
# File 'lib/legate/configuration/webhooks.rb', line 13 def listen_address @listen_address end |
#listen_port ⇒ Integer
Returns The port the listener should bind to. Defaults to 9292.
16 17 18 |
# File 'lib/legate/configuration/webhooks.rb', line 16 def listen_port @listen_port end |
#listener_enabled ⇒ Boolean
Returns Whether the webhook listener is enabled. Defaults to false.
10 11 12 |
# File 'lib/legate/configuration/webhooks.rb', line 10 def listener_enabled @listener_enabled end |
Instance Method Details
#find_validator(name) ⇒ Proc?
Finds a registered validator by name.
69 70 71 |
# File 'lib/legate/configuration/webhooks.rb', line 69 def find_validator(name) @validators[name] end |
#register_route(path) {|route_config| ... } ⇒ Object
Registers a static webhook route. Primarily intended for simple, non-agent-related endpoints like health checks. Agent-related webhooks should typically use the dynamic agent handler.
81 82 83 84 85 86 87 88 |
# File 'lib/legate/configuration/webhooks.rb', line 81 def register_route(path) raise ArgumentError, "Route path \"#{path}\" is already registered." if @static_routes.key?(path) raise ArgumentError, 'Route registration requires a block.' unless block_given? config = RouteConfig.new yield config @static_routes[path] = config end |
#register_validator(name) {|request, secret| ... } ⇒ Object
Registers a named validator proc/lambda.
58 59 60 61 62 63 |
# File 'lib/legate/configuration/webhooks.rb', line 58 def register_validator(name, &block) raise ArgumentError, "Validator name :#{name} is already registered." if @validators.key?(name) raise ArgumentError, 'Validator requires a block.' unless block_given? @validators[name] = block end |
#static_routes ⇒ Hash{String => RouteConfig}
Retrieves the configurations for all registered static routes.
92 93 94 |
# File 'lib/legate/configuration/webhooks.rb', line 92 def static_routes @static_routes.dup # Return a copy to prevent external modification end |