gritano 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +9 -17
- data/Gemfile.lock +78 -50
- data/Guardfile +9 -0
- data/README.rdoc +23 -24
- data/Rakefile +8 -12
- data/TODO +12 -8
- data/VERSION +1 -1
- data/bin/gritano +8 -1
- data/bin/gritano-remote +16 -2
- data/gritano.gemspec +52 -230
- data/lib/gritano.rb +12 -6
- data/lib/gritano/config.rb +11 -31
- data/lib/gritano/console/base.rb +6 -74
- data/lib/gritano/console/git.rb +29 -0
- data/lib/gritano/console/local.rb +131 -0
- data/lib/gritano/console/remote.rb +47 -93
- data/lib/gritano/core/key.rb +18 -0
- data/lib/gritano/core/user.rb +12 -0
- data/lib/gritano/helpers.rb +52 -0
- data/lib/gritano/renderer.rb +36 -0
- data/lib/gritano/thor.rb +27 -0
- data/spec/data/development.yml +2 -0
- data/spec/gritano/console/git_spec.rb +55 -0
- data/spec/gritano/console/local_spec.rb +148 -0
- data/spec/gritano/console/remote_spec.rb +56 -0
- data/spec/gritano/core/key_spec.rb +21 -0
- data/spec/gritano/core/user_spec.rb +43 -0
- data/spec/gritano/helpers_spec.rb +113 -0
- data/spec/gritano/thor_spec.rb +29 -0
- data/spec/spec_helper.rb +1 -16
- data/templates/local.gritano +4 -0
- data/templates/remote.gritano +5 -0
- metadata +61 -280
- data/.gritano/config.yml +0 -2
- data/.gritano/database.yml +0 -2
- data/.ssh/.gitignore +0 -4
- data/bin/gritano-pub-key +0 -15
- data/db/migrate/001_create_users.rb +0 -8
- data/db/migrate/002_create_repositories.rb +0 -9
- data/db/migrate/003_create_permissions.rb +0 -10
- data/db/migrate/004_create_keys.rb +0 -11
- data/db/migrate/005_add_admin_to_users.rb +0 -10
- data/db/migrate/006_add_email_to_users.rb +0 -10
- data/db/migrate/007_add_password_to_users.rb +0 -10
- data/db/migrate/008_remove_password_from_user.rb +0 -10
- data/db/migrate/009_remove_email_from_users.rb +0 -10
- data/features/data/config_true.yml +0 -2
- data/features/data/local_commands/repo_add_tmp_jeka_git.txt +0 -1
- data/features/data/local_commands/repo_add_tmp_p_lang_git.txt +0 -1
- data/features/data/local_commands/repo_add_tmp_p_lang_git_igorbonadio.txt +0 -1
- data/features/data/local_commands/repo_add_tmp_p_lang_git_igorbonadio_jessicaeto.txt +0 -1
- data/features/data/local_commands/repo_list.txt +0 -6
- data/features/data/local_commands/repo_read_add_tmp_gritano_git_arybonadio.txt +0 -1
- data/features/data/local_commands/repo_read_add_tmp_gritano_git_jessicaeto.txt +0 -1
- data/features/data/local_commands/repo_read_add_tmp_p_lang_git_jessicaeto.txt +0 -1
- data/features/data/local_commands/repo_read_rm_tmp_jeka_git_aribonadio.txt +0 -1
- data/features/data/local_commands/repo_read_rm_tmp_jeka_git_igorbonadio.txt +0 -1
- data/features/data/local_commands/repo_read_rm_tmp_p_lang_git_igorbonadio.txt +0 -1
- data/features/data/local_commands/repo_rm_tmp_jeka_git.txt +0 -1
- data/features/data/local_commands/repo_rm_tmp_p_lang_git.txt +0 -1
- data/features/data/local_commands/repo_user_list_tmp_jeka_git.txt +0 -6
- data/features/data/local_commands/repo_user_list_tmp_ruby_git.txt +0 -1
- data/features/data/local_commands/repo_write_add_tmp_gritano_git_arybonadio.txt +0 -1
- data/features/data/local_commands/repo_write_add_tmp_gritano_git_jessicaeto.txt +0 -1
- data/features/data/local_commands/repo_write_add_tmp_p_lang_git_jessicaeto.txt +0 -1
- data/features/data/local_commands/repo_write_rm_tmp_gritano_git_arybonadio.txt +0 -1
- data/features/data/local_commands/repo_write_rm_tmp_gritano_git_igorbonadio.txt +0 -1
- data/features/data/local_commands/repo_write_rm_tmp_p_lang_git_igorbonadio.txt +0 -1
- data/features/data/local_commands/user_add_igorbonadio.txt +0 -1
- data/features/data/local_commands/user_add_jose.txt +0 -1
- data/features/data/local_commands/user_admin_add_arybonadio.txt +0 -1
- data/features/data/local_commands/user_admin_add_igorbonadio.txt +0 -1
- data/features/data/local_commands/user_admin_rm_arybonadio.txt +0 -1
- data/features/data/local_commands/user_admin_rm_igorbonadio.txt +0 -1
- data/features/data/local_commands/user_key_add_igorbonadio_marvin.txt +0 -1
- data/features/data/local_commands/user_key_add_userrr_marvino.txt +0 -1
- data/features/data/local_commands/user_key_list_arybonadio.txt +0 -1
- data/features/data/local_commands/user_key_list_igorbonadio.txt +0 -5
- data/features/data/local_commands/user_key_rm_igorbonadio_eva.txt +0 -1
- data/features/data/local_commands/user_key_rm_igorbonadio_marvino.txt +0 -1
- data/features/data/local_commands/user_list.txt +0 -6
- data/features/data/local_commands/user_repo_list_arybonadio.txt +0 -1
- data/features/data/local_commands/user_repo_list_igorbonadio.txt +0 -6
- data/features/data/local_commands/user_rm_igorbonadio.txt +0 -1
- data/features/data/local_commands/user_rm_jose.txt +0 -1
- data/features/data/local_commands/version.txt +0 -1
- data/features/data/local_help.txt +0 -32
- data/features/data/remote_commands/admin_help_igorbonadio.txt +0 -32
- data/features/data/remote_commands/admin_help_jessicaeto.txt +0 -32
- data/features/data/remote_commands/admin_repo_add_tmp_jeka_git_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_add_tmp_jeka_git_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio_jessicaeto_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio_jessicaeto_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_list_igorbonadio.txt +0 -6
- data/features/data/remote_commands/admin_repo_list_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_read_add_tmp_gritano_git_arybonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_read_add_tmp_gritano_git_arybonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_read_add_tmp_gritano_git_jessicaeto_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_read_add_tmp_gritano_git_jessicaeto_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_read_add_tmp_p_lang_git_jessicaeto_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_read_add_tmp_p_lang_git_jessicaeto_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_read_rm_tmp_jeka_git_aribonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_read_rm_tmp_jeka_git_aribonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_read_rm_tmp_jeka_git_igorbonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_read_rm_tmp_jeka_git_igorbonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_read_rm_tmp_p_lang_git_igorbonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_read_rm_tmp_p_lang_git_igorbonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_rm_tmp_jeka_git_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_rm_tmp_jeka_git_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_rm_tmp_p_lang_git_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_rm_tmp_p_lang_git_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_user_list_tmp_jeka_git_igorbonadio.txt +0 -6
- data/features/data/remote_commands/admin_repo_user_list_tmp_jeka_git_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_user_list_tmp_ruby_git_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_user_list_tmp_ruby_git_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_write_add_tmp_gritano_git_arybonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_write_add_tmp_gritano_git_arybonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_write_add_tmp_gritano_git_jessicaeto_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_write_add_tmp_gritano_git_jessicaeto_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_write_add_tmp_p_lang_git_jessicaeto_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_write_add_tmp_p_lang_git_jessicaeto_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_write_rm_tmp_gritano_git_arybonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_write_rm_tmp_gritano_git_arybonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_write_rm_tmp_gritano_git_igorbonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_write_rm_tmp_gritano_git_igorbonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_repo_write_rm_tmp_p_lang_git_igorbonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_repo_write_rm_tmp_p_lang_git_igorbonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_add_igorbonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_user_add_igorbonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_add_jose_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_user_add_jose_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_admin_add_arybonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_user_admin_add_arybonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_admin_add_igorbonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_user_admin_add_igorbonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_admin_rm_arybonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_user_admin_rm_arybonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_admin_rm_igorbonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_user_admin_rm_igorbonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_key_add_igorbonadio_marvin_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_user_key_add_igorbonadio_marvin_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_key_add_userrr_marvino_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_user_key_add_userrr_marvino_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_key_list_arybonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_user_key_list_arybonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_key_list_igorbonadio_igorbonadio.txt +0 -5
- data/features/data/remote_commands/admin_user_key_list_igorbonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_key_rm_igorbonadio_eva_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_user_key_rm_igorbonadio_eva_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_key_rm_igorbonadio_marvino_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_user_key_rm_igorbonadio_marvino_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_list_igorbonadio.txt +0 -6
- data/features/data/remote_commands/admin_user_list_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_repo_list_arybonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_user_repo_list_arybonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_repo_list_igorbonadio_igorbonadio.txt +0 -6
- data/features/data/remote_commands/admin_user_repo_list_igorbonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_rm_igorbonadio_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_user_rm_igorbonadio_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_user_rm_jose_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_user_rm_jose_jessicaeto.txt +0 -1
- data/features/data/remote_commands/admin_version_igorbonadio.txt +0 -1
- data/features/data/remote_commands/admin_version_jessicaeto.txt +0 -1
- data/features/data/remote_commands/email_get_igorbonadio.txt +0 -1
- data/features/data/remote_commands/email_get_jessicaeto.txt +0 -1
- data/features/data/remote_commands/email_update_email@server_com_igorbonadio.txt +0 -1
- data/features/data/remote_commands/email_update_email@server_com_jessicaeto.txt +0 -1
- data/features/data/remote_commands/help_igorbonadio.txt +0 -14
- data/features/data/remote_commands/help_jessicaeto.txt +0 -14
- data/features/data/remote_commands/invalid_command_igorbonadio.txt +0 -14
- data/features/data/remote_commands/invalid_command_jessicaeto.txt +0 -14
- data/features/data/remote_commands/key_add_keyname_igorbonadio.txt +0 -1
- data/features/data/remote_commands/key_add_keyname_jessicaeto.txt +0 -1
- data/features/data/remote_commands/key_list_igorbonadio.txt +0 -5
- data/features/data/remote_commands/key_list_jessicaeto.txt +0 -5
- data/features/data/remote_commands/key_rm_hal_igorbonadio.txt +0 -1
- data/features/data/remote_commands/key_rm_hal_jessicaeto.txt +0 -1
- data/features/data/remote_commands/repo_list_igorbonadio.txt +0 -6
- data/features/data/remote_commands/repo_list_jessicaeto.txt +0 -5
- data/features/data/remote_commands/version_igorbonadio.txt +0 -1
- data/features/data/remote_commands/version_jessicaeto.txt +0 -1
- data/features/data/remote_help.txt +0 -14
- data/features/install.feature +0 -40
- data/features/local.feature +0 -80
- data/features/pub_key.feature +0 -25
- data/features/remote.feature +0 -150
- data/features/step_definitions/background_step.rb +0 -26
- data/features/step_definitions/install_step.rb +0 -30
- data/features/step_definitions/local_step.rb +0 -25
- data/features/step_definitions/pub_key_step.rb +0 -15
- data/features/step_definitions/remote_step.rb +0 -49
- data/features/support/database_cleaner.rb +0 -15
- data/features/support/env.rb +0 -30
- data/lib/gritano/cli.rb +0 -49
- data/lib/gritano/console.rb +0 -26
- data/lib/gritano/console/executor.rb +0 -298
- data/lib/gritano/console/gritano.rb +0 -35
- data/lib/gritano/console/installer.rb +0 -55
- data/lib/gritano/models.rb +0 -7
- data/lib/gritano/models/key.rb +0 -37
- data/lib/gritano/models/permission.rb +0 -39
- data/lib/gritano/models/repository.rb +0 -29
- data/lib/gritano/models/user.rb +0 -39
- data/spec/cli_spec.rb +0 -26
- data/spec/config_spec.rb +0 -64
- data/spec/console_base_spec.rb +0 -61
- data/spec/console_executor_spec.rb +0 -183
- data/spec/console_gritano_spec.rb +0 -121
- data/spec/console_installer_spec.rb +0 -28
- data/spec/console_remote_spec.rb +0 -70
- data/spec/console_spec.rb +0 -27
- data/spec/data/help_command_name.txt +0 -7
- data/spec/model_key_spec.rb +0 -44
- data/spec/model_permission_spec.rb +0 -72
- data/spec/model_repository_spec.rb +0 -56
- data/spec/model_user_spec.rb +0 -96
@@ -1,298 +0,0 @@
|
|
1
|
-
require "terminal-table"
|
2
|
-
require 'io/console'
|
3
|
-
|
4
|
-
module Gritano
|
5
|
-
module Console
|
6
|
-
class Executor < Gritano::Console::Base
|
7
|
-
|
8
|
-
def initialize(stdin = STDIN, home_dir = Etc.getpwuid.dir, repo_path = Etc.getpwuid.dir)
|
9
|
-
@stdin = stdin
|
10
|
-
@home_dir = home_dir
|
11
|
-
@repo_path = repo_path
|
12
|
-
@ssh_path = File.join(@home_dir, '.ssh')
|
13
|
-
super(@stdin, @home_dir)
|
14
|
-
end
|
15
|
-
|
16
|
-
before_each_command do
|
17
|
-
check_git
|
18
|
-
check_gritano
|
19
|
-
ActiveRecord::Base.establish_connection(
|
20
|
-
YAML::load(File.open(File.join(@home_dir, '.gritano', 'database.yml'))))
|
21
|
-
end
|
22
|
-
|
23
|
-
add_command "user:list" do |argv|
|
24
|
-
users = User.all
|
25
|
-
msg = Terminal::Table.new do |t|
|
26
|
-
t << ['user', 'admin']
|
27
|
-
t << :separator
|
28
|
-
users.each do |user|
|
29
|
-
t.add_row [user.login, user.admin]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
msg = "there is no user registered" if users.count == 0
|
33
|
-
return [true, msg]
|
34
|
-
end
|
35
|
-
|
36
|
-
add_command "user:key:list", "username" do |argv|
|
37
|
-
login, = argv
|
38
|
-
user = User.find_by_login(login)
|
39
|
-
if user
|
40
|
-
keys = user.keys
|
41
|
-
msg = Terminal::Table.new do |t|
|
42
|
-
t << ['keys']
|
43
|
-
t << :separator
|
44
|
-
keys.each do |key|
|
45
|
-
t.add_row [key.name]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
msg = "there is no key registered" if keys.count == 0
|
49
|
-
return [true, msg]
|
50
|
-
else
|
51
|
-
return [false, "User #{login} is not registered"]
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
add_command "user:repo:list", "username" do |argv|
|
56
|
-
login, = argv
|
57
|
-
user = User.find_by_login(login)
|
58
|
-
if user
|
59
|
-
repos = user.repositories
|
60
|
-
msg = Terminal::Table.new do |t|
|
61
|
-
t << ['repositories']
|
62
|
-
t << :separator
|
63
|
-
repos.each do |repo|
|
64
|
-
t.add_row [repo.name]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
msg = "there is no repository registered" if repos.count == 0
|
68
|
-
return [true, msg]
|
69
|
-
else
|
70
|
-
return [false, "User #{login} is not registered"]
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
add_command "user:add", "username [admin]*" do |argv|
|
75
|
-
login, admin = argv
|
76
|
-
if admin == 'true'
|
77
|
-
admin = true
|
78
|
-
else
|
79
|
-
admin = false
|
80
|
-
end
|
81
|
-
user = User.new(login: login, admin: admin)
|
82
|
-
return [true, "User #{login} added."] if user.save
|
83
|
-
return [false, "#{user.errors.full_messages.join(", ")}."]
|
84
|
-
end
|
85
|
-
|
86
|
-
add_command "user:rm", "username" do |argv|
|
87
|
-
login, = argv
|
88
|
-
user = User.find_by_login(login)
|
89
|
-
if user
|
90
|
-
if user.destroy
|
91
|
-
return [true, "User #{login} removed."]
|
92
|
-
end
|
93
|
-
end
|
94
|
-
return [false, "User #{login} could not be removed."]
|
95
|
-
end
|
96
|
-
|
97
|
-
add_command "user:key:add", "username keyname < key.pub" do |argv|
|
98
|
-
login, key_name, key_file = argv
|
99
|
-
|
100
|
-
if File.exist?(File.join(@home_dir, '.gritano', 'config.yml'))
|
101
|
-
Key.config = YAML::load(File.open(File.join(@home_dir, '.gritano', 'config.yml')))
|
102
|
-
end
|
103
|
-
|
104
|
-
user = User.find_by_login(login)
|
105
|
-
if user
|
106
|
-
begin
|
107
|
-
key_str = "#{@stdin.read.scan(/^ssh-(?:dss|rsa) .* /)[0][0..-2]}"
|
108
|
-
rescue
|
109
|
-
return [false, "Key could not be added."]
|
110
|
-
end
|
111
|
-
key = user.keys.create(name: key_name, key: key_str)
|
112
|
-
if key.valid?
|
113
|
-
File.open(File.join(@ssh_path, 'authorized_keys'), 'w').write(Key.authorized_keys)
|
114
|
-
return [true, "Key added successfully."]
|
115
|
-
end
|
116
|
-
end
|
117
|
-
return [false, "Key could not be added."]
|
118
|
-
end
|
119
|
-
|
120
|
-
add_command "user:key:rm", "username keyname" do |argv|
|
121
|
-
login, key_name = argv
|
122
|
-
key = Key.where(name: key_name).includes(:user).where("users.login" => login).limit(1)[0]
|
123
|
-
if key
|
124
|
-
if key.destroy
|
125
|
-
File.open(File.join(@ssh_path, 'authorized_keys'), 'w').write(Key.authorized_keys)
|
126
|
-
return [true, "Key removed successfully."]
|
127
|
-
end
|
128
|
-
end
|
129
|
-
return [false, "Key could not be removed."]
|
130
|
-
end
|
131
|
-
|
132
|
-
add_command "user:admin:add", "username" do |argv|
|
133
|
-
login, = argv
|
134
|
-
user = User.find_by_login(login)
|
135
|
-
if user
|
136
|
-
user.admin = true
|
137
|
-
if user.save
|
138
|
-
return [true, "Now, user #{login} is an administrator"]
|
139
|
-
end
|
140
|
-
end
|
141
|
-
return [false, "User #{login} could not be modified"]
|
142
|
-
end
|
143
|
-
|
144
|
-
add_command "user:admin:rm", "username" do |argv|
|
145
|
-
login, = argv
|
146
|
-
user = User.find_by_login(login)
|
147
|
-
if user
|
148
|
-
user.admin = false
|
149
|
-
if user.save
|
150
|
-
return [true, "Now, user #{login} is not an administrator"]
|
151
|
-
end
|
152
|
-
end
|
153
|
-
return [false, "User #{login} could not be modified"]
|
154
|
-
end
|
155
|
-
|
156
|
-
add_command "user:admin", "username" do |argv|
|
157
|
-
login, = argv
|
158
|
-
user = User.find_by_login(login)
|
159
|
-
if user
|
160
|
-
return [true, user.admin]
|
161
|
-
end
|
162
|
-
return [false, "User #{login} does not exist"]
|
163
|
-
end
|
164
|
-
|
165
|
-
add_command "repo:list" do |argv|
|
166
|
-
repos = Repository.all
|
167
|
-
msg = Terminal::Table.new do |t|
|
168
|
-
t << ['repositories']
|
169
|
-
t << :separator
|
170
|
-
repos.each do |repo|
|
171
|
-
t.add_row [repo.name]
|
172
|
-
end
|
173
|
-
end
|
174
|
-
msg = "there is no repository registered" if repos.count == 0
|
175
|
-
return [true, msg]
|
176
|
-
end
|
177
|
-
|
178
|
-
add_command "repo:add", "reponame.git [username1 username2 ...]*" do |argv|
|
179
|
-
name, user_login = argv
|
180
|
-
repo = Repository.new(name: name, path: @repo_path)
|
181
|
-
if repo.save
|
182
|
-
if user_login
|
183
|
-
argv[1..-1].each do |login|
|
184
|
-
user = User.find_by_login(login)
|
185
|
-
if user
|
186
|
-
user.add_access(repo, :read)
|
187
|
-
user.add_access(repo, :write)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
return [true, "Repository #{name} created successfully."]
|
192
|
-
end
|
193
|
-
return [false, "Repository #{name} could not be created."]
|
194
|
-
end
|
195
|
-
|
196
|
-
add_command "repo:user:list", "reponame.git" do |argv|
|
197
|
-
name, = argv
|
198
|
-
repo = Repository.find_by_name(name)
|
199
|
-
if repo
|
200
|
-
users = repo.users
|
201
|
-
msg = Terminal::Table.new do |t|
|
202
|
-
t << ['user', 'permission']
|
203
|
-
t << :separator
|
204
|
-
users.each do |user|
|
205
|
-
permissions = ""
|
206
|
-
user.permissions.find_by_repository_id(repo.id) do |p|
|
207
|
-
permissions += "r" if p.is(:read)
|
208
|
-
permissions += "w" if p.is(:write)
|
209
|
-
end
|
210
|
-
t.add_row [user.login, permissions]
|
211
|
-
end
|
212
|
-
end
|
213
|
-
msg = "No user have access to this repository" if users.count == 0
|
214
|
-
return [true, msg]
|
215
|
-
end
|
216
|
-
return [false, "Repository #{name} doesn't exist."]
|
217
|
-
end
|
218
|
-
|
219
|
-
add_command "repo:rm", "reponame.git" do |argv|
|
220
|
-
name, = argv
|
221
|
-
repo = Repository.find_by_name(name)
|
222
|
-
if repo
|
223
|
-
if repo.destroy
|
224
|
-
return [true, "Repository #{name} removed successfully."]
|
225
|
-
end
|
226
|
-
end
|
227
|
-
return [false, "Repository #{name} could not be removed."]
|
228
|
-
end
|
229
|
-
|
230
|
-
add_command "repo:read:add", "reponame.git username" do |argv|
|
231
|
-
repo_name, login = argv
|
232
|
-
user = User.find_by_login(login)
|
233
|
-
repo = Repository.find_by_name(repo_name)
|
234
|
-
if repo and user
|
235
|
-
return [true, "User #{login} has read access to #{repo_name}."] if user.add_access(repo, :read)
|
236
|
-
end
|
237
|
-
return [false, "An error occurred. Permissions was not modified."]
|
238
|
-
end
|
239
|
-
|
240
|
-
add_command "repo:write:add", "reponame.git username" do |argv|
|
241
|
-
repo_name, login = argv
|
242
|
-
user = User.find_by_login(login)
|
243
|
-
repo = Repository.find_by_name(repo_name)
|
244
|
-
if repo and user
|
245
|
-
return [true, "User #{login} has write access to #{repo_name}."] if user.add_access(repo, :write)
|
246
|
-
end
|
247
|
-
return [false, "An error occurred. Permissions was not modified."]
|
248
|
-
end
|
249
|
-
|
250
|
-
add_command "repo:read:rm", "reponame.git username" do |argv|
|
251
|
-
repo_name, login = argv
|
252
|
-
user = User.find_by_login(login)
|
253
|
-
repo = Repository.find_by_name(repo_name)
|
254
|
-
if repo and user
|
255
|
-
return [true, "User #{login} has not read access to #{repo_name}."] if user.remove_access(repo, :read)
|
256
|
-
end
|
257
|
-
return [false, "An error occurred. Permissions was not modified."]
|
258
|
-
end
|
259
|
-
|
260
|
-
add_command "repo:write:rm", "reponame.git username" do |argv|
|
261
|
-
repo_name, login = argv
|
262
|
-
user = User.find_by_login(login)
|
263
|
-
repo = Repository.find_by_name(repo_name)
|
264
|
-
if repo and user
|
265
|
-
return [true, "User #{login} has not write access to #{repo_name}."] if user.remove_access(repo, :write)
|
266
|
-
end
|
267
|
-
return [false, "An error occurred. Permissions was not modified."]
|
268
|
-
end
|
269
|
-
|
270
|
-
add_command "config:host_url:set", "url" do |argv|
|
271
|
-
url, = argv
|
272
|
-
config = Config.new(File.join(@home_dir, '.gritano', 'config.yml'))
|
273
|
-
config.host_url = url
|
274
|
-
config.save
|
275
|
-
return [true, "done!"]
|
276
|
-
end
|
277
|
-
|
278
|
-
add_command "config:host_url:get" do |argv|
|
279
|
-
config = Config.new(File.join(@home_dir, '.gritano', 'config.yml'))
|
280
|
-
return [true, config.host_url]
|
281
|
-
end
|
282
|
-
|
283
|
-
add_command "config:ssh_user:set", "user" do |argv|
|
284
|
-
user, = argv
|
285
|
-
config = Config.new(File.join(@home_dir, '.gritano', 'config.yml'))
|
286
|
-
config.ssh_user = user
|
287
|
-
config.save
|
288
|
-
return [true, "done!"]
|
289
|
-
end
|
290
|
-
|
291
|
-
add_command "config:ssh_user:get" do |argv|
|
292
|
-
config = Config.new(File.join(@home_dir, '.gritano', 'config.yml'))
|
293
|
-
return [true, config.ssh_user]
|
294
|
-
end
|
295
|
-
|
296
|
-
end
|
297
|
-
end
|
298
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module Gritano
|
2
|
-
module Console
|
3
|
-
class Gritano < Gritano::Console::Base
|
4
|
-
|
5
|
-
def initialize(stdin = STDIN, home_dir = Etc.getpwuid.dir, repo_path = Etc.getpwuid.dir)
|
6
|
-
@stdin = stdin
|
7
|
-
@home_dir = home_dir
|
8
|
-
@repo_path = repo_path
|
9
|
-
@ssh_path = File.join(@home_dir, '.ssh')
|
10
|
-
super(@stdin, @home_dir)
|
11
|
-
end
|
12
|
-
|
13
|
-
add_command "help" do |argv|
|
14
|
-
Gritano.commands = Gritano.commands.merge(Installer.commands).merge(Executor.commands)
|
15
|
-
[true, Gritano.help]
|
16
|
-
end
|
17
|
-
|
18
|
-
add_command "version" do |argv|
|
19
|
-
version = "v#{File.open(File.join(File.dirname(__FILE__), '..', '..', '..', 'VERSION')).readlines.join}"
|
20
|
-
[true, version]
|
21
|
-
end
|
22
|
-
|
23
|
-
def method_missing(meth, *args, &block)
|
24
|
-
params = [meth.to_s.gsub("_", ":")] + args[0]
|
25
|
-
begin
|
26
|
-
installer = Installer.new(@stdin, @home_dir)
|
27
|
-
installer.execute(params)
|
28
|
-
rescue
|
29
|
-
executor = Executor.new(@stdin, @home_dir, @repo_path)
|
30
|
-
executor.execute(params)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
module Gritano
|
2
|
-
module Console
|
3
|
-
class Installer < Gritano::Console::Base
|
4
|
-
|
5
|
-
def initialize(stdin = STDIN, home_dir = Etc.getpwuid.dir)
|
6
|
-
@home_dir = home_dir
|
7
|
-
@stdin = stdin
|
8
|
-
@ssh_path = File.join(@home_dir, '.ssh')
|
9
|
-
super(@stdin, @home_dir)
|
10
|
-
end
|
11
|
-
|
12
|
-
before_each_command do
|
13
|
-
check_git
|
14
|
-
end
|
15
|
-
|
16
|
-
def create_gritano_dirs
|
17
|
-
FileUtils.mkdir_p(File.join(@home_dir, '.gritano')) unless File.exist?(File.join(@home_dir, '.gritano'))
|
18
|
-
FileUtils.mkdir_p(File.join(@home_dir, '.ssh')) unless File.exist?(File.join(@home_dir, '.ssh'))
|
19
|
-
end
|
20
|
-
|
21
|
-
def create_sqlite_config
|
22
|
-
File.open(File.join(@home_dir, '.gritano', 'database.yml'), "w") do |f|
|
23
|
-
f.write("adapter: sqlite3\ndatabase: #{File.join(@home_dir, '.gritano', 'database.db')}\n")
|
24
|
-
end
|
25
|
-
if File.exist?(File.join(@home_dir, '.gritano', 'database.db'))
|
26
|
-
FileUtils.rm(File.join(@home_dir, '.gritano', 'database.db'))
|
27
|
-
end
|
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."]
|
34
|
-
end
|
35
|
-
|
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)
|
39
|
-
ActiveRecord::Migrator.migrate(
|
40
|
-
File.join(File.dirname(__FILE__),'..', '..', '..', 'db/migrate'),
|
41
|
-
ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
|
42
|
-
end
|
43
|
-
|
44
|
-
def create_authorization_keys
|
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
|
51
|
-
[true, "gritano has been installed"]
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
data/lib/gritano/models.rb
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
require 'active_record'
|
2
|
-
require 'grit'
|
3
|
-
|
4
|
-
require File.join(ROOT_PATH, 'gritano/models/user')
|
5
|
-
require File.join(ROOT_PATH, 'gritano/models/repository')
|
6
|
-
require File.join(ROOT_PATH, 'gritano/models/permission')
|
7
|
-
require File.join(ROOT_PATH, 'gritano/models/key')
|
data/lib/gritano/models/key.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module Gritano
|
2
|
-
class Key < ActiveRecord::Base
|
3
|
-
|
4
|
-
validates :name, :key, presence: true
|
5
|
-
validates :name, :uniqueness => { :scope => :user_id, :message => "should happen once per user" }
|
6
|
-
|
7
|
-
belongs_to :user
|
8
|
-
|
9
|
-
def self.config=(cfg)
|
10
|
-
@config = cfg
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.authorized_keys
|
14
|
-
if @config
|
15
|
-
unless @config['ssh']
|
16
|
-
return generate_authorized_keys
|
17
|
-
end
|
18
|
-
else
|
19
|
-
return generate_authorized_keys
|
20
|
-
end
|
21
|
-
return ""
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.generate_authorized_keys
|
25
|
-
authorized_keys = ""
|
26
|
-
keys = Key.find(:all)
|
27
|
-
keys.each do |k|
|
28
|
-
user_key = k.key
|
29
|
-
unless k.key[-1] == "\n"
|
30
|
-
user_key = user_key + "\n"
|
31
|
-
end
|
32
|
-
authorized_keys += "command=\"gritano-remote #{k.user.login}\" #{user_key}\n"
|
33
|
-
end
|
34
|
-
return authorized_keys
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module Gritano
|
2
|
-
class Permission < ActiveRecord::Base
|
3
|
-
belongs_to :user
|
4
|
-
belongs_to :repository
|
5
|
-
|
6
|
-
READ = 1
|
7
|
-
WRITE = 2
|
8
|
-
|
9
|
-
def add_access(access)
|
10
|
-
if access == :read
|
11
|
-
self.access = READ | (self.access || 0)
|
12
|
-
elsif access == :write
|
13
|
-
self.access = WRITE | (self.access || 0)
|
14
|
-
else
|
15
|
-
return false
|
16
|
-
end
|
17
|
-
return true
|
18
|
-
end
|
19
|
-
|
20
|
-
def remove_access(access)
|
21
|
-
if access == :read
|
22
|
-
self.access = (self.access || 0) & (~ READ)
|
23
|
-
elsif access == :write
|
24
|
-
self.access = (self.access || 0) & (~ WRITE)
|
25
|
-
else
|
26
|
-
return false
|
27
|
-
end
|
28
|
-
return true
|
29
|
-
end
|
30
|
-
|
31
|
-
def is(access)
|
32
|
-
if access == :read
|
33
|
-
return (self.access & READ) == READ
|
34
|
-
elsif access == :write
|
35
|
-
return (self.access & WRITE) == WRITE
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|