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
data/lib/gritano.rb
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
-
|
1
|
+
root_path = File.expand_path(File.dirname(__FILE__))
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "gritano-core"
|
4
|
+
require 'terminal-table'
|
4
5
|
|
5
|
-
require File.join(
|
6
|
-
require File.join(
|
7
|
-
require File.join(
|
8
|
-
require File.join(
|
6
|
+
require File.join(root_path, 'gritano/thor')
|
7
|
+
require File.join(root_path, 'gritano/renderer')
|
8
|
+
require File.join(root_path, 'gritano/helpers')
|
9
|
+
require File.join(root_path, 'gritano/console/remote')
|
10
|
+
require File.join(root_path, 'gritano/console/local')
|
11
|
+
require File.join(root_path, 'gritano/console/git')
|
12
|
+
require File.join(root_path, 'gritano/config')
|
13
|
+
require File.join(root_path, 'gritano/core/user')
|
14
|
+
require File.join(root_path, 'gritano/core/key')
|
data/lib/gritano/config.rb
CHANGED
@@ -1,38 +1,18 @@
|
|
1
1
|
module Gritano
|
2
|
-
|
3
|
-
def
|
4
|
-
|
5
|
-
|
2
|
+
module CLI
|
3
|
+
def CLI.configure(&block)
|
4
|
+
Config.database_connection = File.open(File.join(Etc.getpwuid.dir, '.gritano/database.yml'))
|
5
|
+
Config.repository_path = File.join(Etc.getpwuid.dir)
|
6
|
+
Config.remote_ssh_prefix = 'ssh git@server.com'
|
7
|
+
yield Config
|
6
8
|
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@config = YAML::load(File.open(@config_file))
|
13
|
-
unless @config
|
14
|
-
@config = Hash.new
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def remove(parameter)
|
19
|
-
@config.delete(parameter.to_s)
|
20
|
-
end
|
21
|
-
|
22
|
-
def save
|
23
|
-
File.open(@config_file, "w") do |f|
|
24
|
-
f.write(@config.to_yaml)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def method_missing(name, *args, &block)
|
29
|
-
if name[-1] == '='
|
30
|
-
@config[name.to_s[0..-2]] = args[0]
|
31
|
-
else
|
32
|
-
if @config[name.to_s]
|
33
|
-
@config[name.to_s]
|
10
|
+
class Config
|
11
|
+
def self.method_missing(method, *args)
|
12
|
+
if /\=$/.match(method)
|
13
|
+
instance_variable_set("@#{method.to_s.gsub("=", "")}", args[0])
|
34
14
|
else
|
35
|
-
"
|
15
|
+
instance_variable_get("@#{method}")
|
36
16
|
end
|
37
17
|
end
|
38
18
|
end
|
data/lib/gritano/console/base.rb
CHANGED
@@ -1,78 +1,10 @@
|
|
1
|
-
require "terminal-table"
|
2
|
-
|
3
1
|
module Gritano
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@stdin = stdin
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.add_command(command, parameters = "", &block)
|
13
|
-
define_method(command.gsub(':', '_'), &block)
|
14
|
-
commands[command] = parameters
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.before_each_command(&block)
|
18
|
-
define_method(:before_each_command_filter, &block);
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.commands
|
22
|
-
@commands || @commands = Hash.new
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.commands=(cmds)
|
26
|
-
@commands = cmds
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.bin_name
|
30
|
-
@bin_name || "gritano "
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.bin_name=(name)
|
34
|
-
@bin_name = name
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.help
|
38
|
-
msg = " #{self.bin_name}[command]\n\n"
|
39
|
-
msg += " Examples:\n"
|
40
|
-
commands.each do |command, parameters|
|
41
|
-
msg += " #{self.bin_name}#{command} #{parameters}\n"
|
42
|
-
end
|
43
|
-
msg += "\n --\n v#{File.open(File.join(File.dirname(__FILE__), '..', '..', '..', 'VERSION')).readlines.join}"
|
44
|
-
msg
|
45
|
-
end
|
46
|
-
|
47
|
-
def execute_without_filters(argv)
|
48
|
-
send(argv[0].gsub(':', '_'), argv[1..-1])
|
49
|
-
end
|
50
|
-
|
51
|
-
def execute(argv)
|
52
|
-
send(:before_each_command_filter)
|
53
|
-
execute_without_filters(argv)
|
54
|
-
end
|
55
|
-
|
56
|
-
def check_gritano
|
57
|
-
unless File.exist?(File.join(@home_dir, '.gritano'))
|
58
|
-
puts "Error: First run 'gritano setup:prepare && gritano setup:install'"
|
59
|
-
exit
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def check_git
|
64
|
-
if unknown_command('git')
|
65
|
-
puts "Error: git must be installed on the local system"
|
66
|
-
exit
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def unknown_command(command)
|
71
|
-
`which #{command}` == ""
|
72
|
-
end
|
73
|
-
|
74
|
-
def before_each_command_filter
|
2
|
+
module CLI
|
3
|
+
module Console
|
4
|
+
class Base < Thor
|
5
|
+
include Gritano::CLI::Renderer
|
6
|
+
include Gritano::CLI::Helpers
|
75
7
|
end
|
76
8
|
end
|
77
9
|
end
|
78
|
-
end
|
10
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'base')
|
2
|
+
|
3
|
+
module Gritano
|
4
|
+
module CLI
|
5
|
+
module Console
|
6
|
+
class Git < Base
|
7
|
+
before %w{ git:receive:pack
|
8
|
+
git:upload:pack
|
9
|
+
} do
|
10
|
+
ActiveRecord::Base.establish_connection(YAML::load(Config.database_connection))
|
11
|
+
end
|
12
|
+
|
13
|
+
define_task("git:receive:pack", "") do |repo_name|
|
14
|
+
use_if_not_nil Gritano::Core::User.where(login: Config.remote_user).first do |user|
|
15
|
+
repo = Gritano::Core::Repository.where(name: repo_name.gsub("'", "")).first
|
16
|
+
Kernel.exec "git-receive-pack '#{repo.full_path}'" if user.check_access(repo, :write)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
define_task("git:upload:pack", "") do |repo_name|
|
21
|
+
use_if_not_nil Gritano::Core::User.where(login: Config.remote_user).first do |user|
|
22
|
+
repo = Gritano::Core::Repository.where(name: repo_name.gsub("'", "")).first
|
23
|
+
Kernel.exec "git-upload-pack '#{repo.full_path}'" if user.check_access(repo, :read)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'base')
|
2
|
+
|
3
|
+
module Gritano
|
4
|
+
module CLI
|
5
|
+
module Console
|
6
|
+
class Local < Base
|
7
|
+
|
8
|
+
before %w{ user:list user:add user:rm user:update
|
9
|
+
user:key:list user:key:add user:key:rm
|
10
|
+
repo:list repo:add repo:rm
|
11
|
+
repo:read:add repo:read:rm
|
12
|
+
repo:write:add repo:write:rm
|
13
|
+
repo:user:list
|
14
|
+
} do
|
15
|
+
ActiveRecord::Base.establish_connection(YAML::load(Config.database_connection)) unless ActiveRecord::Base.connected?
|
16
|
+
end
|
17
|
+
|
18
|
+
define_task("init", "create a .gritano folder in your home directory which will store gritano configuration files.") do
|
19
|
+
unless File.exist? File.join(Etc.getpwuid.dir, '.gritano')
|
20
|
+
create_gritano_dirs
|
21
|
+
create_database_config_file
|
22
|
+
create_command_scripts
|
23
|
+
render_text "config files were successfully created."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
define_task("db:migrate", "create database tables") do
|
28
|
+
Gritano::Core::Migration.migrate(YAML::load(File.open(File.join(Etc.getpwuid.dir, '.gritano/database.yml'))))
|
29
|
+
render_text "done!"
|
30
|
+
end
|
31
|
+
|
32
|
+
define_task("user:list", "list all gritano users") do
|
33
|
+
render_table(Gritano::Core::User.order(:login), :login, :admin)
|
34
|
+
end
|
35
|
+
|
36
|
+
define_task("user:add", "add a gritano user") do |login|
|
37
|
+
create_model(Gritano::Core::User, login: login)
|
38
|
+
end
|
39
|
+
|
40
|
+
define_task("user:rm", "remove a gritano user") do |login|
|
41
|
+
destroy_model(Gritano::Core::User, login: login)
|
42
|
+
end
|
43
|
+
|
44
|
+
method_option :admin, :aliases => "-a", :desc => "change admin status of a user"
|
45
|
+
define_task("user:update", "update user information") do |login|
|
46
|
+
use_if_not_nil Gritano::Core::User.where(login: login).first, valid_options?(options) do |user|
|
47
|
+
update_model(user, options)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
define_task("user:key:list", "list all user's keys") do |login|
|
52
|
+
use_if_not_nil Gritano::Core::User.where(login: login).first do |user|
|
53
|
+
render_table(user.keys.order(:name), :name)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
define_task("user:key:add", "add a user's key") do |login, key_name|
|
58
|
+
use_if_not_nil Gritano::Core::User.where(login: login).first do |user|
|
59
|
+
create_model(user.keys, name: key_name, key: $stdin.readlines.join)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
define_task("user:key:rm", "remove a user's key") do |login, key_name|
|
64
|
+
use_if_not_nil Gritano::Core::User.where(login: login).first do |user|
|
65
|
+
destroy_model(user.keys, name: key_name)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
define_task("repo:list", "list all repositories") do
|
70
|
+
render_table(Gritano::Core::Repository.order(:name), :name)
|
71
|
+
end
|
72
|
+
|
73
|
+
define_task("repo:add", "add a new repository") do |name|
|
74
|
+
create_model(Gritano::Core::Repository, name: name, path: Config.repository_path)
|
75
|
+
end
|
76
|
+
|
77
|
+
define_task("repo:rm", "remove a repository") do |name|
|
78
|
+
destroy_model(Gritano::Core::Repository, name: name)
|
79
|
+
end
|
80
|
+
|
81
|
+
define_task("repo:read:add", "add read access to a repository") do |repo_name, user_login|
|
82
|
+
use_if_not_nil Gritano::Core::User.where(login: user_login).first, Gritano::Core::Repository.where(name: repo_name).first do |user, repo|
|
83
|
+
try_change_access(user, repo, :add, :read)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
define_task("repo:read:rm", "remove read access to a repository") do |repo_name, user_login|
|
88
|
+
use_if_not_nil Gritano::Core::User.where(login: user_login).first, Gritano::Core::Repository.where(name: repo_name).first do |user, repo|
|
89
|
+
try_change_access(user, repo, :remove, :read)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
define_task("repo:write:add", "add write access to a repository") do |repo_name, user_login|
|
94
|
+
use_if_not_nil Gritano::Core::User.where(login: user_login).first, Gritano::Core::Repository.where(name: repo_name).first do |user, repo|
|
95
|
+
try_change_access(user, repo, :add, :write)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
define_task("repo:write:rm", "remove write access to a repository") do |repo_name, user_login|
|
100
|
+
use_if_not_nil Gritano::Core::User.where(login: user_login).first, Gritano::Core::Repository.where(name: repo_name).first do |user, repo|
|
101
|
+
try_change_access(user, repo, :remove, :write)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
define_task("repo:user:list", "list all user that have access to a repository") do |repo_name|
|
106
|
+
use_if_not_nil Gritano::Core::Repository.where(name: repo_name).first do |repo|
|
107
|
+
render_table(repo.users.order(:login), :login, :access => repo)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
def create_gritano_dirs
|
113
|
+
Dir.mkdir(File.join(Etc.getpwuid.dir, '.gritano')) unless File.exist? File.join(Etc.getpwuid.dir, '.gritano')
|
114
|
+
Dir.mkdir(File.join(Etc.getpwuid.dir, '.ssh')) unless File.exist? File.join(Etc.getpwuid.dir, '.ssh')
|
115
|
+
end
|
116
|
+
|
117
|
+
def create_database_config_file
|
118
|
+
File.open(File.join(Etc.getpwuid.dir, '.gritano/database.yml'), "w").write(
|
119
|
+
{'adapter' => 'sqlite3', 'database' => File.join(Etc.getpwuid.dir, '.gritano/database.sqlite3')}.to_yaml)
|
120
|
+
end
|
121
|
+
|
122
|
+
def create_command_scripts
|
123
|
+
File.open(File.join(Etc.getpwuid.dir, '.gritano/local.gritano'), "w").write(
|
124
|
+
File.open(File.join(File.dirname(__FILE__), '../../../templates/local.gritano')).readlines.join)
|
125
|
+
File.open(File.join(Etc.getpwuid.dir, '.gritano/remote.gritano'), "w").write(
|
126
|
+
File.open(File.join(File.dirname(__FILE__), '../../../templates/remote.gritano')).readlines.join)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -1,104 +1,58 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'base')
|
2
|
+
|
1
3
|
module Gritano
|
2
|
-
module
|
3
|
-
|
4
|
+
module CLI
|
5
|
+
module Console
|
6
|
+
class Remote < Base
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@repo_path = repo_path
|
9
|
-
@ssh_path = File.join(@home_dir, '.ssh')
|
10
|
-
@executor = Gritano.new(@stdin, @home_dir, @repo_path)
|
11
|
-
super(@stdin, @home_dir)
|
12
|
-
end
|
13
|
-
|
14
|
-
before_each_command do
|
15
|
-
check_git
|
16
|
-
check_gritano
|
17
|
-
ActiveRecord::Base.establish_connection(
|
18
|
-
YAML::load(File.open(File.join(@home_dir, '.gritano', 'database.yml'))))
|
19
|
-
end
|
20
|
-
|
21
|
-
add_command "version" do |argv|
|
22
|
-
version = "v#{File.open(File.join(File.dirname(__FILE__), '..', '..', '..', 'VERSION')).readlines.join}"
|
23
|
-
[true, version]
|
24
|
-
end
|
25
|
-
|
26
|
-
add_command "help" do |args|
|
27
|
-
[true, Remote.help]
|
28
|
-
end
|
8
|
+
def self.basename
|
9
|
+
Gritano::CLI::Config.remote_ssh_prefix
|
10
|
+
end
|
29
11
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
add_command "repo:list" do |args|
|
36
|
-
login, = args
|
37
|
-
@executor.execute(["user:repo:list"] + [login])
|
38
|
-
end
|
39
|
-
|
40
|
-
add_command "key:list" do |args|
|
41
|
-
login, = args
|
42
|
-
@executor.execute(["user:key:list"] + [login])
|
43
|
-
end
|
44
|
-
|
45
|
-
add_command "key:add", "keyname < key.pub" do |args|
|
46
|
-
keyname, login = args
|
47
|
-
@executor.execute(["user:key:add"] + [login, keyname])
|
48
|
-
end
|
49
|
-
|
50
|
-
add_command "key:rm", "keyname" do |args|
|
51
|
-
keyname, login = args
|
52
|
-
@executor.execute(["user:key:rm"] + [login, keyname])
|
53
|
-
end
|
54
|
-
|
55
|
-
add_command "admin:help" do |args|
|
56
|
-
gritano = Gritano.new(@stdin)
|
57
|
-
gritano.execute(["help"])
|
58
|
-
end
|
59
|
-
|
60
|
-
def admin_command(meth, params)
|
61
|
-
@executor.execute([meth] + params)
|
62
|
-
end
|
63
|
-
|
64
|
-
def git_receive_pack(repo, login)
|
65
|
-
user = ::Gritano::User.find_by_login(login)
|
66
|
-
if user
|
67
|
-
Kernel.exec "git-receive-pack #{repo(repo).full_path}" if user.check_access(repo(repo), :read)
|
12
|
+
before %w{ repo:list
|
13
|
+
key:list key:add key:rm
|
14
|
+
admin
|
15
|
+
} do
|
16
|
+
ActiveRecord::Base.establish_connection(YAML::load(Config.database_connection)) unless ActiveRecord::Base.connected?
|
68
17
|
end
|
69
|
-
end
|
70
18
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
19
|
+
define_task("repo:list", "list all repositories") do
|
20
|
+
use_if_not_nil Gritano::Core::User.where(login: Config.remote_user).first do |user|
|
21
|
+
render_table(user.repositories.order(:name), :name)
|
22
|
+
end
|
75
23
|
end
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
24
|
+
|
25
|
+
define_task("key:list", "list all your keys") do
|
26
|
+
use_if_not_nil Gritano::Core::User.where(login: Config.remote_user).first do |user|
|
27
|
+
render_table(user.keys.order(:name), :name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
define_task("key:add", "add a key") do |key_name|
|
32
|
+
use_if_not_nil Gritano::Core::User.where(login: Config.remote_user).first do |user|
|
33
|
+
create_model(user.keys, name: key_name, key: $stdin.readlines.join)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
define_task("key:rm", "remove a user's key") do |key_name|
|
38
|
+
use_if_not_nil Gritano::Core::User.where(login: Config.remote_user).first do |user|
|
39
|
+
destroy_model(user.keys, name: key_name)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
define_task("admin", "execute admin commands") do |*command|
|
44
|
+
use_if_not_nil Gritano::Core::User.where(login: Config.remote_user).first do |user|
|
45
|
+
if user.admin?
|
46
|
+
def Local.basename
|
47
|
+
"#{Remote.basename} admin"
|
48
|
+
end
|
49
|
+
Local.start(command)
|
50
|
+
else
|
51
|
+
render_text "you are not an admin!"
|
52
|
+
end
|
85
53
|
end
|
86
|
-
elsif meth.to_s =~ /^git-receive-pack/
|
87
|
-
repo, login = args[0]
|
88
|
-
git_receive_pack(repo, login)
|
89
|
-
elsif meth.to_s =~ /^git-upload-pack/
|
90
|
-
repo, login = args[0]
|
91
|
-
git_upload_pack(repo, login)
|
92
|
-
else
|
93
|
-
super
|
94
54
|
end
|
95
55
|
end
|
96
|
-
|
97
|
-
def repo(repo)
|
98
|
-
repo = repo.gsub("'", '').strip
|
99
|
-
::Gritano::Repository.find_by_name(repo)
|
100
|
-
end
|
101
|
-
|
102
56
|
end
|
103
57
|
end
|
104
|
-
end
|
58
|
+
end
|