gritano 0.5.3 → 0.5.4

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.
data/Gemfile.lock CHANGED
@@ -1,27 +1,27 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (3.2.8)
5
- activesupport (= 3.2.8)
4
+ activemodel (3.2.11)
5
+ activesupport (= 3.2.11)
6
6
  builder (~> 3.0.0)
7
- activerecord (3.2.8)
8
- activemodel (= 3.2.8)
9
- activesupport (= 3.2.8)
7
+ activerecord (3.2.11)
8
+ activemodel (= 3.2.11)
9
+ activesupport (= 3.2.11)
10
10
  arel (~> 3.0.2)
11
11
  tzinfo (~> 0.3.29)
12
- activesupport (3.2.8)
12
+ activesupport (3.2.11)
13
13
  i18n (~> 0.6)
14
14
  multi_json (~> 1.0)
15
15
  arel (3.0.2)
16
- builder (3.0.2)
16
+ builder (3.0.4)
17
17
  cucumber (1.2.1)
18
18
  builder (>= 2.1.2)
19
19
  diff-lcs (>= 1.1.3)
20
20
  gherkin (~> 2.11.0)
21
21
  json (>= 1.4.6)
22
- database_cleaner (0.8.0)
22
+ database_cleaner (0.9.1)
23
23
  diff-lcs (1.1.3)
24
- gherkin (2.11.2)
24
+ gherkin (2.11.5)
25
25
  json (>= 1.4.6)
26
26
  git (1.2.5)
27
27
  grit (2.5.0)
@@ -34,28 +34,28 @@ GEM
34
34
  git (>= 1.2.5)
35
35
  rake
36
36
  rdoc
37
- json (1.7.5)
37
+ json (1.7.6)
38
38
  mime-types (1.19)
39
- multi_json (1.3.6)
39
+ multi_json (1.5.0)
40
40
  posix-spawn (0.3.6)
41
- rake (0.9.2.2)
41
+ rake (10.0.3)
42
42
  rdoc (3.12)
43
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)
44
+ rspec (2.12.0)
45
+ rspec-core (~> 2.12.0)
46
+ rspec-expectations (~> 2.12.0)
47
+ rspec-mocks (~> 2.12.0)
48
+ rspec-core (2.12.2)
49
+ rspec-expectations (2.12.1)
50
50
  diff-lcs (~> 1.1.3)
51
- rspec-mocks (2.11.2)
52
- simplecov (0.6.4)
51
+ rspec-mocks (2.12.2)
52
+ simplecov (0.7.1)
53
53
  multi_json (~> 1.0)
54
- simplecov-html (~> 0.5.3)
55
- simplecov-html (0.5.3)
56
- sqlite3 (1.3.6)
54
+ simplecov-html (~> 0.7.1)
55
+ simplecov-html (0.7.1)
56
+ sqlite3 (1.3.7)
57
57
  terminal-table (1.4.5)
58
- tzinfo (0.3.33)
58
+ tzinfo (0.3.35)
59
59
 
60
60
  PLATFORMS
61
61
  ruby
data/README.rdoc CHANGED
@@ -71,19 +71,19 @@ 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 admin:user:add username
74
+ $ ssh git@host.com admin:user:add username
75
75
 
76
- $ ssh git@hot.com admin:user:rm username
76
+ $ ssh git@host.com admin:user:rm username
77
77
 
78
- $ ssh git@hot.com admin:user:key:add username keyname < key.pub
78
+ $ ssh git@host.com admin:user:key:add username keyname < key.pub
79
79
 
80
- $ ssh git@hot.com admin:user:key:rm username keyname
80
+ $ ssh git@host.com admin:user:key:rm username keyname
81
81
 
82
- $ ssh git@hot.com admin:repo:add reponame.git
82
+ $ ssh git@host.com admin:repo:add reponame.git
83
83
 
84
- $ ssh git@hot.com admin:repo:rm reponame.git
84
+ $ ssh git@host.com admin:repo:rm reponame.git
85
85
 
86
- $ ssh git@hot.com admin:repo:list
86
+ $ ssh git@host.com admin:repo:list
87
87
 
88
88
  == For more Information
89
89
 
data/TODO CHANGED
@@ -1,7 +1,7 @@
1
1
  v0.6.0
2
2
  - melhorar o instalador/updater
3
3
  - escolha de db
4
- - escolha de pasta dos repos
4
+ gritano setup:prepare -db sqlite
5
5
 
6
6
  v0.7.0
