gritano 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- = Gritano v0.3.1
1
+ = Gritano v0.4.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
 
@@ -29,23 +29,23 @@ All you need to do to set up Gritano is
29
29
 
30
30
  After that you can add users:
31
31
 
32
- $ gritano user add igorbonadio
32
+ $ gritano user:add igorbonadio
33
33
 
34
34
  add administrator rights to this user:
35
35
 
36
- $ gritano user addadmin igorbonadio
36
+ $ gritano user:admin:add igorbonadio
37
37
 
38
38
  add user's public keys:
39
39
 
40
- $ gritano user addkey igorbonadio mykey < id_rsa.pub
40
+ $ gritano user:key:add igorbonadio mykey < id_rsa.pub
41
41
 
42
42
  create bare repositories:
43
43
 
44
- $ gritano repo add proj.git
44
+ $ gritano repo:add proj.git
45
45
 
46
46
  and control access:
47
47
 
48
- $ gritano repo addread proj.git igorbonadio
48
+ $ gritano repo:read:add proj.git igorbonadio
49
49
 
50
50
  For more information, execute
51
51
 
@@ -55,13 +55,13 @@ For more information, execute
55
55
 
56
56
  Gritano 0.2.0 introduced a new feature that enables users to execute some simple commands via ssh:
57
57
 
58
- $ ssh git@host.com repos
58
+ $ ssh git@host.com repo:list
59
59
 
60
- $ ssh git@host.com keys
60
+ $ ssh git@host.com key:list
61
61
 
62
- $ ssh git@host.com addkey mykey < id_rsa.pub
62
+ $ ssh git@host.com key:add mykey < id_rsa.pub
63
63
 
64
- $ ssh git@host.com rmkey mykey
64
+ $ ssh git@host.com key:add mykey
65
65
 
66
66
  For more information, execute
67
67
 
@@ -71,23 +71,23 @@ For more information, execute
71
71
 
72
72
  Starting from Gritano 0.3.0, administrators can execute commands via ssh:
73
73
 
74
- $ ssh git@hot.com user add username
74
+ $ ssh git@hot.com admin:user:add username
75
75
 
76
- $ ssh git@hot.com user rm username
76
+ $ ssh git@hot.com admin:user:rm username
77
77
 
78
- $ ssh git@hot.com user addkey username keyname < key.pub
78
+ $ ssh git@hot.com admin:user:key:add username keyname < key.pub
79
79
 
80
- $ ssh git@hot.com user rmkey username keyname
80
+ $ ssh git@hot.com admin:user:key:rm username keyname
81
81
 
82
- $ ssh git@hot.com repo add reponame.git
82
+ $ ssh git@hot.com admin:repo:add reponame.git
83
83
 
84
- $ ssh git@hot.com repo rm reponame.git
84
+ $ ssh git@hot.com admin:repo:rm reponame.git
85
85
 
86
- $ ssh git@hot.com repo list
86
+ $ ssh git@hot.com admin:repo:list
87
87
 
88
88
  For more information, execute
89
89
 
90
- $ ssh git@host.com admin help
90
+ $ ssh git@host.com admin:help
91
91
 
92
92
  == Contributing to Gritano
93
93
 
data/TODO CHANGED
@@ -1,7 +1,8 @@
1
1
  Outros
2
- - melhorar comandos
3
- gritano user:add igorbonadio
4
- - usuário pode (ou não) criar repositorios via ssh
5
- ssh git@host.com addrepo reponame.git
6
- ssh git@host.com rmrepo reponame.git
7
- - recuperar acesso via email/código e envio de chave via código
2
+
3
+ v0.4.0
4
+ - recuperar acesso via email/código e envio de chave via código
5
+ - melhorar o help
6
+
7
+ v0.5.0
8
+ - melhorar o instalador/updater
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.4.0
data/bin/gritano CHANGED
@@ -8,28 +8,29 @@ require 'etc'
8
8
 
9
9
  def help
10
10
  puts "
11
- gritano [install|user|repo] [command] parameters
11
+ gritano [command] parameters
12
12
 
13
13
  Examples:
14
14
  gritano install
15
15
  gritano update
