Module: CommandTower::AdminScope::Resolve

Defined in:
lib/command_tower/admin_scope/resolve.rb

Class Method Summary collapse

Class Method Details

.call(tool_id:, principal:, scope_value:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/command_tower/admin_scope/resolve.rb', line 8

def call(tool_id:, principal:, scope_value:)
  definition = CommandTower.config.registry.admin_workspace.fetch(tool_id)
  return nil unless definition.scope_required?

  token = scope_value.to_s.strip
  if token.empty?
    raise CommandTower::Errors::ForbiddenError
  end

  registration = CommandTower.config.admin_scope.fetch(tool_id)
  valid = registration.validate.call(value: token, principal:)
  unless valid
    raise CommandTower::Errors::ForbiddenError
  end

  ScopeContext.new(
    tool_id: definition.id,
    scope_value: token,
    scope_parameter: definition.scope_parameter
  )
end