gritano 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ adapter: sqlite3
2
+ database: .gritano/development.sqlite3
@@ -1,4 +1,4 @@
1
1
  # Ignore everything in this directory
2
2
  *
3
3
  # Except this file
4
- !.gitignore
4
+ !.gitignore
data/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- = Gritano v0.4.1
1
+ = Gritano v0.5.0
2
2
 
3
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
4
 
@@ -17,7 +17,7 @@ If you are using a previous version, you should update your instalation:
17
17
 
18
18
  $ gem install gritano
19
19
 
20
- $ gritano update
20
+ $ gritano setup:install
21
21
 
22
22
  == Usage
23
23
 
@@ -25,7 +25,7 @@ First of all you should create a git user who will be responsible for store and
25
25
 
26
26
  All you need to do to set up Gritano is
27
27
 
28
- $ gritano install
28
+ $ gritano setup:prepare && gritano setup:install
29
29
 
30
30
  After that you can add users:
31
31
 
data/Rakefile CHANGED
@@ -56,7 +56,7 @@ require 'yaml'
56
56
  namespace :db do
57
57
  desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
58
58
  task :migrate do
59
- ActiveRecord::Base.establish_connection(YAML::load(File.open('db/database.yml')))
59
+ ActiveRecord::Base.establish_connection(YAML::load(File.open('.gritano/database.yml')))
60
60
  ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
61
61
  end
62
- end
62
+ end
data/TODO CHANGED
@@ -1,2 +1,4 @@
1
1
  v1.0.0
2
- - melhorar o instalador/updater
2
+ - melhorar o instalador/updater
3
+ - escolha de db
4
+ - escolha de pasta dos repos
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.5.0
data/bin/gritano CHANGED
@@ -4,99 +4,4 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
4
 
5
5
  require 'gritano'
6
6
 
