hasura_handler 0.1.4 → 0.1.5
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/README.md +4 -23
- data/app/controllers/hasura_handler/actions_controller.rb +8 -2
- data/app/controllers/hasura_handler/application_controller.rb +5 -3
- data/app/controllers/hasura_handler/auth_hook_controller.rb +35 -0
- data/app/controllers/hasura_handler/events_controller.rb +4 -4
- data/config/routes.rb +5 -0
- data/lib/hasura_handler.rb +12 -2
- data/lib/hasura_handler/action.rb +3 -1
- data/lib/hasura_handler/authenticator.rb +21 -0
- metadata +13 -7
- data/lib/hasura_handler/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d39e768059737605f096e2fb1ebc03b97a30ff3c05a55a580bc4f99b96e0e60e
|
4
|
+
data.tar.gz: 9322488f0d8cd4934509279e28b824926cb1f7a14a982700c323f5c11dab5d81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 021c7736f7148d728ea3b09562051e5b3679a6b9370a127304f988274a81cf2959b012dc2b2561fb257f43c10a2e396d753ce01101d19d1c1cc300337df9da69
|
7
|
+
data.tar.gz: ddda66c93f15b46b003f063b878fc00c59adba67bc0d6ec500d1b514ad1dfd0ecedf6f761db967a146678fb442060e8dbcb4cbea0306688ef0490ac31293118f
|
data/README.md
CHANGED
@@ -1,28 +1,9 @@
|
|
1
|
-
# HasuraHandler
|
2
|
-
|
1
|
+
# HasuraHandler  [](https://github.com/KazW/HasuraHandler/actions?query=workflow%3Atests) [](https://codeclimate.com/github/KazW/HasuraHandler/maintainability) [](https://codeclimate.com/github/KazW/HasuraHandler/test_coverage)
|
2
|
+
HasuraHandler is a Rails framework that makes building microservices for Hasura easy.
|
3
|
+
HasuraHandler also simplifies adding Hasura to an existing Rails app.
|
3
4
|
|
4
5
|
## Usage
|
5
|
-
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
Add this line to your application's Gemfile:
|
9
|
-
|
10
|
-
```ruby
|
11
|
-
gem 'hasura_handler'
|
12
|
-
```
|
13
|
-
|
14
|
-
And then execute:
|
15
|
-
```bash
|
16
|
-
$ bundle
|
17
|
-
```
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
```bash
|
21
|
-
$ gem install hasura_handler
|
22
|
-
```
|
23
|
-
|
24
|
-
## Contributing
|
25
|
-
Contribution directions go here.
|
6
|
+
Please see the [documentation site](https://kazw.github.io/HasuraHandler).
|
26
7
|
|
27
8
|
## License
|
28
9
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -2,6 +2,8 @@ require_dependency 'hasura_handler/application_controller'
|
|
2
2
|
|
3
3
|
module HasuraHandler
|
4
4
|
class ActionsController < ApplicationController
|
5
|
+
before_action :check_header
|
6
|
+
|
5
7
|
def index
|
6
8
|
unless HasuraHandler::Action.hasura_actions.keys.include?(action_params['action']['name'])
|
7
9
|
render json: { error: true, message: 'action name not registered' }, status: 404
|
@@ -9,9 +11,13 @@ module HasuraHandler
|
|
9
11
|
end
|
10
12
|
|
11
13
|
klass = HasuraHandler::Action.hasura_actions[action_params['action']['name']]
|
12
|
-
action = klass.new(
|
13
|
-
|
14
|
+
action = klass.new(
|
15
|
+
clean_headers,
|
16
|
+
action_params['session_variables'].to_h,
|
17
|
+
action_params['input'].to_h
|
18
|
+
)
|
14
19
|
|
20
|
+
action.run
|
15
21
|
if action.error_message.present?
|
16
22
|
render json: { error: true, message: action.error_message }, status: 400
|
17
23
|
else
|
@@ -1,7 +1,5 @@
|
|
1
1
|
module HasuraHandler
|
2
2
|
class ApplicationController < ActionController::API
|
3
|
-
before_action :check_header
|
4
|
-
|
5
3
|
private
|
6
4
|
|
7
5
|
def check_header
|
@@ -11,7 +9,11 @@ module HasuraHandler
|
|
11
9
|
end
|
12
10
|
|
13
11
|
def full_params
|
14
|
-
ActionController::Parameters.new(JSON.parse(request.
|
12
|
+
ActionController::Parameters.new(JSON.parse(request.raw_post))
|
13
|
+
end
|
14
|
+
|
15
|
+
def clean_headers
|
16
|
+
request.headers.reject{ |k,v| k.include?('.') }.to_h
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_dependency "hasura_handler/application_controller"
|
2
|
+
|
3
|
+
module HasuraHandler
|
4
|
+
class AuthHookController < ApplicationController
|
5
|
+
def get_mode
|
6
|
+
@headers = clean_headers.to_h.select{ |k,v| k =~ /\AHTTP_/ }.to_h
|
7
|
+
authenticate
|
8
|
+
end
|
9
|
+
|
10
|
+
def post_mode
|
11
|
+
@headers = post_params['auth_hook']['headers'].
|
12
|
+
to_h.
|
13
|
+
map{ |k,v| ['HTTP_' + k.to_s.gsub('-', '_').upcase, v] }.
|
14
|
+
to_h
|
15
|
+
|
16
|
+
authenticate
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def post_params
|
22
|
+
params.permit(auth_hook: {}, headers: {})
|
23
|
+
end
|
24
|
+
|
25
|
+
def authenticate
|
26
|
+
@authenticator = HasuraHandler.authenticator.new(@headers)
|
27
|
+
|
28
|
+
if @authenticator.success?
|
29
|
+
render json: @authenticator.response, status: 200
|
30
|
+
else
|
31
|
+
render json: { error: true, message: @authenticator.error_message }, status: 401
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -2,6 +2,8 @@ require_dependency 'hasura_handler/application_controller'
|
|
2
2
|
|
3
3
|
module HasuraHandler
|
4
4
|
class EventsController < ApplicationController
|
5
|
+
before_action :check_header
|
6
|
+
|
5
7
|
def index
|
6
8
|
processor = HasuraHandler::EventProcessor.new(event_params.to_h)
|
7
9
|
|
@@ -35,6 +37,7 @@ module HasuraHandler
|
|
35
37
|
full_params.permit(
|
36
38
|
:id,
|
37
39
|
:created_at,
|
40
|
+
delivery_info: {},
|
38
41
|
table: [
|
39
42
|
:schema,
|
40
43
|
:name
|
@@ -46,10 +49,7 @@ module HasuraHandler
|
|
46
49
|
:op,
|
47
50
|
{
|
48
51
|
session_variables: {},
|
49
|
-
data: {
|
50
|
-
new: {},
|
51
|
-
old: {}
|
52
|
-
}
|
52
|
+
data: {}
|
53
53
|
}
|
54
54
|
]
|
55
55
|
)
|
data/config/routes.rb
CHANGED
data/lib/hasura_handler.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'hasura_handler/engine'
|
2
|
+
require 'hasura_handler/authenticator'
|
2
3
|
require 'hasura_handler/event_handler'
|
3
4
|
require 'hasura_handler/event_processor'
|
4
5
|
require 'hasura_handler/event'
|
@@ -8,6 +9,8 @@ module HasuraHandler
|
|
8
9
|
class << self
|
9
10
|
mattr_accessor :auth_header,
|
10
11
|
:auth_key,
|
12
|
+
:authentication_enabled,
|
13
|
+
:authenticator,
|
11
14
|
:events_enabled,
|
12
15
|
:actions_enabled,
|
13
16
|
:event_job_queue,
|
@@ -17,6 +20,8 @@ module HasuraHandler
|
|
17
20
|
:retry_after
|
18
21
|
|
19
22
|
self.auth_header = 'HTTP_X_HASURA_SERVICE_KEY'
|
23
|
+
self.authentication_enabled = false
|
24
|
+
self.authenticator = nil
|
20
25
|
self.events_enabled = true
|
21
26
|
self.async_events = true
|
22
27
|
self.fanout_events = true
|
@@ -28,8 +33,13 @@ module HasuraHandler
|
|
28
33
|
|
29
34
|
def self.setup(&block)
|
30
35
|
yield self
|
31
|
-
|
32
|
-
|
36
|
+
|
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."
|
39
|
+
end
|
40
|
+
|
41
|
+
if self.authentication_enabled && self.authenticator.blank?
|
42
|
+
raise "HasuraHandler requires the authenticator to be configured if authentication hook is enabled."
|
33
43
|
end
|
34
44
|
end
|
35
45
|
end
|
@@ -17,11 +17,13 @@ module HasuraHandler
|
|
17
17
|
end
|
18
18
|
|
19
19
|
attr_reader :session_variables,
|
20
|
+
:headers,
|
20
21
|
:input,
|
21
22
|
:output,
|
22
23
|
:error_message
|
23
24
|
|
24
|
-
def initialize(session_variables, input)
|
25
|
+
def initialize(headers, session_variables, input)
|
26
|
+
@headers = headers
|
25
27
|
@session_variables = session_variables
|
26
28
|
@input = input
|
27
29
|
@output = {}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module HasuraHandler
|
2
|
+
class Authenticator
|
3
|
+
attr_accessor :response,
|
4
|
+
:error_message
|
5
|
+
|
6
|
+
def initialize(headers)
|
7
|
+
@headers = headers
|
8
|
+
@response = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def success?
|
12
|
+
begin
|
13
|
+
authenticate
|
14
|
+
ensure
|
15
|
+
return false if @response.blank?
|
16
|
+
end
|
17
|
+
|
18
|
+
@response.present? || @error_message.blank?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
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.
|
4
|
+
version: 0.1.5
|
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-
|
11
|
+
date: 2020-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -30,7 +30,8 @@ dependencies:
|
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 6.0.3.2
|
33
|
-
description:
|
33
|
+
description: HasuraHandler is a Rails framework that makes building microservices
|
34
|
+
for Hasura easy.
|
34
35
|
email:
|
35
36
|
- me@kaz.codes
|
36
37
|
executables: []
|
@@ -42,6 +43,7 @@ files:
|
|
42
43
|
- Rakefile
|
43
44
|
- app/controllers/hasura_handler/actions_controller.rb
|
44
45
|
- app/controllers/hasura_handler/application_controller.rb
|
46
|
+
- app/controllers/hasura_handler/auth_hook_controller.rb
|
45
47
|
- app/controllers/hasura_handler/events_controller.rb
|
46
48
|
- app/jobs/hasura_handler/application_job.rb
|
47
49
|
- app/jobs/hasura_handler/event_handler_job.rb
|
@@ -49,16 +51,20 @@ files:
|
|
49
51
|
- config/routes.rb
|
50
52
|
- lib/hasura_handler.rb
|
51
53
|
- lib/hasura_handler/action.rb
|
54
|
+
- lib/hasura_handler/authenticator.rb
|
52
55
|
- lib/hasura_handler/engine.rb
|
53
56
|
- lib/hasura_handler/event.rb
|
54
57
|
- lib/hasura_handler/event_handler.rb
|
55
58
|
- lib/hasura_handler/event_processor.rb
|
56
|
-
- lib/hasura_handler/version.rb
|
57
59
|
- lib/tasks/hasura_handler_tasks.rake
|
58
|
-
homepage: https://github.
|
60
|
+
homepage: https://kazw.github.io/HasuraHandler
|
59
61
|
licenses:
|
60
62
|
- MIT
|
61
|
-
metadata:
|
63
|
+
metadata:
|
64
|
+
bug_tracker_uri: https://github.com/KazW/HasuraHandler/issues
|
65
|
+
documentation_uri: https://kazw.github.io/HasuraHandler
|
66
|
+
homepage_uri: https://kazw.github.io/HasuraHandler
|
67
|
+
source_code_uri: https://github.com/KazW/HasuraHandler
|
62
68
|
post_install_message:
|
63
69
|
rdoc_options: []
|
64
70
|
require_paths:
|
@@ -74,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
80
|
- !ruby/object:Gem::Version
|
75
81
|
version: '0'
|
76
82
|
requirements: []
|
77
|
-
rubygems_version: 3.1.
|
83
|
+
rubygems_version: 3.1.2
|
78
84
|
signing_key:
|
79
85
|
specification_version: 4
|
80
86
|
summary: Integrates Hasura with Rails
|