16
- gritano user add username
17
- gritano user rm username
18
- gritano user addkey username keyname < key.pub
19
- gritano user rmkey username keyname
20
- gritano user addadmin username
21
- gritano user rmadmin username
22
- gritano user list
23
- gritano user keys username
24
- gritano user repos username
25
- gritano repo add reponame.git
26
- gritano repo rm reponame.git
27
- gritano repo addread reponame.git username
28
- gritano repo addwrite reponame.git username
29
- gritano repo rmread reponame.git username
30
- gritano repo rmwrite reponame.git username
31
- gritano repo list
32
- gritano repo users reponame.git
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
33
34
 
34
35
  --
35
36
  v#{File.open(File.join(File.dirname(__FILE__), '..', 'VERSION')).readlines.join}"
@@ -69,7 +70,10 @@ def check_gritano
69
70
  end
70
71
 
71
72
  check_git
72
- if ARGV.length == 1
73
+ if ARGV.length == 0
74
+ help
75
+ else
76
+
73
77
  if ARGV[0] =='install'
74
78
  install
75
79
  elsif ARGV[0] =='update'
@@ -77,24 +81,20 @@ if ARGV.length == 1
77
81
  elsif ARGV[0] =='version'
78
82
  version
79
83
  else
80
- help
81
- end
82
- elsif ARGV.length == 0
83
- help
84
- else
85
- check_gritano
86
- ActiveRecord::Base.establish_connection(YAML::load(File.open(File.join(Etc.getpwuid.dir, '.gritano', 'database.yml'))))
87
- console = Gritano::Console.new(STDIN)
88
- console.repo_path = Etc.getpwuid.dir
89
- console.ssh_path = File.join(Etc.getpwuid.dir, '.ssh')
90
- begin
91
- cmd_return = console.execute(ARGV)
92
- if cmd_return[0]
93
- puts "#{cmd_return[1]}"
94
- else
95
- puts "error: #{cmd_return[1]}"
84
+ check_gritano
85
+ ActiveRecord::Base.establish_connection(YAML::load(File.open(File.join(Etc.getpwuid.dir, '.gritano', 'database.yml'))))
86
+ console = Gritano::Console.new(STDIN)
87
+ console.repo_path = Etc.getpwuid.dir
88
+ console.ssh_path = File.join(Etc.getpwuid.dir, '.ssh')
89
+ begin
90
+ cmd_return = console.execute(ARGV)
91
+ if cmd_return[0]
92
+ puts "#{cmd_return[1]}"
93
+ else
94
+ puts "error: #{cmd_return[1]}"
95
+ end
96
+ rescue NoMethodError
97
+ puts help
96
98
  end
97
- rescue NoMethodError
98
- puts help
99
99
  end
100
100
  end
data/bin/gritano-check CHANGED
@@ -9,11 +9,11 @@ def help
9
9
  ssh user@host command
10
10
 
11
11
  Examples:
12
- ssh git@host.com repos
13
- ssh git@host.com keys
14
- ssh git@host.com addkey keyname < key.pub
15
- ssh git@host.com rmkey keyname
16
- ssh git@host.com admin help
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
17
 
18
18
  --
19
19
  v#{File.open(File.join(File.dirname(__FILE__), '..', 'VERSION')).readlines.join}"
@@ -30,19 +30,13 @@ begin
30
30
  repository = Gritano::Repository.find_by_name(command[:repo])
31
31
  if user and repository
32
32
  if user.check_access(repository, command[:access])
33
+ puts "#{command[:command]} #{File.join(repository.full_path)}"
33
34
  exec "#{command[:command]} #{File.join(repository.full_path)}"
34
35
  end
35
36
  end
36
37
  when :user_cmd
37
- cmd = command[:command]
38
- if cmd.start_with? "addkey" or cmd.start_with? "rmkey"
39
- tmp = cmd.split(" ")
40
- tmp = tmp[0..-2] + [login] + tmp[-1..-1]
41
- cmd = tmp.join(" ")
42
- else
43
- cmd = cmd + " " + login
44
- end
45
- exec "gritano user #{cmd}"
38
+ cmd = command[:command].gsub("[USER]", login)
39
+ exec "gritano #{cmd}"
46
40
  when :admin_cmd
47
41
  cmd = command[:command]
48
42
  user = Gritano::User.find_by_login(login)
@@ -7,26 +7,26 @@ Feature: Command
7
7
  When I receive a "<original_command>" command
