gritano 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +72 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +51 -0
- data/Rakefile +62 -0
- data/TODO +0 -0
- data/VERSION +1 -0
- data/bin/gritano +74 -0
- data/bin/gritano-check +17 -0
- data/db/database.yml +2 -0
- data/db/migrate/001_create_users.rb +8 -0
- data/db/migrate/002_create_repositories.rb +9 -0
- data/db/migrate/003_create_permissions.rb +10 -0
- data/db/migrate/004_create_keys.rb +11 -0
- data/features/command.feature +12 -0
- data/features/console.feature +59 -0
- data/features/data/keys/full_authorized_keys +2 -0
- data/features/data/keys/igorbonadio.pub +1 -0
- data/features/data/keys/igorbonadio_authorized_keys +1 -0
- data/features/data/keys/jessicaeto.pub +1 -0
- data/features/data/keys/jessicaeto_authorized_keys +1 -0
- data/features/keys.feature +31 -0
- data/features/polices.feature +55 -0
- data/features/step_definitions/command_step.rb +8 -0
- data/features/step_definitions/console_step.rb +14 -0
- data/features/step_definitions/keys_steps.rb +23 -0
- data/features/step_definitions/polices_steps.rb +54 -0
- data/features/support/database_cleaner.rb +15 -0
- data/features/support/env.rb +25 -0
- data/lib/gritano.rb +5 -0
- data/lib/gritano/command.rb +16 -0
- data/lib/gritano/console.rb +119 -0
- data/lib/gritano/models.rb +7 -0
- data/lib/gritano/models/key.rb +21 -0
- data/lib/gritano/models/permission.rb +39 -0
- data/lib/gritano/models/repository.rb +24 -0
- data/lib/gritano/models/user.rb +41 -0
- data/spec/command_spec.rb +17 -0
- data/spec/console_spec.rb +51 -0
- data/spec/model_key_spec.rb +18 -0
- data/spec/model_repository_spec.rb +23 -0
- data/spec/model_user_spec.rb +84 -0
- data/spec/spec_helper.rb +32 -0
- data/tmp/.gitignore +4 -0
- metadata +260 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem 'activerecord'
|
7
|
+
gem 'sqlite3'
|
8
|
+
gem 'grit'
|
9
|
+
|
10
|
+
# Add dependencies to develop your gem here.
|
11
|
+
# Include everything needed to run rake, tests, features, etc.
|
12
|
+
group :development do
|
13
|
+
gem "rspec"
|
14
|
+
gem "rdoc"
|
15
|
+
gem "cucumber"
|
16
|
+
gem "bundler"
|
17
|
+
gem "jeweler"
|
18
|
+
gem "simplecov"
|
19
|
+
gem 'database_cleaner'
|
20
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.2.8)
|
5
|
+
activesupport (= 3.2.8)
|
6
|
+
builder (~> 3.0.0)
|
7
|
+
activerecord (3.2.8)
|
8
|
+
activemodel (= 3.2.8)
|
9
|
+
activesupport (= 3.2.8)
|
10
|
+
arel (~> 3.0.2)
|
11
|
+
tzinfo (~> 0.3.29)
|
12
|
+
activesupport (3.2.8)
|
13
|
+
i18n (~> 0.6)
|
14
|
+
multi_json (~> 1.0)
|
15
|
+
arel (3.0.2)
|
16
|
+
builder (3.0.2)
|
17
|
+
cucumber (1.2.1)
|
18
|
+
builder (>= 2.1.2)
|
19
|
+
diff-lcs (>= 1.1.3)
|
20
|
+
gherkin (~> 2.11.0)
|
21
|
+
json (>= 1.4.6)
|
22
|
+
database_cleaner (0.8.0)
|
23
|
+
diff-lcs (1.1.3)
|
24
|
+
gherkin (2.11.2)
|
25
|
+
json (>= 1.4.6)
|
26
|
+
git (1.2.5)
|
27
|
+
grit (2.5.0)
|
28
|
+
diff-lcs (~> 1.1)
|
29
|
+
mime-types (~> 1.15)
|
30
|
+
posix-spawn (~> 0.3.6)
|
31
|
+
i18n (0.6.1)
|
32
|
+
jeweler (1.8.4)
|
33
|
+
bundler (~> 1.0)
|
34
|
+
git (>= 1.2.5)
|
35
|
+
rake
|
36
|
+
rdoc
|
37
|
+
json (1.7.5)
|
38
|
+
mime-types (1.19)
|
39
|
+
multi_json (1.3.6)
|
40
|
+
posix-spawn (0.3.6)
|
41
|
+
rake (0.9.2.2)
|
42
|
+
rdoc (3.12)
|
43
|
+
json (~> 1.4)
|
44
|
+
rspec (2.11.0)
|
45
|
+
rspec-core (~> 2.11.0)
|
46
|
+
rspec-expectations (~> 2.11.0)
|
47
|
+
rspec-mocks (~> 2.11.0)
|
48
|
+
rspec-core (2.11.1)
|
49
|
+
rspec-expectations (2.11.3)
|
50
|
+
diff-lcs (~> 1.1.3)
|
51
|
+
rspec-mocks (2.11.2)
|
52
|
+
simplecov (0.6.4)
|
53
|
+
multi_json (~> 1.0)
|
54
|
+
simplecov-html (~> 0.5.3)
|
55
|
+
simplecov-html (0.5.3)
|
56
|
+
sqlite3 (1.3.6)
|
57
|
+
tzinfo (0.3.33)
|
58
|
+
|
59
|
+
PLATFORMS
|
60
|
+
ruby
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
activerecord
|
64
|
+
bundler
|
65
|
+
cucumber
|
66
|
+
database_cleaner
|
67
|
+
grit
|
68
|
+
jeweler
|
69
|
+
rdoc
|
70
|
+
rspec
|
71
|
+
simplecov
|
72
|
+
sqlite3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Ígor Bonadio
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
= Gritano v0.1.1
|
2
|
+
|
3
|
+
Gritano is the simplest way to configure a git server over ssh. You can create repositories and manage user access using this practical tool.
|
4
|
+
|
5
|
+
== Requirements
|
6
|
+
|
7
|
+
* ruby 1.9 (http://www.ruby-lang.org)
|
8
|
+
* git (http://git-scm.com)
|
9
|
+
|
10
|
+
== Install
|
11
|
+
|
12
|
+
$ gem install gritano
|
13
|
+
|
14
|
+
== Usage
|
15
|
+
|
16
|
+
First of all you should create a git user who will be responsible for store and manipulate repositories. Lets suppose we are logged as this user.
|
17
|
+
|
18
|
+
All you need to do to set up Gritano is
|
19
|
+
|
20
|
+
$ gritano install
|
21
|
+
|
22
|
+
After that you can add users:
|
23
|
+
|
24
|
+
$ gritano user add igorbonadio
|
25
|
+
|
26
|
+
add user's public keys:
|
27
|
+
|
28
|
+
$ gritano user +key mykey id_rsa.pub
|
29
|
+
|
30
|
+
create bare repositories:
|
31
|
+
|
32
|
+
$ gritano repo add proj.git
|
33
|
+
|
34
|
+
and control access:
|
35
|
+
|
36
|
+
$ gritano repo +read proj.git igorbonadio
|
37
|
+
|
38
|
+
== Contributing to Gritano
|
39
|
+
|
40
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
41
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
42
|
+
* Fork the project.
|
43
|
+
* Start a feature/bugfix branch.
|
44
|
+
* Commit and push until you are happy with your contribution.
|
45
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
46
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
47
|
+
|
48
|
+
== Copyright
|
49
|
+
|
50
|
+
Copyright (c) 2012 Ígor Bonadio. See LICENSE.txt for
|
51
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "gritano"
|
18
|
+
gem.homepage = "http://github.com/igorbonadio/gritano"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Gritano is a tool to configure your git server over ssh}
|
21
|
+
gem.description = %Q{Gritano is the simplest way to configure your git server over ssh. You can create repositories and manage user access.}
|
22
|
+
gem.email = "igorbonadio@gmail.com"
|
23
|
+
gem.authors = ["Igor Bonadio"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
require 'cucumber/rake/task'
|
40
|
+
Cucumber::Rake::Task.new(:features)
|
41
|
+
|
42
|
+
task :default => :spec
|
43
|
+
|
44
|
+
require 'rdoc/task'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "gritano #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
53
|
+
|
54
|
+
require 'active_record'
|
55
|
+
require 'yaml'
|
56
|
+
namespace :db do
|
57
|
+
desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
|
58
|
+
task :migrate do
|
59
|
+
ActiveRecord::Base.establish_connection(YAML::load(File.open('db/database.yml')))
|
60
|
+
ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
|
61
|
+
end
|
62
|
+
end
|
data/TODO
ADDED
File without changes
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2
|
data/bin/gritano
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
|
5
|
+
require 'gritano'
|
6
|
+
|
7
|
+
require 'etc'
|
8
|
+
|
9
|
+
def help
|
10
|
+
puts "
|
11
|
+
gritano [install|user|repo] [command] parameters
|
12
|
+
|
13
|
+
Examples:
|
14
|
+
gritano install
|
15
|
+
gritano user add username
|
16
|
+
gritano user rm username
|
17
|
+
gritano user +key username keyname key.pub
|
18
|
+
gritano user -key username keyname
|
19
|
+
gritano repo add reponame.git
|
20
|
+
gritano repo rm reponame.git
|
21
|
+
gritano repo +read reponame.git username
|
22
|
+
gritano repo +write reponame.git username
|
23
|
+
gritano repo -read reponame.git username
|
24
|
+
gritano repo -write reponame.git username"
|
25
|
+
end
|
26
|
+
|
27
|
+
def install
|
28
|
+
Dir.mkdir(File.join(Etc.getpwuid.dir, '.gritano')) unless File.exist?(File.join(Etc.getpwuid.dir, '.gritano'))
|
29
|
+
Dir.mkdir(File.join(Etc.getpwuid.dir, '.ssh')) unless File.exist?(File.join(Etc.getpwuid.dir, '.ssh'))
|
30
|
+
File.open(File.join(Etc.getpwuid.dir, '.gritano', 'database.yml'), "w") do |f|
|
31
|
+
f.write("adapter: sqlite3\ndatabase: #{File.join(Etc.getpwuid.dir, '.gritano', 'database.db')}\n")
|
32
|
+
end
|
33
|
+
FileUtils.rm(File.join(Etc.getpwuid.dir, '.gritano', 'database.db')) if File.exist?(File.join(Etc.getpwuid.dir, '.gritano', 'database.db'))
|
34
|
+
ActiveRecord::Base.establish_connection(YAML::load(File.open(File.join(Etc.getpwuid.dir, '.gritano', 'database.yml'))))
|
35
|
+
ActiveRecord::Migrator.migrate(File.join(File.dirname(__FILE__),'../db/migrate'), ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
|
36
|
+
end
|
37
|
+
|
38
|
+
def version
|
39
|
+
puts "v#{File.open(File.join(File.dirname(__FILE__),'../VERSION')).readlines.join}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def check_git
|
43
|
+
if `which git` == ""
|
44
|
+
puts "Error: git must be installed on the local system"
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
check_git
|
50
|
+
if ARGV.length == 1
|
51
|
+
if ARGV[0] =='install'
|
52
|
+
install
|
53
|
+
elsif ARGV[0] =='version'
|
54
|
+
version
|
55
|
+
else
|
56
|
+
help
|
57
|
+
end
|
58
|
+
elsif ARGV.length == 2 or ARGV.length == 0
|
59
|
+
help
|
60
|
+
else
|
61
|
+
ActiveRecord::Base.establish_connection(YAML::load(File.open(File.join(Etc.getpwuid.dir, '.gritano', 'database.yml'))))
|
62
|
+
console = Gritano::Console.new
|
63
|
+
console.repo_path = Etc.getpwuid.dir
|
64
|
+
console.ssh_path = File.join(Etc.getpwuid.dir, '.ssh')
|
65
|
+
begin
|
66
|
+
if console.execute(ARGV)
|
67
|
+
puts "command executed successfully"
|
68
|
+
else
|
69
|
+
puts "an error occurred"
|
70
|
+
end
|
71
|
+
rescue NoMethodError
|
72
|
+
puts help
|
73
|
+
end
|
74
|
+
end
|
data/bin/gritano-check
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
4
|
+
|
5
|
+
require 'gritano'
|
6
|
+
|
7
|
+
ActiveRecord::Base.establish_connection(YAML::load(File.open(File.join(Etc.getpwuid.dir, '.gritano', 'database.yml'))))
|
8
|
+
|
9
|
+
login = ARGV[0]
|
10
|
+
access, git_command, repo = Gritano::Command.eval(ENV['SSH_ORIGINAL_COMMAND'])
|
11
|
+
user = Gritano::User.find_by_login(login)
|
12
|
+
repository = Gritano::Repository.find_by_name(repo)
|
13
|
+
if user and repository
|
14
|
+
if user.check_access(repository, access)
|
15
|
+
exec "#{git_command} #{File.join(repository.full_path)}"
|
16
|
+
end
|
17
|
+
end
|
data/db/database.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Feature: Command
|
2
|
+
In order to restrict access to repositories
|
3
|
+
As Gritano
|
4
|
+
I want to know if a command is a read/write command
|
5
|
+
|
6
|
+
Scenario Outline: Write command
|
7
|
+
When I receive a "<command>" command
|
8
|
+
Then I should see that it is a "<access>" access to "<repo>"
|
9
|
+
Examples:
|
10
|
+
| command | access | repo |
|
11
|
+
| git-receive-pack proj.git | write | proj.git |
|
12
|
+
| git-upload-pack proj.git | read | proj.git |
|
@@ -0,0 +1,59 @@
|
|
1
|
+
Feature: Console operations
|
2
|
+
In order to use gritano via console
|
3
|
+
As a user
|
4
|
+
I want to execute some commands
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given the following users exist:
|
8
|
+
| login |
|
9
|
+
| igorbonadio |
|
10
|
+
| jessicaeto |
|
11
|
+
|
12
|
+
And the following keys exist:
|
13
|
+
| login | key |
|
14
|
+
| igorbonadio | eva |
|
15
|
+
| jessicaeto | hal |
|
16
|
+
|
17
|
+
And the following repositories exist:
|
18
|
+
| name |
|
19
|
+
| tmp/gritano.git |
|
20
|
+
| tmp/jeka.git |
|
21
|
+
|
22
|
+
And the following permissions exist:
|
23
|
+
| user | repo | access |
|
24
|
+
| igorbonadio | tmp/gritano.git | read |
|
25
|
+
| igorbonadio | tmp/gritano.git | write |
|
26
|
+
| igorbonadio | tmp/jeka.git | read |
|
27
|
+
| jessicaeto | tmp/jeka.git | read |
|
28
|
+
| jessicaeto | tmp/jeka.git | write |
|
29
|
+
|
30
|
+
Scenario Outline: Add user
|
31
|
+
Given I start the gritano console
|
32
|
+
When I execute "<command>"
|
33
|
+
Then I should see a <message> message
|
34
|
+
Examples:
|
35
|
+
| command | message |
|
36
|
+
| user add jose | success |
|
37
|
+
| user +key igorbonadio marvin features/data/keys/igorbonadio.pub | success |
|
38
|
+
| user -key igorbonadio eva | success |
|
39
|
+
| user rm igorbonadio | success |
|
40
|
+
| repo add tmp/p-lang.git | success |
|
41
|
+
| repo rm tmp/jeka.git | success |
|
42
|
+
| repo +read tmp/gritano.git jessicaeto | success |
|
43
|
+
| repo +write tmp/gritano.git jessicaeto | success |
|
44
|
+
| repo -read tmp/jeka.git igorbonadio | success |
|
45
|
+
| repo -write tmp/gritano.git igorbonadio | success |
|
46
|
+
| user add igorbonadio | error |
|
47
|
+
| user rm jose | error |
|
48
|
+
| user +key igorbonadio marvin features/data/keys/arybonadio.pub | error |
|
49
|
+
| user -key igorbonadio marvino | error |
|
50
|
+
| repo add tmp/jeka.git | error |
|
51
|
+
| repo rm tmp/p-lang.git | error |
|
52
|
+
| repo +read tmp/gritano.git arybonadio | error |
|
53
|
+
| repo +read tmp/p-lang.git jessicaeto | error |
|
54
|
+
| repo +write tmp/gritano.git arybonadio | error |
|
55
|
+
| repo +write tmp/p-lang.git jessicaeto | error |
|
56
|
+
| repo -read tmp/jeka.git aribonadio | error |
|
57
|
+
| repo -read tmp/p-lang.git igorbonadio | error |
|
58
|
+
| repo -write tmp/gritano.git arybonadio | error |
|
59
|
+
| repo -write tmp/p-lang.git igorbonadio | error |
|