foobara-http-command-connector 0.0.18 → 0.0.20

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: bf60ac4b2586bf6a354520e1f5628d5d15553c8d1b77c5928ccf9c2dc19d3ba8
4
- data.tar.gz: a86337c5edea3aff592f62cb756afac76e84fd7cce39b41f8b6bfc0b74a728e6
3
+ metadata.gz: 84f98d62ccf5d4607dfa7fcec72c146783afdcaf05fea4c6a783886d51a76446
4
+ data.tar.gz: d5d43e938ff41147061148b8fdac2bc15f54dfa8303f3b3225079d49d880d200
5
5
  SHA512:
6
- metadata.gz: 7ba72c2c08688e6b08aeb76f9fcf4fe0c28f4c727093d051383f907999cedd64c773e70329079698cbbd4cbfdc390d9a27c1c73db8fd20ff2a4ba18cb252fbd3
7
- data.tar.gz: fd2142b3f17b81148a9db464d761bb0a97368fdaaf421fd3392063e84aa4b919b6dbbd2a66089abbc1a66f0de444de5f65f521db67b50d2edee9c715e78924e8
6
+ metadata.gz: 40d905a7991b607b9b1dae7604969cb1eb40f357c1850bc743f2200a27badce71d6fc76d13680c348216047ec3c67587e83f23730657319839301c5c536e82bc
7
+ data.tar.gz: 3a81ef2395e42ad2027b86d5e21651b3e9ba95db4be779964d0a954e025336a67bb01ac0aa91ab539d58076dcbd2663bdc5196cf10c177849f252bffed462f81
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.0.20] - 2025-04-14
2
+
3
+ - Handle more cors scenarios
4
+
5
+ ## [0.0.19] - 2025-03-31
6
+
7
+ - Add SetHeader response mutator
8
+ - Use / instead of :: for paths
9
+
1
10
  ## [0.0.18] - 2025-03-29
2
11
 
3
12
  - Implement SetInputsFromHeader request mutator and MoveAttributeToHeader response mutator
@@ -14,7 +14,7 @@ module Foobara
14
14
  end
15
15
 
16
16
  def in_detached_context(&)
17
- Thread.foobara_with_var("foobara_manifest_context", detached: true, &)
17
+ TypeDeclarations.with_manifest_context(detached: true, &)
18
18
  end
19
19
 
20
20
  def build_manifest
@@ -4,11 +4,49 @@ module Foobara
4
4
  module Commands
5
5
  # TODO: this is a bit of a hack, just a total no-op... shouldn't really need this command at all ideally
6
6
  class GetOptions < Foobara::Command
7
+ inputs do
8
+ request :duck, :required
9
+ end
7
10
  result :string
8
11
 
9
12
  def execute
13
+ initialize_response_headers
14
+
15
+ set_allow_methods
16
+ set_allow_headers
17
+ set_access_control_max_age
18
+
19
+ # TODO: what's with this empty string?
10
20
  ""
11
21
  end
22
+
23
+ def initialize_response_headers
24
+ request.response_headers ||= {}
25
+ end
26
+
27
+ def set_allow_methods
28
+ allow_methods = ENV.fetch("FOOBARA_HTTP_RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_METHODS", nil)
29
+ if allow_methods
30
+ request.response_headers["access-control-allow-methods"] = allow_methods
31
+ end
32
+ end
33
+
34
+ def set_allow_headers
35
+ allow_headers = ENV.fetch("FOOBARA_HTTP_RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_HEADERS", nil)
36
+ if allow_headers
37
+ if allow_headers == "*"
38
+ allow_headers = request.headers["HTTP_ACCESS_CONTROL_REQUEST_HEADERS"]
39
+ end
40
+ request.response_headers["access-control-allow-headers"] = allow_headers
41
+ end
42
+ end
43
+
44
+ def set_access_control_max_age
45
+ access_control_max_age = ENV.fetch("FOOBARA_HTTP_RESPONSE_HEADER_ACCESS_CONTROL_MAX_AGE", nil)
46
+ if access_control_max_age
47
+ request.response_headers["access-control-max-age"] = access_control_max_age
48
+ end
49
+ end
12
50
  end