8
8
  Then I should see that it is a "<access>": "<command>" "<repo>"
9
9
  Examples:
10
- | original_command | access | command | repo |
11
- | git-receive-pack proj.git | write | git-receive-pack | proj.git |
12
- | git-upload-pack proj.git | read | git-upload-pack | proj.git |
13
- | repos | user_cmd | repos | |
14
- | keys | user_cmd | keys | |
15
- | addkey keyname | user_cmd | addkey keyname | |
16
- | rmkey keyname | user_cmd | rmkey keyname | |
17
- | user add username | admin_cmd | user add username | |
18
- | user rm username | admin_cmd | user rm username | |
19
- | user addkey username keyname | admin_cmd | user addkey username keyname | |
20
- | user rmkey username keyname | admin_cmd | user rmkey username keyname | |
21
- | user list | admin_cmd | user list | |
22
- | user keys username | admin_cmd | user keys username | |
23
- | user repos username | admin_cmd | user repos username | |
24
- | repo add reponame.git | admin_cmd | repo add reponame.git | |
25
- | repo rm reponame.git | admin_cmd | repo rm reponame.git | |
26
- | repo addread reponame.git username | admin_cmd | repo addread reponame.git username | |
27
- | repo addwrite reponame.git username | admin_cmd | repo addwrite reponame.git username | |
28
- | repo rmread reponame.git username | admin_cmd | repo rmread reponame.git username | |
29
- | repo rmwrite reponame.git username | admin_cmd | repo rmwrite reponame.git username | |
30
- | repo list | admin_cmd | repo list | |
31
- | repo users reponame.git | admin_cmd | repo users reponame.git | |
32
- | admin help | admin_cmd | help | |
10
+ | original_command | access | command | repo |
11
+ | git-receive-pack proj.git | write | git-receive-pack | proj.git |
12
+ | git-upload-pack proj.git | read | git-upload-pack | proj.git |
13
+ | repo:list | user_cmd | user:repo:list [USER] | |
14
+ | key:list | user_cmd | user:key:list [USER] | |
15
+ | key:add keyname | user_cmd | user:key:add [USER] keyname | |
16
+ | key:rm keyname | user_cmd | user:key:rm [USER] keyname | |
17
+ | admin:user:add username | admin_cmd | user:add username | |
18
+ | admin:user:rm username | admin_cmd | user:rm username | |
19
+ | admin:user:key:add username keyname | admin_cmd | user:key:add username keyname | |
20
+ | admin:user:key:rm username keyname | admin_cmd | user:key:rm username keyname | |
21
+ | admin:user:list | admin_cmd | user:list | |
22
+ | admin:user:key:list username | admin_cmd | user:key:list username | |
23
+ | admin:user:repo:list username | admin_cmd | user:repo:list username | |
24
+ | admin:repo:add reponame.git | admin_cmd | repo:add reponame.git | |
25
+ | admin:repo:rm reponame.git | admin_cmd | repo:rm reponame.git | |
26
+ | admin:repo:read:add reponame.git username | admin_cmd | repo:read:add reponame.git username | |
27
+ | admin:repo:write:add reponame.git username | admin_cmd | repo:write:add reponame.git username | |
28
+ | admin:repo:read:rm reponame.git username | admin_cmd | repo:read:rm reponame.git username | |
29
+ | admin:repo:write:rm reponame.git username | admin_cmd | repo:write:rm reponame.git username | |
30
+ | admin:repo:list | admin_cmd | repo:list | |
31
+ | admin:repo:user:list reponame.git | admin_cmd | repo:user:list reponame.git | |
32
+ | admin:help | admin_cmd | help | |
@@ -32,40 +32,42 @@ Feature: Console operations
32
32
  When I execute "<command>"
33
33
  Then I should see a <result> message
34
34
  Examples:
