gritano 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. data/Gemfile +9 -17
  2. data/Gemfile.lock +78 -50
  3. data/Guardfile +9 -0
  4. data/README.rdoc +23 -24
  5. data/Rakefile +8 -12
  6. data/TODO +12 -8
  7. data/VERSION +1 -1
  8. data/bin/gritano +8 -1
  9. data/bin/gritano-remote +16 -2
  10. data/gritano.gemspec +52 -230
  11. data/lib/gritano.rb +12 -6
  12. data/lib/gritano/config.rb +11 -31
  13. data/lib/gritano/console/base.rb +6 -74
  14. data/lib/gritano/console/git.rb +29 -0
  15. data/lib/gritano/console/local.rb +131 -0
  16. data/lib/gritano/console/remote.rb +47 -93
  17. data/lib/gritano/core/key.rb +18 -0
  18. data/lib/gritano/core/user.rb +12 -0
  19. data/lib/gritano/helpers.rb +52 -0
  20. data/lib/gritano/renderer.rb +36 -0
  21. data/lib/gritano/thor.rb +27 -0
  22. data/spec/data/development.yml +2 -0
  23. data/spec/gritano/console/git_spec.rb +55 -0
  24. data/spec/gritano/console/local_spec.rb +148 -0
  25. data/spec/gritano/console/remote_spec.rb +56 -0
  26. data/spec/gritano/core/key_spec.rb +21 -0
  27. data/spec/gritano/core/user_spec.rb +43 -0
  28. data/spec/gritano/helpers_spec.rb +113 -0
  29. data/spec/gritano/thor_spec.rb +29 -0
  30. data/spec/spec_helper.rb +1 -16
  31. data/templates/local.gritano +4 -0
  32. data/templates/remote.gritano +5 -0
  33. metadata +61 -280
  34. data/.gritano/config.yml +0 -2
  35. data/.gritano/database.yml +0 -2
  36. data/.ssh/.gitignore +0 -4
  37. data/bin/gritano-pub-key +0 -15
  38. data/db/migrate/001_create_users.rb +0 -8
  39. data/db/migrate/002_create_repositories.rb +0 -9
  40. data/db/migrate/003_create_permissions.rb +0 -10
  41. data/db/migrate/004_create_keys.rb +0 -11
  42. data/db/migrate/005_add_admin_to_users.rb +0 -10
  43. data/db/migrate/006_add_email_to_users.rb +0 -10
  44. data/db/migrate/007_add_password_to_users.rb +0 -10
  45. data/db/migrate/008_remove_password_from_user.rb +0 -10
  46. data/db/migrate/009_remove_email_from_users.rb +0 -10
  47. data/features/data/config_true.yml +0 -2
  48. data/features/data/local_commands/repo_add_tmp_jeka_git.txt +0 -1
  49. data/features/data/local_commands/repo_add_tmp_p_lang_git.txt +0 -1
  50. data/features/data/local_commands/repo_add_tmp_p_lang_git_igorbonadio.txt +0 -1
  51. data/features/data/local_commands/repo_add_tmp_p_lang_git_igorbonadio_jessicaeto.txt +0 -1
  52. data/features/data/local_commands/repo_list.txt +0 -6
  53. data/features/data/local_commands/repo_read_add_tmp_gritano_git_arybonadio.txt +0 -1
  54. data/features/data/local_commands/repo_read_add_tmp_gritano_git_jessicaeto.txt +0 -1
  55. data/features/data/local_commands/repo_read_add_tmp_p_lang_git_jessicaeto.txt +0 -1
  56. data/features/data/local_commands/repo_read_rm_tmp_jeka_git_aribonadio.txt +0 -1
  57. data/features/data/local_commands/repo_read_rm_tmp_jeka_git_igorbonadio.txt +0 -1
  58. data/features/data/local_commands/repo_read_rm_tmp_p_lang_git_igorbonadio.txt +0 -1
  59. data/features/data/local_commands/repo_rm_tmp_jeka_git.txt +0 -1
  60. data/features/data/local_commands/repo_rm_tmp_p_lang_git.txt +0 -1
  61. data/features/data/local_commands/repo_user_list_tmp_jeka_git.txt +0 -6
  62. data/features/data/local_commands/repo_user_list_tmp_ruby_git.txt +0 -1
  63. data/features/data/local_commands/repo_write_add_tmp_gritano_git_arybonadio.txt +0 -1
  64. data/features/data/local_commands/repo_write_add_tmp_gritano_git_jessicaeto.txt +0 -1
  65. data/features/data/local_commands/repo_write_add_tmp_p_lang_git_jessicaeto.txt +0 -1
  66. data/features/data/local_commands/repo_write_rm_tmp_gritano_git_arybonadio.txt +0 -1
  67. data/features/data/local_commands/repo_write_rm_tmp_gritano_git_igorbonadio.txt +0 -1
  68. data/features/data/local_commands/repo_write_rm_tmp_p_lang_git_igorbonadio.txt +0 -1
  69. data/features/data/local_commands/user_add_igorbonadio.txt +0 -1
  70. data/features/data/local_commands/user_add_jose.txt +0 -1
  71. data/features/data/local_commands/user_admin_add_arybonadio.txt +0 -1
  72. data/features/data/local_commands/user_admin_add_igorbonadio.txt +0 -1
  73. data/features/data/local_commands/user_admin_rm_arybonadio.txt +0 -1
  74. data/features/data/local_commands/user_admin_rm_igorbonadio.txt +0 -1
  75. data/features/data/local_commands/user_key_add_igorbonadio_marvin.txt +0 -1
  76. data/features/data/local_commands/user_key_add_userrr_marvino.txt +0 -1
  77. data/features/data/local_commands/user_key_list_arybonadio.txt +0 -1
  78. data/features/data/local_commands/user_key_list_igorbonadio.txt +0 -5
  79. data/features/data/local_commands/user_key_rm_igorbonadio_eva.txt +0 -1
  80. data/features/data/local_commands/user_key_rm_igorbonadio_marvino.txt +0 -1
  81. data/features/data/local_commands/user_list.txt +0 -6
  82. data/features/data/local_commands/user_repo_list_arybonadio.txt +0 -1
  83. data/features/data/local_commands/user_repo_list_igorbonadio.txt +0 -6
  84. data/features/data/local_commands/user_rm_igorbonadio.txt +0 -1
  85. data/features/data/local_commands/user_rm_jose.txt +0 -1
  86. data/features/data/local_commands/version.txt +0 -1
  87. data/features/data/local_help.txt +0 -32
  88. data/features/data/remote_commands/admin_help_igorbonadio.txt +0 -32
  89. data/features/data/remote_commands/admin_help_jessicaeto.txt +0 -32
  90. data/features/data/remote_commands/admin_repo_add_tmp_jeka_git_igorbonadio.txt +0 -1
  91. data/features/data/remote_commands/admin_repo_add_tmp_jeka_git_jessicaeto.txt +0 -1
  92. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio.txt +0 -1
  93. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio_igorbonadio.txt +0 -1
  94. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio_jessicaeto.txt +0 -1
  95. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio_jessicaeto_igorbonadio.txt +0 -1
  96. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_igorbonadio_jessicaeto_jessicaeto.txt +0 -1
  97. data/features/data/remote_commands/admin_repo_add_tmp_p_lang_git_jessicaeto.txt +0 -1
  98. data/features/data/remote_commands/admin_repo_list_igorbonadio.txt +0 -6
  99. data/features/data/remote_commands/admin_repo_list_jessicaeto.txt +0 -1
  100. data/features/data/remote_commands/admin_repo_read_add_tmp_gritano_git_arybonadio_igorbonadio.txt +0 -1
  101. data/features/data/remote_commands/admin_repo_read_add_tmp_gritano_git_arybonadio_jessicaeto.txt +0 -1
  102. data/features/data/remote_commands/admin_repo_read_add_tmp_gritano_git_jessicaeto_igorbonadio.txt +0 -1
  103. data/features/data/remote_commands/admin_repo_read_add_tmp_gritano_git_jessicaeto_jessicaeto.txt +0 -1
  104. data/features/data/remote_commands/admin_repo_read_add_tmp_p_lang_git_jessicaeto_igorbonadio.txt +0 -1
  105. data/features/data/remote_commands/admin_repo_read_add_tmp_p_lang_git_jessicaeto_jessicaeto.txt +0 -1
  106. data/features/data/remote_commands/admin_repo_read_rm_tmp_jeka_git_aribonadio_igorbonadio.txt +0 -1
  107. data/features/data/remote_commands/admin_repo_read_rm_tmp_jeka_git_aribonadio_jessicaeto.txt +0 -1
  108. data/features/data/remote_commands/admin_repo_read_rm_tmp_jeka_git_igorbonadio_igorbonadio.txt +0 -1
  109. data/features/data/remote_commands/admin_repo_read_rm_tmp_jeka_git_igorbonadio_jessicaeto.txt +0 -1
  110. data/features/data/remote_commands/admin_repo_read_rm_tmp_p_lang_git_igorbonadio_igorbonadio.txt +0 -1
  111. data/features/data/remote_commands/admin_repo_read_rm_tmp_p_lang_git_igorbonadio_jessicaeto.txt +0 -1
  112. data/features/data/remote_commands/admin_repo_rm_tmp_jeka_git_igorbonadio.txt +0 -1
  113. data/features/data/remote_commands/admin_repo_rm_tmp_jeka_git_jessicaeto.txt +0 -1
  114. data/features/data/remote_commands/admin_repo_rm_tmp_p_lang_git_igorbonadio.txt +0 -1
  115. data/features/data/remote_commands/admin_repo_rm_tmp_p_lang_git_jessicaeto.txt +0 -1
  116. data/features/data/remote_commands/admin_repo_user_list_tmp_jeka_git_igorbonadio.txt +0 -6
  117. data/features/data/remote_commands/admin_repo_user_list_tmp_jeka_git_jessicaeto.txt +0 -1
  118. data/features/data/remote_commands/admin_repo_user_list_tmp_ruby_git_igorbonadio.txt +0 -1
  119. data/features/data/remote_commands/admin_repo_user_list_tmp_ruby_git_jessicaeto.txt +0 -1
  120. data/features/data/remote_commands/admin_repo_write_add_tmp_gritano_git_arybonadio_igorbonadio.txt +0 -1
  121. data/features/data/remote_commands/admin_repo_write_add_tmp_gritano_git_arybonadio_jessicaeto.txt +0 -1
  122. data/features/data/remote_commands/admin_repo_write_add_tmp_gritano_git_jessicaeto_igorbonadio.txt +0 -1
  123. data/features/data/remote_commands/admin_repo_write_add_tmp_gritano_git_jessicaeto_jessicaeto.txt +0 -1
  124. data/features/data/remote_commands/admin_repo_write_add_tmp_p_lang_git_jessicaeto_igorbonadio.txt +0 -1
  125. data/features/data/remote_commands/admin_repo_write_add_tmp_p_lang_git_jessicaeto_jessicaeto.txt +0 -1
  126. data/features/data/remote_commands/admin_repo_write_rm_tmp_gritano_git_arybonadio_igorbonadio.txt +0 -1
  127. data/features/data/remote_commands/admin_repo_write_rm_tmp_gritano_git_arybonadio_jessicaeto.txt +0 -1
  128. data/features/data/remote_commands/admin_repo_write_rm_tmp_gritano_git_igorbonadio_igorbonadio.txt +0 -1
  129. data/features/data/remote_commands/admin_repo_write_rm_tmp_gritano_git_igorbonadio_jessicaeto.txt +0 -1
  130. data/features/data/remote_commands/admin_repo_write_rm_tmp_p_lang_git_igorbonadio_igorbonadio.txt +0 -1
  131. data/features/data/remote_commands/admin_repo_write_rm_tmp_p_lang_git_igorbonadio_jessicaeto.txt +0 -1
  132. data/features/data/remote_commands/admin_user_add_igorbonadio_igorbonadio.txt +0 -1
  133. data/features/data/remote_commands/admin_user_add_igorbonadio_jessicaeto.txt +0 -1
  134. data/features/data/remote_commands/admin_user_add_jose_igorbonadio.txt +0 -1
  135. data/features/data/remote_commands/admin_user_add_jose_jessicaeto.txt +0 -1
  136. data/features/data/remote_commands/admin_user_admin_add_arybonadio_igorbonadio.txt +0 -1
  137. data/features/data/remote_commands/admin_user_admin_add_arybonadio_jessicaeto.txt +0 -1
  138. data/features/data/remote_commands/admin_user_admin_add_igorbonadio_igorbonadio.txt +0 -1
  139. data/features/data/remote_commands/admin_user_admin_add_igorbonadio_jessicaeto.txt +0 -1
  140. data/features/data/remote_commands/admin_user_admin_rm_arybonadio_igorbonadio.txt +0 -1
  141. data/features/data/remote_commands/admin_user_admin_rm_arybonadio_jessicaeto.txt +0 -1
  142. data/features/data/remote_commands/admin_user_admin_rm_igorbonadio_igorbonadio.txt +0 -1
  143. data/features/data/remote_commands/admin_user_admin_rm_igorbonadio_jessicaeto.txt +0 -1
  144. data/features/data/remote_commands/admin_user_key_add_igorbonadio_marvin_igorbonadio.txt +0 -1
  145. data/features/data/remote_commands/admin_user_key_add_igorbonadio_marvin_jessicaeto.txt +0 -1
  146. data/features/data/remote_commands/admin_user_key_add_userrr_marvino_igorbonadio.txt +0 -1
  147. data/features/data/remote_commands/admin_user_key_add_userrr_marvino_jessicaeto.txt +0 -1
  148. data/features/data/remote_commands/admin_user_key_list_arybonadio_igorbonadio.txt +0 -1
  149. data/features/data/remote_commands/admin_user_key_list_arybonadio_jessicaeto.txt +0 -1
  150. data/features/data/remote_commands/admin_user_key_list_igorbonadio_igorbonadio.txt +0 -5
  151. data/features/data/remote_commands/admin_user_key_list_igorbonadio_jessicaeto.txt +0 -1
  152. data/features/data/remote_commands/admin_user_key_rm_igorbonadio_eva_igorbonadio.txt +0 -1
  153. data/features/data/remote_commands/admin_user_key_rm_igorbonadio_eva_jessicaeto.txt +0 -1
  154. data/features/data/remote_commands/admin_user_key_rm_igorbonadio_marvino_igorbonadio.txt +0 -1
  155. data/features/data/remote_commands/admin_user_key_rm_igorbonadio_marvino_jessicaeto.txt +0 -1
  156. data/features/data/remote_commands/admin_user_list_igorbonadio.txt +0 -6
  157. data/features/data/remote_commands/admin_user_list_jessicaeto.txt +0 -1
  158. data/features/data/remote_commands/admin_user_repo_list_arybonadio_igorbonadio.txt +0 -1
  159. data/features/data/remote_commands/admin_user_repo_list_arybonadio_jessicaeto.txt +0 -1
  160. data/features/data/remote_commands/admin_user_repo_list_igorbonadio_igorbonadio.txt +0 -6
  161. data/features/data/remote_commands/admin_user_repo_list_igorbonadio_jessicaeto.txt +0 -1
  162. data/features/data/remote_commands/admin_user_rm_igorbonadio_igorbonadio.txt +0 -1
  163. data/features/data/remote_commands/admin_user_rm_igorbonadio_jessicaeto.txt +0 -1
  164. data/features/data/remote_commands/admin_user_rm_jose_igorbonadio.txt +0 -1
  165. data/features/data/remote_commands/admin_user_rm_jose_jessicaeto.txt +0 -1
  166. data/features/data/remote_commands/admin_version_igorbonadio.txt +0 -1
  167. data/features/data/remote_commands/admin_version_jessicaeto.txt +0 -1
  168. data/features/data/remote_commands/email_get_igorbonadio.txt +0 -1
  169. data/features/data/remote_commands/email_get_jessicaeto.txt +0 -1
  170. data/features/data/remote_commands/email_update_email@server_com_igorbonadio.txt +0 -1
  171. data/features/data/remote_commands/email_update_email@server_com_jessicaeto.txt +0 -1
  172. data/features/data/remote_commands/help_igorbonadio.txt +0 -14
  173. data/features/data/remote_commands/help_jessicaeto.txt +0 -14
  174. data/features/data/remote_commands/invalid_command_igorbonadio.txt +0 -14
  175. data/features/data/remote_commands/invalid_command_jessicaeto.txt +0 -14
  176. data/features/data/remote_commands/key_add_keyname_igorbonadio.txt +0 -1
  177. data/features/data/remote_commands/key_add_keyname_jessicaeto.txt +0 -1
  178. data/features/data/remote_commands/key_list_igorbonadio.txt +0 -5
  179. data/features/data/remote_commands/key_list_jessicaeto.txt +0 -5
  180. data/features/data/remote_commands/key_rm_hal_igorbonadio.txt +0 -1
  181. data/features/data/remote_commands/key_rm_hal_jessicaeto.txt +0 -1
  182. data/features/data/remote_commands/repo_list_igorbonadio.txt +0 -6
  183. data/features/data/remote_commands/repo_list_jessicaeto.txt +0 -5
  184. data/features/data/remote_commands/version_igorbonadio.txt +0 -1
  185. data/features/data/remote_commands/version_jessicaeto.txt +0 -1
  186. data/features/data/remote_help.txt +0 -14
  187. data/features/install.feature +0 -40
  188. data/features/local.feature +0 -80
  189. data/features/pub_key.feature +0 -25
  190. data/features/remote.feature +0 -150
  191. data/features/step_definitions/background_step.rb +0 -26
  192. data/features/step_definitions/install_step.rb +0 -30
  193. data/features/step_definitions/local_step.rb +0 -25
  194. data/features/step_definitions/pub_key_step.rb +0 -15
  195. data/features/step_definitions/remote_step.rb +0 -49
  196. data/features/support/database_cleaner.rb +0 -15
  197. data/features/support/env.rb +0 -30
  198. data/lib/gritano/cli.rb +0 -49
  199. data/lib/gritano/console.rb +0 -26
  200. data/lib/gritano/console/executor.rb +0 -298
  201. data/lib/gritano/console/gritano.rb +0 -35
  202. data/lib/gritano/console/installer.rb +0 -55
  203. data/lib/gritano/models.rb +0 -7
  204. data/lib/gritano/models/key.rb +0 -37
  205. data/lib/gritano/models/permission.rb +0 -39
  206. data/lib/gritano/models/repository.rb +0 -29
  207. data/lib/gritano/models/user.rb +0 -39
  208. data/spec/cli_spec.rb +0 -26
  209. data/spec/config_spec.rb +0 -64
  210. data/spec/console_base_spec.rb +0 -61
  211. data/spec/console_executor_spec.rb +0 -183
  212. data/spec/console_gritano_spec.rb +0 -121
  213. data/spec/console_installer_spec.rb +0 -28
  214. data/spec/console_remote_spec.rb +0 -70
  215. data/spec/console_spec.rb +0 -27
  216. data/spec/data/help_command_name.txt +0 -7
  217. data/spec/model_key_spec.rb +0 -44
  218. data/spec/model_permission_spec.rb +0 -72
  219. data/spec/model_repository_spec.rb +0 -56
  220. data/spec/model_user_spec.rb +0 -96
