foobara 0.0.9 → 0.0.11
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 +8 -0
- data/LICENSE-MPL-2.0.txt +373 -0
- data/LICENSE.txt +6 -2
- data/README.md +1 -8
- data/projects/command/src/transformed_command.rb +2 -2
- data/projects/command_connectors/lib/foobara/command_connectors.rb +1 -1
- data/projects/command_connectors/src/{commands → command_connector/commands}/describe.rb +2 -6
- data/projects/command_connectors/src/{commands → command_connector/commands}/list_commands.rb +1 -1
- data/projects/command_connectors/src/{commands → command_connector/commands}/ping.rb +1 -1
- data/projects/command_connectors/src/{commands → command_connector/commands}/query_git_commit_info.rb +1 -1
- data/projects/command_connectors/src/{request.rb → command_connector/request.rb} +24 -13
- data/projects/command_connectors/src/{response.rb → command_connector/response.rb} +1 -1
- data/projects/command_connectors/src/command_connector.rb +29 -20
- data/projects/domain/src/domain_module_extension.rb +2 -0
- data/projects/domain/src/module_extension.rb +2 -2
- metadata +11 -39
- data/LICENSE-AGPL.txt +0 -666
- data/projects/command_connectors_http/lib/foobara/command_connectors_http.rb +0 -6
- data/projects/command_connectors_http/src/http/commands/get_options.rb +0 -16
- data/projects/command_connectors_http/src/http/commands/help/presenter/command.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/domain.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/entity.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/error.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/model.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/organization.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/processor.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/processor_class.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/root.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter/type.rb +0 -14
- data/projects/command_connectors_http/src/http/commands/help/presenter.rb +0 -178
- data/projects/command_connectors_http/src/http/commands/help/templates/command.html.erb +0 -11
- data/projects/command_connectors_http/src/http/commands/help/templates/domain.html.erb +0 -1
- data/projects/command_connectors_http/src/http/commands/help/templates/entity.html.erb +0 -11
- data/projects/command_connectors_http/src/http/commands/help/templates/error.html.erb +0 -1
- data/projects/command_connectors_http/src/http/commands/help/templates/model.html.erb +0 -8
- data/projects/command_connectors_http/src/http/commands/help/templates/organization.html.erb +0 -1
- data/projects/command_connectors_http/src/http/commands/help/templates/processor.html.erb +0 -1
- data/projects/command_connectors_http/src/http/commands/help/templates/processor_class.html.erb +0 -1
- data/projects/command_connectors_http/src/http/commands/help/templates/root.html.erb +0 -3
- data/projects/command_connectors_http/src/http/commands/help/templates/type.html.erb +0 -1
- data/projects/command_connectors_http/src/http/commands/help.rb +0 -98
- data/projects/command_connectors_http/src/http/request.rb +0 -98
- data/projects/command_connectors_http/src/http/response.rb +0 -14
- data/projects/command_connectors_http/src/http.rb +0 -93
@@ -1,93 +0,0 @@
|
|
1
|
-
module Foobara
|
2
|
-
module CommandConnectors
|
3
|
-
class Http < CommandConnector
|
4
|
-
include TruncatedInspect
|
5
|
-
|
6
|
-
def request_to_command(context)
|
7
|
-
if context.method == "OPTIONS"
|
8
|
-
# TODO: this feels a bit hacky and like overkill...
|
9
|
-
return Foobara::CommandConnectors::Http::Commands::GetOptions.new
|
10
|
-
end
|
11
|
-
|
12
|
-
command = super
|
13
|
-
|
14
|
-
if context.action == "help"
|
15
|
-
# Let's unwrap the transformed command to avoid serialization
|
16
|
-
# TODO: maybe instead register Help without serializers?
|
17
|
-
command = command.command
|
18
|
-
end
|
19
|
-
|
20
|
-
command
|
21
|
-
end
|
22
|
-
|
23
|
-
# TODO: eliminate passing the command here...
|
24
|
-
def request_to_response(request)
|
25
|
-
command = request.command
|
26
|
-
outcome = command.outcome
|
27
|
-
|
28
|
-
# TODO: feels awkward to call this here... Maybe use result/errors transformers instead??
|
29
|
-
# Or call the serializer here??
|
30
|
-
body = command.respond_to?(:serialize_result) ? command.serialize_result : outcome.result
|
31
|
-
|
32
|
-
status = if outcome.success?
|
33
|
-
200
|
34
|
-
else
|
35
|
-
errors = outcome.errors
|
36
|
-
|
37
|
-
if errors.size == 1
|
38
|
-
error = errors.first
|
39
|
-
|
40
|
-
case error
|
41
|
-
when CommandConnector::UnknownError
|
42
|
-
500
|
43
|
-
when CommandConnector::NotFoundError, Foobara::Entity::NotFoundError
|
44
|
-
# TODO: we should not be coupled to Entities here...
|
45
|
-
body ||= "Not found"
|
46
|
-
404
|
47
|
-
when CommandConnector::UnauthenticatedError
|
48
|
-
401
|
49
|
-
when CommandConnector::NotAllowedError
|
50
|
-
403
|
51
|
-
end
|
52
|
-
end || 422
|
53
|
-
end
|
54
|
-
|
55
|
-
headers = headers_for(request)
|
56
|
-
|
57
|
-
Response.new(status:, headers:, body:, request:)
|
58
|
-
end
|
59
|
-
|
60
|
-
def headers_for(request)
|
61
|
-
response_headers = request.response_headers
|
62
|
-
|
63
|
-
if response_headers.nil? || !response_headers.key?("content-type")
|
64
|
-
if request.command.respond_to?(:serialize_result)
|
65
|
-
# TODO: we should ask the request this not the command.
|
66
|
-
if request.command.serializers.include?(Serializers::JsonSerializer)
|
67
|
-
response_headers = (response_headers || {}).merge("content-type" => "application/json")
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
if response_headers
|
73
|
-
static_headers.merge(response_headers)
|
74
|
-
else
|
75
|
-
static_headers.dup
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
private
|
80
|
-
|
81
|
-
def static_headers
|
82
|
-
@static_headers ||= ENV.each_with_object({}) do |(key, value), headers|
|
83
|
-
match = key.match(/\AFOOBARA_HTTP_RESPONSE_HEADER_(.*)\z/)
|
84
|
-
|
85
|
-
if match
|
86
|
-
header_name = match[1].downcase.tr("_", "-")
|
87
|
-
headers[header_name] = value
|
88
|
-
end
|
89
|
-
end.freeze
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|