foobara 0.0.113 → 0.0.114
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/projects/command/src/transformed_command.rb +11 -17
- data/projects/command_connectors/src/authenticator.rb +22 -4
- data/projects/command_connectors/src/authenticator_selector.rb +29 -0
- data/projects/command_connectors/src/command_connector.rb +17 -2
- data/projects/value/src/processor/selection.rb +15 -4
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a65302dbd9dc22dd5ba53bb011e0f4fab25899634940519e1dbe954ecd7cace
|
4
|
+
data.tar.gz: bb03693721af1e40ec818209d1f32566e72a9152394055d07b93264ce121cf0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3436e3ef29601c86662f913a6ea2d6fd2d6b018e778423703fa0e382b5d19d057425b0e39ddccc0b3273c57a609fff0bd70d02ea776f39ba84563cc171802a97
|
7
|
+
data.tar.gz: bd83c8e7df911f6e5960e956581c6c2de0a9a4c562b76b2ae2e0ef1e70d278764856361ccfd38340b7e428974ac5b532c52a71f0bbcf898b040b553fe298416b
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# [0.0.114] - 2025-05-01
|
2
|
+
|
3
|
+
- Support choosing among multiple processors
|
4
|
+
- Make Authenticator a Processor
|
5
|
+
- Give a way for Processor::Selection to give nil when nothing matches
|
6
|
+
|
1
7
|
# [0.0.113] - 2025-04-25
|
2
8
|
|
3
9
|
- If an inputs transformer fails give relevant error/outcome not an unknown error
|
@@ -217,9 +217,6 @@ module Foobara
|
|
217
217
|
end
|
218
218
|
|
219
219
|
def types_depended_on
|
220
|
-
# Seems to be not necessary?
|
221
|
-
# types = command_class.types_depended_on
|
222
|
-
|
223
220
|
types = Set.new
|
224
221
|
|
225
222
|
# TODO: memoize this
|
@@ -299,18 +296,14 @@ module Foobara
|
|
299
296
|
response_mutators = mutators_to_manifest_symbols(self.response_mutators, to_include:)
|
300
297
|
request_mutators = mutators_to_manifest_symbols(self.request_mutators, to_include:)
|
301
298
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
|
-
inputs_types_depended_on = TypeDeclarations.with_manifest_context(remove_sensitive: false) do
|
299
|
+
authenticator_details = if authenticator
|
300
|
+
{
|
301
|
+
symbol: authenticator.symbol,
|
302
|
+
explanation: authenticator.explanation
|
303
|
+
}
|
304
|
+
end
|
305
|
+
|
306
|
+
inputs_types_depended_on = TypeDeclarations.with_manifest_context(remove_sensitive: false) do
|
314
307
|
self.inputs_types_depended_on.map(&:foobara_manifest_reference).sort
|
315
308
|
end
|
316
309
|
|
@@ -338,7 +331,7 @@ module Foobara
|
|
338
331
|
response_mutators:,
|
339
332
|
request_mutators:,
|
340
333
|
requires_authentication:,
|
341
|
-
authenticator:
|
334
|
+
authenticator: authenticator_details
|
342
335
|
)
|
343
336
|
)
|
344
337
|
end
|
@@ -486,7 +479,8 @@ module Foobara
|
|
486
479
|
end
|
487
480
|
end
|
488
481
|
|
489
|
-
attr_accessor :command, :untransformed_inputs, :transformed_inputs, :outcome, :authenticated_user
|
482
|
+
attr_accessor :command, :untransformed_inputs, :transformed_inputs, :outcome, :authenticated_user,
|
483
|
+
:authenticated_credential
|
490
484
|
|
491
485
|
def initialize(untransformed_inputs = {})
|
492
486
|
self.untransformed_inputs = untransformed_inputs || {}
|
@@ -1,14 +1,32 @@
|
|
1
1
|
module Foobara
|
2
2
|
class CommandConnector
|
3
|
-
|
4
|
-
|
3
|
+
# TODO: should switch to a processor and give errors if the authenticator header is malformed
|
4
|
+
class Authenticator < Value::Transformer
|
5
|
+
attr_reader :block
|
5
6
|
|
6
7
|
def initialize(symbol: nil, explanation: nil, &block)
|
7
8
|
symbol ||= Util.non_full_name_underscore(self.class).to_sym
|
9
|
+
explanation ||= symbol
|
10
|
+
|
11
|
+
super(symbol:, explanation:)
|
8
12
|
|
9
|
-
@symbol = symbol
|
10
13
|
@block = block
|
11
|
-
|
14
|
+
end
|
15
|
+
|
16
|
+
def symbol
|
17
|
+
declaration_data[:symbol]
|
18
|
+
end
|
19
|
+
|
20
|
+
def explanation
|
21
|
+
declaration_data[:explanation]
|
22
|
+
end
|
23
|
+
|
24
|
+
def transform(request)
|
25
|
+
request.instance_exec(&to_proc)
|
26
|
+
end
|
27
|
+
|
28
|
+
def authenticate(request)
|
29
|
+
transform(request)
|
12
30
|
end
|
13
31
|
|
14
32
|
def to_proc
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative "authenticator"
|
2
|
+
|
3
|
+
module Foobara
|
4
|
+
class CommandConnector
|
5
|
+
# TODO: should switch to a processor and give errors if the authenticator header is malformed
|
6
|
+
class AuthenticatorSelector < Authenticator
|
7
|
+
attr_accessor :authenticators
|
8
|
+
|
9
|
+
def initialize(authenticators:, symbol: nil, explanation: nil, &block)
|
10
|
+
self.authenticators = authenticators
|
11
|
+
|
12
|
+
symbol ||= authenticators.map(&:symbol).map(&:to_s).join("_or_").to_sym
|
13
|
+
explanation ||= authenticators.map(&:explanation).join(", or ")
|
14
|
+
|
15
|
+
super(symbol:, explanation:)
|
16
|
+
|
17
|
+
@block = block
|
18
|
+
end
|
19
|
+
|
20
|
+
def selector
|
21
|
+
@selector ||= Value::Processor::Selection.new(processors: authenticators, error_if_none_applicable: false)
|
22
|
+
end
|
23
|
+
|
24
|
+
def authenticate(request)
|
25
|
+
selector.process_value!(request)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -85,6 +85,19 @@ module Foobara
|
|
85
85
|
end
|
86
86
|
|
87
87
|
authenticator
|
88
|
+
when ::Array
|
89
|
+
case object.size
|
90
|
+
when 0
|
91
|
+
# TODO: test this
|
92
|
+
# :nocov:
|
93
|
+
nil
|
94
|
+
# :nocov:
|
95
|
+
when 1
|
96
|
+
to_authenticator(object.first)
|
97
|
+
else
|
98
|
+
authenticators = object.map { |authenticatorish| to_authenticator(authenticatorish) }
|
99
|
+
AuthenticatorSelector.new(authenticators:, symbol:)
|
100
|
+
end
|
88
101
|
else
|
89
102
|
if object.respond_to?(:call)
|
90
103
|
Authenticator.new(symbol:, &object)
|
@@ -403,12 +416,14 @@ module Foobara
|
|
403
416
|
|
404
417
|
def authenticate(request)
|
405
418
|
request_command = request.command
|
406
|
-
|
419
|
+
authenticator = request_command.authenticator || self.authenticator
|
407
420
|
|
408
421
|
request_command.after_load_records do |command:, **|
|
409
|
-
authenticated_user =
|
422
|
+
authenticated_user, authenticated_credential = authenticator.authenticate(request)
|
410
423
|
|
424
|
+
# TODO: why are these on the command instead of the request??
|
411
425
|
request_command.authenticated_user = authenticated_user
|
426
|
+
request_command.authenticated_credential = authenticated_credential
|
412
427
|
|
413
428
|
unless authenticated_user
|
414
429
|
request_command.outcome = Outcome.error(CommandConnector::UnauthenticatedError.new)
|
@@ -16,10 +16,12 @@ module Foobara
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
attr_accessor :enforce_unique
|
19
|
+
attr_accessor :enforce_unique, :error_if_none_applicable
|
20
20
|
|
21
|
-
def initialize(*, enforce_unique: true, **)
|
21
|
+
def initialize(*, enforce_unique: true, error_if_none_applicable: true, **)
|
22
22
|
self.enforce_unique = enforce_unique
|
23
|
+
self.error_if_none_applicable = error_if_none_applicable
|
24
|
+
|
23
25
|
super(*, **)
|
24
26
|
end
|
25
27
|
|
@@ -29,12 +31,19 @@ module Foobara
|
|
29
31
|
|
30
32
|
if outcome.success?
|
31
33
|
processor = outcome.result
|
32
|
-
|
34
|
+
|
35
|
+
unless processor.nil?
|
36
|
+
outcome = processor.process_value(value)
|
37
|
+
end
|
33
38
|
end
|
34
39
|
|
35
40
|
outcome
|
36
41
|
end
|
37
42
|
|
43
|
+
def process_value!(value)
|
44
|
+
process_value(value).result!
|
45
|
+
end
|
46
|
+
|
38
47
|
def processor_for(value)
|
39
48
|
processor = if enforce_unique
|
40
49
|
applicable_processors = processors.select { |p| p.applicable?(value) }
|
@@ -59,8 +68,10 @@ module Foobara
|
|
59
68
|
|
60
69
|
if processor
|
61
70
|
Outcome.success(processor)
|
62
|
-
|
71
|
+
elsif error_if_none_applicable
|
63
72
|
Outcome.error(build_error(value, error_class: NoApplicableProcessorError))
|
73
|
+
else
|
74
|
+
Outcome.success(nil)
|
64
75
|
end
|
65
76
|
end
|
66
77
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foobara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.114
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Georgi
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 2025-05-01 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bigdecimal
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- projects/command/src/transformed_command.rb
|
183
183
|
- projects/command_connectors/lib/foobara/command_connectors.rb
|
184
184
|
- projects/command_connectors/src/authenticator.rb
|
185
|
+
- projects/command_connectors/src/authenticator_selector.rb
|
185
186
|
- projects/command_connectors/src/command_connector.rb
|
186
187
|
- projects/command_connectors/src/command_connector/command_connector_error.rb
|
187
188
|
- projects/command_connectors/src/command_connector/commands/describe.rb
|
@@ -508,7 +509,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
508
509
|
- !ruby/object:Gem::Version
|
509
510
|
version: '0'
|
510
511
|
requirements: []
|
511
|
-
rubygems_version: 3.6.
|
512
|
+
rubygems_version: 3.6.2
|
512
513
|
specification_version: 4
|
513
514
|
summary: A command-centric and discoverable software framework with a focus on domain
|
514
515
|
concepts and abstracting away integration code
|