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,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
@@ -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')
@@ -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