Class: Axn::Webhooks::Outbound::DSL
- Inherits:
-
Object
- Object
- Axn::Webhooks::Outbound::DSL
- Defined in:
- lib/axn/webhooks/outbound/dsl.rb
Overview
Receiver for the Axn::Webhooks.outbound do … end block.
Instance Method Summary collapse
-
#__config__ ⇒ Object
Internal: build the resolved Config, validating declarations.
-
#allow_url(callable = UNSET, &block) ⇒ Object
A general escape hatch alongside
allowed_hosts-- called with the parsed URI, must return truthy to allow the target through. -
#allowed_hosts(*values) ⇒ Object
A host policy for resolved targets (both a static
to:Array and a runtimesubscribers/to:lambda's return value go through the same check) -- see TargetPolicy for exact matching semantics. - #backoff(callable = nil, &block) ⇒ Object
-
#event(name, to: nil, type: nil, vendor: nil) ⇒ Object
rubocop:disable-next Naming/MethodParameterName.
-
#headers(callable = UNSET, &block) ⇒ Object
Per-destination extra headers (e.g. a subscriber's bearer token) -- resolved fresh per DELIVERY ATTEMPT from the Subscriber, never stored, same convention
sign'ssecret:follows. -
#initialize ⇒ DSL
constructor
A new instance of DSL.
- #max_attempts(value) ⇒ Object
- #sign(strategy = nil, **opts, &block) ⇒ Object
- #subscribers(resolver = nil, &block) ⇒ Object
- #timeouts(open: nil, read: nil) ⇒ Object
- #transport(obj) ⇒ Object
-
#user_agent(value = nil, &block) ⇒ Object
A suffix identifying the sending app/deploy, appended to the fixed "axn-webhooks/
" User-Agent as "axn-webhooks/ ( )". -
#vendor(value) ⇒ Object
The observability facet (Axn::Webhooks.config.vendor_facet) stamped on every Emit/Deliver for events with no per-event override — see
event'svendor:.
Constructor Details
#initialize ⇒ DSL
Returns a new instance of DSL.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/axn/webhooks/outbound/dsl.rb', line 17 def initialize @events = {} @sign_spec = nil @default_subscribers = nil @max_attempts = nil @backoff = nil @transport = nil @vendor = nil @user_agent = nil @open_timeout = nil @read_timeout = nil @allowed_hosts = nil @allow_url = nil @headers = nil end |
Instance Method Details
#__config__ ⇒ Object
Internal: build the resolved Config, validating declarations.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/axn/webhooks/outbound/dsl.rb', line 80 def __config__ # A pure declaration mistake (decided once at boot, never at runtime) — ArgumentError, not # Axn::Webhooks::Error, matching Config's own misconfiguration-vs-runtime split. raise ArgumentError, "outbound block must declare `sign`" if @sign_spec.nil? @events.each do |name, spec| next unless spec[:to].is_a?(Array) && spec[:to].empty? Axn.config.logger.warn("[axn-webhooks] outbound event #{name.inspect} declares an empty `to:` — it will deliver nowhere") end Config.new( signer: Signer.build(**@sign_spec), events: @events, default_subscribers: @default_subscribers, max_attempts: @max_attempts, backoff: @backoff, transport: @transport, vendor: @vendor, user_agent: @user_agent, open_timeout: @open_timeout, read_timeout: @read_timeout, allowed_hosts: @allowed_hosts, allow_url: @allow_url, headers: @headers, ) end |
#allow_url(callable = UNSET, &block) ⇒ Object
A general escape hatch alongside allowed_hosts -- called with the parsed URI, must
return truthy to allow the target through. Both nil by default (no host policy at all).
67 |
# File 'lib/axn/webhooks/outbound/dsl.rb', line 67 def allow_url(callable = UNSET, &block) = @allow_url = resolve_settable(callable, block) |
#allowed_hosts(*values) ⇒ Object
A host policy for resolved targets (both a static to: Array and a runtime
subscribers/to: lambda's return value go through the same check) -- see TargetPolicy
for exact matching semantics. Splat-friendly: allowed_hosts "a.example", "b.example" and
allowed_hosts %w[a.example b.example] both work.
63 |
# File 'lib/axn/webhooks/outbound/dsl.rb', line 63 def allowed_hosts(*values) = @allowed_hosts = values.flatten |
#backoff(callable = nil, &block) ⇒ Object
42 |
# File 'lib/axn/webhooks/outbound/dsl.rb', line 42 def backoff(callable = nil, &block) = @backoff = callable || block |
#event(name, to: nil, type: nil, vendor: nil) ⇒ Object
rubocop:disable-next Naming/MethodParameterName
75 76 77 |
# File 'lib/axn/webhooks/outbound/dsl.rb', line 75 def event(name, to: nil, type: nil, vendor: nil) @events[name.to_sym] = { to:, type:, vendor: } end |
#headers(callable = UNSET, &block) ⇒ Object
Per-destination extra headers (e.g. a subscriber's bearer token) -- resolved fresh per
DELIVERY ATTEMPT from the Subscriber, never stored, same convention sign's secret:
follows. 0-arity (ignores the subscriber) or 1-arity (receives it). nil by default.
72 |
# File 'lib/axn/webhooks/outbound/dsl.rb', line 72 def headers(callable = UNSET, &block) = @headers = resolve_settable(callable, block) |
#max_attempts(value) ⇒ Object
41 |
# File 'lib/axn/webhooks/outbound/dsl.rb', line 41 def max_attempts(value) = @max_attempts = value |
#sign(strategy = nil, **opts, &block) ⇒ Object
33 34 35 |
# File 'lib/axn/webhooks/outbound/dsl.rb', line 33 def sign(strategy = nil, **opts, &block) @sign_spec = { strategy:, opts:, block: } end |
#subscribers(resolver = nil, &block) ⇒ Object
37 38 39 |
# File 'lib/axn/webhooks/outbound/dsl.rb', line 37 def subscribers(resolver = nil, &block) @default_subscribers = resolver || block end |
#timeouts(open: nil, read: nil) ⇒ Object
54 55 56 57 |
# File 'lib/axn/webhooks/outbound/dsl.rb', line 54 def timeouts(open: nil, read: nil) @open_timeout = open @read_timeout = read end |
#transport(obj) ⇒ Object
43 |
# File 'lib/axn/webhooks/outbound/dsl.rb', line 43 def transport(obj) = @transport = obj |
#user_agent(value = nil, &block) ⇒ Object
A suffix identifying the sending app/deploy, appended to the fixed
"axn-webhooks/
52 |
# File 'lib/axn/webhooks/outbound/dsl.rb', line 52 def user_agent(value = nil, &block) = @user_agent = value || block |
#vendor(value) ⇒ Object
The observability facet (Axn::Webhooks.config.vendor_facet) stamped on every Emit/Deliver
for events with no per-event override — see event's vendor:.
47 |
# File 'lib/axn/webhooks/outbound/dsl.rb', line 47 def vendor(value) = @vendor = value |