heroku_config_vars 0.0.2.pre → 1.0.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.
- data/README.md +71 -1
- data/app/controllers/heroku_config_vars/application_controller.rb +31 -25
- data/app/views/layouts/heroku_config_vars/application.html.erb +2 -2
- data/lib/heroku_config_vars/version.rb +1 -1
- data/lib/heroku_config_vars.rb +2 -0
- data/spec/dummy/app/controllers/application_controller.rb +13 -3
- data/spec/dummy/config/initializers/heroku_config_vars.rb +1 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/log/test.log +7052 -0
- data/spec/dummy/tmp/capybara/capybara-201303191317084976807424.html +26 -0
- data/spec/dummy/tmp/pids/server.pid +1 -1
- data/spec/features/config_vars/edit_spec.rb +7 -7
- data/spec/features/config_vars/show_spec.rb +2 -2
- data/spec/features/env/show_spec.rb +1 -1
- data/spec/features/security/requires_admin_spec.rb +3 -1
- data/spec/features/security/suggests_ssl_spec.rb +5 -5
- data/spec/features/setup/new_app_spec.rb +6 -6
- data/spec/spec_helper.rb +0 -1
- metadata +17 -10
data/README.md
CHANGED
@@ -1 +1,71 @@
|
|
1
|
-
|
1
|
+
# HerokuConfigVars
|
2
|
+
|
3
|
+
[](https://travis-ci.org/danielfone/heroku_config_vars)
|
4
|
+
[](https://gemnasium.com/danielfone/heroku_config_vars)
|
5
|
+
[](https://codeclimate.com/github/danielfone/heroku_config_vars)
|
6
|
+
|
7
|
+
This engine allows you to manage Heroku configuration variables from within your application.
|
8
|
+
|
9
|
+
## Installation into your application
|
10
|
+
|
11
|
+
1. Add `gem 'heroku_config_vars'` to your Gemfile
|
12
|
+
2. Add `mount HerokuConfigVars::Engine => "/heroku_config_vars"` to your routes.rb
|
13
|
+
3. Implement the method `:heroku_config_vars_authorized?` on your ApplicationController. (See [Customization](#customization))
|
14
|
+
4. To make authorization easy, this engine inherits from your ApplicationController.
|
15
|
+
This means that you may have to change named routes to be more specific. e.g.
|
16
|
+
|
17
|
+
```diff
|
18
|
+
class ApplicationController < ActionController::Base
|
19
|
+
before_filter :authenticate
|
20
|
+
|
21
|
+
def authenticate
|
22
|
+
- redirect_to new_session_path unless logged_in?
|
23
|
+
+ redirect_to main_app.new_session_path unless logged_in?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
## Setup
|
29
|
+
|
30
|
+
1. Deploy your app to Heroku
|
31
|
+
2. Visit /heroku_config_vars
|
32
|
+
3. Enter valid Heroku credentials for your application.
|
33
|
+
These are stored in the Heroku configuration for this application so you don't need to enter them again.
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
With this engine you can:
|
38
|
+
|
39
|
+
* View the complete ruby ENV hash
|
40
|
+
* View the Heroku configuration
|
41
|
+
* Update, add and delete Heroku configuration variables
|
42
|
+
|
43
|
+
|
44
|
+
## Customization
|
45
|
+
|
46
|
+
You can change the path to the engine by changing the line in your routes.rb
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
# config/routes.rb
|
50
|
+
mount HerokuConfigVars::Engine => "/whatever_path_you_like"`
|
51
|
+
```
|
52
|
+
|
53
|
+
You can also change the name of the authorization method to call on ApplicationController.
|
54
|
+
You may wish to do this if you already have an appropriate authorization method defined. e.g.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
# config/initializers/heroku_config_vars.rb
|
58
|
+
HerokuConfigVars.authorization_method = :admin_logged_in?
|
59
|
+
```
|
60
|
+
|
61
|
+
A typical implementation of this method might look like:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
class ApplicationController < ActionController::Base
|
65
|
+
...
|
66
|
+
def heroku_config_vars_authorized?
|
67
|
+
current_user && current_user.admin?
|
68
|
+
end
|
69
|
+
...
|
70
|
+
end
|
71
|
+
```
|
@@ -1,36 +1,42 @@
|
|
1
|
-
|
1
|
+
module HerokuConfigVars
|
2
|
+
class ApplicationController < ::ApplicationController
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
before_filter :require_authenticated
|
5
|
+
before_filter :recommend_https, :if => :insecure?
|
5
6
|
|
6
|
-
|
7
|
+
layout 'heroku_config_vars/application'
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def env
|
10
|
+
@env = ENV
|
11
|
+
end
|
11
12
|
|
12
13
|
private
|
13
14
|
|
14
15
|
def require_authenticated
|
15
|
-
# This is where we shell out to ApplicationController
|
16
16
|
# raising RoutingError will render 404 in production
|
17
|
-
if not respond_to?
|
17
|
+
if not respond_to? HerokuConfigVars.authorization_method
|
18
18
|
raise ActionController::RoutingError.new <<-ERROR.strip_heredoc
|
19
|
-
`#{
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
19
|
+
`#{HerokuConfigVars.authorization_method}` must be implemented in ApplicationController and return true for authorized users.
|
20
|
+
|
21
|
+
e.g.
|
22
|
+
class ApplicationController < ActionController::Base
|
23
|
+
...
|
24
|
+
|
25
|
+
def #{HerokuConfigVars.authorization_method}
|
26
|
+
current_user.admin?
|
27
|
+
end
|
28
|
+
|
29
|
+
...
|
30
|
+
end
|
31
|
+
|
32
|
+
You can change the name of this method. e.g.
|
33
|
+
|
34
|
+
# config/initializers/heroku_config_vars.rb
|
35
|
+
HerokuConfigVars.authorization_method = :my_other_auth?
|
36
|
+
|
31
37
|
ERROR
|
32
|
-
elsif not
|
33
|
-
raise ActionController::RoutingError.new
|
38
|
+
elsif not send HerokuConfigVars.authorization_method
|
39
|
+
raise ActionController::RoutingError.new "Authorisation block returned false"
|
34
40
|
end
|
35
41
|
end
|
36
42
|
|
@@ -42,5 +48,5 @@ class HerokuConfigVars::ApplicationController < ApplicationController
|
|
42
48
|
def insecure?
|
43
49
|
not request.ssl? and (session[:insecure] ||= params[:insecure]) != 'ok'
|
44
50
|
end
|
45
|
-
|
46
|
-
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
2
|
<html>
|
3
3
|
<head>
|
4
|
-
<title>
|
4
|
+
<title>Heroku Configuration</title>
|
5
5
|
<%= stylesheet_link_tag "heroku_config_vars/application", :media => "all" %>
|
6
6
|
<%= javascript_include_tag "heroku_config_vars/application" %>
|
7
7
|
<%= csrf_meta_tags %>
|
8
8
|
</head>
|
9
9
|
<body>
|
10
|
-
<h1>Heroku
|
10
|
+
<h1>Heroku Configuration</h1>
|
11
11
|
|
12
12
|
<ul class="submenu">
|
13
13
|
<li><%= menu_link 'Heroku Configuration Variables', heroku_app_path %></li>
|
data/lib/heroku_config_vars.rb
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
class ApplicationController < ActionController::Base
|
2
2
|
protect_from_forgery
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
before_filter :break_inheritance
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
def heroku_config_auth?
|
9
|
+
params[:admin] != 'false'
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def break_inheritance
|
15
|
+
main_app.widgets_path
|
16
|
+
end
|
7
17
|
|
8
18
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
HerokuConfigVars.authorization_method = :heroku_config_auth?
|