7
- require 'etc'
8
-
9
- def help
10
- puts "
11
- gritano [command] parameters
12
-
13
- Examples:
14
- gritano install
15
- gritano update
16
- gritano user:add username
17
- gritano user:rm username
18
- gritano user:key:add username keyname < key.pub
19
- gritano user:key:rm username keyname
20
- gritano user:admin:add username
21
- gritano user:admin:rm username
22
- gritano user:list
23
- gritano user:key:list username
24
- gritano user:repo:list username
25
- gritano repo:add reponame.git
26
- gritano repo:add reponame.git user1 user2 user3
27
- gritano repo:rm reponame.git
28
- gritano repo:read:add reponame.git username
29
- gritano repo:write:add reponame.git username
30
- gritano repo:read:rm reponame.git username
31
- gritano repo:write:rm reponame.git username
32
- gritano repo:list
33
- gritano repo:user:list reponame.git
34
-
35
- --
36
- v#{File.open(File.join(File.dirname(__FILE__), '..', 'VERSION')).readlines.join}"
37
- end
38
-
39
- def migrate
40
- ActiveRecord::Base.establish_connection(YAML::load(File.open(File.join(Etc.getpwuid.dir, '.gritano', 'database.yml'))))
41
- ActiveRecord::Migrator.migrate(File.join(File.dirname(__FILE__),'../db/migrate'), ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
42
- end
43
-
44
- def install
45
- Dir.mkdir(File.join(Etc.getpwuid.dir, '.gritano')) unless File.exist?(File.join(Etc.getpwuid.dir, '.gritano'))
46
- Dir.mkdir(File.join(Etc.getpwuid.dir, '.ssh')) unless File.exist?(File.join(Etc.getpwuid.dir, '.ssh'))
47
- File.open(File.join(Etc.getpwuid.dir, '.gritano', 'database.yml'), "w") do |f|
48
- f.write("adapter: sqlite3\ndatabase: #{File.join(Etc.getpwuid.dir, '.gritano', 'database.db')}\n")
49
- end
50
- FileUtils.rm(File.join(Etc.getpwuid.dir, '.gritano', 'database.db')) if File.exist?(File.join(Etc.getpwuid.dir, '.gritano', 'database.db'))
51
- migrate
52
- end
53
-
54
- def version
55
- puts "v#{File.open(File.join(File.dirname(__FILE__),'../VERSION')).readlines.join}"
56
- end
57
-
58
- def check_git
59
- if `which git` == ""
60
- puts "Error: git must be installed on the local system"
61
- exit
62
- end
63
- end
64
-
65
- def check_gritano
66
- unless File.exist?(File.join(Etc.getpwuid.dir, '.gritano'))
67
- puts "Error: First run 'gritano install'"
68
- exit
69
- end
70
- end
71
-
72
- check_git
73
- if ARGV.length == 0
74
- help
75
- else
76
-
77
- if ARGV[0] =='install'
78
- install
79
- elsif ARGV[0] =='update'
80
- migrate
81
- elsif ARGV[0] =='version'
82
- version
83
- elsif ARGV[0] =='help'
84
- help
85
- else
86
- check_gritano
87
- ActiveRecord::Base.establish_connection(YAML::load(File.open(File.join(Etc.getpwuid.dir, '.gritano', 'database.yml'))))
88
- console = Gritano::Console.new(STDIN)
89
- console.repo_path = Etc.getpwuid.dir
90
- console.ssh_path = File.join(Etc.getpwuid.dir, '.ssh')
91
- begin
92
- cmd_return = console.execute(ARGV)
93
- if cmd_return[0]
94
- puts "#{cmd_return[1]}"
95
- else
96
- puts "error: #{cmd_return[1]}"
97
- end
98
- rescue NoMethodError
99
- puts help
100
- end
101
- end
102
- end
7
+ puts Gritano::CLI::execute(ARGV)
data/bin/gritano-check CHANGED
@@ -1,51 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
3
 
5
4
  require 'gritano'
6
5
 
7
- def help
8
- puts "
9
- ssh user@host command
10
-
11
- Examples:
12
- ssh git@host.com repo:list
13
- ssh git@host.com key:list
14
- ssh git@host.com key:add keyname < key.pub
15
- ssh git@host.com key:rm keyname
16
- ssh git@host.com admin:help
17
-
18
- --
19
- v#{File.open(File.join(File.dirname(__FILE__), '..', 'VERSION')).readlines.join}"
20
- end
21
-
22
- ActiveRecord::Base.establish_connection(YAML::load(File.open(File.join(Etc.getpwuid.dir, '.gritano', 'database.yml'))))
23
-
24
- login = ARGV[0]
25
- command = Gritano::Command.eval(ENV['SSH_ORIGINAL_COMMAND'])
26
- begin
27
- case command[:access]
28
- when :read, :write then
29
- user = Gritano::User.find_by_login(login)
30
- repository = Gritano::Repository.find_by_name(command[:repo])
31
- if user and repository
32
- if user.check_access(repository, command[:access])
33
- puts "#{command[:command]} #{File.join(repository.full_path)}"
34
- exec "#{command[:command]} #{File.join(repository.full_path)}"
35
- end
36
- end
37
- when :user_cmd
38
- cmd = command[:command].gsub("[USER]", login)
39
- exec "gritano #{cmd}"
40
- when :admin_cmd
41
- cmd = command[:command]
42
- user = Gritano::User.find_by_login(login)
43
- if user.admin?
44
- exec "gritano #{cmd}"
45
- else
46
- puts "access denied"
47
- end
48
- end
49
- rescue
50
- puts help
51
- end
6
+ puts Gritano::CLI::check(ENV['SSH_ORIGINAL_COMMAND'].split(' '), ARGV[0])
@@ -0,0 +1,183 @@
1
+ Feature: Console operations
2
+ In order to use gritano via CLI
3
+ As a user
4
+ I want to execute some commands
5
+
6
+ Background:
7
+ Given the following users exist:
8
+ | login | admin |
9
+ | igorbonadio | true |
10
+ | jessicaeto | false |
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: Git read access
31
+ Given I start the CLI with "igorbonadio"
32
+ When I try to get tmp/gritano.git from CLI.check
33
+ Then I should get it
34
+
35
+ Scenario: Git write access
36
+ Given I start the CLI with "igorbonadio"
37
+ When I try to send data to tmp/gritano.git from CLI.check
38
+ Then I should send it
39
+
40
+ Scenario: Error
41
+ Given I start the CLI with "igorbonadio"
42
+ When I try to send an invalid command to CLI.check
43
+ Then CLI should return the help-check
44
+
45
+ Scenario: Get help
46
+ Given I start the CLI
47
+ When I send "help" to the CLI.execute
48
+ Then CLI should return the help
49
+
50
+ Scenario: Check git
51
+ Given I start the CLI but gritano is not installed
52
+ When I send a command to the CLI.execute
53
+ Then CLI should exit
54
+
55
+ Scenario Outline: Add user
56
+ Given I start the CLI
57
+ When I send "<command>" to the CLI.execute
58
+ Then CLI should return "<result>"
59
+ Examples:
60
+ | command | result |
61
+ | version | v0.4.1 |
62
+ | user:add jose | User jose added. |
63
+ | user:key:add igorbonadio marvin | Key added successfully. |
64
+ | user:key:rm igorbonadio eva | Key removed successfully. |
65
+ | user:rm igorbonadio | User igorbonadio removed. |
66
+ | user:admin:add igorbonadio | Now, user igorbonadio is an administrator |
67
+ | user:admin:rm igorbonadio | Now, user igorbonadio is not an administrator |
68
+ | repo:add tmp/p-lang.git | Repository tmp/p-lang.git created successfully. |
69
+ | repo:add tmp/p-lang.git igorbonadio | Repository tmp/p-lang.git created successfully. |
70
+ | repo:add tmp/p-lang.git igorbonadio jessicaeto | Repository tmp/p-lang.git created successfully. |
71
+ | repo:rm tmp/jeka.git | Repository tmp/jeka.git removed successfully. |
72
+ | repo:read:add tmp/gritano.git jessicaeto | User jessicaeto has read access to tmp/gritano.git. |
73
+ | repo:write:add tmp/gritano.git jessicaeto | User jessicaeto has write access to tmp/gritano.git. |
74
+ | repo:read:rm tmp/jeka.git igorbonadio | User igorbonadio has not read access to tmp/jeka.git. |
75
+ | repo:write:rm tmp/gritano.git igorbonadio | User igorbonadio has not write access to tmp/gritano.git. |
76
+ | user:add igorbonadio | error: Login has already been taken. |
77
+ | user:rm jose | error: User jose could not be removed. |
78
+ | user:key:add userrr marvino | error: Key could not be added. |
79
+ | user:key:rm igorbonadio marvino | error: Key could not be removed. |
80
+ | user:key:list arybonadio | error: User arybonadio is not registered |
81
+ | user:repo:list arybonadio | error: User arybonadio is not registered |
82
+ | user:admin:add arybonadio | error: User arybonadio could not be modified |
83
+ | user:admin:rm arybonadio | error: User arybonadio could not be modified |
84
+ | repo:add tmp/jeka.git | error: Repository tmp/jeka.git could not be created. |
85
+ | repo:rm tmp/p-lang.git | error: Repository tmp/p-lang.git could not be removed. |
86
+ | repo:read:add tmp/gritano.git arybonadio | error: An error occurred. Permissions was not modified. |
87
+ | repo:read:add tmp/p-lang.git jessicaeto | error: An error occurred. Permissions was not modified. |
88
+ | repo:write:add tmp/gritano.git arybonadio | error: An error occurred. Permissions was not modified. |
89
+ | repo:write:add tmp/p-lang.git jessicaeto | error: An error occurred. Permissions was not modified. |
90
+ | repo:read:rm tmp/jeka.git aribonadio | error: An error occurred. Permissions was not modified. |
91
+ | repo:read:rm tmp/p-lang.git igorbonadio | error: An error occurred. Permissions was not modified. |
92
+ | repo:write:rm tmp/gritano.git arybonadio | error: An error occurred. Permissions was not modified. |
93
+ | repo:write:rm tmp/p-lang.git igorbonadio | error: An error occurred. Permissions was not modified. |
94
+ | repo:user:list tmp/ruby.git | error: Repository tmp/ruby.git doesn't exist. |
95
+
96
+ Scenario Outline: Admin via ssh
97
+ Given I start the CLI with "igorbonadio"
98
+ When I send "<command>" to the CLI.check
99
+ Then CLI should return "<result>"
100
+ Examples:
101
+ | command | result |
102
+ | version | v0.4.1 |
103
+ | key:add keyname | Key added successfully. |
104
+ | key:rm eva | Key removed successfully. |
105
+ | key:rm keyname | error: Key could not be removed. |
106
+ | admin:user:add jose | User jose added. |
107
+ | admin:user:key:add igorbonadio marvin | Key added successfully. |
108
+ | admin:user:key:rm igorbonadio eva | Key removed successfully. |
109
+ | admin:user:rm igorbonadio | User igorbonadio removed. |
110
+ | admin:user:admin:add igorbonadio | Now, user igorbonadio is an administrator |
111
+ | admin:user:admin:rm igorbonadio | Now, user igorbonadio is not an administrator |
112
+ | admin:repo:add tmp/p-lang.git | Repository tmp/p-lang.git created successfully. |
113
+ | admin:repo:add tmp/p-lang.git igorbonadio | Repository tmp/p-lang.git created successfully. |
114
+ | admin:repo:add tmp/p-lang.git igorbonadio jessicaeto | Repository tmp/p-lang.git created successfully. |
115
+ | admin:repo:rm tmp/jeka.git | Repository tmp/jeka.git removed successfully. |
116
+ | admin:repo:read:add tmp/gritano.git jessicaeto | User jessicaeto has read access to tmp/gritano.git. |
117
+ | admin:repo:write:add tmp/gritano.git jessicaeto | User jessicaeto has write access to tmp/gritano.git. |
118
+ | admin:repo:read:rm tmp/jeka.git igorbonadio | User igorbonadio has not read access to tmp/jeka.git. |
119
+ | admin:repo:write:rm tmp/gritano.git igorbonadio | User igorbonadio has not write access to tmp/gritano.git. |
120
+ | admin:user:add igorbonadio | error: Login has already been taken. |
121
+ | admin:user:rm jose | error: User jose could not be removed. |
122
+ | admin:user:key:add userrr marvino | error: Key could not be added. |
123
+ | admin:user:key:rm igorbonadio marvino | error: Key could not be removed. |
124
+ | admin:user:key:list arybonadio | error: User arybonadio is not registered |
125
+ | admin:user:repo:list arybonadio | error: User arybonadio is not registered |
126
+ | admin:user:admin:add arybonadio | error: User arybonadio could not be modified |
127
+ | admin:user:admin:rm arybonadio | error: User arybonadio could not be modified |
128
+ | admin:repo:add tmp/jeka.git | error: Repository tmp/jeka.git could not be created. |
129
+ | admin:repo:rm tmp/p-lang.git | error: Repository tmp/p-lang.git could not be removed. |
130
+ | admin:repo:read:add tmp/gritano.git arybonadio | error: An error occurred. Permissions was not modified. |
131
+ | admin:repo:read:add tmp/p-lang.git jessicaeto | error: An error occurred. Permissions was not modified. |
132
+ | admin:repo:write:add tmp/gritano.git arybonadio | error: An error occurred. Permissions was not modified. |
133
+ | admin:repo:write:add tmp/p-lang.git jessicaeto | error: An error occurred. Permissions was not modified. |
134
+ | admin:repo:read:rm tmp/jeka.git aribonadio | error: An error occurred. Permissions was not modified. |
135
+ | admin:repo:read:rm tmp/p-lang.git igorbonadio | error: An error occurred. Permissions was not modified. |
136
+ | admin:repo:write:rm tmp/gritano.git arybonadio | error: An error occurred. Permissions was not modified. |
137
+ | admin:repo:write:rm tmp/p-lang.git igorbonadio | error: An error occurred. Permissions was not modified. |
138
+ | admin:repo:user:list tmp/ruby.git | error: Repository tmp/ruby.git doesn't exist. |
139
+
140
+ Scenario Outline: Normal user via ssh
141
+ Given I start the CLI with "jessicaeto"
142
+ When I send "<command>" to the CLI.check
143
+ Then CLI should return "<result>"
144
+ Examples:
145
+ | command | result |
146
+ | version | v0.4.1 |
147
+ | key:add keyname | Key added successfully. |
148
+ | key:rm hal | Key removed successfully. |
149
+ | key:rm keyname | error: Key could not be removed. |
150
+ | admin:user:add jose | error: access denied |
151
+ | admin:user:key:add igorbonadio marvin | error: access denied |
152
+ | admin:user:key:rm igorbonadio eva | error: access denied |
153
+ | admin:user:rm igorbonadio | error: access denied |
154
+ | admin:user:admin:add igorbonadio | error: access denied |
155
+ | admin:user:admin:rm igorbonadio | error: access denied |
156
+ | admin:repo:add tmp/p-lang.git | error: access denied |
157
+ | admin:repo:add tmp/p-lang.git igorbonadio | error: access denied |
158
+ | admin:repo:add tmp/p-lang.git igorbonadio jessicaeto | error: access denied |
159
+ | admin:repo:rm tmp/jeka.git | error: access denied |
160
+ | admin:repo:read:add tmp/gritano.git jessicaeto | error: access denied |
161
+ | admin:repo:write:add tmp/gritano.git jessicaeto | error: access denied |
162
+ | admin:repo:read:rm tmp/jeka.git igorbonadio | error: access denied |
163
+ | admin:repo:write:rm tmp/gritano.git igorbonadio | error: access denied |
164
+ | admin:user:add igorbonadio | error: access denied |
165
+ | admin:user:rm jose | error: access denied |
166
+ | admin:user:key:add userrr marvino | error: access denied |
167
+ | admin:user:key:rm igorbonadio marvino | error: access denied |
168
+ | admin:user:key:list arybonadio | error: access denied |
169
+ | admin:user:repo:list arybonadio | error: access denied |
170
+ | admin:user:admin:add arybonadio | error: access denied |
171
+ | admin:user:admin:rm arybonadio | error: access denied |
172
+ | admin:repo:add tmp/jeka.git | error: access denied |
173
+ | admin:repo:rm tmp/p-lang.git | error: access denied |
174
+ | admin:repo:read:add tmp/gritano.git arybonadio | error: access denied |
175
+ | admin:repo:read:add tmp/p-lang.git jessicaeto | error: access denied |
176
+ | admin:repo:write:add tmp/gritano.git arybonadio | error: access denied |
177
+ | admin:repo:write:add tmp/p-lang.git jessicaeto | error: access denied |
178
+ | admin:repo:read:rm tmp/jeka.git aribonadio | error: access denied |
179
+ | admin:repo:read:rm tmp/p-lang.git igorbonadio | error: access denied |
180
+ | admin:repo:write:rm tmp/gritano.git arybonadio | error: access denied |
181
+ | admin:repo:write:rm tmp/p-lang.git igorbonadio | error: access denied |
182
+ | admin:repo:user:list tmp/ruby.git | error: access denied |
183
+
@@ -27,12 +27,28 @@ Feature: Console operations
27
27
  | jessicaeto | tmp/jeka.git | read |
28
28
  | jessicaeto | tmp/jeka.git | write |
29
29
 
30
+ Scenario: Get help
31
+ Given I start the gritano console
32
+ When I execute "help"
33
+ Then I should see the help
34
+
35
+ Scenario: Check git
36
+ Given I start the gritano console but gritano is not installed
37
+ When I execute a command
38
+ Then I should see an error
39
+
40
+ Scenario: Install
41
+ Given I start the gritano console but gritano is not installed
42
+ When I install it
43
+ Then I should see a success message
44
+
30
45
  Scenario Outline: Add user
31
46
  Given I start the gritano console
32
47
  When I execute "<command>"
33
48
  Then I should see a <result> message
34
49
  Examples:
35
50
  | command | result |
51
+ | version | success |
36
52
  | user:add jose | success |
37
53
  | user:key:add igorbonadio marvin | success |
38
54
  | user:key:rm igorbonadio eva | success |
@@ -0,0 +1,13 @@
1
+ ssh git@host.com [command]
2
+
3
+ Examples:
4
+ ssh git@host.com version
5
+ ssh git@host.com help
6
+ ssh git@host.com repo:list
7
+ ssh git@host.com key:list
8
+ ssh git@host.com key:add keyname < key.pub
9
+ ssh git@host.com key:rm keyname
10
+ ssh git@host.com admin:help
11
+
12
+ --
13
+ v0.4.1
@@ -0,0 +1,27 @@
1
+ test [command]
2
+
3
+ Examples:
4
+ test help
5
+ test version
6
+ test setup:prepare
7
+ test setup:install
8
+ test user:list
9
+ test user:key:list username
10
+ test user:repo:list username
11
+ test user:add username
12
+ test user:rm username
13
+ test user:key:add username keyname < key.pub
14
+ test user:key:rm username keyname
15
+ test user:admin:add username
16
+ test user:admin:rm username
17
+ test repo:list
18
+ test repo:add reponame.git [username1 username2 ...]*
19
+ test repo:user:list reponame.git
20
+ test repo:rm reponame.git
21
+ test repo:read:add reponame.git username
22
+ test repo:write:add reponame.git username
23
+ test repo:read:rm reponame.git username
24
+ test repo:write:rm reponame.git username
25
+
26
+ --
27
+ v0.4.1