35
- | command | result |
36
- | user add jose | success |
37
- | user addkey igorbonadio marvin | success |
38
- | user rmkey igorbonadio eva | success |
39
- | user rm igorbonadio | success |
40
- | user list | success |
41
- | user keys igorbonadio | success |
42
- | user repos igorbonadio | success |
43
- | user addadmin igorbonadio | success |
44
- | user rmadmin igorbonadio | success |
45
- | repo add tmp/p-lang.git | success |
46
- | repo rm tmp/jeka.git | success |
47
- | repo addread tmp/gritano.git jessicaeto | success |
48
- | repo addwrite tmp/gritano.git jessicaeto | success |
49
- | repo rmread tmp/jeka.git igorbonadio | success |
50
- | repo rmwrite tmp/gritano.git igorbonadio | success |
51
- | repo list | success |
52
- | repo users tmp/jeka.git | success |
53
- | user add igorbonadio | error |
54
- | user rm jose | error |
55
- | user addkey userrr marvino | error |
56
- | user rmkey igorbonadio marvino | error |
57
- | user keys arybonadio | error |
58
- | user repos arybonadio | error |
59
- | user addadmin arybonadio | error |
60
- | user rmadmin arybonadio | error |
61
- | repo add tmp/jeka.git | error |
62
- | repo rm tmp/p-lang.git | error |
63
- | repo addread tmp/gritano.git arybonadio | error |
64
- | repo addread tmp/p-lang.git jessicaeto | error |
65
- | repo addwrite tmp/gritano.git arybonadio | error |
66
- | repo addwrite tmp/p-lang.git jessicaeto | error |
67
- | repo rmread tmp/jeka.git aribonadio | error |
68
- | repo rmread tmp/p-lang.git igorbonadio | error |
69
- | repo rmwrite tmp/gritano.git arybonadio | error |
70
- | repo rmwrite tmp/p-lang.git igorbonadio | error |
71
- | repo users tmp/ruby.git | error |
35
+ | command | result |
36
+ | user:add jose | success |
37
+ | user:key:add igorbonadio marvin | success |
38
+ | user:key:rm igorbonadio eva | success |
39
+ | user:rm igorbonadio | success |
40
+ | user:list | success |
41
+ | user:key:list igorbonadio | success |
42
+ | user:repo:list igorbonadio | success |
43
+ | user:admin:add igorbonadio | success |
44
+ | user:admin:rm igorbonadio | success |
45
+ | repo:add tmp/p-lang.git | success |
46
+ | repo:add tmp/p-lang.git igorbonadio | success |
47
+ | repo:add tmp/p-lang.git igorbonadio jessicaeto | success |
48
+ | repo:rm tmp/jeka.git | success |
49
+ | repo:read:add tmp/gritano.git jessicaeto | success |
50
+ | repo:write:add tmp/gritano.git jessicaeto | success |
51
+ | repo:read:rm tmp/jeka.git igorbonadio | success |
52
+ | repo:write:rm tmp/gritano.git igorbonadio | success |
53
+ | repo:list | success |
54
+ | repo:user:list tmp/jeka.git | success |
55
+ | user:add igorbonadio | error |
56
+ | user:rm jose | error |
57
+ | user:key:add userrr marvino | error |
58
+ | user:key:rm igorbonadio marvino | error |
59
+ | user:key:list arybonadio | error |
60
+ | user:repo:list arybonadio | error |
61
+ | user:admin:add arybonadio | error |
62
+ | user:admin:rm arybonadio | error |
63
+ | repo:add tmp/jeka.git | error |
64
+ | repo:rm tmp/p-lang.git | error |
65
+ | repo:read:add tmp/gritano.git arybonadio | error |
66
+ | repo:read:add tmp/p-lang.git jessicaeto | error |
67
+ | repo:write:add tmp/gritano.git arybonadio | error |
68
+ | repo:write:add tmp/p-lang.git jessicaeto | error |
69
+ | repo:read:rm tmp/jeka.git aribonadio | error |
70
+ | repo:read:rm tmp/p-lang.git igorbonadio | error |
71
+ | repo:write:rm tmp/gritano.git arybonadio | error |
72
+ | repo:write:rm tmp/p-lang.git igorbonadio | error |
73
+ | repo:user:list tmp/ruby.git | error |
data/gritano.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "gritano"
8
- s.version = "0.3.2"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Igor Bonadio"]
12
- s.date = "2012-12-07"
12
+ s.date = "2012-12-08"
13
13
  s.description = "Gritano is the simplest way to configure your git server over ssh. You can create repositories and manage user access."
14
14
  s.email = "igorbonadio@gmail.com"
15
15
  s.executables = ["gritano", "gritano-check"]
@@ -6,12 +6,14 @@ module Gritano
6
6
  return {access: :write, command: "git-receive-pack", repo: self.repo(cmd)}
