Class: Legate::Configuration::Webhooks

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeWebhooks

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_pathString

Returns The base path for all webhook routes. Defaults to ‘/webhooks’.

Returns:

  • (String)

    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_serviceLegate::SessionService::Base?

Returns The default session service instance to use in the webhook worker.

Returns:



34
35
36
# File 'lib/legate/configuration/webhooks.rb', line 34

def default_session_service
  @default_session_service
end

#dynamic_agent_route_patternString

Returns The path pattern for the dynamic agent handler. Defaults to ‘/agents/:agent_name/trigger’.

Returns:

  • (String)

    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_handlerBoolean

Returns Whether the dynamic agent handler route is enabled. Defaults to false.

Returns:

  • (Boolean)

    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_secretString?

Returns The secret key used by the global validator (e.g., for HMAC).

Returns:

  • (String, nil)

    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_validatorSymbol, ...

Returns A global validator to apply if an agent doesn’t specify one.

Returns:

  • (Symbol, Proc, nil)

    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_addressString

Returns The IP address the listener should bind to. Defaults to ‘127.0.0.1’.

Returns:

  • (String)

    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_portInteger

Returns The port the listener should bind to. Defaults to 9292.

Returns:

  • (Integer)

    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_enabledBoolean

Returns Whether the webhook listener is enabled. Defaults to false.

Returns:

  • (Boolean)

    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.

Parameters:

  • name (Symbol)

    The name of the validator.

Returns:

  • (Proc, nil)

    The validator proc or nil if not found.



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.

Parameters:

  • path (String)

    The HTTP method and path pattern (e.g., “GET /system/health”, “POST /simple”).

Yields:

  • (route_config)

    The block to configure the route.

Yield Parameters:

  • route_config (RouteConfig)

    The configuration object for this route.

Raises:

  • (ArgumentError)

    If the path is already registered or no block is given.



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.

Parameters:

  • name (Symbol)

    The name to register the validator under.

Yields:

  • (request, secret)

    The block that performs validation.

Yield Parameters:

  • request

    The Rack request object.

  • secret (String, nil)

    The secret associated with the route/agent.

Yield Returns:

  • (Boolean)

    True if the request is valid, false otherwise.

Raises:

  • (ArgumentError)

    If the name is already registered or no block is given.



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_routesHash{String => RouteConfig}

Retrieves the configurations for all registered static routes.

Returns:

  • (Hash{String => RouteConfig})

    A hash mapping path patterns to their configurations.



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