@@ -1,8 +1,14 @@
1
- ROOT_PATH = File.expand_path(File.dirname(__FILE__))
1
+ root_path = File.expand_path(File.dirname(__FILE__))
2
2
 
3
- require "fileutils"
3
+ require "gritano-core"
4
+ require 'terminal-table'
4
5
 
5
- require File.join(ROOT_PATH, '/gritano/models')
6
- require File.join(ROOT_PATH, '/gritano/console')
7
- require File.join(ROOT_PATH, '/gritano/cli')
8
- require File.join(ROOT_PATH, '/gritano/config')
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')
@@ -1,38 +1,18 @@
1
1
  module Gritano
2
- class Config
3
- def initialize(config_file)
4
- @config_file = config_file
5
- load
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
- def load
9
- unless File.exist?(@config_file)
10
- File.open(@config_file, "w").close
11
- end
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
- "undefined"
15
+ instance_variable_get("@#{method}")
36
16
  end
37
17
  end
38
18
  end
@@ -1,78 +1,10 @@
1
- require "terminal-table"
2
-
3
1
  module Gritano
4
- module Console
5
- class Base
6
-
7
- def initialize(stdin = STDIN, home_dir = Etc.getpwuid.dir)
8
- @home_dir = home_dir
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 Console
3
- class Remote < Base
4
+ module CLI
5
+ module Console
6
+ class Remote < Base
4
7
 
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
- @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
- add_command "username" do |args|
31
- login, = args
32
- [true, login]
33
- end
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
- def git_upload_pack(repo, login)
72
- user = ::Gritano::User.find_by_login(login)
73
- if user
74
- Kernel.exec "git-upload-pack #{repo(repo).full_path}" if user.check_access(repo(repo), :write)
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
- end
77
-
78
- def method_missing(meth, *args, &block)
79
- if meth.to_s =~ /^admin/
80
- user = ::Gritano::User.find_by_login(args[0][-1])
81
- if user.admin?
82
- admin_command(meth.to_s[6..-1], args[0][0..-2])
83
- else
84
- [false, "access denied"]
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