7
7
  when /^git-upload-pack/ then
8
8
  return {access: :read, command: "git-upload-pack", repo: self.repo(cmd)}
9
- when /^repos/, /^keys/, /^addkey/, /^rmkey/ then
10
- return {access: :user_cmd, command: cmd}
11
- when /^user/, /^repo/ then
12
- return {access: :admin_cmd, command: cmd}
13
- when /^admin help/ then
14
- return {access: :admin_cmd, command: 'help'}
9
+ when /^repo:/ then
10
+ return {access: :user_cmd, command: ("user:#{cmd} [USER]")}
11
+ when /^key:/ then
12
+ cmd = cmd.split(" ")
13
+ cmd = [cmd[0]] + ["[USER]"] + cmd[1..-1]
14
+ return {access: :user_cmd, command: ("user:" + cmd.join(" "))}
15
+ when /admin:/ then
16
+ return {access: :admin_cmd, command: cmd.gsub("admin:", "")}
15
17
  end
16
18
  end
17
19
 
@@ -13,7 +13,7 @@ module Gritano
13
13
  end
14
14
 
15
15
  def execute(argv)
16
- send(argv[0..1].join('_'), argv[2..-1])
16
+ send(argv[0].gsub(':', '_'), argv[1..-1])
17
17
  end
18
18
 
19
19
  def user_list(argv)
@@ -29,7 +29,7 @@ module Gritano
29
29
  return [true, msg]
30
30
  end
31
31
 
32
- def user_keys(argv)
32
+ def user_key_list(argv)
33
33
  login, = argv
34
34
  user = User.find_by_login(login)
35
35
  if user
@@ -48,7 +48,7 @@ module Gritano
48
48
  end
49
49
  end
50
50
 
51
- def user_repos(argv)
51
+ def user_repo_list(argv)
52
52
  login, = argv
53
53
  user = User.find_by_login(login)
54
54
  if user
@@ -85,6 +85,55 @@ module Gritano
85
85
  return [false, "User #{login} could not be removed."]
86
86
  end
87
87
 
88
+ def user_key_add(argv)
89
+ login, key_name, key_file = argv
90
+ user = User.find_by_login(login)
91
+ if user
92
+ key = user.keys.create(name: key_name, key: @stdin.read)
93
+ if key.valid?
94
+ File.open(File.join(@ssh_path, 'authorized_keys'), 'w').write(Key.authorized_keys)
95
+ return [true, "Key added successfully."]
96
+ end
97
+ end
98
+ return [false, "Key could not be added."]
99
+ end
100
+
101
+ def user_key_rm(argv)
102
+ login, key_name = argv
103
+ key = Key.where(name: key_name).includes(:user).where("users.login" => login).limit(1)[0]
104
+ if key
105
+ if key.destroy
106
+ File.open(File.join(@ssh_path, 'authorized_keys'), 'w').write(Key.authorized_keys)
107
+ return [true, "Key removed successfully."]
108
+ end
109
+ end
110
+ return [false, "Key could not be removed."]
111
+ end
112
+
113
+ def user_admin_add(argv)
114
+ login, = argv
115
+ user = User.find_by_login(login)
116
+ if user
117
+ user.admin = true
118
+ if user.save
119
+ return [true, "Now, user #{login} is an administrator"]
120
+ end
121
+ end
122
+ return [false, "User #{login} could not be modified"]
123
+ end
124
+
125
+ def user_admin_rm(argv)
126
+ login, = argv
127
+ user = User.find_by_login(login)
128
+ if user
129
+ user.admin = false
130
+ if user.save
131
+ return [true, "Now, user #{login} is not an administrator"]
132
+ end
133
+ end
134
+ return [false, "User #{login} could not be modified"]
135
+ end
136
+
88
137
  def repo_list(argv)
89
138
  repos = Repository.all
90
139
  msg = Terminal::Table.new do |t|
@@ -99,13 +148,24 @@ module Gritano
99
148
  end
100
149
 
101
150
  def repo_add(argv)
102
- name, = argv
151
+ name, user_login = argv
103
152
  repo = Repository.new(name: name, path: @repo_path)
