balrog 1.0.0 → 1.1.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +83 -67
- data/README.md +39 -4
- data/app/views/balrog/gate.html.erb +6 -26
- data/app/views/layouts/balrog.html.erb +21 -0
- data/lib/balrog/generators.rb +1 -1
- data/lib/balrog/generators/install_generator.rb +1 -0
- data/lib/balrog/generators/view_generator.rb +25 -0
- data/lib/balrog/guard.rb +24 -0
- data/lib/balrog/helpers.rb +6 -2
- data/lib/balrog/middleware.rb +14 -1
- data/lib/balrog/routes_middleware.rb +7 -4
- data/lib/balrog/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 232b0520af207a4da00798bba32874e5ef4ee33c55419793c7ec23e8312c5712
|
|
4
|
+
data.tar.gz: 4fc0f719261215f6b2c657f4d2a1964df096d92b67cf2b94f1585ec99a609b94
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4521321149b2a0636694f064e43cb20e8416c8eb2f93fd90668195d82a68dfd17bca183618664049139428dec095e7a74f1754b0b66a650d71d3d78610a91806
|
|
7
|
+
data.tar.gz: 4d7fbda793ea374006246abae4c9f1aa62b9369972e33f94aa090a152c799a2800d0081b29ec65a1a8d9a1b2a351f11bfe7ce9a85a47ff0637b54b769a707e69
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# 1.1.0
|
|
2
|
+
- added `Balrog::Middleware#session_expires_after`, which would force end users to login again after a certain period of time.
|
|
3
|
+
- added `balrog:view` generator, enabling users to modify their Balrog gate view.
|
|
4
|
+
|
|
1
5
|
# 1.0.0
|
|
2
6
|
|
|
3
7
|
- added `Balrog::RoutesMiddleware` module, which can be used to protect mounted Rack applications.
|
data/Gemfile.lock
CHANGED
|
@@ -1,66 +1,79 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
balrog (1.
|
|
4
|
+
balrog (1.1.0)
|
|
5
5
|
bcrypt (~> 3.0)
|
|
6
6
|
rails (>= 5)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
actioncable (
|
|
12
|
-
actionpack (=
|
|
11
|
+
actioncable (6.0.1)
|
|
12
|
+
actionpack (= 6.0.1)
|
|
13
13
|
nio4r (~> 2.0)
|
|
14
14
|
websocket-driver (>= 0.6.1)
|
|
15
|
-
|
|
16
|
-
actionpack (=
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
actionmailbox (6.0.1)
|
|
16
|
+
actionpack (= 6.0.1)
|
|
17
|
+
activejob (= 6.0.1)
|
|
18
|
+
activerecord (= 6.0.1)
|
|
19
|
+
activestorage (= 6.0.1)
|
|
20
|
+
activesupport (= 6.0.1)
|
|
21
|
+
mail (>= 2.7.1)
|
|
22
|
+
actionmailer (6.0.1)
|
|
23
|
+
actionpack (= 6.0.1)
|
|
24
|
+
actionview (= 6.0.1)
|
|
25
|
+
activejob (= 6.0.1)
|
|
19
26
|
mail (~> 2.5, >= 2.5.4)
|
|
20
27
|
rails-dom-testing (~> 2.0)
|
|
21
|
-
actionpack (
|
|
22
|
-
actionview (=
|
|
23
|
-
activesupport (=
|
|
28
|
+
actionpack (6.0.1)
|
|
29
|
+
actionview (= 6.0.1)
|
|
30
|
+
activesupport (= 6.0.1)
|
|
24
31
|
rack (~> 2.0)
|
|
25
32
|
rack-test (>= 0.6.3)
|
|
26
33
|
rails-dom-testing (~> 2.0)
|
|
27
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
35
|
+
actiontext (6.0.1)
|
|
36
|
+
actionpack (= 6.0.1)
|
|
37
|
+
activerecord (= 6.0.1)
|
|
38
|
+
activestorage (= 6.0.1)
|
|
39
|
+
activesupport (= 6.0.1)
|
|
40
|
+
nokogiri (>= 1.8.5)
|
|
41
|
+
actionview (6.0.1)
|
|
42
|
+
activesupport (= 6.0.1)
|
|
30
43
|
builder (~> 3.1)
|
|
31
44
|
erubi (~> 1.4)
|
|
32
45
|
rails-dom-testing (~> 2.0)
|
|
33
|
-
rails-html-sanitizer (~> 1.
|
|
34
|
-
activejob (
|
|
35
|
-
activesupport (=
|
|
46
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
47
|
+
activejob (6.0.1)
|
|
48
|
+
activesupport (= 6.0.1)
|
|
36
49
|
globalid (>= 0.3.6)
|
|
37
|
-
activemodel (
|
|
38
|
-
activesupport (=
|
|
39
|
-
activerecord (
|
|
40
|
-
activemodel (=
|
|
41
|
-
activesupport (=
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
activerecord (=
|
|
50
|
+
activemodel (6.0.1)
|
|
51
|
+
activesupport (= 6.0.1)
|
|
52
|
+
activerecord (6.0.1)
|
|
53
|
+
activemodel (= 6.0.1)
|
|
54
|
+
activesupport (= 6.0.1)
|
|
55
|
+
activestorage (6.0.1)
|
|
56
|
+
actionpack (= 6.0.1)
|
|
57
|
+
activejob (= 6.0.1)
|
|
58
|
+
activerecord (= 6.0.1)
|
|
46
59
|
marcel (~> 0.3.1)
|
|
47
|
-
activesupport (
|
|
60
|
+
activesupport (6.0.1)
|
|
48
61
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
49
62
|
i18n (>= 0.7, < 2)
|
|
50
63
|
minitest (~> 5.1)
|
|
51
64
|
tzinfo (~> 1.1)
|
|
52
|
-
|
|
53
|
-
bcrypt (3.1.
|
|
65
|
+
zeitwerk (~> 2.2)
|
|
66
|
+
bcrypt (3.1.13)
|
|
54
67
|
builder (3.2.3)
|
|
55
68
|
concurrent-ruby (1.1.5)
|
|
56
|
-
crass (1.0.
|
|
69
|
+
crass (1.0.5)
|
|
57
70
|
diff-lcs (1.3)
|
|
58
|
-
erubi (1.
|
|
71
|
+
erubi (1.9.0)
|
|
59
72
|
globalid (0.4.2)
|
|
60
73
|
activesupport (>= 4.2.0)
|
|
61
|
-
i18n (1.
|
|
74
|
+
i18n (1.7.0)
|
|
62
75
|
concurrent-ruby (~> 1.0)
|
|
63
|
-
loofah (2.
|
|
76
|
+
loofah (2.3.1)
|
|
64
77
|
crass (~> 1.0.2)
|
|
65
78
|
nokogiri (>= 1.5.9)
|
|
66
79
|
mail (2.7.1)
|
|
@@ -69,54 +82,56 @@ GEM
|
|
|
69
82
|
mimemagic (~> 0.3.2)
|
|
70
83
|
method_source (0.9.2)
|
|
71
84
|
mimemagic (0.3.3)
|
|
72
|
-
mini_mime (1.0.
|
|
85
|
+
mini_mime (1.0.2)
|
|
73
86
|
mini_portile2 (2.4.0)
|
|
74
|
-
minitest (5.
|
|
75
|
-
nio4r (2.
|
|
76
|
-
nokogiri (1.10.
|
|
87
|
+
minitest (5.13.0)
|
|
88
|
+
nio4r (2.5.2)
|
|
89
|
+
nokogiri (1.10.5)
|
|
77
90
|
mini_portile2 (~> 2.4.0)
|
|
78
91
|
rack (2.0.7)
|
|
79
92
|
rack-test (1.1.0)
|
|
80
93
|
rack (>= 1.0, < 3)
|
|
81
|
-
rails (
|
|
82
|
-
actioncable (=
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
rails (6.0.1)
|
|
95
|
+
actioncable (= 6.0.1)
|
|
96
|
+
actionmailbox (= 6.0.1)
|
|
97
|
+
actionmailer (= 6.0.1)
|
|
98
|
+
actionpack (= 6.0.1)
|
|
99
|
+
actiontext (= 6.0.1)
|
|
100
|
+
actionview (= 6.0.1)
|
|
101
|
+
activejob (= 6.0.1)
|
|
102
|
+
activemodel (= 6.0.1)
|
|
103
|
+
activerecord (= 6.0.1)
|
|
104
|
+
activestorage (= 6.0.1)
|
|
105
|
+
activesupport (= 6.0.1)
|
|
91
106
|
bundler (>= 1.3.0)
|
|
92
|
-
railties (=
|
|
107
|
+
railties (= 6.0.1)
|
|
93
108
|
sprockets-rails (>= 2.0.0)
|
|
94
109
|
rails-dom-testing (2.0.3)
|
|
95
110
|
activesupport (>= 4.2.0)
|
|
96
111
|
nokogiri (>= 1.6)
|
|
97
|
-
rails-html-sanitizer (1.0
|
|
98
|
-
loofah (~> 2.
|
|
99
|
-
railties (
|
|
100
|
-
actionpack (=
|
|
101
|
-
activesupport (=
|
|
112
|
+
rails-html-sanitizer (1.3.0)
|
|
113
|
+
loofah (~> 2.3)
|
|
114
|
+
railties (6.0.1)
|
|
115
|
+
actionpack (= 6.0.1)
|
|
116
|
+
activesupport (= 6.0.1)
|
|
102
117
|
method_source
|
|
103
118
|
rake (>= 0.8.7)
|
|
104
|
-
thor (>= 0.
|
|
119
|
+
thor (>= 0.20.3, < 2.0)
|
|
105
120
|
rake (10.5.0)
|
|
106
|
-
rspec (3.
|
|
107
|
-
rspec-core (~> 3.
|
|
108
|
-
rspec-expectations (~> 3.
|
|
109
|
-
rspec-mocks (~> 3.
|
|
110
|
-
rspec-core (3.
|
|
111
|
-
rspec-support (~> 3.
|
|
112
|
-
rspec-expectations (3.
|
|
121
|
+
rspec (3.9.0)
|
|
122
|
+
rspec-core (~> 3.9.0)
|
|
123
|
+
rspec-expectations (~> 3.9.0)
|
|
124
|
+
rspec-mocks (~> 3.9.0)
|
|
125
|
+
rspec-core (3.9.0)
|
|
126
|
+
rspec-support (~> 3.9.0)
|
|
127
|
+
rspec-expectations (3.9.0)
|
|
113
128
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
114
|
-
rspec-support (~> 3.
|
|
115
|
-
rspec-mocks (3.
|
|
129
|
+
rspec-support (~> 3.9.0)
|
|
130
|
+
rspec-mocks (3.9.0)
|
|
116
131
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
117
|
-
rspec-support (~> 3.
|
|
118
|
-
rspec-support (3.
|
|
119
|
-
sprockets (
|
|
132
|
+
rspec-support (~> 3.9.0)
|
|
133
|
+
rspec-support (3.9.0)
|
|
134
|
+
sprockets (4.0.0)
|
|
120
135
|
concurrent-ruby (~> 1.0)
|
|
121
136
|
rack (> 1, < 3)
|
|
122
137
|
sprockets-rails (3.2.1)
|
|
@@ -127,9 +142,10 @@ GEM
|
|
|
127
142
|
thread_safe (0.3.6)
|
|
128
143
|
tzinfo (1.2.5)
|
|
129
144
|
thread_safe (~> 0.1)
|
|
130
|
-
websocket-driver (0.7.
|
|
145
|
+
websocket-driver (0.7.1)
|
|
131
146
|
websocket-extensions (>= 0.1.0)
|
|
132
|
-
websocket-extensions (0.1.
|
|
147
|
+
websocket-extensions (0.1.4)
|
|
148
|
+
zeitwerk (2.2.1)
|
|
133
149
|
|
|
134
150
|
PLATFORMS
|
|
135
151
|
ruby
|
data/README.md
CHANGED
|
@@ -30,8 +30,8 @@ Run the installer to generate an initializer:
|
|
|
30
30
|
|
|
31
31
|
```shell
|
|
32
32
|
$ bundle exec rails generate balrog:install
|
|
33
|
-
Enter New Password:
|
|
34
|
-
Confirm New Password:
|
|
33
|
+
Enter New Password:
|
|
34
|
+
Confirm New Password:
|
|
35
35
|
create config/initializers/balrog.rb
|
|
36
36
|
$
|
|
37
37
|
```
|
|
@@ -107,6 +107,43 @@ Other usage examples:
|
|
|
107
107
|
<%= balrog_logout_button class: 'fancy-button--with-default-text' %>
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
+
## Changing session expiry length
|
|
111
|
+
|
|
112
|
+
`set_session_expiry` requires the user to login again after a period of time.
|
|
113
|
+
To customise this value, open `config/initializers/balrog.rb` after running `balrog:install`
|
|
114
|
+
and change the argument being passed to `set_session_expiry`.
|
|
115
|
+
|
|
116
|
+
The argument passed to `set_session_expiry` can be any of the
|
|
117
|
+
[Rails time extensions](https://api.rubyonrails.org/classes/Numeric.html).
|
|
118
|
+
|
|
119
|
+
If you don't want sessions to expire, remove `set_session_expiry`
|
|
120
|
+
from the initializer completely.
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
Rails.application.config.middleware.use Balrog::Middleware do
|
|
124
|
+
password_hash '$2a$12$BLz7XCFdG9YfwL64KlTgY.T3FY55aQk8SZEzHfpHfw15F2uN1kuSi'
|
|
125
|
+
set_session_expiry 30.minutes
|
|
126
|
+
end
|
|
127
|
+
```
|
|
128
|
+
## Configuring the Balrog gate view
|
|
129
|
+
|
|
130
|
+
We built Balrog to have a default view and stylesheet so that you can drop
|
|
131
|
+
Balrog into your project and everything should “just work”.
|
|
132
|
+
However, we don't want to be in your way if you needed to customise
|
|
133
|
+
your Balrog gate view.
|
|
134
|
+
|
|
135
|
+
If you want to customise the Balrog view, you can run the `balrog:view`
|
|
136
|
+
generator, which will copy the required view and layout to your application:
|
|
137
|
+
|
|
138
|
+
```shell
|
|
139
|
+
$ rails generate balrog:view
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
After running the generator, you can now add elements and classes to the
|
|
143
|
+
`views/balrog/gate.html.erb`, add styles to the
|
|
144
|
+
`assets/stylesheets/application.css` and import the application stylesheet in
|
|
145
|
+
`app/views/layouts/balrog.html.erb`. For an example, see the
|
|
146
|
+
[dummy-rails-app](https://github.com/pixielabs/balrog/tree/master/spec/dummy-rails-app) in the spec folder.
|
|
110
147
|
|
|
111
148
|
## Contributing
|
|
112
149
|
|
|
@@ -137,5 +174,3 @@ Before contributing, please read the [code of conduct](CODE_OF_CONDUCT.md).
|
|
|
137
174
|
|
|
138
175
|
* Restricting access via `routes.rb`
|
|
139
176
|
* Test coverage
|
|
140
|
-
* Check it's OK with Ruby on Rails 6
|
|
141
|
-
* Expire sessions
|
|
@@ -1,26 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
<
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
</head>
|
|
8
|
-
|
|
9
|
-
<body>
|
|
10
|
-
|
|
11
|
-
<section>
|
|
12
|
-
<form action='/balrog/signin' method='POST'>
|
|
13
|
-
<input autofocus type='password' name='password' placeholder='Password'>
|
|
14
|
-
<button type='submit'>Login</button>
|
|
15
|
-
</form>
|
|
16
|
-
</section>
|
|
17
|
-
|
|
18
|
-
<footer>
|
|
19
|
-
<a href="https://github.com/pixielabs/balrog" target="_blank">
|
|
20
|
-
<%= image_tag "balrog/logo.png", class: 'logo' %>
|
|
21
|
-
</a>
|
|
22
|
-
</footer>
|
|
23
|
-
|
|
24
|
-
</body>
|
|
25
|
-
|
|
26
|
-
</html>
|
|
1
|
+
<section>
|
|
2
|
+
<form action='/balrog/signin' method='POST'>
|
|
3
|
+
<input autofocus type='password' name='password' placeholder='Password'>
|
|
4
|
+
<button type='submit'>Login</button>
|
|
5
|
+
</form>
|
|
6
|
+
</section>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang=en>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset=utf-8>
|
|
5
|
+
<title>Login</title>
|
|
6
|
+
<%= stylesheet_link_tag "balrog/gate" %>
|
|
7
|
+
</head>
|
|
8
|
+
|
|
9
|
+
<body>
|
|
10
|
+
|
|
11
|
+
<%= yield %>
|
|
12
|
+
|
|
13
|
+
<footer>
|
|
14
|
+
<a href="https://github.com/pixielabs/balrog" target="_blank">
|
|
15
|
+
<%= image_tag "balrog/logo.png", class: 'logo' %>
|
|
16
|
+
</a>
|
|
17
|
+
</footer>
|
|
18
|
+
|
|
19
|
+
</body>
|
|
20
|
+
|
|
21
|
+
</html>
|
data/lib/balrog/generators.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# This Railtie makes the Balrog Generators available from the command line.
|
|
2
2
|
class Balrog::Generators < Rails::Railtie
|
|
3
3
|
generators do
|
|
4
|
-
|
|
4
|
+
Dir[File.join(__dir__, 'generators', '*.rb')].each { |file| require file }
|
|
5
5
|
end
|
|
6
6
|
end
|
|
@@ -8,6 +8,7 @@ class Balrog::InstallGenerator < Rails::Generators::Base
|
|
|
8
8
|
contents = <<~EOF
|
|
9
9
|
Rails.application.config.middleware.use Balrog::Middleware do
|
|
10
10
|
password_hash '#{password_hash}'
|
|
11
|
+
set_session_expiry 30.minutes
|
|
11
12
|
end
|
|
12
13
|
EOF
|
|
13
14
|
create_file "config/initializers/balrog.rb", contents
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class Balrog::ViewGenerator < Rails::Generators::Base
|
|
2
|
+
|
|
3
|
+
desc "Copies the Balrog gate view and layout into your application, where you can edit and style them."
|
|
4
|
+
def copy_gate_view
|
|
5
|
+
gate_view = File.open(
|
|
6
|
+
File.join(__dir__, '../../../', 'app/views/balrog/gate.html.erb'),
|
|
7
|
+
'r')
|
|
8
|
+
|
|
9
|
+
content = gate_view.read
|
|
10
|
+
gate_view.close
|
|
11
|
+
|
|
12
|
+
create_file "app/views/balrog/gate.html.erb", content
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def copy_layout
|
|
16
|
+
gate_view = File.open(
|
|
17
|
+
File.join(__dir__, '../../../', 'app/views/layouts/balrog.html.erb'),
|
|
18
|
+
'r')
|
|
19
|
+
|
|
20
|
+
content = gate_view.read
|
|
21
|
+
gate_view.close
|
|
22
|
+
|
|
23
|
+
create_file "app/views/layouts/balrog.html.erb", content
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/balrog/guard.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Contains authentication logic to check the user has been authenticated,
|
|
2
|
+
# and that the session hasn't expired.
|
|
3
|
+
module Balrog::Guard
|
|
4
|
+
def authenticated?(balrog_session)
|
|
5
|
+
@balrog_session = balrog_session
|
|
6
|
+
previously_authenticated? && still_valid?
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
# A method to check that the user has been authenticated before.
|
|
12
|
+
def previously_authenticated?
|
|
13
|
+
return false unless @balrog_session
|
|
14
|
+
@balrog_session['value'] == 'authenticated'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# A method to check that the authentication has not expired.
|
|
18
|
+
def still_valid?
|
|
19
|
+
# If the user did not set configured the Balrog session
|
|
20
|
+
# to expire, the cookie is valid.
|
|
21
|
+
return true unless @balrog_session['expiry_date']
|
|
22
|
+
DateTime.current < @balrog_session['expiry_date']
|
|
23
|
+
end
|
|
24
|
+
end
|
data/lib/balrog/helpers.rb
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
require_relative 'guard'
|
|
2
|
+
|
|
1
3
|
# Helpers methods are made available in all controllers by the code in engine.rb.
|
|
2
4
|
module Balrog::Helpers
|
|
5
|
+
include Balrog::Guard
|
|
6
|
+
|
|
3
7
|
def authenticate_with_balrog!
|
|
4
|
-
unless session[:balrog]
|
|
5
|
-
render 'balrog/gate', layout:
|
|
8
|
+
unless authenticated?(session[:balrog])
|
|
9
|
+
render 'balrog/gate', layout: 'balrog'
|
|
6
10
|
end
|
|
7
11
|
end
|
|
8
12
|
end
|
data/lib/balrog/middleware.rb
CHANGED
|
@@ -34,6 +34,10 @@ class Balrog::Middleware
|
|
|
34
34
|
@password_hash = BCrypt::Password.new(input)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
def set_session_expiry(time_period)
|
|
38
|
+
@session_length = time_period
|
|
39
|
+
end
|
|
40
|
+
|
|
37
41
|
def handle_login(env)
|
|
38
42
|
if env['rack.request.form_hash']
|
|
39
43
|
submitted_password = env['rack.request.form_hash']['password']
|
|
@@ -56,7 +60,9 @@ class Balrog::Middleware
|
|
|
56
60
|
end
|
|
57
61
|
|
|
58
62
|
if @password_hash == submitted_password
|
|
59
|
-
|
|
63
|
+
session_data = { value: 'authenticated' }
|
|
64
|
+
add_expiry_date!(session_data)
|
|
65
|
+
env['rack.session'][:balrog] = session_data
|
|
60
66
|
end
|
|
61
67
|
|
|
62
68
|
referer = env["HTTP_REFERER"] || '/'
|
|
@@ -69,5 +75,12 @@ class Balrog::Middleware
|
|
|
69
75
|
[302, {"Location" => '/'}, [""]]
|
|
70
76
|
end
|
|
71
77
|
|
|
78
|
+
# If the user configured the Balrog session to expire, add the
|
|
79
|
+
# expiry_date to the Balrog session.
|
|
80
|
+
def add_expiry_date!(session_data)
|
|
81
|
+
if @session_length
|
|
82
|
+
session_data[:expiry_date] = DateTime.current + @session_length
|
|
83
|
+
end
|
|
84
|
+
end
|
|
72
85
|
end
|
|
73
86
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require_relative 'guard'
|
|
2
|
+
|
|
1
3
|
# Public: Balrog routes middleware that redirects the user to a security
|
|
2
4
|
# gate unless the session includes { 'balrog' => 'authenticated' }.
|
|
3
5
|
#
|
|
@@ -11,17 +13,18 @@
|
|
|
11
13
|
# mount Sidekiq::Web => '/sidekiq'
|
|
12
14
|
|
|
13
15
|
class Balrog::RoutesMiddleware
|
|
16
|
+
include Balrog::Guard
|
|
17
|
+
|
|
14
18
|
def initialize(app)
|
|
15
19
|
@app = app
|
|
16
20
|
end
|
|
17
21
|
|
|
18
22
|
def call(env)
|
|
19
|
-
unless env['rack.session']['balrog']
|
|
20
|
-
html = ApplicationController.renderer.render 'balrog/gate', layout:
|
|
23
|
+
unless authenticated?(env['rack.session']['balrog'])
|
|
24
|
+
html = ApplicationController.renderer.render 'balrog/gate', layout: 'balrog'
|
|
21
25
|
return [200, {"Content-Type" => "text/html"}, [html]]
|
|
22
26
|
end
|
|
23
27
|
@app.call(env)
|
|
24
|
-
end
|
|
25
|
-
|
|
28
|
+
end
|
|
26
29
|
end
|
|
27
30
|
|
data/lib/balrog/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: balrog
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Pixie Labs
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-11-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bcrypt
|
|
@@ -102,6 +102,7 @@ files:
|
|
|
102
102
|
- app/assets/images/balrog/logo.png
|
|
103
103
|
- app/assets/stylesheets/balrog/gate.css
|
|
104
104
|
- app/views/balrog/gate.html.erb
|
|
105
|
+
- app/views/layouts/balrog.html.erb
|
|
105
106
|
- balrog.gemspec
|
|
106
107
|
- bin/console
|
|
107
108
|
- bin/setup
|
|
@@ -109,6 +110,8 @@ files:
|
|
|
109
110
|
- lib/balrog/engine.rb
|
|
110
111
|
- lib/balrog/generators.rb
|
|
111
112
|
- lib/balrog/generators/install_generator.rb
|
|
113
|
+
- lib/balrog/generators/view_generator.rb
|
|
114
|
+
- lib/balrog/guard.rb
|
|
112
115
|
- lib/balrog/helpers.rb
|
|
113
116
|
- lib/balrog/middleware.rb
|
|
114
117
|
- lib/balrog/password_hasher.rb
|