7
7
  - gritano-openssh
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.3
1
+ 0.5.4
@@ -0,0 +1,13 @@
1
+ gritano [command]
2
+
3
+ Examples:
4
+ gritano version
5
+ gritano help
6
+ gritano repo:list
7
+ gritano key:list
8
+ gritano key:add keyname < key.pub
9
+ gritano key:rm keyname
10
+ gritano admin:help
11
+
12
+ --
13
+ v{{VERSION}}
@@ -1,7 +1,7 @@
1
1
  Given /^I start the gritano console but gritano is not installed$/ do
2
2
  stdin = double()
3
3
  stdin.stub(:read).and_return("Your SSHKEY here...")
4
- FileUtils.rm_rf('tmp\.gritano')
4
+ FileUtils.rm_rf('tmp/.gritano')
5
5
  @home_dir = 'tmp'
6
6
  @repo_dir = 'tmp'
7
7
  @console = Gritano::CLI
@@ -21,7 +21,7 @@ When /^I install it$/ do
21
21
  end
22
22
 
23
23
  Then /^I should see that gritano was successful (installed|updated)$/ do |opt|
24
- @prepare_output.should be == 'configuration has been generated' if opt == 'installed'
24
+ @prepare_output.should be == "Gritano's configuration has been generated.\nIf you want to customize it, check your '#{File.join(@home_dir, '.gritano')}' directory." if opt == 'installed'
25
25
  @install_output.should be == 'gritano has been installed'
26
26
  end
27
27
 
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.5.3"
8
+ s.version = "0.5.4"
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 = "2013-01-03"
12
+ s.date = "2013-01-28"
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-remote"]
@@ -170,6 +170,7 @@ Gem::Specification.new do |s|
170
170
  "features/data/remote_commands/repo_list_jessicaeto.txt",
171
171
  "features/data/remote_commands/version_igorbonadio.txt",
172
172
  "features/data/remote_commands/version_jessicaeto.txt",
173
+ "features/data/remote_help.txt",
173
174
  "features/install.feature",
174
175
  "features/local.feature",
175
176
  "features/remote.feature",
@@ -193,10 +194,16 @@ Gem::Specification.new do |s|
193
194
  "lib/gritano/models/permission.rb",
194
195
  "lib/gritano/models/repository.rb",
195
196
  "lib/gritano/models/user.rb",
196
- "spec/executor_spec.rb",
197
- "spec/gritano_spec.rb",
198
- "spec/installer_spec.rb",
197
+ "spec/cli_spec.rb",
198
+ "spec/console_base_spec.rb",
199
+ "spec/console_executor_spec.rb",
200
+ "spec/console_gritano_spec.rb",
201
+ "spec/console_installer_spec.rb",
202
+ "spec/console_remote_spec.rb",
203
+ "spec/console_spec.rb",
204
+ "spec/data/help_command_name.txt",
199
205
  "spec/model_key_spec.rb",
206
+ "spec/model_permission_spec.rb",
200
207
  "spec/model_repository_spec.rb",
201
208
  "spec/model_user_spec.rb",
202
209
  "spec/spec_helper.rb"
@@ -61,11 +61,15 @@ module Gritano
61
61
  end
62
62
 
63
63
  def check_git
64
- if `which git` == ""
64
+ if unknown_command('git')
65
65
  puts "Error: git must be installed on the local system"
66
66
  exit
67
67
  end
68
68
  end
69
+
70
+ def unknown_command(command)
71
+ `which #{command}` == ""
72
+ end
69
73
 
70
74
  def before_each_command_filter
71
75
  end
@@ -23,7 +23,7 @@ module Gritano
23
23
  def method_missing(meth, *args, &block)
24
24
  params = [meth.to_s.gsub("_", ":")] + args[0]
25
25
  begin
26
- installer = Installer.new
26
+ installer = Installer.new(@stdin, @home_dir)
27
27
  installer.execute(params)
28
28
  rescue
29
29
  executor = Executor.new(@stdin, @home_dir, @repo_path)
@@ -13,25 +13,41 @@ module Gritano
13
13
  check_git
14
14
  end
15
15
 
16
- add_command "setup:prepare" do |argv|
16
+ def create_gritano_dirs
17
17
  Dir.mkdir(File.join(@home_dir, '.gritano')) unless File.exist?(File.join(@home_dir, '.gritano'))
18
18
  Dir.mkdir(File.join(@home_dir, '.ssh')) unless File.exist?(File.join(@home_dir, '.ssh'))
19
+ end
20
+
21
+ def create_sqlite_config
19
22
  File.open(File.join(@home_dir, '.gritano', 'database.yml'), "w") do |f|