104
- return [true, "Repository #{name} created successfully."] if repo.save
153
+ if repo.save
154
+ if user_login
155
+ argv[1..-1].each do |login|
156
+ user = User.find_by_login(login)
157
+ if user
158
+ user.add_access(repo, :read)
159
+ user.add_access(repo, :write)
160
+ end
161
+ end
162
+ end
163
+ return [true, "Repository #{name} created successfully."]
164
+ end
105
165
  return [false, "Repository #{name} could not be created."]
106
166
  end
107
167
 
108
- def repo_users(argv)
168
+ def repo_user_list(argv)
109
169
  name, = argv
110
170
  repo = Repository.find_by_name(name)
111
171
  if repo
@@ -139,7 +199,7 @@ module Gritano
139
199
  return [false, "Repository #{name} could not be removed."]
140
200
  end
141
201
 
142
- def repo_addread(argv)
202
+ def repo_read_add(argv)
143
203
  repo_name, login = argv
144
204
  user = User.find_by_login(login)
145
205
  repo = Repository.find_by_name(repo_name)
@@ -149,7 +209,7 @@ module Gritano
149
209
  return [false, "An error occurred. Permissions was not modified."]
150
210
  end
151
211
 
152
- def repo_addwrite(argv)
212
+ def repo_write_add(argv)
153
213
  repo_name, login = argv
154
214
  user = User.find_by_login(login)
155
215
  repo = Repository.find_by_name(repo_name)
@@ -159,7 +219,7 @@ module Gritano
159
219
  return [false, "An error occurred. Permissions was not modified."]
160
220
  end
161
221
 
162
- def repo_rmread(argv)
222
+ def repo_read_rm(argv)
163
223
  repo_name, login = argv
164
224
  user = User.find_by_login(login)
165
225
  repo = Repository.find_by_name(repo_name)
@@ -169,7 +229,7 @@ module Gritano
169
229
  return [false, "An error occurred. Permissions was not modified."]
170
230
  end
171
231
 
172
- def repo_rmwrite(argv)
232
+ def repo_write_rm(argv)
173
233
  repo_name, login = argv
174
234
  user = User.find_by_login(login)
175
235
  repo = Repository.find_by_name(repo_name)
@@ -178,54 +238,5 @@ module Gritano
178
238
  end
179
239
  return [false, "An error occurred. Permissions was not modified."]
180
240
  end
181
-
182
- def user_addkey(argv)
183
- login, key_name, key_file = argv
184
- user = User.find_by_login(login)
185
- if user
186
- key = user.keys.create(name: key_name, key: @stdin.read)
187
- if key.valid?
188
- File.open(File.join(@ssh_path, 'authorized_keys'), 'w').write(Key.authorized_keys)
189
- return [true, "Key added successfully."]
190
- end
191
- end
192
- return [false, "Key could not be added."]
193
- end
194
-
195
- def user_rmkey(argv)
196
- login, key_name = argv
197
- key = Key.where(name: key_name).includes(:user).where("users.login" => login).limit(1)[0]
198
- if key
199
- if key.destroy
200
- File.open(File.join(@ssh_path, 'authorized_keys'), 'w').write(Key.authorized_keys)
201
- return [true, "Key removed successfully."]
202
- end
203
- end
204
- return [false, "Key could not be removed."]
205
- end
206
-
207
- def user_addadmin(argv)
208
- login, = argv
209
- user = User.find_by_login(login)
210
- if user
211
- user.admin = true
212
- if user.save
213
- return [true, "Now, user #{login} is an administrator"]
214
- end
215
- end
216
- return [false, "User #{login} could not be modified"]
217
- end
218
-
219
- def user_rmadmin(argv)
220
- login, = argv
221
- user = User.find_by_login(login)
222
- if user
223
- user.admin = false
224
- if user.save
225
- return [true, "Now, user #{login} is not an administrator"]
226
- end
227
- end
228
- return [false, "User #{login} could not be modified"]
229
- end
230
241
  end
231
242
  end
data/spec/command_spec.rb CHANGED
@@ -16,26 +16,26 @@ describe Gritano::Command do
16
16
  end
17
17
 
18
18
  it 'should interpret repos' do
19
- command = Gritano::Command.eval("repos")
19
+ command = Gritano::Command.eval("repo:list")
20
20
  command[:access].to_s.should be == "user_cmd"
21
- command[:command].should be == "repos"
21
+ command[:command].should be == "user:repo:list [USER]"
22
22
  end
23
23
 
