heroku_config_vars 0.0.2.pre → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1 +1,71 @@
1
- TODO
1
+ # HerokuConfigVars
2
+
3
+ [![Build Status](https://travis-ci.org/danielfone/heroku_config_vars.png?branch=master)](https://travis-ci.org/danielfone/heroku_config_vars)
4
+ [![Dependency Status](https://gemnasium.com/danielfone/heroku_config_vars.png)](https://gemnasium.com/danielfone/heroku_config_vars)
5
+ [![Code Climate](https://codeclimate.com/github/danielfone/heroku_config_vars.png)](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
- class HerokuConfigVars::ApplicationController < ApplicationController
1
+ module HerokuConfigVars
2
+ class ApplicationController < ::ApplicationController
2
3
 
3
- before_filter :require_authenticated
4
- before_filter :recommend_https, :if => :insecure?
4
+ before_filter :require_authenticated
5
+ before_filter :recommend_https, :if => :insecure?
5
6
 
6
- AUTH_METHOD = :heroku_config_authorized?
7
+ layout 'heroku_config_vars/application'
7
8
 
8
- def env
9
- @env = ENV
10
- end
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? AUTH_METHOD
17
+ if not respond_to? HerokuConfigVars.authorization_method
18
18
  raise ActionController::RoutingError.new <<-ERROR.strip_heredoc
19
- `#{AUTH_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 #{AUTH_METHOD}
26
- current_user.admin?
27
- end
28
-
29
- ...
30
- end
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 heroku_config_authorized?
33
- raise ActionController::RoutingError.new ':heroku_config_authorized? returned false'
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>HerokuConfigVars</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 Configurator</h1>
10
+ <h1>Heroku Configuration</h1>
11
11
 
12
12
  <ul class="submenu">
13
13
  <li><%= menu_link 'Heroku Configuration Variables', heroku_app_path %></li>
@@ -1,3 +1,3 @@
1
1
  module HerokuConfigVars
2
- VERSION = "0.0.2.pre"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -2,4 +2,6 @@ require 'heroku-api'
2
2
  require "heroku_config_vars/engine"
3
3
 
4
4
  module HerokuConfigVars
5
+ mattr_accessor :authorization_method
6
+ self.authorization_method = :heroku_config_vars_authorized?
5
7
  end
@@ -1,8 +1,18 @@
1
1
  class ApplicationController < ActionController::Base
2
2
  protect_from_forgery
3
3
 
4
- def heroku_config_authorized?
5
- params[:admin] != 'false'
6
- end
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?
@@ -1,4 +1,7 @@
1
1
  Rails.application.routes.draw do
2
2
 
3
+ resources :widgets
4
+
3
5
  mount HerokuConfigVars::Engine => "/heroku_config_vars"
6
+
4
7
  end