fuik 0.13.0 → 0.14.0

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: 7e63ae360a189d38134db206274a5733ad73ea37ae2b338686c952df7ac3c109
4
- data.tar.gz: c59410136f9c4143690b96b496c3e83fdf0419d806cc308a5ab4e73c1c1b21fb
3
+ metadata.gz: 0c28fbd74f30e65da8686f95d2f79fb4633a0bc5a8016eceb9a9241f2f523463
4
+ data.tar.gz: 5855978ebda1cef5cd8ae2388f4cce3893dcfc4090eb1956a1f0b3f4a4192925
5
5
  SHA512:
6
- metadata.gz: 07d53ebe3d570ec39d8e2b669492433972789437100dd811b795e5abad902e5d921fc93cf6714c3fef5f5a484cbcdedab04280becea9ec02fb2e65e762517beb
7
- data.tar.gz: 604fb6bc76e23853ca980b1f25861eab8ee45bfd2f0d66182d805db8b133fe411d35e485b44042937114236a040e5deb9563f248a703f245cedcc86d58b40cdc
6
+ metadata.gz: 62dcd0249b6b8b594c75c1833965aa9aebac051131e1fc81dd3740faeb16a6e92eb43a6cf00798f2f1543e37f77f640011b05a0467f8066323c63d00d8c6da02
7
+ data.tar.gz: 4436624e6f1d0e7a90f1af3c6c45871a7e75e6188bc1be051c48b4db37fdd39c0aa19b4a08bd917e5c3ca28df52c8377cf50a2df2d704a71ae24a27e24ed4fbe
data/README.md CHANGED
@@ -57,7 +57,8 @@ Visit `/webhooks` to see all received webhooks. Click any event to view all the
57
57
 
58
58
  <img alt="Fuik event detail interface" src="https://raw.githubusercontent.com/Rails-Designer/fuik/HEAD/.github/docs/event-detail.jpg" style="max-width: 100%;">
59
59
 
60
- ⚠️ The `/webhooks` path is by default not protected. Set `Fuik.configuration.events_controller_parent` to a controller that requires authentication.
60
+ > [!IMPORTANT]
61
+ > The dashboard is enabled in development and test only (not authenticated). For production, set `Fuik.configuration.dashboard_enabled = true` and point `Fuik.configuration.events_controller_parent` to a controller that requires authentication.
61
62
 
62
63
 
63
64
  ### Dashboard features
@@ -140,6 +141,7 @@ Configure Fuik in `config/initializers/fuik.rb`:
140
141
  Fuik.configure do |config|
141
142
  # config.events_controller_parent = "AdministrationController"
142
143
  # config.providers_allowed = %w[stripe github postmark]
144
+ # config.dashboard_enabled = Rails.env.development? || Rails.env.test?
143
145
  end
144
146
  ```
145
147
 
@@ -241,20 +243,13 @@ end
241
243
 
242
244
  ### Provider allowlist
243
245
 
244
- By default:
245
- - **Development/test**: all providers are allowed
246
- - **Production/staging**: only providers in `app/webhooks/` are allowed
247
-
248
- Configure with `Fuik.configuration.providers_allowed`:
246
+ By default all providers are accepted, in every environment. Tighten with `Fuik.configuration.providers_allowed`:
249
247
  ```ruby
250
- # Allow all (including production)
251
- Fuik.configuration.providers_allowed = :all
252
-
253
- # Explicit allowlist (overrides directory scan)
248
+ # Explicit allowlist
254
249
  Fuik.configuration.providers_allowed = %w[stripe github postmark]
