foobara 0.0.113 → 0.0.115

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6311b48e0b7d0f27986d0536f437d60db1409f9a71c36cfc5858f3637b37629d
4
- data.tar.gz: e4e057f18a757133d17cd938275aa6c93a97e6ab03ea207a1eca603ed25f1866
3
+ metadata.gz: 94baacc7205e4b750c59df65dede92b2c95f15053144ba8d8324c81eb80da770
4
+ data.tar.gz: 696db0d2d875c8f2c40ed9d916019518c3f2ffcc0829015a0333109c83a1e8ef
5
5
  SHA512:
6
- metadata.gz: b48c048cbe4e4c4905222c6564b44842809a160ed07b523ef2a4c9833fc29bcf1b1024729d1431833aa363d0839c41b808b4a09302e070dcca13358a98212327
7
- data.tar.gz: 761e37c588eef4370fe0884250a6e824083c2c420864cbeb2ebf268340ca1beee2410d1e68ea4cef10d69953f633ae0785d9eaa72f6e9c9727705ecfc2a4ce32
6
+ metadata.gz: 5b5cd5e50eee5c8f652d24107027eaf9115128742b57f8964010667d0e12da2a5bc1087d87870c507c9bd0cc6016eaa0248e9707d567c96c4193794863bebb6a
7
+ data.tar.gz: 356150abc278d32b253ddc08ed1f4932ac4432a25f9ed4797518191b9a86fc01c06986df8e314aa5a6fc64b44441adc89946a6b6f49daac42d424a73d41e2589
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # [0.0.115] - 2025-05-01
2
+
3
+ - Make sure Authenticator#authenticate hits #applicable?
4
+
5
+ # [0.0.114] - 2025-05-01
6
+
7
+ - Support choosing among multiple processors
8
+ - Make Authenticator a Processor
9
+ - Give a way for Processor::Selection to give nil when nothing matches
10
+
1
11
  # [0.0.113] - 2025-04-25
2
12
 
3
13
  - 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
- authenticator_manifest = if authenticator
303
- if authenticator.respond_to?(:foobara_manifest)
304
- # TODO: test this path
305
- # :nocov:
306
- authenticator.foobara_manifest
307
- # :nocov:
308
- else
309
- true
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: authenticator_manifest
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
- class Authenticator
4
- attr_reader :block, :explanation, :symbol
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
- @explanation = explanation || symbol
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
+ process_value!(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
- auth_block = request_command.authenticator || authenticator
419
+ authenticator = request_command.authenticator || self.authenticator
407
420
 
408
421
  request_command.after_load_records do |command:, **|
409
- authenticated_user = request.instance_exec(&auth_block)
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
- outcome = processor.process_value(value)
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
- else
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.113
4
+ version: 0.0.115
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
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.8
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