Class: Yes::Command::Api::Commands::BatchAuthorizer
- Inherits:
-
Object
- Object
- Yes::Command::Api::Commands::BatchAuthorizer
- Extended by:
- Yes::Core::OpenTelemetry::Trackable
- Defined in:
- lib/yes/command/api/commands/batch_authorizer.rb
Overview
Authorizes a collection of commands using their respective authorizer classes. Raises if any command is not authorized.
Constant Summary collapse
- CommandsNotAuthorized =
Class.new(Yes::Core::Error)
- CommandAuthorizerNotFound =
Class.new(Yes::Core::Error)
Class Method Summary collapse
-
.call(commands, auth_data) ⇒ void
Authorizes the given commands with the provided auth data.
Class Method Details
.call(commands, auth_data) ⇒ void
This method returns an undefined value.
Authorizes the given commands with the provided auth data.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/yes/command/api/commands/batch_authorizer.rb', line 22 def call(commands, auth_data) = [] commands.each do |command| = (command) .call(command, auth_data) rescue CommandAuthorizerNotFound << (command, 'Not allowed').tap do trace_error('Command authorizer not found', { command: command.to_json }) end rescue Yes::Core::Authorization::CommandAuthorizer::CommandNotAuthorized => e << (command, e.).tap do trace_error('Command not authorized', { command: }) end end return unless .any? trace_error('Unauthorized', { unauthorized: .to_json }) raise CommandsNotAuthorized.new(extra: ) end |