255
250
  ```
256
251
 
257
- Unknown providers return `404 Not Found`.
252
+ Providers not in the allowlist return `404 Not Found`.
258
253
 
259
254
 
260
255
  ### Event type & ID lookup
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Fuik::DownloadsController < ApplicationController
3
+ class Fuik::DownloadsController < Fuik.configuration.events_controller_parent.constantize
4
4
  def create
5
5
  webhook_event = Fuik::WebhookEvent.find(params[:event_id])
6
6
 
data/config/routes.rb CHANGED
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Fuik::Engine.routes.draw do
4
- root to: "events#index"
4
+ constraints Fuik::Routing::DashboardConstraint.new do
5
+ root to: "events#index"
5
6
 
6
- resources :events, only: %w[index show] do
7
- resources :retries, only: %w[create]
7
+ resources :events, only: %w[index show] do
8
+ resources :retries, only: %w[create]
9
+ end
10
+ resources :downloads, only: %w[create]
8
11
  end
9
- resources :downloads, only: %w[create]
10
12
 
11
13
  post ":provider", to: "webhooks#create", constraints: Fuik::Routing::ProviderConstraint.new
12
14
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Fuik
4
4
  class Configuration
5
+ attr_writer :dashboard_enabled
5
6
  attr_accessor :events_controller_parent, :webhooks_controller_parent,
6
7
  :providers_allowed, :title, :color_scheme, :webhook_processing_job_class
7
8
 
@@ -13,6 +14,12 @@ module Fuik
13
14
  @title = "Webhooks"
14
15
  @color_scheme = :light
15
16
  end
17
+
18
+ def dashboard_enabled? = @dashboard_enabled.nil? ? local_env? : @dashboard_enabled
19
+
20
+ private
21
+
22
+ def local_env? = Rails.env.development? || Rails.env.test?
16
23
  end
17
24
 
18
25
  class << self
@@ -12,7 +12,7 @@ module Fuik
12
12
  end
13
13
 
14
14
  def [](key)
15
- value = @payload[key] || @payload[key.to_s] || @payload[key.to_sym]
15
+ value = fetch_value(key)
16
16
 
17
17
  value.is_a?(Hash) ? self.class.new(value) : value
18
18
  end
@@ -22,7 +22,15 @@ module Fuik
22
22
  end
23
23
 
24
24
  def dig(*keys)
25
- value = @payload.dig(*keys)
25
+ value = keys.reduce(self) do |current, key|
26
+ case current
27
+ when nil then return nil
28
+ when AccessPayload then current[key]
29
+ when Hash then self.class.new(current)[key]
30
+ when Array then current[key]
31
+ else raise TypeError, "#{current.class} does not have #dig method"
32
+ end
33
+ end
26
34
 
27
35
  value.is_a?(Hash) ? self.class.new(value) : value
28
36
  end
@@ -34,7 +42,7 @@ module Fuik
34
42
  def method_missing(method_name, *arguments)
35
43
  return super unless arguments.empty? && !block_given?
36
44
 
37
- value = @payload[method_name] || @payload[method_name.to_s] || @payload[method_name.to_sym]
45
+ value = fetch_value(method_name)
38
46
  value.is_a?(Hash) ? self.class.new(value) : value
39
47
  end
40
48
 
@@ -43,6 +51,14 @@ module Fuik
43
51
  end
44
52
 
45
53
  def to_h = @payload
54
+
55
+ private
56
+
57
+ def fetch_value(key)
58
+ found = [key, key.to_s, key.to_s.to_sym].find { @payload.key?(it) }
59
+
60
+ @payload[found] unless found.nil?
61
+ end
46
62
  end
47
63
  end
48
64
  end
data/lib/fuik/engine.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "fuik/routing/provider_constraint"
4
+ require "fuik/routing/dashboard_constraint"
4
5
 
5
6
  module Fuik
6
7
  class Engine < ::Rails::Engine
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fuik
4
+ module Routing
5
+ class DashboardConstraint
6
+ def matches?(request) = Fuik.configuration.dashboard_enabled?
7
+ end
8
+ end
9
+ end
@@ -7,28 +7,18 @@ module Fuik
7
7
  return true if allow_all?
8
8
  return explicit_allowlist.include?(request.params[:provider]) if explicit_allowlist?
9
9
 
10
- return Rails.env.local? if providers_allowed.nil?
11
- return Rails.env.local? if providers_allowed == true
12
-
13
- scanned_allowlist.include?(request.params[:provider])
10
+ false
14
11
  end
15
12
 
16
13
  private
17
14
 
18
- def allow_all? = Fuik.configuration.providers_allowed.in?([:all, "all"])
15
+ def allow_all? = providers_allowed.nil? || providers_allowed == true || providers_allowed.in?([:all, "all"])
19
16
 
20
- def explicit_allowlist? = Fuik.configuration.providers_allowed.is_a?(Array)
17
+ def explicit_allowlist? = providers_allowed.is_a?(Array)
21
18
 
22
- def explicit_allowlist = Fuik.configuration.providers_allowed.to_set
19
+ def explicit_allowlist = providers_allowed.to_set
23
20
 
24
21
  def providers_allowed = Fuik.configuration.providers_allowed
25
-
26
- def scanned_allowlist
27
- @scanned_allowlist ||= Dir["#{Rails.root}/app/webhooks/*"]
28
- .select { File.directory?(it) }
29
- .map { File.basename(it) }
30
- .to_set
31
- end
32
22
  end
33
23
  end
34
24
  end
data/lib/fuik/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fuik
2
- VERSION = "0.13.0"
2
+ VERSION = "0.14.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fuik
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rails Designer
@@ -96,6 +96,7 @@ files:
96
96
  - lib/fuik/engine.rb
97
97
  - lib/fuik/errors.rb
98
98
  - lib/fuik/notifications.rb
99
+ - lib/fuik/routing/dashboard_constraint.rb
99
100
  - lib/fuik/routing/provider_constraint.rb
100
101
  - lib/fuik/test_helpers.rb
101
102
  - lib/fuik/version.rb
@@ -165,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
166
  - !ruby/object:Gem::Version
166
167
  version: '0'
167
168
  requirements: []
168
- rubygems_version: 4.0.14
169
+ rubygems_version: 4.0.24
169
170
  specification_version: 4
170
171
  summary: A fish trap for webhooks
171
172
  test_files: []