trailblazer-endpoint 0.0.1 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +16 -0
- data/Appraisals +5 -0
- data/CHANGES.md +26 -0
- data/README.md +40 -5
- data/Rakefile +7 -1
- data/gemfiles/rails_app.gemfile +12 -0
- data/lib/trailblazer/endpoint.rb +29 -14
- data/lib/trailblazer/endpoint/adapter.rb +30 -121
- data/lib/trailblazer/endpoint/builder.rb +1 -1
- data/lib/trailblazer/endpoint/controller.rb +223 -0
- data/lib/trailblazer/endpoint/dsl.rb +29 -0
- data/lib/trailblazer/endpoint/options.rb +92 -0
- data/lib/trailblazer/endpoint/protocol.rb +5 -8
- data/lib/trailblazer/endpoint/version.rb +1 -1
- data/test/adapter/api_test.rb +6 -11
- data/test/adapter/web_test.rb +2 -5
- data/test/config_test.rb +128 -0
- data/test/docs/controller_test.rb +339 -58
- data/test/endpoint_test.rb +1 -1
- data/test/rails-app/.gitignore +8 -2
- data/test/rails-app/.ruby-version +1 -0
- data/test/rails-app/Gemfile +15 -9
- data/test/rails-app/Gemfile.lock +162 -121
- data/test/rails-app/app/concepts/app/api/v1/representer/errors.rb +16 -0
- data/test/rails-app/app/concepts/auth/jwt.rb +35 -0
- data/test/rails-app/app/concepts/auth/operation/authenticate.rb +32 -0
- data/test/rails-app/app/concepts/auth/operation/policy.rb +9 -0
- data/test/rails-app/app/concepts/song/cell/create.rb +4 -0
- data/test/rails-app/app/concepts/song/cell/new.rb +4 -0
- data/test/rails-app/app/concepts/song/operation/create.rb +17 -0
- data/test/rails-app/app/concepts/song/operation/show.rb +10 -0
- data/test/rails-app/app/concepts/song/representer.rb +5 -0
- data/test/rails-app/app/concepts/song/view/create.erb +1 -0
- data/test/rails-app/app/concepts/song/view/new.erb +1 -0
- data/test/rails-app/app/controllers/api/v1/songs_controller.rb +41 -0
- data/test/rails-app/app/controllers/application_controller.rb +8 -1
- data/test/rails-app/app/controllers/application_controller/api.rb +107 -0
- data/test/rails-app/app/controllers/application_controller/web.rb +44 -0
- data/test/rails-app/app/controllers/auth_controller.rb +44 -0
- data/test/rails-app/app/controllers/home_controller.rb +5 -0
- data/test/rails-app/app/controllers/songs_controller.rb +71 -13
- data/test/rails-app/app/models/song.rb +3 -0
- data/test/rails-app/app/models/user.rb +7 -0
- data/test/rails-app/bin/bundle +114 -0
- data/test/rails-app/bin/rails +4 -0
- data/test/rails-app/bin/rake +4 -0
- data/test/rails-app/bin/setup +33 -0
- data/test/rails-app/config/application.rb +26 -3
- data/test/rails-app/config/credentials.yml.enc +1 -0
- data/test/rails-app/config/database.yml +2 -2
- data/test/rails-app/config/environments/development.rb +7 -17
- data/test/rails-app/config/environments/production.rb +28 -23
- data/test/rails-app/config/environments/test.rb +8 -12
- data/test/rails-app/config/initializers/application_controller_renderer.rb +6 -4
- data/test/rails-app/config/initializers/cors.rb +16 -0
- data/test/rails-app/config/initializers/trailblazer.rb +2 -0
- data/test/rails-app/config/locales/en.yml +11 -1
- data/test/rails-app/config/master.key +1 -0
- data/test/rails-app/config/routes.rb +16 -4
- data/test/rails-app/db/schema.rb +15 -0
- data/test/rails-app/test/controllers/api_songs_controller_test.rb +87 -0
- data/test/rails-app/test/controllers/songs_controller_test.rb +80 -147
- data/test/rails-app/test/test_helper.rb +7 -1
- data/test/test_helper.rb +0 -2
- data/trailblazer-endpoint.gemspec +2 -1
- metadata +70 -22
- data/test/rails-app/config/initializers/cookies_serializer.rb +0 -5
- data/test/rails-app/config/initializers/new_framework_defaults.rb +0 -24
- data/test/rails-app/config/initializers/session_store.rb +0 -3
- data/test/rails-app/config/secrets.yml +0 -22
- data/test/rails-app/test/helpers/.keep +0 -0
- data/test/rails-app/test/integration/.keep +0 -0
- data/test/rails-app/test/mailers/.keep +0 -0
- data/test/rails-app/vendor/assets/javascripts/.keep +0 -0
- data/test/rails-app/vendor/assets/stylesheets/.keep +0 -0
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.5.1
|
data/test/rails-app/Gemfile
CHANGED
@@ -1,17 +1,23 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
|
-
|
2
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
3
3
|
|
4
4
|
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
5
|
-
gem 'rails', '~>
|
5
|
+
gem 'rails', '~> 6.0.3', '>= 6.0.3.1'
|
6
6
|
# Use sqlite3 as the database for Active Record
|
7
|
-
gem 'sqlite3'
|
7
|
+
gem 'sqlite3', '~> 1.4'
|
8
|
+
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
9
|
+
# gem 'jbuilder', '~> 2.7'
|
10
|
+
# Use Active Model has_secure_password
|
11
|
+
# gem 'bcrypt', '~> 3.1.7'
|
8
12
|
|
9
|
-
#
|
10
|
-
gem '
|
13
|
+
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
|
14
|
+
# gem 'rack-cors'
|
11
15
|
|
16
|
+
gem "trailblazer-operation"
|
12
17
|
gem "trailblazer-endpoint", path: "../../."
|
13
|
-
gem "
|
14
|
-
gem "trailblazer-operation", path: "../../../operation"
|
15
|
-
# gem "trailblazer-rails"
|
16
|
-
|
18
|
+
gem "jwt"
|
17
19
|
gem "multi_json"
|
20
|
+
gem "minitest-line"
|
21
|
+
gem "trailblazer-cells"
|
22
|
+
gem "cells-erb"
|
23
|
+
gem "cells-rails"
|
data/test/rails-app/Gemfile.lock
CHANGED
@@ -1,157 +1,198 @@
|
|
1
1
|
PATH
|
2
|
-
remote:
|
2
|
+
remote: ../..
|
3
3
|
specs:
|
4
|
-
trailblazer-
|
5
|
-
|
6
|
-
pipetree (>= 0.0.4, < 0.1.0)
|
7
|
-
uber (>= 0.1.0, < 0.2.0)
|
8
|
-
|
9
|
-
PATH
|
10
|
-
remote: ../../../trailblazer
|
11
|
-
specs:
|
12
|
-
trailblazer (2.0.0.beta1)
|
13
|
-
declarative
|
14
|
-
reform (>= 2.2.0, < 3.0.0)
|
15
|
-
trailblazer-operation
|
16
|
-
uber (>= 0.1.0, < 0.2.0)
|
17
|
-
|
18
|
-
PATH
|
19
|
-
remote: ../../.
|
20
|
-
specs:
|
21
|
-
trailblazer-endpoint (0.0.1)
|
22
|
-
dry-matcher
|
4
|
+
trailblazer-endpoint (0.0.5)
|
5
|
+
trailblazer-activity-dsl-linear (>= 0.3.0, < 0.4.0)
|
23
6
|
|
24
7
|
GEM
|
25
8
|
remote: https://rubygems.org/
|
26
9
|
specs:
|
27
|
-
actioncable (
|
28
|
-
actionpack (=
|
29
|
-
nio4r (~>
|
30
|
-
websocket-driver (
|
31
|
-
|
32
|
-
actionpack (=
|
33
|
-
|
34
|
-
|
10
|
+
actioncable (6.0.3.2)
|
11
|
+
actionpack (= 6.0.3.2)
|
12
|
+
nio4r (~> 2.0)
|
13
|
+
websocket-driver (>= 0.6.1)
|
14
|
+
actionmailbox (6.0.3.2)
|
15
|
+
actionpack (= 6.0.3.2)
|
16
|
+
activejob (= 6.0.3.2)
|
17
|
+
activerecord (= 6.0.3.2)
|
18
|
+
activestorage (= 6.0.3.2)
|
19
|
+
activesupport (= 6.0.3.2)
|
20
|
+
mail (>= 2.7.1)
|
21
|
+
actionmailer (6.0.3.2)
|
22
|
+
actionpack (= 6.0.3.2)
|
23
|
+
actionview (= 6.0.3.2)
|
24
|
+
activejob (= 6.0.3.2)
|
35
25
|
mail (~> 2.5, >= 2.5.4)
|
36
26
|
rails-dom-testing (~> 2.0)
|
37
|
-
actionpack (
|
38
|
-
actionview (=
|
39
|
-
activesupport (=
|
40
|
-
rack (~> 2.0)
|
41
|
-
rack-test (
|
27
|
+
actionpack (6.0.3.2)
|
28
|
+
actionview (= 6.0.3.2)
|
29
|
+
activesupport (= 6.0.3.2)
|
30
|
+
rack (~> 2.0, >= 2.0.8)
|
31
|
+
rack-test (>= 0.6.3)
|
42
32
|
rails-dom-testing (~> 2.0)
|
43
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
44
|
-
|
45
|
-
|
33
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
34
|
+
actiontext (6.0.3.2)
|
35
|
+
actionpack (= 6.0.3.2)
|
36
|
+
activerecord (= 6.0.3.2)
|
37
|
+
activestorage (= 6.0.3.2)
|
38
|
+
activesupport (= 6.0.3.2)
|
39
|
+
nokogiri (>= 1.8.5)
|
40
|
+
actionview (6.0.3.2)
|
41
|
+
activesupport (= 6.0.3.2)
|
46
42
|
builder (~> 3.1)
|
47
|
-
|
43
|
+
erubi (~> 1.4)
|
48
44
|
rails-dom-testing (~> 2.0)
|
49
|
-
rails-html-sanitizer (~> 1.
|
50
|
-
activejob (
|
51
|
-
activesupport (=
|
45
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
46
|
+
activejob (6.0.3.2)
|
47
|
+
activesupport (= 6.0.3.2)
|
52
48
|
globalid (>= 0.3.6)
|
53
|
-
activemodel (
|
54
|
-
activesupport (=
|
55
|
-
activerecord (
|
56
|
-
activemodel (=
|
57
|
-
activesupport (=
|
58
|
-
|
59
|
-
|
49
|
+
activemodel (6.0.3.2)
|
50
|
+
activesupport (= 6.0.3.2)
|
51
|
+
activerecord (6.0.3.2)
|
52
|
+
activemodel (= 6.0.3.2)
|
53
|
+
activesupport (= 6.0.3.2)
|
54
|
+
activestorage (6.0.3.2)
|
55
|
+
actionpack (= 6.0.3.2)
|
56
|
+
activejob (= 6.0.3.2)
|
57
|
+
activerecord (= 6.0.3.2)
|
58
|
+
marcel (~> 0.3.1)
|
59
|
+
activesupport (6.0.3.2)
|
60
60
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
61
|
-
i18n (
|
61
|
+
i18n (>= 0.7, < 2)
|
62
62
|
minitest (~> 5.1)
|
63
63
|
tzinfo (~> 1.1)
|
64
|
-
|
65
|
-
builder (3.2.
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
64
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
65
|
+
builder (3.2.4)
|
66
|
+
cells (4.1.7)
|
67
|
+
declarative-builder (< 0.2.0)
|
68
|
+
declarative-option (< 0.2.0)
|
69
|
+
tilt (>= 1.4, < 3)
|
70
|
+
uber (< 0.2.0)
|
71
|
+
cells-erb (0.1.0)
|
72
|
+
cells (~> 4.0)
|
73
|
+
erbse (>= 0.1.1)
|
74
|
+
cells-rails (0.1.1)
|
75
|
+
actionpack (>= 5.0)
|
76
|
+
cells (>= 4.1.6, < 5.0.0)
|
77
|
+
concurrent-ruby (1.1.7)
|
78
|
+
crass (1.0.6)
|
79
|
+
declarative (0.0.20)
|
80
|
+
declarative-builder (0.1.0)
|
81
|
+
declarative-option (< 0.2.0)
|
82
|
+
declarative-option (0.1.0)
|
83
|
+
erbse (0.1.4)
|
84
|
+
temple
|
85
|
+
erubi (1.9.0)
|
86
|
+
globalid (0.4.2)
|
87
|
+
activesupport (>= 4.2.0)
|
88
|
+
hashie (4.1.0)
|
89
|
+
hirb (0.7.3)
|
90
|
+
i18n (1.8.5)
|
91
|
+
concurrent-ruby (~> 1.0)
|
92
|
+
jwt (2.2.2)
|
93
|
+
loofah (2.7.0)
|
94
|
+
crass (~> 1.0.2)
|
79
95
|
nokogiri (>= 1.5.9)
|
80
|
-
mail (2.
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
96
|
+
mail (2.7.1)
|
97
|
+
mini_mime (>= 0.1.1)
|
98
|
+
marcel (0.3.3)
|
99
|
+
mimemagic (~> 0.3.2)
|
100
|
+
method_source (1.0.0)
|
101
|
+
mimemagic (0.3.5)
|
102
|
+
mini_mime (1.0.2)
|
103
|
+
mini_portile2 (2.4.0)
|
104
|
+
minitest (5.14.2)
|
105
|
+
minitest-line (0.6.5)
|
106
|
+
minitest (~> 5.0)
|
107
|
+
multi_json (1.15.0)
|
108
|
+
nio4r (2.5.2)
|
109
|
+
nokogiri (1.10.10)
|
110
|
+
mini_portile2 (~> 2.4.0)
|
111
|
+
rack (2.2.3)
|
112
|
+
rack-test (1.1.0)
|
113
|
+
rack (>= 1.0, < 3)
|
114
|
+
rails (6.0.3.2)
|
115
|
+
actioncable (= 6.0.3.2)
|
116
|
+
actionmailbox (= 6.0.3.2)
|
117
|
+
actionmailer (= 6.0.3.2)
|
118
|
+
actionpack (= 6.0.3.2)
|
119
|
+
actiontext (= 6.0.3.2)
|
120
|
+
actionview (= 6.0.3.2)
|
121
|
+
activejob (= 6.0.3.2)
|
122
|
+
activemodel (= 6.0.3.2)
|
123
|
+
activerecord (= 6.0.3.2)
|
124
|
+
activestorage (= 6.0.3.2)
|
125
|
+
activesupport (= 6.0.3.2)
|
126
|
+
bundler (>= 1.3.0)
|
127
|
+
railties (= 6.0.3.2)
|
107
128
|
sprockets-rails (>= 2.0.0)
|
108
|
-
rails-dom-testing (2.0.
|
109
|
-
activesupport (>= 4.2.0
|
110
|
-
nokogiri (
|
111
|
-
rails-html-sanitizer (1.0
|
112
|
-
loofah (~> 2.
|
113
|
-
railties (
|
114
|
-
actionpack (=
|
115
|
-
activesupport (=
|
129
|
+
rails-dom-testing (2.0.3)
|
130
|
+
activesupport (>= 4.2.0)
|
131
|
+
nokogiri (>= 1.6)
|
132
|
+
rails-html-sanitizer (1.3.0)
|
133
|
+
loofah (~> 2.3)
|
134
|
+
railties (6.0.3.2)
|
135
|
+
actionpack (= 6.0.3.2)
|
136
|
+
activesupport (= 6.0.3.2)
|
116
137
|
method_source
|
117
138
|
rake (>= 0.8.7)
|
118
|
-
thor (>= 0.
|
119
|
-
rake (
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
uber (
|
124
|
-
|
125
|
-
declarative (~> 0.0.5)
|
126
|
-
uber (>= 0.0.15, < 0.2.0)
|
127
|
-
sprockets (3.7.0)
|
139
|
+
thor (>= 0.20.3, < 2.0)
|
140
|
+
rake (13.0.1)
|
141
|
+
representable (3.0.4)
|
142
|
+
declarative (< 0.1.0)
|
143
|
+
declarative-option (< 0.2.0)
|
144
|
+
uber (< 0.2.0)
|
145
|
+
sprockets (4.0.2)
|
128
146
|
concurrent-ruby (~> 1.0)
|
129
147
|
rack (> 1, < 3)
|
130
|
-
sprockets-rails (3.2.
|
148
|
+
sprockets-rails (3.2.1)
|
131
149
|
actionpack (>= 4.0)
|
132
150
|
activesupport (>= 4.0)
|
133
151
|
sprockets (>= 3.0.0)
|
134
|
-
sqlite3 (1.
|
135
|
-
|
136
|
-
|
137
|
-
|
152
|
+
sqlite3 (1.4.2)
|
153
|
+
temple (0.8.2)
|
154
|
+
thor (1.0.1)
|
155
|
+
thread_safe (0.3.6)
|
156
|
+
tilt (2.0.10)
|
157
|
+
trailblazer-activity (0.11.3)
|
158
|
+
trailblazer-context (>= 0.3.1, < 0.4.0)
|
159
|
+
trailblazer-activity-dsl-linear (0.3.2)
|
160
|
+
trailblazer-activity (>= 0.11.2, < 1.0.0)
|
161
|
+
trailblazer-cells (0.0.3)
|
162
|
+
cells (>= 4.1.0.rc1, < 5.0.0)
|
163
|
+
trailblazer-context (0.3.1)
|
164
|
+
hashie (~> 4.1)
|
165
|
+
trailblazer-developer (0.0.16)
|
166
|
+
hirb
|
167
|
+
representable
|
168
|
+
trailblazer-activity (>= 0.11.0, < 1.0.0)
|
169
|
+
trailblazer-activity-dsl-linear
|
170
|
+
trailblazer-operation (0.6.5)
|
171
|
+
trailblazer-activity (>= 0.11.2, < 1.0.0)
|
172
|
+
trailblazer-activity-dsl-linear (>= 0.3.2, < 1.0.0)
|
173
|
+
trailblazer-developer (>= 0.0.8)
|
174
|
+
tzinfo (1.2.7)
|
138
175
|
thread_safe (~> 0.1)
|
139
176
|
uber (0.1.0)
|
140
|
-
websocket-driver (0.
|
177
|
+
websocket-driver (0.7.3)
|
141
178
|
websocket-extensions (>= 0.1.0)
|
142
|
-
websocket-extensions (0.1.
|
179
|
+
websocket-extensions (0.1.5)
|
180
|
+
zeitwerk (2.4.0)
|
143
181
|
|
144
182
|
PLATFORMS
|
145
183
|
ruby
|
146
184
|
|
147
185
|
DEPENDENCIES
|
186
|
+
cells-erb
|
187
|
+
cells-rails
|
188
|
+
jwt
|
189
|
+
minitest-line
|
148
190
|
multi_json
|
149
|
-
rails (~>
|
150
|
-
sqlite3
|
151
|
-
trailblazer
|
191
|
+
rails (~> 6.0.3, >= 6.0.3.1)
|
192
|
+
sqlite3 (~> 1.4)
|
193
|
+
trailblazer-cells
|
152
194
|
trailblazer-endpoint!
|
153
|
-
trailblazer-operation
|
154
|
-
tzinfo-data
|
195
|
+
trailblazer-operation
|
155
196
|
|
156
197
|
BUNDLED WITH
|
157
|
-
1.
|
198
|
+
2.1.4
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'date'
|
2
|
+
require "jwt"
|
3
|
+
|
4
|
+
# Thanks to pocketrocket GmbH for providing this sample code.
|
5
|
+
module Auth
|
6
|
+
class Jwt
|
7
|
+
# Generate a JWT from arguments
|
8
|
+
def self.generate(encoding_key, encoding_value, payload)
|
9
|
+
# expiration_time = Rails.application.credentials[:jwt_expiration_time].hours.from_now.to_i # TODO: show how to inject config options
|
10
|
+
expiration_time = 1.hours.from_now.to_i
|
11
|
+
payload['exp'] = expiration_time
|
12
|
+
jwt = JWT.encode(payload,
|
13
|
+
Rails.application.credentials[:secret_key_base], 'HS512',
|
14
|
+
{ exp: expiration_time, encoding_key.to_sym => encoding_value }
|
15
|
+
)
|
16
|
+
return jwt
|
17
|
+
end
|
18
|
+
|
19
|
+
# Validate tokens expiration date
|
20
|
+
def self.expired?(token)
|
21
|
+
decoded_token = JwtService.decode(token)
|
22
|
+
expiry_timestamp = decoded_token.first['exp']
|
23
|
+
expiration_date = Time.at(expiry_timestamp).to_datetime
|
24
|
+
return DateTime.now > expiration_date
|
25
|
+
rescue => err
|
26
|
+
return true
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.decode(token)
|
30
|
+
JWT.decode(token, Rails.application.credentials[:secret_key_base], true, { algorithm: 'HS512'})
|
31
|
+
rescue => err # FIXME: is there any way to call {JWT.decode} without an exception?
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# FIXME: this is not final, yet!
|
2
|
+
class Auth::Operation::Authenticate < Trailblazer::Activity::Railway
|
3
|
+
step :verify_token
|
4
|
+
step :is_token_expired?
|
5
|
+
step :set_current_user
|
6
|
+
|
7
|
+
def verify_token(ctx, request:, **)
|
8
|
+
auth_header = request.headers['Authorization'] || ""
|
9
|
+
jwt_encoded_token = auth_header.split(' ').last
|
10
|
+
ctx[:encoded_jwt_token] = jwt_encoded_token
|
11
|
+
|
12
|
+
# FIXME
|
13
|
+
#raise StandardError if JwtService.expired?(jwt_encoded_token)
|
14
|
+
ctx[:decoded_jwt_token] = Auth::Jwt.decode(jwt_encoded_token)
|
15
|
+
end
|
16
|
+
|
17
|
+
def is_token_expired?(ctx, decoded_jwt_token:, **)
|
18
|
+
expiration_integer = decoded_jwt_token.first['exp']
|
19
|
+
return false if expiration_integer.nil?
|
20
|
+
return false if (expiration_integer - DateTime.now.to_i) <= 0
|
21
|
+
return true
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_current_user(ctx, decoded_jwt_token:, **)
|
25
|
+
user_id = decoded_jwt_token.first['user_id']
|
26
|
+
|
27
|
+
ctx[:current_user] = User.find_by(
|
28
|
+
id: user_id
|
29
|
+
)
|
30
|
+
true # FIXME
|
31
|
+
end
|
32
|
+
end
|