hasura_handler 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25f72768507a2bb41a57d8496b0a169a81d9f6a23f1b319b0b75070d9fad060d
4
- data.tar.gz: a45f22682a707e9387daf8243715f48f6e84ac6d813329e87581b128d6822baa
3
+ metadata.gz: b476da389358677671ebee56a1d014dc90779a73ade92eaf6d17f894192d0f4c
4
+ data.tar.gz: 1aef41672a1832e2abe57e78b260fdef87a0e0147c470898ccb17dfb3b05c791
5
5
  SHA512:
6
- metadata.gz: 5047bb08871d97abf679305bf0ec75c0de747b2a9ba9b30287b8f946bb7fe28337dbc38011c5d8224dd292b50cf4b7b6df67331b832ba6bd49120dd22207ef0c
7
- data.tar.gz: bb3a3b2637e97375ab5a8477e3cf5a13e7e2d06800e8758411620c24e9eb938ffe793a9b90e744cdfa05d03b934bee8b96be2b614a9a125d40e3d097fdc5963f
6
+ metadata.gz: 466c57748a94c57040c9d963af6982f4796370c30c582c0c3a306b5d4bc0573f3d3989d6a4e3702f7c162c8e5ad659ee50b032aecc7ac606003dddafca9ffe1a
7
+ data.tar.gz: 921d0f38484c4d6f127660e7a999ef5af1a0bce82013aeccace3abf1ca6d4468c567d11355dc35691c97480056ad88829cba2dd0984ba9b6208679f62ff2b02b
@@ -17,7 +17,12 @@ module HasuraHandler
17
17
  end
18
18
 
19
19
  def clean_headers
20
- request.headers.reject{ |k,v| k.include?('.') }.to_h
20
+ request.
21
+ headers.
22
+ reject{ |k,v| k.include?('.') }.
23
+ to_h.
24
+ select{ |k,v| k =~ /\AHTTP_/ }.
25
+ to_h
21
26
  end
22
27
  end
23
28
  end
@@ -3,14 +3,14 @@ require_dependency "hasura_handler/application_controller"
3
3
  module HasuraHandler
4
4
  class AuthHookController < ApplicationController
5
5
  def get_mode
6
- @headers = clean_headers.to_h.select{ |k,v| k =~ /\AHTTP_/ }.to_h
6
+ @headers = clean_headers
7
7
  authenticate
8
8
  end
9
9
 
10
10
  def post_mode
11
11
  @headers = raw_params['headers'].
12
12
  to_h.
13
- map{ |k,v| ['HTTP_' + k.to_s.gsub('-', '_').upcase, v] }.
13
+ map{ |k,v| [standardize_header(k), v] }.
14
14
  to_h
15
15
 
16
16
  authenticate
@@ -19,7 +19,11 @@ module HasuraHandler
19
19
  private
20
20
 
21
21
  def authenticate
22
- @authenticator = HasuraHandler.authenticator.new(@headers)
22
+ @authenticator = HasuraHandler.
23
+ authenticator.
24
+ to_s.
25
+ constantize.
26
+ new(@headers)
23
27
 
24
28
  if @authenticator.success?
25
29
  render json: @authenticator.response, status: 200
@@ -27,5 +31,9 @@ module HasuraHandler
27
31
  render json: { error: true, message: @authenticator.error_message }, status: 401
28
32
  end
29
33
  end
34
+
35
+ def standardize_header(header)
36
+ "HTTP_#{header.to_s.gsub('-', '_').upcase}"
37
+ end
30
38
  end
31
39
  end
@@ -35,11 +35,11 @@ module HasuraHandler
35
35
  yield self
36
36
 
37
37
  if (self.events_enabled || self.actions_enabled) && self.auth_key.blank?
38
- raise "HasuraHandler requires the auth_key to be configured if actions or events are enabled."
38
+ raise 'HasuraHandler requires the auth_key to be configured if actions or events are enabled.'
39
39
  end
40
40
 
41
41
  if self.authentication_enabled && self.authenticator.blank?
42
- raise "HasuraHandler requires the authenticator to be configured if authentication hook is enabled."
42
+ raise 'HasuraHandler requires the authenticator to be configured if authentication hook is enabled.'
43
43
  end
44
44
  end
45
45
  end
@@ -2,5 +2,13 @@ module HasuraHandler
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace HasuraHandler
4
4
  config.generators.api_only = true
5
+
6
+ if Rails.version.to_f < 6
7
+ config.eager_load_paths += Dir[Rails.root.join('app', '{actions,reactions}', '*.rb')]
8
+ end
9
+
10
+ config.to_prepare do
11
+ Dir[Rails.root.join('app', '{actions,reactions}', '*.rb')].each{ |file| require_dependency file }
12
+ end
5
13
  end
6
14
  end
@@ -1,5 +1,7 @@
1
1
  module HasuraHandler
2
2
  class EventHandler
3
+ extend ActiveSupport::DescendantsTracker
4
+
3
5
  class << self
4
6
  attr_reader :hasura_matchers
5
7
 
@@ -8,8 +10,8 @@ module HasuraHandler
8
10
  allowed_matchers = [:table, :trigger, :op]
9
11
 
10
12
  matchers.keys.each do |matcher|
11
- raise 'invalid matcher' unless allowed_matchers.include?(matcher)
12
- raise 'invalid matcher value' unless matchers[matcher].is_a?(String)
13
+ raise "invalid matcher: #{matcher}" unless allowed_matchers.include?(matcher)
14
+ raise "invalid matcher value for: #{matcher}" unless matchers[matcher].is_a?(String)
13
15
  end
14
16
 
15
17
  @hasura_matchers = matchers
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hasura_handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaz Walker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-04 00:00:00.000000000 Z
11
+ date: 2020-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails