gritano 0.1.2

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.
Files changed (47) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +20 -0
  4. data/Gemfile.lock +72 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +51 -0
  7. data/Rakefile +62 -0
  8. data/TODO +0 -0
  9. data/VERSION +1 -0
  10. data/bin/gritano +74 -0
  11. data/bin/gritano-check +17 -0
  12. data/db/database.yml +2 -0
  13. data/db/migrate/001_create_users.rb +8 -0
  14. data/db/migrate/002_create_repositories.rb +9 -0
  15. data/db/migrate/003_create_permissions.rb +10 -0
  16. data/db/migrate/004_create_keys.rb +11 -0
  17. data/features/command.feature +12 -0
  18. data/features/console.feature +59 -0
  19. data/features/data/keys/full_authorized_keys +2 -0
  20. data/features/data/keys/igorbonadio.pub +1 -0
  21. data/features/data/keys/igorbonadio_authorized_keys +1 -0
  22. data/features/data/keys/jessicaeto.pub +1 -0
  23. data/features/data/keys/jessicaeto_authorized_keys +1 -0
  24. data/features/keys.feature +31 -0
  25. data/features/polices.feature +55 -0
  26. data/features/step_definitions/command_step.rb +8 -0
  27. data/features/step_definitions/console_step.rb +14 -0
  28. data/features/step_definitions/keys_steps.rb +23 -0
  29. data/features/step_definitions/polices_steps.rb +54 -0
  30. data/features/support/database_cleaner.rb +15 -0
  31. data/features/support/env.rb +25 -0
  32. data/lib/gritano.rb +5 -0
  33. data/lib/gritano/command.rb +16 -0
  34. data/lib/gritano/console.rb +119 -0
  35. data/lib/gritano/models.rb +7 -0
  36. data/lib/gritano/models/key.rb +21 -0
  37. data/lib/gritano/models/permission.rb +39 -0
  38. data/lib/gritano/models/repository.rb +24 -0
  39. data/lib/gritano/models/user.rb +41 -0
  40. data/spec/command_spec.rb +17 -0
  41. data/spec/console_spec.rb +51 -0
  42. data/spec/model_key_spec.rb +18 -0
  43. data/spec/model_repository_spec.rb +23 -0
  44. data/spec/model_user_spec.rb +84 -0
  45. data/spec/spec_helper.rb +32 -0
  46. data/tmp/.gitignore +4 -0
  47. metadata +260 -0
@@ -0,0 +1,24 @@
1
+ module Gritano
2
+ class Repository < ActiveRecord::Base
3
+ validates :name, presence: true
4
+ validates_uniqueness_of :name
5
+
6
+ has_many :permissions
7
+ has_many :users, through: :permissions
8
+
9
+ before_create :create_bare_repo
10
+
11
+ def create_bare_repo
12
+ Grit::Repo.init_bare(full_path)
13
+ end
14
+
15
+ def full_path
16
+ if path
17
+ File.join(path, name)
18
+ else
19
+ name
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,41 @@
1
+ module Gritano
2
+ class User < ActiveRecord::Base
3
+ validates :login, presence: true
4
+ validates_uniqueness_of :login
5
+
6
+ has_many :permissions
7
+ has_many :repositories, through: :permissions
8
+ has_many :keys
9
+
10
+ def create_repository(repo)
11
+ repository = Repository.create(repo)
12
+ add_access(repository, :read)
13
+ add_access(repository, :write)
14
+ end
15
+
16
+ def add_access(repo, access)
17
+ change_access(repo, "add", access)
18
+ end
19
+
20
+ def remove_access(repo, access)
21
+ change_access(repo, "remove", access)
22
+ end
23
+
24
+ def change_access(repo, op, access)
25
+ permission = Permission.find_by_user_id_and_repository_id(self.id, repo.id) || Permission.new
26
+ permission.user_id = self.id
27
+ permission.repository_id = repo.id
28
+ if permission.send("#{op}_access", access)
29
+ return permission.save
30
+ else
31
+ return false
32
+ end
33
+ end
34
+
35
+ def check_access(repo, access)
36
+ permission = Permission.find_by_user_id_and_repository_id(self.id, repo.id)
37
+ return permission.is(access) if permission
38
+ return false
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Gritano::Command do
4
+ it 'should interpret git-receive-pack' do
5
+ access, git_command, repo = Gritano::Command.eval("git-receive-pack 'teste.git'")
6
+ access.to_s.should be == "write"
7
+ git_command.should be == "git-receive-pack"
8
+ repo.to_s.should be == "teste.git"
9
+ end
10
+
11
+ it 'should interpret git-upload-pack' do
12
+ access, git_command, repo = Gritano::Command.eval("git-upload-pack 'teste.git'")
13
+ access.to_s.should be == "read"
14
+ git_command.should be == "git-upload-pack"
15
+ repo.to_s.should be == "teste.git"
16
+ end
17
+ end
@@ -0,0 +1,51 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Gritano::Console do
4
+ it "should respond to gritano user add igorbonadio" do
5
+ console = Gritano::Console.new
6
+ console.should_receive(:user_add)
7
+ console.execute("user add igorbonadio".split(' '))
8
+ end
9
+
10
+ it "should respond to gritano user rm igorbonadio" do
11
+ console = Gritano::Console.new
12
+ console.should_receive(:user_rm)
13
+ console.execute("user rm igorbonadio".split(' '))
14
+ end
15
+
16
+ it "should respond to gritano repo add tmp/reponame.git" do
17
+ console = Gritano::Console.new
18
+ console.should_receive(:repo_add)
19
+ console.execute("repo add tmp/reponame.git".split(' '))
20
+ end
21
+
22
+ it "should respond to gritano repo rm tmp/reponame.git" do
23
+ console = Gritano::Console.new
24
+ console.should_receive(:repo_rm)
25
+ console.execute("repo rm tmp/reponame.git".split(' '))
26
+ end
27
+
28
+ it "should respond to gritano repo +read igorbonadio tmp/reponame.git" do
29
+ console = Gritano::Console.new
30
+ console.should_receive(:repo_add_read)
31
+ console.execute("repo +read igorbonadio tmp/reponame.git".split(' '))
32
+ end
33
+
34
+ it "should respond to gritano repo +write igorbonadio tmp/reponame.git" do
35
+ console = Gritano::Console.new
36
+ console.should_receive(:repo_add_write)
37
+ console.execute("repo +write igorbonadio tmp/reponame.git".split(' '))
38
+ end
39
+
40
+ it "should respond to gritano repo -read igorbonadio tmp/reponame.git" do
41
+ console = Gritano::Console.new
42
+ console.should_receive(:repo_remove_read)
43
+ console.execute("repo -read igorbonadio tmp/reponame.git".split(' '))
44
+ end
45
+
46
+ it "should respond to gritano repo -write igorbonadio tmp/reponame.git" do
47
+ console = Gritano::Console.new
48
+ console.should_receive(:repo_remove_write)
49
+ console.execute("repo -write igorbonadio tmp/reponame.git".split(' '))
50
+ end
51
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Gritano::Key do
4
+ it 'should have a name' do
5
+ key = Gritano::Key.new(key: "key")
6
+ key.should be_invalid
7
+ end
8
+
9
+ it 'should have a key' do
10
+ key = Gritano::Key.new(name: "name")
11
+ key.should be_invalid
12
+ end
13
+
14
+ it 'should generate authorized_keys file' do
15
+ Gritano::User.create(login: 'login').keys.create(key: "key", name: "name")
16
+ Gritano::Key.authorized_keys.should match /^command=/
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Gritano::Repository do
4
+ it 'should have a name' do
5
+ repo = Gritano::Repository.new
6
+ repo.should be_invalid
7
+ repo = Gritano::Repository.new(name: 'tmp/name.git')
8
+ repo.should be_valid
9
+ end
10
+
11
+ it 'should have a unique name' do
12
+ repo1 = Gritano::Repository.create(name: 'tmp/name.git')
13
+ repo2 = Gritano::Repository.new(name: 'tmp/name.git')
14
+ repo2.should be_invalid
15
+ end
16
+
17
+ it 'can have a path' do
18
+ repo = Gritano::Repository.new(name: 'name.git', path: 'tmp')
19
+ repo.should be_valid
20
+ repo.save.should be_true
21
+ repo.full_path.should be == 'tmp/name.git'
22
+ end
23
+ end
@@ -0,0 +1,84 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Gritano::User do
4
+ it 'should have a login' do
5
+ user = Gritano::User.new
6
+ user.should be_invalid
7
+ user = Gritano::User.new(login: 'login')
8
+ user.should be_valid
9
+ end
10
+
11
+ it 'should have a unique login' do
12
+ user1 = Gritano::User.create(login: 'test')
13
+ user2 = Gritano::User.new(login: 'test')
14
+ user2.should be_invalid
15
+ end
16
+
17
+ it 'should add read access to a repository' do
18
+ user = Gritano::User.create(login: 'test')
19
+ repo = Gritano::Repository.create(name: 'tmp/repo.git')
20
+ user.add_access(repo, :read).should be_true
21
+ end
22
+
23
+ it 'should add write access to a repository' do
24
+ user = Gritano::User.create(login: 'test')
25
+ repo = Gritano::Repository.create(name: 'tmp/repo.git')
26
+ user.add_access(repo, :read).should be_true
27
+ end
28
+
29
+ it 'should remove read access to a repository' do
30
+ user = Gritano::User.create(login: 'test')
31
+ user.create_repository(name: 'tmp/repo.git')
32
+ user.remove_access(Gritano::Repository.find_by_name('tmp/repo.git'), :read).should be_true
33
+ user.check_access(Gritano::Repository.find_by_name('tmp/repo.git'), :read).should be_false
34
+ end
35
+
36
+ it 'should remove write access to a repository' do
37
+ user = Gritano::User.create(login: 'test')
38
+ user.create_repository(name: 'tmp/repo.git')
39
+ user.remove_access(Gritano::Repository.find_by_name('tmp/repo.git'), :write).should be_true
40
+ user.check_access(Gritano::Repository.find_by_name('tmp/repo.git'), :write).should be_false
41
+ end
42
+
43
+ it 'should not add an wrong type access to a repository' do
44
+ user = Gritano::User.create(login: 'test')
45
+ repo = Gritano::Repository.create(name: 'tmp/repo.git')
46
+ user.add_access(repo, :wrong).should be_false
47
+ end
48
+
49
+ it 'should not remove an wrong type access to a repository' do
50
+ user = Gritano::User.create(login: 'test')
51
+ repo = Gritano::Repository.create(name: 'tmp/repo.git')
52
+ user.remove_access(repo, :wrong).should be_false
53
+ end
54
+
55
+ it 'should have read access to a repository' do
56
+ user = Gritano::User.create(login: 'test')
57
+ user.create_repository(name: 'tmp/gritano.git')
58
+ user.check_access(Gritano::Repository.find_by_name('tmp/gritano.git'), :read).should be_true
59
+ end
60
+
61
+ it 'should have write access to a repository' do
62
+ user = Gritano::User.create(login: 'test')
63
+ user.create_repository(name: 'tmp/gritano.git')
64
+ user.check_access(Gritano::Repository.find_by_name('tmp/gritano.git'), :write).should be_true
65
+ end
66
+
67
+ it 'should not have read access to a repository' do
68
+ user = Gritano::User.create(login: 'test')
69
+ repo = Gritano::Repository.create(name: 'tmp/repo.git')
70
+ user.check_access(repo, :read).should be_false
71
+ end
72
+
73
+ it 'should not have write access to a repository' do
74
+ user = Gritano::User.create(login: 'test')
75
+ repo = Gritano::Repository.create(name: 'tmp/repo.git')
76
+ user.check_access(repo, :write).should be_false
77
+ end
78
+
79
+ it 'should not have wrong access to a repository' do
80
+ user = Gritano::User.create(login: 'test')
81
+ repo = Gritano::Repository.create(name: 'tmp/repo.git')
82
+ user.check_access(repo, :wrong).should be_false
83
+ end
84
+ end
@@ -0,0 +1,32 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter "/features/"
4
+ add_filter "/spec/"
5
+ end
6
+
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
9
+ require 'rspec'
10
+ require 'database_cleaner'
11
+ require 'active_record'
12
+ require 'gritano'
13
+
14
+ # Requires supporting files with custom matchers and macros, etc,
15
+ # in ./support/ and its subdirectories.
16
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
17
+
18
+ RSpec.configure do |config|
19
+ config.before(:suite) do
20
+ ActiveRecord::Base.establish_connection(YAML::load(File.open('db/database.yml')))
21
+ DatabaseCleaner.strategy = :transaction
22
+ DatabaseCleaner.clean_with(:truncation)
23
+ end
24
+
25
+ config.before(:each) do
26
+ DatabaseCleaner.start
27
+ end
28
+
29
+ config.after(:each) do
30
+ DatabaseCleaner.clean
31
+ end
32
+ end
data/tmp/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ # Ignore everything in this directory
2
+ *
3
+ # Except this file
4
+ !.gitignore
metadata ADDED
@@ -0,0 +1,260 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gritano
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Igor Bonadio
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sqlite3
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: grit
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rdoc
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: cucumber
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: bundler
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: jeweler
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: simplecov
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: database_cleaner
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ description: Gritano is the simplest way to configure your git server over ssh. You
175
+ can create repositories and manage user access.
176
+ email: igorbonadio@gmail.com
177
+ executables:
178
+ - gritano
179
+ - gritano-check
180
+ extensions: []
181
+ extra_rdoc_files:
182
+ - LICENSE.txt
183
+ - README.rdoc
184
+ - TODO
185
+ files:
186
+ - .document
187
+ - .rspec
188
+ - Gemfile
189
+ - Gemfile.lock
190
+ - LICENSE.txt
191
+ - README.rdoc
192
+ - Rakefile
193
+ - VERSION
194
+ - bin/gritano
195
+ - bin/gritano-check
196
+ - db/database.yml
197
+ - db/migrate/001_create_users.rb
198
+ - db/migrate/002_create_repositories.rb
199
+ - db/migrate/003_create_permissions.rb
200
+ - db/migrate/004_create_keys.rb
201
+ - features/command.feature
202
+ - features/console.feature
203
+ - features/data/keys/full_authorized_keys
204
+ - features/data/keys/igorbonadio.pub
205
+ - features/data/keys/igorbonadio_authorized_keys
206
+ - features/data/keys/jessicaeto.pub
207
+ - features/data/keys/jessicaeto_authorized_keys
208
+ - features/keys.feature
209
+ - features/polices.feature
210
+ - features/step_definitions/command_step.rb
211
+ - features/step_definitions/console_step.rb
212
+ - features/step_definitions/keys_steps.rb
213
+ - features/step_definitions/polices_steps.rb
214
+ - features/support/database_cleaner.rb
215
+ - features/support/env.rb
216
+ - lib/gritano.rb
217
+ - lib/gritano/command.rb
218
+ - lib/gritano/console.rb
219
+ - lib/gritano/models.rb
220
+ - lib/gritano/models/key.rb
221
+ - lib/gritano/models/permission.rb
222
+ - lib/gritano/models/repository.rb
223
+ - lib/gritano/models/user.rb
224
+ - spec/command_spec.rb
225
+ - spec/console_spec.rb
226
+ - spec/model_key_spec.rb
227
+ - spec/model_repository_spec.rb
228
+ - spec/model_user_spec.rb
229
+ - spec/spec_helper.rb
230
+ - tmp/.gitignore
231
+ - TODO
232
+ homepage: http://github.com/igorbonadio/gritano
233
+ licenses:
234
+ - MIT
235
+ post_install_message:
236
+ rdoc_options: []
237
+ require_paths:
238
+ - lib
239
+ required_ruby_version: !ruby/object:Gem::Requirement
240
+ none: false
241
+ requirements:
242
+ - - ! '>='
243
+ - !ruby/object:Gem::Version
244
+ version: '0'
245
+ segments:
246
+ - 0
247
+ hash: 3868573402934525831
248
+ required_rubygems_version: !ruby/object:Gem::Requirement
249
+ none: false
250
+ requirements:
251
+ - - ! '>='
252
+ - !ruby/object:Gem::Version
253
+ version: '0'
254
+ requirements: []
255
+ rubyforge_project:
256
+ rubygems_version: 1.8.24
257
+ signing_key:
258
+ specification_version: 3
259
+ summary: Gritano is a tool to configure your git server over ssh
260
+ test_files: []