consul 0.1.2 → 0.2.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.
Potentially problematic release.
This version of consul might be problematic. Click here for more details.
- data/Gemfile +2 -8
- data/README.md +275 -0
- data/Rakefile +4 -25
- data/consul.gemspec +20 -96
- data/lib/consul.rb +1 -0
- data/lib/consul/active_record.rb +14 -0
- data/lib/consul/controller.rb +29 -0
- data/lib/consul/errors.rb +4 -3
- data/lib/consul/power.rb +2 -0
- data/lib/consul/version.rb +3 -0
- data/spec/app_root/app/controllers/application_controller.rb +2 -4
- data/spec/app_root/app/controllers/dashboards_controller.rb +12 -1
- data/spec/app_root/app/controllers/songs_controller.rb +3 -4
- data/spec/app_root/app/controllers/users_controller.rb +3 -3
- data/spec/app_root/app/models/power.rb +10 -6
- data/spec/app_root/config/routes.rb +1 -1
- data/spec/app_root/db/migrate/001_create_users.rb +3 -1
- data/spec/consul/active_record_spec.rb +37 -0
- data/spec/consul/power_spec.rb +17 -6
- data/spec/controllers/dashboards_controller_spec.rb +17 -0
- data/spec/controllers/songs_controller_spec.rb +4 -4
- data/spec/controllers/users_controller_spec.rb +3 -3
- data/spec/spec_helper.rb +10 -1
- data/spec/support/spec.opts +4 -0
- data/spec/support/spec_candy.rb +179 -0
- metadata +124 -42
- data/README.rdoc +0 -213
- data/VERSION +0 -1
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consul
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Henning Koch
|
@@ -15,29 +15,131 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
date: 2012-02-28 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
name: rails
|
33
|
+
version_requirements: *id001
|
34
|
+
type: :runtime
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
name: assignable_values
|
47
|
+
version_requirements: *id002
|
48
|
+
type: :runtime
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 5
|
57
|
+
segments:
|
58
|
+
- 2
|
59
|
+
- 3
|
60
|
+
version: "2.3"
|
61
|
+
name: rails
|
62
|
+
version_requirements: *id003
|
63
|
+
type: :development
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ~>
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 9
|
72
|
+
segments:
|
73
|
+
- 1
|
74
|
+
- 3
|
75
|
+
version: "1.3"
|
76
|
+
name: rspec
|
77
|
+
version_requirements: *id004
|
78
|
+
type: :development
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
prerelease: false
|
81
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ~>
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 9
|
87
|
+
segments:
|
88
|
+
- 1
|
89
|
+
- 3
|
90
|
+
version: "1.3"
|
91
|
+
name: rspec-rails
|
92
|
+
version_requirements: *id005
|
93
|
+
type: :development
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
prerelease: false
|
96
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
name: shoulda-matchers
|
106
|
+
version_requirements: *id006
|
107
|
+
type: :development
|
108
|
+
- !ruby/object:Gem::Dependency
|
109
|
+
prerelease: false
|
110
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
hash: 3
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
119
|
+
name: sqlite3
|
120
|
+
version_requirements: *id007
|
121
|
+
type: :development
|
122
|
+
description: A scope-based authorization solution for Ruby on Rails.
|
22
123
|
email: henning.koch@makandra.de
|
23
124
|
executables: []
|
24
125
|
|
25
126
|
extensions: []
|
26
127
|
|
27
|
-
extra_rdoc_files:
|
28
|
-
|
128
|
+
extra_rdoc_files: []
|
129
|
+
|
29
130
|
files:
|
30
131
|
- .gitignore
|
31
132
|
- Gemfile
|
32
|
-
- README.
|
133
|
+
- README.md
|
33
134
|
- Rakefile
|
34
|
-
- VERSION
|
35
135
|
- consul.gemspec
|
36
136
|
- lib/consul.rb
|
137
|
+
- lib/consul/active_record.rb
|
37
138
|
- lib/consul/controller.rb
|
38
139
|
- lib/consul/errors.rb
|
39
140
|
- lib/consul/power.rb
|
40
141
|
- lib/consul/spec/matchers.rb
|
142
|
+
- lib/consul/version.rb
|
41
143
|
- spec/app_root/app/controllers/application_controller.rb
|
42
144
|
- spec/app_root/app/controllers/dashboards_controller.rb
|
43
145
|
- spec/app_root/app/controllers/songs_controller.rb
|
@@ -61,6 +163,7 @@ files:
|
|
61
163
|
- spec/app_root/lib/console_with_fixtures.rb
|
62
164
|
- spec/app_root/log/.gitignore
|
63
165
|
- spec/app_root/script/console
|
166
|
+
- spec/consul/active_record_spec.rb
|
64
167
|
- spec/consul/power_spec.rb
|
65
168
|
- spec/controllers/dashboards_controller_spec.rb
|
66
169
|
- spec/controllers/songs_controller_spec.rb
|
@@ -68,12 +171,15 @@ files:
|
|
68
171
|
- spec/rcov.opts
|
69
172
|
- spec/spec.opts
|
70
173
|
- spec/spec_helper.rb
|
71
|
-
|
174
|
+
- spec/support/spec.opts
|
175
|
+
- spec/support/spec_candy.rb
|
176
|
+
has_rdoc: true
|
177
|
+
homepage: https://github.com/makandra/consul
|
72
178
|
licenses: []
|
73
179
|
|
74
180
|
post_install_message:
|
75
|
-
rdoc_options:
|
76
|
-
|
181
|
+
rdoc_options: []
|
182
|
+
|
77
183
|
require_paths:
|
78
184
|
- lib
|
79
185
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -97,33 +203,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
203
|
requirements: []
|
98
204
|
|
99
205
|
rubyforge_project:
|
100
|
-
rubygems_version: 1.
|
206
|
+
rubygems_version: 1.3.9.4
|
101
207
|
signing_key:
|
102
208
|
specification_version: 3
|
103
|
-
summary:
|
104
|
-
test_files:
|
105
|
-
|
106
|
-
- spec/controllers/songs_controller_spec.rb
|
107
|
-
- spec/controllers/dashboards_controller_spec.rb
|
108
|
-
- spec/spec_helper.rb
|
109
|
-
- spec/consul/power_spec.rb
|
110
|
-
- spec/app_root/app/controllers/songs_controller.rb
|
111
|
-
- spec/app_root/app/controllers/dashboards_controller.rb
|
112
|
-
- spec/app_root/app/controllers/application_controller.rb
|
113
|
-
- spec/app_root/app/controllers/users_controller.rb
|
114
|
-
- spec/app_root/app/models/client.rb
|
115
|
-
- spec/app_root/app/models/power.rb
|
116
|
-
- spec/app_root/app/models/user.rb
|
117
|
-
- spec/app_root/app/models/note.rb
|
118
|
-
- spec/app_root/lib/console_with_fixtures.rb
|
119
|
-
- spec/app_root/config/boot.rb
|
120
|
-
- spec/app_root/config/routes.rb
|
121
|
-
- spec/app_root/config/environments/mysql.rb
|
122
|
-
- spec/app_root/config/environments/sqlite3.rb
|
123
|
-
- spec/app_root/config/environments/in_memory.rb
|
124
|
-
- spec/app_root/config/environments/postgresql.rb
|
125
|
-
- spec/app_root/config/environments/sqlite.rb
|
126
|
-
- spec/app_root/config/environment.rb
|
127
|
-
- spec/app_root/db/migrate/001_create_users.rb
|
128
|
-
- spec/app_root/db/migrate/002_create_clients.rb
|
129
|
-
- spec/app_root/db/migrate/003_create_notes.rb
|
209
|
+
summary: A scope-based authorization solution for Ruby on Rails.
|
210
|
+
test_files: []
|
211
|
+
|
data/README.rdoc
DELETED
@@ -1,213 +0,0 @@
|
|
1
|
-
= Consul - A scope-based authorization solution
|
2
|
-
|
3
|
-
Consul is a authorization solution for Ruby on Rails that uses scopes to control what a user can see or edit.
|
4
|
-
|
5
|
-
|
6
|
-
== Status of this project
|
7
|
-
|
8
|
-
Consul is a new kind of authorization solution for Rails applications that are mainly driven by scopes.
|
9
|
-
While Consul has been used in production code, we are still figuring out whether or not it is a good idea.
|
10
|
-
Also documentation is still sparse.
|
11
|
-
|
12
|
-
If you are looking for something less adventurous with a stable API and great documentation, checkout out our
|
13
|
-
other authorization solution, {Aegis}[https://github.com/makandra/aegis].
|
14
|
-
|
15
|
-
|
16
|
-
== Describing a power for your application
|
17
|
-
|
18
|
-
You describe access to your application by putting a <tt>Power</tt> model into <tt>app/models/power.rb</tt>:
|
19
|
-
|
20
|
-
class Power
|
21
|
-
include Consul::Power
|
22
|
-
|
23
|
-
def initialize(user)
|
24
|
-
@user = user
|
25
|
-
end
|
26
|
-
|
27
|
-
power :notes do
|
28
|
-
Note.by_author(@user)
|
29
|
-
end
|
30
|
-
|
31
|
-
power :users do
|
32
|
-
User if @user.admin?
|
33
|
-
end
|
34
|
-
|
35
|
-
power :dashboard do
|
36
|
-
true # not a scope, but a boolean power. This is useful to control access to stuff that doesn't live in the database.
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
== Querying a power
|
43
|
-
|
44
|
-
Common things you might want from a power:
|
45
|
-
|
46
|
-
1. Get its scope
|
47
|
-
2. Ask whether it is there
|
48
|
-
3. Raise an error unless it its there
|
49
|
-
4. Ask whether a given record is included in its scope
|
50
|
-
5. Raise an error unless a given record is included in its scope
|
51
|
-
|
52
|
-
Here is how to do all of that:
|
53
|
-
|
54
|
-
power = Power.new(user)
|
55
|
-
power.notes # => returns an ActiveRecord::Scope
|
56
|
-
power.notes? # => returns true if Power#notes returns a scope
|
57
|
-
power.notes! # => raises Consul::Powerless unless Power#notes returns a scope
|
58
|
-
power.note?(Note.last) # => returns whether the given Note is in the Power#notes scope. Caches the result for subsequent queries.
|
59
|
-
power.note!(Note.last) # => raises Consul::Powerless unless the given Note is in the Power#notes scope
|
60
|
-
|
61
|
-
You can also write power checks like this:
|
62
|
-
|
63
|
-
power.include?(:notes)
|
64
|
-
power.include!(:notes)
|
65
|
-
power.include?(:note, Note.last)
|
66
|
-
power.include!(:note, Note.last)
|
67
|
-
|
68
|
-
|
69
|
-
== Boolean powers
|
70
|
-
|
71
|
-
Boolean powers are useful to control access to stuff that doesn't live in the database:
|
72
|
-
|
73
|
-
class Power
|
74
|
-
...
|
75
|
-
|
76
|
-
power :dashboard do
|
77
|
-
true
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
You can query it like the other powers:
|
83
|
-
|
84
|
-
power.dashboard? # => true
|
85
|
-
power.dashboard! # => raises Consul::Powerless unless Power#dashboard? returns true
|
86
|
-
|
87
|
-
|
88
|
-
== Role-based permissions
|
89
|
-
|
90
|
-
Consul has no built-in support for role-based permissions, but you can easily implement it yourself. Let's say your <tt>User</tt> model has a string column <tt>role</tt> which can be <tt>"author"</tt> or "<tt>"admin"</tt>:
|
91
|
-
|
92
|
-
class Power
|
93
|
-
include Consul::Power
|
94
|
-
|
95
|
-
def initialize(user)
|
96
|
-
@user = user
|
97
|
-
end
|
98
|
-
|
99
|
-
power :notes do
|
100
|
-
case role
|
101
|
-
when :admin then Note
|
102
|
-
when :author then Note.by_author
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
private
|
107
|
-
|
108
|
-
def role
|
109
|
-
@user.role.to_sym
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
|
115
|
-
== Controller integration
|
116
|
-
|
117
|
-
It is convenient to expose a helper method <tt>current_power</tt> for your controllers and views:
|
118
|
-
|
119
|
-
class ApplicationController < ActionController::Base
|
120
|
-
|
121
|
-
private
|
122
|
-
|
123
|
-
def current_power
|
124
|
-
@current_power ||= Power.new(current_user)
|
125
|
-
end
|
126
|
-
|
127
|
-
helper_method :current_power
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
You can now use power scopes to control access:
|
132
|
-
|
133
|
-
class NotesController < ApplicationController
|
134
|
-
|
135
|
-
def show
|
136
|
-
@note = current_power.notes.find(params[:id])
|
137
|
-
end
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
Get convenient controller macros by including <tt>Consul::Controller</tt> in your application:
|
142
|
-
|
143
|
-
class ApplicationController < ActionController::Base
|
144
|
-
include Consul::Controller
|
145
|
-
end
|
146
|
-
|
147
|
-
To make sure a power is given before every action in a controller:
|
148
|
-
|
149
|
-
class NotesController < ApplicationController
|
150
|
-
power :notes
|
151
|
-
end
|
152
|
-
|
153
|
-
You can use <tt>:except</tt> and <tt>:only</tt> options like in before filters.
|
154
|
-
|
155
|
-
You can also map different powers to different actions:
|
156
|
-
|
157
|
-
class NotesController < ApplicationController
|
158
|
-
power :notes, :map => { [:edit, :update, :destroy] => :changable_notes }
|
159
|
-
end
|
160
|
-
|
161
|
-
It is often convenient to map a power scope to a private controller method:
|
162
|
-
|
163
|
-
class NotesController < ApplicationController
|
164
|
-
|
165
|
-
power :notes, :as => end_of_association_chain
|
166
|
-
|
167
|
-
def show
|
168
|
-
@note = end_of_association_chain.find(params[:id])
|
169
|
-
end
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
|
-
This is especially useful when you are using a RESTful controller library like {resource_controller}[https://github.com/jamesgolick/resource_controller]. The mapped method is aware of the <tt>:map</tt> option.
|
174
|
-
|
175
|
-
You can force yourself to use a <tt>power</tt> check in every controller. This will raise <tt>Consul::UncheckedPower</tt> if you ever forget it:
|
176
|
-
|
177
|
-
class ApplicationController < ActionController::Base
|
178
|
-
include Consul::Controller
|
179
|
-
require_power_check
|
180
|
-
end
|
181
|
-
|
182
|
-
Should you for some obscure reason want to forego the power check:
|
183
|
-
|
184
|
-
class ApiController < ApplicationController
|
185
|
-
skip_power_check
|
186
|
-
end
|
187
|
-
|
188
|
-
== Installation
|
189
|
-
|
190
|
-
Add the following to your <tt>Gemfile</tt>:
|
191
|
-
gem 'consul'
|
192
|
-
|
193
|
-
Now run
|
194
|
-
bundle install
|
195
|
-
|
196
|
-
|
197
|
-
== Rails 3 compatibility
|
198
|
-
|
199
|
-
We cannot guarantee Rails 3 compatibility at this point.
|
200
|
-
|
201
|
-
|
202
|
-
== Development
|
203
|
-
|
204
|
-
A Rails 2 test application lives in <tt>spec/app_root</tt>. You can run specs from the project root by saying:
|
205
|
-
|
206
|
-
bundle exec rake spec
|
207
|
-
|
208
|
-
|
209
|
-
== Credits
|
210
|
-
|
211
|
-
Henning Koch
|
212
|
-
|
213
|
-
{makandra.com}[http://makandra.com/]
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.2
|