20
23
  f.write("adapter: sqlite3\ndatabase: #{File.join(Etc.getpwuid.dir, '.gritano', 'database.db')}\n")
21
24
  end
22
25
  if File.exist?(File.join(@home_dir, '.gritano', 'database.db'))
23
26
  FileUtils.rm(File.join(@home_dir, '.gritano', 'database.db'))
24
27
  end
25
- return [true, "configuration has been generated"]
28
+ end
29
+
30
+ add_command "setup:prepare" do |argv|
31
+ create_gritano_dirs
32
+ create_sqlite_config
33
+ return [true, "Gritano's configuration has been generated.\nIf you want to customize it, check your '#{File.join(@home_dir, '.gritano')}' directory."]
26
34
  end
27
35
 
28
- add_command "setup:install" do |argv|
29
- ActiveRecord::Base.establish_connection(
30
- YAML::load(File.open(File.join(@home_dir, '.gritano', 'database.yml'))))
36
+ def create_database
37
+ db_config = YAML::load(File.open(File.join(@home_dir, '.gritano', 'database.yml')))
38
+ ActiveRecord::Base.establish_connection(db_config)
31
39
  ActiveRecord::Migrator.migrate(
32
40
  File.join(File.dirname(__FILE__),'..', '..', '..', 'db/migrate'),
33
41
  ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
42
+ end
43
+
44
+ def create_authorization_keys
34
45
  File.open(File.join(@ssh_path, 'authorized_keys'), 'w').write(Key.authorized_keys)
46
+ end
47
+
48
+ add_command "setup:install" do |argv|
49
+ create_database
50
+ create_authorization_keys
35
51
  [true, "gritano has been installed"]
36
52
  end
37
53
  end
@@ -52,28 +52,38 @@ module Gritano
52
52
  gritano.execute(["help"])
53
53
  end
54
54
 
55
+ def admin_command(meth, params)
56
+ @executor.execute([meth] + params)
57
+ end
58
+
59
+ def git_receive_pack(repo, login)
60
+ user = ::Gritano::User.find_by_login(login)
61
+ if user
62
+ Kernel.exec "git-receive-pack #{repo(repo).full_path}" if user.check_access(repo(repo), :read)
63
+ end
64
+ end
65
+
66
+ def git_upload_pack(repo, login)
67
+ user = ::Gritano::User.find_by_login(login)
68
+ if user
69
+ Kernel.exec "git-upload-pack #{repo(repo).full_path}" if user.check_access(repo(repo), :write)
70
+ end
71
+ end
72
+
55
73
  def method_missing(meth, *args, &block)
56
74
  if meth.to_s =~ /^admin/
57
75
  user = ::Gritano::User.find_by_login(args[0][-1])
58
76
  if user.admin?
59
- meth = meth.to_s[6..-1]
60
- params = args[0][0..-2]
61
- @executor.execute([meth] + params)
77
+ admin_command(meth.to_s[6..-1], args[0][0..-2])
62
78
  else
63
79
  [false, "access denied"]
64
80
  end
65
81
  elsif meth.to_s =~ /^git-receive-pack/
66
82
  repo, login = args[0]
67
- user = ::Gritano::User.find_by_login(login)
68
- if user
69
- Kernel.exec "git-receive-pack #{repo(repo).full_path}" if user.check_access(repo(repo), :read)
70
- end
83
+ git_receive_pack(repo, login)
71
84
  elsif meth.to_s =~ /^git-upload-pack/
72
85
  repo, login = args[0]
73
- user = ::Gritano::User.find_by_login(login)
74
- if user
75
- Kernel.exec "git-upload-pack #{repo(repo).full_path}" if user.check_access(repo(repo), :write)
76
- end
86
+ git_upload_pack(repo, login)
77
87
  else
78
88
  super
79
89
  end
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module Gritano
4
+ describe CLI do
5
+ it "should execute local commands" do
6
+ console = double()
7
+ console.should_receive(:execute).and_return([true, "ok"])
8
+ Gritano::Console.should_receive(:remote_console).with(false)
9
+ Gritano::Console::Gritano.should_receive(:new).and_return(console)
10
+ CLI.execute(["user:list"])
11
+ end
12
+
13
+ it "should execute remote commands" do
14
+ console = double()
15
+ console.should_receive(:execute).and_return([true, "ok"])
16
+ Gritano::Console.should_receive(:remote_console).with(true)
17
+ Gritano::Console::Remote.should_receive(:new).and_return(console)
18
+ CLI.check(["repo:list"], "login")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,61 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module Gritano
4
+ module Console
5
+ describe Base do
6
+ def create_base(home)
7
+ stdin = double()
8
+ stdin.stub(:read).and_return("Your SSHKEY here...")
9
+ Base.new(stdin, home)
10
+ end
11
+
12
+ it "should define commands" do
13
+ Base.should_receive(:define_method).with("command_name")
14
+ Base.add_command "command:name", "parameters" do end
15
+ end
16
+
17
+ it "should execute commands" do
18
+ Base.add_command "command:name", "parameters" do end
19
+ base = create_base('.')
20
+ base.should_receive('command_name')
21
+ base.execute(['command:name'])
22
+ end
23
+
24
+ it "should show a help message" do
25
+ Base.add_command "command:name", "parameters" do end
26
+ Base.help.should == File.open("spec/data/help_command_name.txt").readlines.join.
27
+ gsub('{{VERSION}}', File.open("VERSION").readlines.join)
28
+ end
29
+
30
+ it "should check if gritano is not installed" do
31
+ FileUtils.rm_rf('tmp\.gritano')
32
+ base = create_base('tmp')
33
+ lambda { base.check_gritano }.should raise_error SystemExit
34
+ end
35
+
36
+ it "should check if gritano is installed" do
37
+ base = create_base('.')
38
+ lambda { base.check_gritano }.should_not raise_error SystemExit
39
+ end
40
+
41
+ it "should check if git is not installed" do
42
+ base = create_base('.')
43
+ base.stub(:unknown_command).and_return(true)
44
+ lambda { base.check_git }.should raise_error SystemExit
45
+ end
46
+
47
+ it "should check if git is installed" do
48
+ base = create_base('.')
49
+ base.stub(:unknown_command).and_return(false)
50
+ lambda { base.check_git }.should_not raise_error SystemExit
51
+ end
52
+
53
+ it "should check if a command exists" do
54
+ base = create_base('.')
55
+ base.unknown_command('ls').should be_false
56
+ base.unknown_command('qwertyuioplkjhgfdsa').should be_true
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,168 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ module Gritano
4
+ module Console
5
+ describe Executor do
6
+ def create_executor(home, repo_dir)
7
+ stdin = double()
8
+ stdin.stub(:read).and_return("Your SSHKEY here...")
9
+ Executor.new(stdin, home, repo_dir)
10
+ end
11
+
12
+ it "should list users" do
13
+ User.should_receive(:all).and_return([])
14
+ create_executor('.', 'tmp').execute(["user:list"])
15
+ end
16
+
17
+ it "should list users' keys" do
18
+ user = double()
19
+ user.should_receive(:keys).and_return([])
20
+ User.should_receive(:find_by_login).with("login").and_return(user)
21
+ create_executor('.', 'tmp').execute(["user:key:list", "login"])
22
+ end
23
+
24
+ it "should list users' repos" do
25
+ user = double()
26
+ user.should_receive(:repositories).and_return([])
27
+ User.should_receive(:find_by_login).with("login").and_return(user)
28
+ create_executor('.', 'tmp').execute(["user:repo:list", "login"])
29
+ end
30
+
31
+ it "should add users" do
32
+ user = double()
33
+ user.should_receive(:save).and_return(true)
34
+ User.should_receive(:new).with(login: "login").and_return(user)
35
+ create_executor('.', 'tmp').execute(["user:add", "login"])
36
+ end
37
+
38
+ it "should remove users" do
39
+ user = double()
40
+ user.should_receive(:destroy).and_return(true)
41
+ User.should_receive(:find_by_login).with("login").and_return(user)
42
+ create_executor('.', 'tmp').execute(["user:rm", "login"])
43
+ end
44
+
45
+ it "should add users' keys" do
46
+ user = double()
47
+ keys = double()
48
+ key = double()
49
+ key.should_receive(:valid?).and_return(true)
50
+ keys.should_receive(:create).with(name: "keyname", key: "Your SSHKEY here...").and_return(key)
51
+ user.should_receive(:keys).and_return(keys)
52
+ User.should_receive(:find_by_login).with("login").and_return(user)
53
+ create_executor('.', 'tmp').execute(["user:key:add", "login", "keyname"])
54
+ end
55
+
56
+ it "should remove users' keys" do
57
+ keys = double()
58
+ users = double()
59
+ limit = double()
60
+ key = double()
61
+ key.should_receive(:destroy).and_return(true)
62
+ limit.should_receive(:limit).with(1).and_return([key])
63
+ users.should_receive(:where).with("users.login" => "login").and_return(limit)
64
+ keys.should_receive(:includes).with(:user).and_return(users)
65
+ Key.should_receive(:where).with(name: "keyname").and_return(keys)
66
+ create_executor('.', 'tmp').execute(["user:key:rm", "login", "keyname"])
67
+ end
68
+
69
+ it "should add admin rights to user" do
70
+ user = double()
71
+ user.should_receive(:admin=).with(true)
72
+ user.should_receive(:save).and_return(true)
73
+ User.should_receive(:find_by_login).with("login").and_return(user)
74
+ create_executor('.', 'tmp').execute(["user:admin:add", "login"])
75
+ end
76
+
77
+ it "should remove admin rights from users" do
78
+ user = double()
79
+ user.should_receive(:admin=).with(false)
80
+ user.should_receive(:save).and_return(true)
81
+ User.should_receive(:find_by_login).with("login").and_return(user)
82
+ create_executor('.', 'tmp').execute(["user:admin:rm", "login"])
83
+ end
84
+
85
+ it "should list repos" do
86
+ Repository.should_receive(:all).and_return([])
87
+ create_executor('.', 'tmp').execute(["repo:list"])
88
+ end
89
+
90
+ it "should create repos" do
91
+ repo = double()
92
+ repo.should_receive(:save).and_return(true)
93
+ Repository.should_receive(:new).with(name: "repo.git", path: "tmp").and_return(repo)
94
+ create_executor('.', 'tmp').execute(["repo:add", "repo.git"])
95
+ end
96
+
97
+ it "should create repos and add a user" do
98
+ repo = double()
99
+ repo.should_receive(:save).and_return(true)
100
+ Repository.should_receive(:new).with(name: "repo.git", path: "tmp").and_return(repo)
101
+
102
+ user = double()
103
+ user.should_receive(:add_access).twice
104
+ User.should_receive(:find_by_login).with("login").and_return(user)
105
+
106
+ create_executor('.', 'tmp').execute(["repo:add", "repo.git", "login"])
107
+ end
108
+
109
+ it "should list repos' users" do
110
+ repo = double()
111
+ repo.should_receive(:users).and_return([])
112
+ Repository.should_receive(:find_by_name).with("repo.git").and_return(repo)
113
+ create_executor('.', 'tmp').execute(["repo:user:list", "repo.git"])
114
+ end
115
+
116
+ it "should remove repos" do
117
+ repo = double()
118
+ repo.should_receive(:destroy).and_return(true)
119
+ Repository.should_receive(:find_by_name).with("repo.git").and_return(repo)
120
+ create_executor('.', 'tmp').execute(["repo:rm", "repo.git"])
121
+ end
122
+
123
+ it "should allow user to read a repo" do
124
+ repo = double()
125
+ Repository.should_receive(:find_by_name).with("repo.git").and_return(repo)
126
+
127
+ user = double()
128
+ user.should_receive(:add_access).with(repo, :read).and_return(true)
129
+ User.should_receive(:find_by_login).with("login").and_return(user)
130
+
131
+ create_executor('.', 'tmp').execute(["repo:read:add", "repo.git", "login"])
132
+ end
133
+
134
+ it "should allow user to write to a repo" do
135
+ repo = double()
136
+ Repository.should_receive(:find_by_name).with("repo.git").and_return(repo)
137
+
138
+ user = double()
139
+ user.should_receive(:add_access).with(repo, :write).and_return(true)
140
+ User.should_receive(:find_by_login).with("login").and_return(user)
141
+
142
+ create_executor('.', 'tmp').execute(["repo:write:add", "repo.git", "login"])
143
+ end
144
+
145
+ it "should deny user to read a repo" do
146
+ repo = double()
147
+ Repository.should_receive(:find_by_name).with("repo.git").and_return(repo)
148
+
149
+ user = double()
150
+ user.should_receive(:remove_access).with(repo, :read).and_return(true)
151
+ User.should_receive(:find_by_login).with("login").and_return(user)
152
+
153
+ create_executor('.', 'tmp').execute(["repo:read:rm", "repo.git", "login"])
154
+ end
155
+
156
+ it "should deny user to write to a repo"do
157
+ repo = double()
158
+ Repository.should_receive(:find_by_name).with("repo.git").and_return(repo)
159
+
160
+ user = double()
161
+ user.should_receive(:remove_access).with(repo, :write).and_return(true)
162
+ User.should_receive(:find_by_login).with("login").and_return(user)
163
+
164
+ create_executor('.', 'tmp').execute(["repo:write:rm", "repo.git", "login"])
165
+ end
166
+ end
167
+ end
168
+ end