13
51
  end
14
52
  end
data/src/http/request.rb CHANGED
@@ -93,7 +93,9 @@ module Foobara
93
93
  end
94
94
 
95
95
  def set_action_and_command_name
96
- @action, @full_command_name = prefixless_path[1..].split("/")
96
+ @action, *full_command_name = prefixless_path[1..].split("/")
97
+
98
+ @full_command_name = full_command_name.join("::").gsub("/", "::")
97
99
  end
98
100
 
99
101
  def prefixless_path
@@ -0,0 +1,38 @@
1
+ module Foobara
2
+ module CommandConnectors
3
+ class Http < CommandConnector
4
+ class SetHeader < ResponseMutator
5
+ class << self
6
+ attr_accessor :header_name, :header_value
7
+
8
+ def for(header_name, header_value)
9
+ subclass = Class.new(self)
10
+
11
+ subclass.header_name = header_name
12
+ subclass.header_value = header_value
13
+
14
+ subclass
15
+ end
16
+ end
17
+
18
+ attr_writer :header_name, :header_value
19
+
20
+ def result_type_from(result_type)
21
+ result_type
22
+ end
23
+
24
+ def mutate(response)
25
+ response.add_header(header_name.to_s, header_value)
26
+ end
27
+
28
+ def header_name
29
+ @header_name ||= self.class.header_name
30
+ end
31
+
32
+ def header_value
33
+ @header_value ||= self.class.header_value
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
data/src/http.rb CHANGED
@@ -60,13 +60,11 @@ module Foobara
60
60
 
61
61
  def request_to_command(request)
62
62
  if request.method == "OPTIONS"
63
- # TODO: this feels a bit hacky and like overkill...
64
- return Foobara::CommandConnectors::Http::Commands::GetOptions.new
63
+ return Foobara::CommandConnectors::Http::Commands::GetOptions.new(request:)
65
64
  end
66
65
 
67
66
  command = super
68
67
 
69
- # TODO: We should kill these case statements and require connecting these commands
70
68
  if request.action == "help"
71
69
  command.class.serializers = [Commands::Help::ResultSerializer]
72
70
  end
@@ -136,6 +134,12 @@ module Foobara
136
134
 
137
135
  def static_headers
138
136
  @static_headers ||= ENV.each_with_object({}) do |(key, value), headers|
137
+ next if %w[
138
+ FOOBARA_HTTP_RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_HEADERS
139
+ FOOBARA_HTTP_RESPONSE_HEADER_ACCESS_CONTROL_ALLOW_METHODS
140
+ FOOBARA_HTTP_RESPONSE_HEADER_ACCESS_CONTROL_MAX_AGE
141
+ ].include?(key)
142
+
139
143
  match = key.match(/\AFOOBARA_HTTP_RESPONSE_HEADER_(.*)\z/)
140
144
 
141
145
  if match
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-http-command-connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-30 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: foobara
@@ -70,6 +70,7 @@ files:
70
70
  - src/http/response.rb
71
71
  - src/http/response_mutators/move_attribute_to_cookie.rb
72
72
  - src/http/response_mutators/move_attribute_to_header.rb
73
+ - src/http/response_mutators/set_header.rb
73
74
  homepage: https://github.com/foobara/http-command-connector
74
75
  licenses:
75
76
  - Apache-2.0
@@ -93,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
94
  - !ruby/object:Gem::Version
94
95
  version: '0'
95
96
  requirements: []
96
- rubygems_version: 3.6.6
97
+ rubygems_version: 3.6.7
97
98
  specification_version: 4
98
99
  summary: No description. Add one.
99
100
  test_files: []