foobara 0.4.2 → 0.4.3
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 +4 -0
- data/projects/command_connectors/spec/command_connector_spec.rb +2 -1
- data/projects/command_connectors/spec/request_spec.rb +23 -0
- data/projects/command_connectors/src/command_connector/request.rb +20 -11
- data/projects/command_connectors/src/command_connector.rb +10 -1
- data/projects/typesystem/projects/type_declarations/src/typed_transformer.rb +8 -1
- data/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: db631f3175aa83feaee1a634560a7086c24e3c46b5c7df0b0a958252b531a377
|
|
4
|
+
data.tar.gz: 479a5728d5c86fdb689841d8cb422c564330d55a0502acbe3a32c27891573694
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: de898a650ff1066c7eb4ac304050a77c3a08bbf075bca85e7cf22c448a1ea3a1f128dd8cec36356a0cf1cae7a2590b3a98f547090f94b43674808b62c4178009
|
|
7
|
+
data.tar.gz: 6d900e6391ebd970950e43c42b106cbc0595480e14c7c594f90ed7be564234235f242b1824117cdc41975056e55763b854acfa4f6e412f02e6371e2b779a44d6
|
data/CHANGELOG.md
CHANGED
|
@@ -2201,7 +2201,8 @@ RSpec.describe Foobara::CommandConnector do
|
|
|
2201
2201
|
command_connector_b.connect(command_class, :auth)
|
|
2202
2202
|
command_connector_c.connect(command_class, requires_authentication: true)
|
|
2203
2203
|
command_connector_d.connect(command_class, requires_authentication: true)
|
|
2204
|
-
command_connector_e.connect(command_class, requires_authentication: true,
|
|
2204
|
+
command_connector_e.connect(command_class, requires_authentication: true,
|
|
2205
|
+
authenticator: [authenticator_e])
|
|
2205
2206
|
|
|
2206
2207
|
response = command_connector_a.run(full_command_name:, action:, inputs:)
|
|
2207
2208
|
expect(response.status).to be(0)
|
|
@@ -92,4 +92,27 @@ RSpec.describe Foobara::CommandConnector::Request do
|
|
|
92
92
|
end
|
|
93
93
|
end
|
|
94
94
|
end
|
|
95
|
+
|
|
96
|
+
context "with an auth-mapped method" do
|
|
97
|
+
let(:command_class) do
|
|
98
|
+
stub_class("SomeCommand", Foobara::Command) do
|
|
99
|
+
def self.requires_authentication = true
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
let(:request) do
|
|
104
|
+
foo_mapper = Foobara::TypeDeclarations::TypedTransformer.subclass(to: :symbol) { :bar }.instance
|
|
105
|
+
# TODO: make a block form of this
|
|
106
|
+
authenticator = Foobara::CommandConnector.to_authenticator(-> { :some_user })
|
|
107
|
+
|
|
108
|
+
described_class.new(authenticator:, auth_mappers: { foo: foo_mapper }).tap do |request|
|
|
109
|
+
request.command_class = command_class
|
|
110
|
+
request.authenticate
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it "can access the auth-mapped method" do
|
|
115
|
+
expect(request.foo).to eq(:bar)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
95
118
|
end
|
|
@@ -16,10 +16,12 @@ module Foobara
|
|
|
16
16
|
:action,
|
|
17
17
|
:response,
|
|
18
18
|
:authenticated_user,
|
|
19
|
-
:authenticated_credential
|
|
19
|
+
:authenticated_credential,
|
|
20
|
+
:auth_mappers,
|
|
21
|
+
:authenticator
|
|
20
22
|
|
|
21
23
|
def initialize(**opts)
|
|
22
|
-
valid_keys = [:inputs, :full_command_name, :action, :serializers]
|
|
24
|
+
valid_keys = [:inputs, :full_command_name, :action, :serializers, :authenticator, :auth_mappers]
|
|
23
25
|
|
|
24
26
|
invalid_keys = opts.keys - valid_keys
|
|
25
27
|
|
|
@@ -31,6 +33,8 @@ module Foobara
|
|
|
31
33
|
|
|
32
34
|
self.inputs = opts[:inputs] if opts.key?(:inputs)
|
|
33
35
|
self.action = opts[:action] if opts.key?(:action)
|
|
36
|
+
self.auth_mappers = opts[:auth_mappers] if opts.key?(:auth_mappers)
|
|
37
|
+
self.authenticator = opts[:authenticator] if opts.key?(:authenticator)
|
|
34
38
|
self.full_command_name = opts[:full_command_name] if opts.key?(:full_command_name)
|
|
35
39
|
self.serializers = Util.array(opts[:serializers]) if opts.key?(:serializers)
|
|
36
40
|
end
|
|
@@ -59,15 +63,6 @@ module Foobara
|
|
|
59
63
|
end
|
|
60
64
|
end
|
|
61
65
|
|
|
62
|
-
def authenticator
|
|
63
|
-
command_class.authenticator
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def auth_mappers
|
|
67
|
-
# TODO: make this consistent?
|
|
68
|
-
command_connector.auth_map
|
|
69
|
-
end
|
|
70
|
-
|
|
71
66
|
def auth_mapped_method?(method_name)
|
|
72
67
|
auth_mappers&.key?(method_name)
|
|
73
68
|
end
|
|
@@ -88,6 +83,20 @@ module Foobara
|
|
|
88
83
|
end
|
|
89
84
|
end
|
|
90
85
|
|
|
86
|
+
def method_missing(method_name, ...)
|
|
87
|
+
if auth_mapped_method?(method_name)
|
|
88
|
+
auth_mapped_value_for(method_name)
|
|
89
|
+
else
|
|
90
|
+
# :nocov:
|
|
91
|
+
super
|
|
92
|
+
# :nocov:
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def respond_to_missing?(method_name, private = false)
|
|
97
|
+
auth_mapped_method?(method_name) || super
|
|
98
|
+
end
|
|
99
|
+
|
|
91
100
|
def serializer
|
|
92
101
|
return @serializer if defined?(@serializer)
|
|
93
102
|
|
|
@@ -206,6 +206,7 @@ module Foobara
|
|
|
206
206
|
|
|
207
207
|
self.authenticator = authenticator
|
|
208
208
|
self.command_registry = CommandRegistry.new(authenticator:)
|
|
209
|
+
|
|
209
210
|
self.capture_unknown_error = capture_unknown_error
|
|
210
211
|
self.name = name
|
|
211
212
|
|
|
@@ -556,7 +557,7 @@ module Foobara
|
|
|
556
557
|
|
|
557
558
|
def build_request(...)
|
|
558
559
|
self.class::Request.new(...).tap do |request|
|
|
559
|
-
# TODO: feels like a smell
|
|
560
|
+
# TODO: feels like a smell? Can we deprecate this somehow? Request no longer calls command_connector it seems...
|
|
560
561
|
request.command_connector = self
|
|
561
562
|
end
|
|
562
563
|
end
|
|
@@ -566,6 +567,14 @@ module Foobara
|
|
|
566
567
|
command_class = determine_command_class(request)
|
|
567
568
|
request.command_class = command_class
|
|
568
569
|
|
|
570
|
+
if command_class.respond_to?(:requires_authentication) && command_class.requires_authentication
|
|
571
|
+
request.authenticator ||= command_class.authenticator || authenticator
|
|
572
|
+
|
|
573
|
+
if auth_map
|
|
574
|
+
request.auth_mappers ||= auth_map
|
|
575
|
+
end
|
|
576
|
+
end
|
|
577
|
+
|
|
569
578
|
return build_response(request) unless command_class
|
|
570
579
|
|
|
571
580
|
begin
|
|
@@ -9,7 +9,14 @@ module Foobara
|
|
|
9
9
|
|
|
10
10
|
klass.to(to) if to
|
|
11
11
|
klass.from(from) if from
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
if map_proc
|
|
14
|
+
if map_proc.arity.zero?
|
|
15
|
+
klass.define_method(:transform) { |_ignored| map_proc.call }
|
|
16
|
+
else
|
|
17
|
+
klass.define_method(:transform, &map_proc)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
13
20
|
|
|
14
21
|
klass
|
|
15
22
|
end
|
data/version.rb
CHANGED