Module: Reeve::Authorization::Current

Defined in:
lib/reeve/authorization/current.rb

Overview

The invocation in progress on this thread.

scoped(Model) is called from inside a tool body, which has no reference to the envelope, so the envelope's caller publishes the state here and clears it in an ensure. Fiber-local storage (Thread#[]) rather than thread-global, so concurrent invocations — the normal case for an MCP server — cannot see each other's principal.

Defined Under Namespace

Classes: State

Constant Summary collapse

KEY =
:reeve_current_invocation

Class Method Summary collapse

Class Method Details

.active?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/reeve/authorization/current.rb', line 38

def active?
  !state.nil?
end

.finish(previous = nil) ⇒ Object



27
28
29
# File 'lib/reeve/authorization/current.rb', line 27

def finish(previous = nil)
  Thread.current[KEY] = previous
end

.start(context:, declaration:, adapter:) ⇒ Object



20
21
22
23
24
25
# File 'lib/reeve/authorization/current.rb', line 20

def start(context:, declaration:, adapter:)
  previous = state
  Thread.current[KEY] =
    State.new(context: context, declaration: declaration, adapter: adapter)
  previous
end

.stateObject



16
17
18
# File 'lib/reeve/authorization/current.rb', line 16

def state
  Thread.current[KEY]
end

.with(context:, declaration:, adapter:) ⇒ Object



31
32
33
34
35
36
# File 'lib/reeve/authorization/current.rb', line 31

def with(context:, declaration:, adapter:)
  previous = start(context: context, declaration: declaration, adapter: adapter)
  yield(state)
ensure
  finish(previous)
end