24
24
  it 'should interpret keys' do
25
- command = Gritano::Command.eval("keys")
25
+ command = Gritano::Command.eval("key:list")
26
26
  command[:access].to_s.should be == "user_cmd"
27
- command[:command].should be == "keys"
27
+ command[:command].should be == "user:key:list [USER]"
28
28
  end
29
29
 
30
30
  it 'should interpret addkey keyname' do
31
- command = Gritano::Command.eval("addkey keyname")
31
+ command = Gritano::Command.eval("key:add keyname")
32
32
  command[:access].to_s.should be == "user_cmd"
33
- command[:command].should be == "addkey keyname"
33
+ command[:command].should be == "user:key:add [USER] keyname"
34
34
  end
35
35
 
36
36
  it 'should interpret rmkey keyname' do
37
- command = Gritano::Command.eval("rmkey keyname")
37
+ command = Gritano::Command.eval("key:rm keyname")
38
38
  command[:access].to_s.should be == "user_cmd"
39
- command[:command].should be == "rmkey keyname"
39
+ command[:command].should be == "user:key:rm [USER] keyname"
40
40
  end
41
41
  end
data/spec/console_spec.rb CHANGED
@@ -8,88 +8,88 @@ describe Gritano::Console do
8
8
  @console = Gritano::Console.new(stdin)
9
9
  end
10
10
 
11
- it "should respond to gritano user add igorbonadio" do
11
+ it "should respond to gritano user:add igorbonadio" do
12
12
  @console.should_receive(:user_add)
13
- @console.execute("user add igorbonadio".split(' '))
13
+ @console.execute("user:add igorbonadio".split(' '))
14
14
  end
15
15
 
16
- it "should respond to gritano user rm igorbonadio" do
16
+ it "should respond to gritano user:rm igorbonadio" do
17
17
  @console.should_receive(:user_rm)
18
- @console.execute("user rm igorbonadio".split(' '))
18
+ @console.execute("user:rm igorbonadio".split(' '))
19
19
  end
20
20
 
21
- it "should respond to gritano user addkey username keyname < key.pub" do
22
- @console.should_receive(:user_addkey)
23
- @console.execute("user addkey igorbonadio keyname".split(' '))
21
+ it "should respond to gritano user:key:add username keyname < key.pub" do
22
+ @console.should_receive(:user_key_add)
23
+ @console.execute("user:key:add igorbonadio keyname".split(' '))
24
24
  end
25
25
 
26
- it "should respond to gritano user rmkey username keyname" do
27
- @console.should_receive(:user_rmkey)
28
- @console.execute("user rmkey username keyname".split(' '))
26
+ it "should respond to gritano user:key:rm username keyname" do
27
+ @console.should_receive(:user_key_rm)
28
+ @console.execute("user:key:rm username keyname".split(' '))
29
29
  end
30
30
 
31
- it "should respond to gritano user list" do
31
+ it "should respond to gritano user:list" do
32
32
  @console.should_receive(:user_list)
33
- @console.execute("user list".split(' '))
33
+ @console.execute("user:list".split(' '))
34
34
  end
35
35
 
36
- it "should respond to gritano user keys username" do
37
- @console.should_receive(:user_keys)
38
- @console.execute("user keys username".split(' '))
36
+ it "should respond to gritano user:key:list username" do
37
+ @console.should_receive(:user_key_list)
38
+ @console.execute("user:key:list username".split(' '))
39
39
  end
40
40
 
41
- it "should respond to gritano user repos username" do
42
- @console.should_receive(:user_repos)
43
- @console.execute("user repos username".split(' '))
41
+ it "should respond to gritano user:repo:list username" do
42
+ @console.should_receive(:user_repo_list)
43
+ @console.execute("user:repo:list username".split(' '))
44
44
  end
45
45
 
46
- it "should respond to gritano repo add tmp/reponame.git" do
47
- @console.should_receive(:repo_add)
48
- @console.execute("repo add tmp/reponame.git".split(' '))
46
+ it "should respond to gritano repo:user:list reponame.git" do
47
+ @console.should_receive(:repo_user_list)
48
+ @console.execute("repo:user:list reponame.git".split(' '))
49
49
  end
50
50
 
51
- it "should respond to gritano repo rm tmp/reponame.git" do
52
- @console.should_receive(:repo_rm)
53
- @console.execute("repo rm tmp/reponame.git".split(' '))
51
+ it "should respond to gritano user:admin:add igorbonadio" do
52
+ @console.should_receive(:user_admin_add)
53
+ @console.execute("user:admin:add igorbonadio".split(' '))
54
54
  end
55
55
 
56
- it "should respond to gritano repo addread igorbonadio tmp/reponame.git" do
57
- @console.should_receive(:repo_addread)
58
- @console.execute("repo addread igorbonadio tmp/reponame.git".split(' '))
56
+ it "should respond to gritano user:admin:rm igorbonadio" do
57
+ @console.should_receive(:user_admin_rm)
58
+ @console.execute("user:admin:rm igorbonadio".split(' '))
59
59
  end
60
60
 
61
- it "should respond to gritano repo addwrite igorbonadio tmp/reponame.git" do
62
- @console.should_receive(:repo_addwrite)
63
- @console.execute("repo addwrite igorbonadio tmp/reponame.git".split(' '))
61
+ it "should respond to gritano repo:add tmp/reponame.git" do
62
+ @console.should_receive(:repo_add)
63
+ @console.execute("repo:add tmp/reponame.git".split(' '))
64
64
  end
65
65
 
66
- it "should respond to gritano repo rmread igorbonadio tmp/reponame.git" do
67
- @console.should_receive(:repo_rmread)
68
- @console.execute("repo rmread igorbonadio tmp/reponame.git".split(' '))
66
+ it "should respond to gritano repo:rm tmp/reponame.git" do
67
+ @console.should_receive(:repo_rm)
68
+ @console.execute("repo:rm tmp/reponame.git".split(' '))
69
69
  end
70
70
 
71
- it "should respond to gritano repo rmwrite igorbonadio tmp/reponame.git" do
72
- @console.should_receive(:repo_rmwrite)
73
- @console.execute("repo rmwrite igorbonadio tmp/reponame.git".split(' '))
71
+ it "should respond to gritano repo:read:add igorbonadio tmp/reponame.git" do
72
+ @console.should_receive(:repo_read_add)
73
+ @console.execute("repo:read:add igorbonadio tmp/reponame.git".split(' '))
74
74
  end
75
75
 
76
- it "should respond to gritano repo list" do
77
- @console.should_receive(:repo_list)
78
- @console.execute("repo list".split(' '))
76
+ it "should respond to gritano repo:write:add igorbonadio tmp/reponame.git" do
77
+ @console.should_receive(:repo_write_add)
78
+ @console.execute("repo:write:add igorbonadio tmp/reponame.git".split(' '))
79
79
  end
80
80
 
81
- it "should respond to gritano repo users reponame.git" do
82
- @console.should_receive(:repo_users)
83
- @console.execute("repo users reponame.git".split(' '))
81
+ it "should respond to gritano repo:read:rm igorbonadio tmp/reponame.git" do
82
+ @console.should_receive(:repo_read_rm)
83
+ @console.execute("repo:read:rm igorbonadio tmp/reponame.git".split(' '))
84
84
  end
85
85
 
86
- it "should respond to gritano user addadmin igorbonadio" do
87
- @console.should_receive(:user_addadmin)
88
- @console.execute("user addadmin igorbonadio".split(' '))
86
+ it "should respond to gritano repo:write:rm igorbonadio tmp/reponame.git" do
87
+ @console.should_receive(:repo_write_rm)
88
+ @console.execute("repo:write:rm igorbonadio tmp/reponame.git".split(' '))
89
89
  end
90
90
 
91
- it "should respond to gritano user rmadmin igorbonadio" do
92
- @console.should_receive(:user_rmadmin)
93
- @console.execute("user rmadmin igorbonadio".split(' '))
91
+ it "should respond to gritano repo:list" do
92
+ @console.should_receive(:repo_list)
93
+ @console.execute("repo:list".split(' '))
94
94
  end
95
95
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gritano
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-07 00:00:00.000000000 Z
12
+ date: 2012-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -262,7 +262,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
262
262
  version: '0'
263
263
  segments:
264
264
  - 0
265
- hash: -4358117798513437799
265
+ hash: 3887910005578174046
266
266
  required_rubygems_version: !ruby/object:Gem::Requirement
267
267
  none: false
268
268
  requirements: