dtk-client 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (310) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/Gemfile +1 -3
  4. data/README.md +2 -121
  5. data/Rakefile +44 -0
  6. data/bin/dtk +10 -88
  7. data/dtk-client.gemspec +21 -44
  8. data/examples/simple/dtk.module.yaml +32 -0
  9. data/{lib/git-logs/git.log → examples/simple/test/README.md} +0 -0
  10. data/examples/spark/dtk.module.yaml +120 -0
  11. data/examples/with_repo_content/deploy/puppet/manifests/hostname.pp +54 -0
  12. data/examples/with_repo_content/dtk.module.yaml +49 -0
  13. data/examples/with_repo_content/test/README.txt +0 -0
  14. data/features/dtk.feature +8 -0
  15. data/features/step_definitions/dtk_steps.rb +6 -0
  16. data/features/support/env.rb +15 -0
  17. data/lib/cli/command/mixin.rb +101 -0
  18. data/lib/cli/command/module/clone.rb +42 -0
  19. data/lib/cli/command/module/install.rb +52 -0
  20. data/lib/cli/command/module/list.rb +31 -0
  21. data/lib/cli/command/module/list_assemblies.rb +39 -0
  22. data/lib/cli/command/module/push.rb +34 -0
  23. data/lib/cli/command/module/uninstall.rb +46 -0
  24. data/lib/cli/command/module.rb +33 -0
  25. data/lib/cli/command/options.rb +33 -0
  26. data/lib/cli/command/service/cancel_task.rb +33 -0
  27. data/lib/cli/command/service/converge.rb +37 -0
  28. data/lib/{parser/adapters/thor/common_option_defs.rb → cli/command/service/create_workspace.rb} +13 -17
  29. data/lib/cli/command/service/destroy.rb +47 -0
  30. data/lib/cli/command/service/edit.rb +47 -0
  31. data/lib/cli/command/service/exec.rb +42 -0
  32. data/lib/cli/command/service/exec_sync.rb +53 -0
  33. data/lib/cli/command/service/list.rb +30 -0
  34. data/lib/cli/command/service/list_actions.rb +39 -0
  35. data/lib/cli/command/service/list_attributes.rb +44 -0
  36. data/lib/cli/command/service/list_component_links.rb +33 -0
  37. data/lib/cli/command/service/list_components.rb +39 -0
  38. data/lib/cli/command/service/list_dependent_modules.rb +33 -0
  39. data/lib/cli/command/service/list_nodes.rb +33 -0
  40. data/lib/cli/command/service/list_violations.rb +33 -0
  41. data/lib/cli/command/service/pull.rb +32 -0
  42. data/lib/cli/command/service/push.rb +37 -0
  43. data/lib/{shell/parse_monkey_patch.rb → cli/command/service/set_default_target.rb} +9 -17
  44. data/lib/cli/command/service/set_required_attributes.rb +32 -0
  45. data/lib/cli/command/service/ssh.rb +42 -0
  46. data/lib/cli/command/service/stage.rb +55 -0
  47. data/lib/cli/command/service/start.rb +33 -0
  48. data/lib/{shell/context_aux.rb → cli/command/service/stop.rb} +10 -23
  49. data/lib/cli/command/service/task_status.rb +39 -0
  50. data/lib/cli/command/service.rb +55 -0
  51. data/lib/{commands.rb → cli/command/subcommand.rb} +22 -25
  52. data/lib/{bundler_monkey_patch.rb → cli/command/token/arg.rb} +6 -6
  53. data/lib/cli/command/token/class_mixin.rb +96 -0
  54. data/lib/cli/command/token/flag.rb +42 -0
  55. data/lib/{execute/command/rest_call.rb → cli/command/token/mixin.rb} +23 -14
  56. data/lib/cli/command/token/switch.rb +35 -0
  57. data/lib/cli/command/token.rb +76 -0
  58. data/lib/cli/command.rb +46 -0
  59. data/lib/cli/context/attributes.rb +50 -0
  60. data/lib/cli/context/type/module.rb +34 -0
  61. data/lib/{commands/thor/state_change.rb → cli/context/type/service.rb} +11 -5
  62. data/lib/cli/context/type/top.rb +32 -0
  63. data/lib/cli/context/type.rb +42 -0
  64. data/lib/cli/context.rb +174 -0
  65. data/lib/cli/directory_parser/file_system.rb +105 -0
  66. data/lib/{execute/command.rb → cli/directory_parser.rb} +14 -17
  67. data/lib/{execute.rb → cli/file_obj.rb} +13 -9
  68. data/lib/cli/processor/plugin/gli.rb +70 -0
  69. data/lib/cli/processor.rb +60 -0
  70. data/lib/cli/runner/dtkn_access.rb +75 -0
  71. data/lib/cli/runner.rb +58 -0
  72. data/lib/cli/version.rb +8 -0
  73. data/lib/{config → client/config}/cacert.pem +0 -0
  74. data/lib/client/config/default.conf +20 -0
  75. data/lib/client/config.rb +106 -0
  76. data/lib/client/configurator.rb +182 -0
  77. data/lib/client/conn.rb +197 -0
  78. data/lib/client/content_generator.rb +127 -0
  79. data/lib/client/error/subclasses.rb +105 -0
  80. data/lib/client/error.rb +98 -0
  81. data/lib/client/git_repo/adapter/git_gem/error_handler.rb +70 -0
  82. data/lib/client/git_repo/adapter/git_gem.rb +179 -0
  83. data/lib/client/git_repo.rb +122 -0
  84. data/lib/client/logger.rb +136 -0
  85. data/lib/client/operation/account.rb +66 -0
  86. data/lib/client/operation/client_module_dir/git_repo.rb +286 -0
  87. data/lib/client/operation/client_module_dir.rb +138 -0
  88. data/lib/client/operation/module/clone_module.rb +52 -0
  89. data/lib/client/operation/module/install/common_module.rb +58 -0
  90. data/lib/client/operation/module/install/external_module.rb +122 -0
  91. data/lib/client/operation/module/install.rb +91 -0
  92. data/lib/client/operation/module/install_from_catalog.rb +76 -0
  93. data/lib/client/operation/module/list.rb +34 -0
  94. data/lib/client/operation/module/list_assemblies.rb +35 -0
  95. data/lib/client/operation/module/push.rb +62 -0
  96. data/lib/client/operation/module/uninstall.rb +44 -0
  97. data/lib/client/operation/module.rb +58 -0
  98. data/lib/{commands/common/thor/reparse.rb → client/operation/module_service_common.rb} +27 -16
  99. data/lib/client/operation/service/cancel_task.rb +29 -0
  100. data/lib/client/operation/service/commit_and_push.rb +128 -0
  101. data/lib/client/operation/service/converge.rb +50 -0
  102. data/lib/{util/common_util.rb → client/operation/service/create_workspace.rb} +13 -13
  103. data/lib/client/operation/service/destroy.rb +42 -0
  104. data/lib/client/operation/service/edit.rb +54 -0
  105. data/lib/client/operation/service/exec.rb +73 -0
  106. data/lib/client/operation/service/list.rb +32 -0
  107. data/lib/client/operation/service/list_actions.rb +34 -0
  108. data/lib/{commands/thor/dependency.rb → client/operation/service/list_attributes.rb} +16 -12
  109. data/lib/client/operation/service/list_component_links.rb +29 -0
  110. data/lib/{commands/common/thor/pull_clone_changes.rb → client/operation/service/list_components.rb} +13 -7
  111. data/lib/client/operation/service/list_dependent_modules.rb +29 -0
  112. data/lib/client/operation/service/list_nodes.rb +29 -0
  113. data/lib/{commands/thor/project.rb → client/operation/service/list_violations.rb} +8 -13
  114. data/lib/client/operation/service/pull.rb +37 -0
  115. data/lib/client/operation/service/set_default_target.rb +31 -0
  116. data/lib/client/operation/service/set_required_attributes.rb +41 -0
  117. data/lib/client/operation/service/ssh.rb +118 -0
  118. data/lib/client/operation/service/stage.rb +54 -0
  119. data/lib/client/operation/service/start.rb +29 -0
  120. data/lib/client/operation/service/stop.rb +30 -0
  121. data/lib/{task_status → client/operation/service/task_status}/refresh_mode.rb +15 -25
  122. data/lib/{task_status → client/operation/service/task_status}/snapshot_mode.rb +4 -5
  123. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/format.rb +1 -1
  124. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/action.rb +1 -1
  125. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/components.rb +1 -1
  126. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/node_level.rb +1 -1
  127. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result.rb +4 -4
  128. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/action.rb +1 -1
  129. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/components.rb +1 -1
  130. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/node_level.rb +1 -1
  131. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps.rb +4 -4
  132. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task.rb +3 -3
  133. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/no_results.rb +1 -1
  134. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/render.rb +1 -1
  135. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/stage/render.rb +1 -1
  136. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/stage.rb +3 -3
  137. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/task_end.rb +1 -1
  138. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/task_start.rb +1 -1
  139. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element.rb +13 -13
  140. data/lib/{task_status → client/operation/service/task_status}/stream_mode.rb +5 -9
  141. data/lib/client/operation/service/task_status.rb +77 -0
  142. data/lib/client/operation/service.rb +54 -0
  143. data/lib/client/operation.rb +67 -0
  144. data/lib/client/operation_args.rb +40 -0
  145. data/lib/{execute/execute_context/result_store.rb → client/render/view/simple.rb} +15 -14
  146. data/lib/client/render/view/table/processor.rb +248 -0
  147. data/lib/client/render/view/table.rb +75 -0
  148. data/lib/client/render.rb +113 -0
  149. data/lib/client/response/error_handler.rb +97 -0
  150. data/lib/client/response/render_helper.rb +78 -0
  151. data/lib/client/response/subclasses.rb +62 -0
  152. data/lib/client/response.rb +83 -0
  153. data/lib/client/session.rb +62 -0
  154. data/lib/client/util/auxiliary.rb +34 -0
  155. data/lib/client/util/console.rb +81 -0
  156. data/lib/client/util/disk_cacher.rb +66 -0
  157. data/lib/client/util/dtk_path.rb +28 -0
  158. data/lib/{search_hash.rb → client/util/hash_with_optional_keys.rb} +29 -21
  159. data/lib/client/util/interactive_wizard.rb +84 -0
  160. data/lib/client/util/module_ref.rb +92 -0
  161. data/lib/client/util/os_util/print.rb +121 -0
  162. data/lib/client/util/os_util.rb +122 -0
  163. data/lib/{commands/thor/utils.rb → client/util/post_body.rb} +1 -1
  164. data/lib/{execute/error_usage.rb → client/util/query_string_hash.rb} +2 -2
  165. data/lib/client/util/remote_dependency.rb +67 -0
  166. data/lib/client/util/ssh_util.rb +89 -0
  167. data/lib/client/util/validation.rb +28 -0
  168. data/lib/client/util.rb +18 -0
  169. data/lib/{util/permission_util.rb → dtk_cli.rb} +10 -9
  170. data/lib/dtk_client.rb +18 -14
  171. data/test/default_test.rb +14 -0
  172. data/test/test_helper.rb +9 -0
  173. metadata +196 -307
  174. data/Gemfile_dev +0 -13
  175. data/bin/dtk-execute +0 -32
  176. data/bin/dtk-shell +0 -31
  177. data/lib/auxiliary.rb +0 -61
  178. data/lib/client.rb +0 -58
  179. data/lib/command_helper.rb +0 -33
  180. data/lib/command_helpers/git_repo/merge.rb +0 -153
  181. data/lib/command_helpers/git_repo.rb +0 -589
  182. data/lib/command_helpers/jenkins_client/config_xml.rb +0 -288
  183. data/lib/command_helpers/jenkins_client.rb +0 -106
  184. data/lib/command_helpers/service_importer.rb +0 -251
  185. data/lib/command_helpers/service_link.rb +0 -33
  186. data/lib/command_helpers/test_module_creator.rb +0 -69
  187. data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +0 -10
  188. data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +0 -10
  189. data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +0 -5
  190. data/lib/commands/common/thor/access_control.rb +0 -133
  191. data/lib/commands/common/thor/action_result_handler.rb +0 -74
  192. data/lib/commands/common/thor/assembly_template.rb +0 -92
  193. data/lib/commands/common/thor/assembly_workspace.rb +0 -1638
  194. data/lib/commands/common/thor/base_command_helper.rb +0 -59
  195. data/lib/commands/common/thor/clone.rb +0 -82
  196. data/lib/commands/common/thor/common.rb +0 -88
  197. data/lib/commands/common/thor/common_base.rb +0 -49
  198. data/lib/commands/common/thor/create_target.rb +0 -70
  199. data/lib/commands/common/thor/edit.rb +0 -255
  200. data/lib/commands/common/thor/inventory_parser.rb +0 -98
  201. data/lib/commands/common/thor/list_diffs.rb +0 -128
  202. data/lib/commands/common/thor/module/import.rb +0 -215
  203. data/lib/commands/common/thor/module.rb +0 -1011
  204. data/lib/commands/common/thor/node.rb +0 -53
  205. data/lib/commands/common/thor/poller.rb +0 -65
  206. data/lib/commands/common/thor/pull_from_remote.rb +0 -152
  207. data/lib/commands/common/thor/puppet_forge.rb +0 -72
  208. data/lib/commands/common/thor/purge_clone.rb +0 -101
  209. data/lib/commands/common/thor/push_clone_changes.rb +0 -162
  210. data/lib/commands/common/thor/push_to_remote.rb +0 -94
  211. data/lib/commands/common/thor/remotes.rb +0 -71
  212. data/lib/commands/common/thor/set_required_attributes.rb +0 -46
  213. data/lib/commands/thor/account.rb +0 -239
  214. data/lib/commands/thor/assembly.rb +0 -361
  215. data/lib/commands/thor/attribute.rb +0 -79
  216. data/lib/commands/thor/component.rb +0 -70
  217. data/lib/commands/thor/component_module.rb +0 -501
  218. data/lib/commands/thor/component_template.rb +0 -174
  219. data/lib/commands/thor/developer.rb +0 -144
  220. data/lib/commands/thor/dtk.rb +0 -152
  221. data/lib/commands/thor/library.rb +0 -125
  222. data/lib/commands/thor/node.rb +0 -504
  223. data/lib/commands/thor/node_group.rb +0 -203
  224. data/lib/commands/thor/node_template.rb +0 -94
  225. data/lib/commands/thor/provider.rb +0 -233
  226. data/lib/commands/thor/remotes.rb +0 -49
  227. data/lib/commands/thor/service.rb +0 -932
  228. data/lib/commands/thor/service_module.rb +0 -900
  229. data/lib/commands/thor/target.rb +0 -250
  230. data/lib/commands/thor/task.rb +0 -116
  231. data/lib/commands/thor/test_module.rb +0 -310
  232. data/lib/commands/thor/workspace.rb +0 -698
  233. data/lib/config/client.conf.header +0 -20
  234. data/lib/config/configuration.rb +0 -99
  235. data/lib/config/default.conf +0 -16
  236. data/lib/config/disk_cacher.rb +0 -80
  237. data/lib/configurator.rb +0 -176
  238. data/lib/context_router.rb +0 -44
  239. data/lib/core.rb +0 -489
  240. data/lib/domain/git_adapter.rb +0 -412
  241. data/lib/domain/git_error_handler.rb +0 -64
  242. data/lib/domain/response/error_handler.rb +0 -86
  243. data/lib/domain/response.rb +0 -285
  244. data/lib/dtk-client/version.rb +0 -20
  245. data/lib/dtk_constants.rb +0 -40
  246. data/lib/dtk_error.rb +0 -114
  247. data/lib/dtk_logger.rb +0 -113
  248. data/lib/error.rb +0 -85
  249. data/lib/execute/cli_pure/cli_rerouter.rb +0 -102
  250. data/lib/execute/command/api_call/map.rb +0 -60
  251. data/lib/execute/command/api_call/service.rb +0 -91
  252. data/lib/execute/command/api_call/translation_term.rb +0 -119
  253. data/lib/execute/command/api_call.rb +0 -60
  254. data/lib/execute/command_processor/rest_call.rb +0 -59
  255. data/lib/execute/command_processor.rb +0 -30
  256. data/lib/execute/execute_context.rb +0 -86
  257. data/lib/execute/script/add_tenant.rb +0 -121
  258. data/lib/execute/script.rb +0 -64
  259. data/lib/parser/adapters/option_parser.rb +0 -70
  260. data/lib/parser/adapters/thor.rb +0 -555
  261. data/lib/require_first.rb +0 -104
  262. data/lib/shell/context.rb +0 -1064
  263. data/lib/shell/domain/active_context.rb +0 -186
  264. data/lib/shell/domain/context_entity.rb +0 -89
  265. data/lib/shell/domain/context_params.rb +0 -223
  266. data/lib/shell/domain/override_tasks.rb +0 -88
  267. data/lib/shell/domain/shadow_entity.rb +0 -76
  268. data/lib/shell/header_shell.rb +0 -44
  269. data/lib/shell/help_monkey_patch.rb +0 -283
  270. data/lib/shell/interactive_wizard.rb +0 -256
  271. data/lib/shell/message_queue.rb +0 -63
  272. data/lib/shell/status_monitor.rb +0 -124
  273. data/lib/shell.rb +0 -261
  274. data/lib/task_status.rb +0 -83
  275. data/lib/util/console.rb +0 -235
  276. data/lib/util/dtk_puppet.rb +0 -65
  277. data/lib/util/module_util.rb +0 -66
  278. data/lib/util/os_util.rb +0 -385
  279. data/lib/util/remote_dependency_util.rb +0 -84
  280. data/lib/util/ssh_util.rb +0 -94
  281. data/lib/view_processor/augmented_simple_list.rb +0 -44
  282. data/lib/view_processor/hash_pretty_print.rb +0 -123
  283. data/lib/view_processor/simple_list.rb +0 -156
  284. data/lib/view_processor/table_print.rb +0 -309
  285. data/lib/view_processor.rb +0 -129
  286. data/puppet/manifests/init.pp +0 -72
  287. data/puppet/manifests/params.pp +0 -16
  288. data/puppet/r8meta.puppet.yml +0 -35
  289. data/puppet/templates/bash_profile.erb +0 -2
  290. data/puppet/templates/client.conf.erb +0 -1
  291. data/puppet/templates/dtkclient.erb +0 -2
  292. data/spec/component_module_spec.rb +0 -34
  293. data/spec/dependency_spec.rb +0 -6
  294. data/spec/dtk_shell_spec.rb +0 -13
  295. data/spec/dtk_spec.rb +0 -33
  296. data/spec/lib/spec_helper.rb +0 -10
  297. data/spec/lib/spec_thor.rb +0 -108
  298. data/spec/node_template_spec.rb +0 -24
  299. data/spec/project_spec.rb +0 -6
  300. data/spec/repo_spec.rb +0 -7
  301. data/spec/response_spec.rb +0 -52
  302. data/spec/service_module_spec.rb +0 -38
  303. data/spec/service_spec.rb +0 -50
  304. data/spec/state_change_spec.rb +0 -7
  305. data/spec/table_print_spec.rb +0 -48
  306. data/spec/target_spec.rb +0 -57
  307. data/spec/task_spec.rb +0 -28
  308. data/views/assembly/augmented_simple_list.rb +0 -12
  309. data/views/assembly_template/augmented_simple_list.rb +0 -12
  310. data/views/list_task/augmented_simple_list.rb +0 -12
@@ -0,0 +1,66 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ class Operation
20
+ class Account < self
21
+ RoutePrefix = 'account'
22
+
23
+ # opts can have keys
24
+ # :first_registration - Booelan (default: false)
25
+ # :name - (default: 'dtk-client')
26
+ def self.add_key(path_to_key, opts = {})
27
+ match, matched_username = nil, nil
28
+
29
+ unless File.file?(path_to_key)
30
+ raise Error,"[ERROR] No ssh key file found at (#{path_to_key}). Path is wrong or it is necessary to generate the public rsa key (e.g., run `ssh-keygen -t rsa`)."
31
+ end
32
+
33
+ response = add_user_access(path_to_key, opts)
34
+
35
+ if response.ok? and !response.data(:match)
36
+ repo_manager_fingerprint, repo_manager_dns = response.data_ret_and_remove!(:repo_manager_fingerprint, :repo_manager_dns)
37
+ SSHUtil.update_ssh_known_hosts(repo_manager_dns, repo_manager_fingerprint)
38
+ OsUtil.print_info("SSH key '#{response.data('new_username')}' added successfully!")
39
+ end
40
+
41
+ response
42
+ end
43
+
44
+ private
45
+
46
+ # opts can have keys
47
+ # :first_registration - Booelan (default: false)
48
+ # :name - (default: 'dtk-client')
49
+ def self.add_user_access(path_to_key, opts = {})
50
+ first_registration = opts[:first_registration] || false
51
+ name = opts[:name] || 'dtk-client'
52
+
53
+ rsa_pub_key = SSHUtil.read_and_validate_pub_key(path_to_key)
54
+
55
+ post_body = {
56
+ :rsa_pub_key => rsa_pub_key.chomp,
57
+ :username? => name && name.chomp,
58
+ :first_registration => first_registration,
59
+ }
60
+ rest_post "#{RoutePrefix}/add_user_direct_access", PostBody.new(post_body)
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+
@@ -0,0 +1,286 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ class Operation::ClientModuleDir
20
+ # Operations for managing module folders that are git repos
21
+ class GitRepo < self
22
+ def self.commit_and_push_to_service_repo(args)
23
+ wrap_operation(args) do |args|
24
+ response_data_hash(:head_sha => Internal.commit_and_push_to_service_repo(args))
25
+ end
26
+ end
27
+
28
+ def self.clone_exists?(args)
29
+ wrap_operation(args) do |args|
30
+ type = args.required(:type)
31
+ local_dir_exists?(type, args.required("#{type}_name".to_sym))
32
+ end
33
+ end
34
+
35
+ def self.clone_service_repo(args)
36
+ wrap_operation(args) do |args|
37
+ response_data_hash(:target_repo_dir => Internal.clone_service_repo(args))
38
+ end
39
+ end
40
+
41
+ def self.clone_module_repo(args)
42
+ wrap_operation(args) do |args|
43
+ response_data_hash(:target_repo_dir => Internal.clone_module_repo(args))
44
+ end
45
+ end
46
+
47
+ def self.create_add_remote_and_push(args)
48
+ wrap_operation(args) do |args|
49
+ repo_dir = args.required(:repo_dir)
50
+ repo_url = args.required(:repo_url)
51
+ remote_branch = args.required(:remote_branch)
52
+ response_data_hash(:head_sha => Internal.create_add_remote_and_push(repo_dir, repo_url, remote_branch))
53
+ end
54
+ end
55
+
56
+ def self.create_add_remote_and_pull(args)
57
+ wrap_operation(args) do |args|
58
+ repo_dir = args.required(:repo_dir)
59
+ repo_url = args.required(:repo_url)
60
+ remote_branch = args.required(:remote_branch)
61
+ response_data_hash(:head_sha => Internal.create_add_remote_and_pull(repo_dir, repo_url, remote_branch))
62
+ end
63
+ end
64
+
65
+ def self.fetch_merge_and_push(args)
66
+ wrap_operation(args) do |args|
67
+ response_data_hash(:head_sha => Internal.fetch_merge_and_push(args))
68
+ end
69
+ end
70
+
71
+ def self.init_and_push_from_existing_repo(args)
72
+ wrap_operation(args) do |args|
73
+ repo_dir = args.required(:repo_dir)
74
+ repo_url = args.required(:repo_url)
75
+ remote_branch = args.required(:remote_branch)
76
+ response_data_hash(:head_sha => Internal.init_and_push_from_existing_repo(repo_dir, repo_url, remote_branch))
77
+ end
78
+ end
79
+
80
+ def self.pull_from_remote(args)
81
+ wrap_operation(args) do |args|
82
+ response_data_hash(:target_repo_dir => Internal.pull_from_remote(args))
83
+ end
84
+ end
85
+
86
+ def self.pull_from_service_repo(args)
87
+ wrap_operation(args) do |args|
88
+ response_data_hash(:repo => Internal.pull_from_service_repo(args))
89
+ end
90
+ end
91
+
92
+ private
93
+
94
+ def self.response_data_hash(hash)
95
+ hash.inject({}) { |h, (k, v)| h.merge(k.to_s => v) }
96
+ end
97
+
98
+ # All Internal methods do not have wrap_operation and can only be accessed by a method that wraps it
99
+ class Internal < self
100
+ # Git Params for dtk server
101
+ module Dtk_Server
102
+ GIT_REMOTE = 'dtk-server'
103
+ end
104
+ # Git params for dtkn
105
+ module Dtkn
106
+ GIT_REMOTE = 'dtkn'
107
+ LOCAL_BRANCH = 'master'
108
+ end
109
+
110
+ # returns head_sha
111
+ def self.commit_and_push_to_service_repo(args)
112
+ branch = args.required(:branch)
113
+ remote_branch = args[:remote_branch] || branch
114
+ service_instance = args.required(:service_instance)
115
+ commit_message = args[:commit_message]
116
+
117
+ repo_dir = ret_base_path(:service, service_instance)
118
+ repo = git_repo.new(repo_dir, :branch => branch)
119
+ repo.stage_and_commit
120
+ # TODO: want to switch over to using Dtk_Server::GIT_REMOTE rather than 'origin'
121
+ dtk_server_remote = 'origin'
122
+ repo.push(dtk_server_remote, remote_branch)
123
+ repo.head_commit_sha
124
+ end
125
+
126
+ def self.clone_service_repo(args)
127
+ repo_url = args.required(:repo_url)
128
+ module_ref = args.required(:module_ref)
129
+ branch = args.required(:branch)
130
+ service_instance = args.required(:service_instance)
131
+ remove_existing = args[:remove_existing]
132
+
133
+ target_repo_dir = create_service_dir(service_instance, :remove_existing => remove_existing)
134
+ begin
135
+ git_repo.clone(repo_url, target_repo_dir, branch)
136
+ rescue => e
137
+ #cleanup by deleting directory
138
+
139
+ FileUtils.rm_rf(target_repo_dir) if File.directory?(target_repo_dir)
140
+ # Log error details
141
+ Logger.instance.error_pp(e.message, e.backtrace)
142
+
143
+ # User-friendly error
144
+ raise Error::Usage, "Clone to directory '#{target_repo_dir}' failed"
145
+ end
146
+ target_repo_dir
147
+ end
148
+
149
+ def self.clone_module_repo(args)
150
+ module_type = args.required(:module_type)
151
+ repo_url = args.required(:repo_url)
152
+ branch = args.required(:branch)
153
+ module_name = args.required(:module_name)
154
+ remove_existing = args[:remove_existing]
155
+ repo_dir = args[:repo_dir]
156
+
157
+ target_repo_dir = create_module_dir(module_type, module_name, :remove_existing => remove_existing, :path => repo_dir)
158
+ begin
159
+ git_repo.clone(repo_url, target_repo_dir, branch)
160
+ rescue => e
161
+ FileUtils.rm_rf(target_repo_dir) if File.directory?(target_repo_dir)
162
+ Logger.instance.error_pp(e.message, e.backtrace)
163
+
164
+ raise Error::Usage, "Clone to directory '#{target_repo_dir}' failed"
165
+ end
166
+
167
+ target_repo_dir
168
+ end
169
+
170
+ def self.fetch_merge_and_push(args)
171
+ repo_dir = args.required(:repo_dir)
172
+ repo_url = args.required(:repo_url)
173
+ remote_branch = args.required(:branch)
174
+
175
+ head_sha =
176
+ if git_repo.is_git_repo?(repo_dir)
177
+ init_and_push_from_existing_repo(repo_dir, repo_url, remote_branch)
178
+ else
179
+ create_repo_from_remote_and_push(repo_dir, repo_url, remote_branch)
180
+ end
181
+
182
+ head_sha
183
+ end
184
+
185
+ def self.create_add_remote_and_push(repo_dir, repo_url, remote_branch)
186
+ repo = git_repo.new(repo_dir)
187
+ add_remote_and_push(repo, repo_url, remote_branch)
188
+ repo.head_commit_sha
189
+ end
190
+
191
+ def self.create_add_remote_and_pull(repo_dir, repo_url, remote_branch)
192
+ repo = create_repo_from_dtkn_remote(repo_dir, repo_url, remote_branch)
193
+ add_dtkn_remote_and_pull(repo, repo_url, remote_branch)
194
+ repo.head_commit_sha
195
+ end
196
+
197
+ def self.init_and_push_from_existing_repo(repo_dir, repo_url, remote_branch)
198
+ repo = git_repo.new(repo_dir)
199
+
200
+ if repo.is_there_remote?(Dtk_Server::GIT_REMOTE)
201
+ push_when_there_is_dtk_remote(repo, repo_dir, repo_url, remote_branch)
202
+ else
203
+ add_remote_and_push(repo, repo_url, remote_branch)
204
+ end
205
+
206
+ repo.head_commit_sha
207
+ end
208
+
209
+ def self.pull_from_remote(args)
210
+ repo_url = args.required(:repo_url)
211
+ remote_branch = args.required(:branch)
212
+ repo_dir = args.required(:repo_dir)
213
+
214
+ repo = git_repo.new(repo_dir, :branch => remote_branch)
215
+ repo.pull(repo.remotes.first, remote_branch)
216
+ end
217
+
218
+ # returns the repo
219
+ def self.pull_from_service_repo(args)
220
+ repo_url = args.required(:repo_url)
221
+ remote_branch = args.required(:branch)
222
+ service_instance = args.required(:service_instance)
223
+
224
+ repo_dir = ret_base_path(:service, service_instance)
225
+ repo = git_repo.new(repo_dir, :branch => remote_branch)
226
+
227
+ repo.pull(repo.remotes.first, remote_branch)
228
+ repo
229
+ end
230
+
231
+ def self.push_when_there_is_dtk_remote(repo, repo_dir, repo_url, remote_branch)
232
+ # if there is only one remote and it is dtk-server; remove .git and initialize and push as new repo to dtk-server remote
233
+ # else if multiple remotes and dtk-server being one of them; remove dtk-server; add new dtk-server remote and push
234
+ if repo.remotes.size == 1
235
+ git_repo.unlink_local_clone?(repo_dir)
236
+ create_repo_from_remote_and_push(repo_dir, repo_url, remote_branch)
237
+ else
238
+ repo.remove_remote(Dtk_Server::GIT_REMOTE)
239
+ add_remote_and_push(repo, repo_url, remote_branch)
240
+ end
241
+ end
242
+
243
+ def self.create_repo_from_server_remote(repo_dir, repo_url, remote_branch)
244
+ repo = git_repo.new(repo_dir, :branch => Dtkn::LOCAL_BRANCH)
245
+ repo.checkout(Dtkn::LOCAL_BRANCH, :new_branch => true)
246
+ repo.add_remote(Dtk_Server::GIT_REMOTE, repo_url)
247
+ repo
248
+ end
249
+
250
+ def self.create_repo_from_dtkn_remote(repo_dir, repo_url, remote_branch)
251
+ repo = git_repo.new(repo_dir, :branch => Dtkn::LOCAL_BRANCH)
252
+ repo.checkout(Dtkn::LOCAL_BRANCH, :new_branch => true)
253
+ repo.stage_and_commit
254
+ repo.add_remote(Dtkn::GIT_REMOTE, repo_url)
255
+ repo
256
+ end
257
+
258
+ def self.create_repo_from_remote_and_push(repo_dir, repo_url, remote_branch)
259
+ repo = create_repo_from_server_remote(repo_dir, repo_url, remote_branch)
260
+ # repo = git_repo.new(repo_dir, :branch => Dtkn::LOCAL_BRANCH)
261
+ # repo.checkout(Dtkn::LOCAL_BRANCH, :new_branch => true)
262
+ # repo.add_remote(Dtk_Server::GIT_REMOTE, repo_url)
263
+ repo.stage_and_commit
264
+ repo.push(Dtk_Server::GIT_REMOTE, remote_branch, { :force => true })
265
+ repo.head_commit_sha
266
+ end
267
+
268
+ def self.add_remote_and_push(repo, repo_url, remote_branch)
269
+ repo.add_remote(Dtk_Server::GIT_REMOTE, repo_url)
270
+ repo.stage_and_commit
271
+ repo.push(Dtk_Server::GIT_REMOTE, remote_branch, { :force => true })
272
+ end
273
+
274
+ def self.add_dtkn_remote_and_pull(repo, repo_url, remote_branch)
275
+ repo.add_remote(Dtkn::GIT_REMOTE, repo_url)
276
+ repo.pull(Dtkn::GIT_REMOTE, remote_branch)
277
+ end
278
+
279
+ def self.git_repo
280
+ ::DTK::Client::GitRepo
281
+ end
282
+ end
283
+ end
284
+ end
285
+ end
286
+
@@ -0,0 +1,138 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ require 'fileutils'
19
+
20
+ module DTK::Client
21
+ class Operation
22
+ # Operations for managing module folders
23
+ class ClientModuleDir < self
24
+ require_relative('client_module_dir/git_repo')
25
+
26
+ NAMESPACE_SEPERATOR = ':'
27
+ # opts can have keys
28
+ # :backup_if_exist - Boolean (default: false)
29
+ # :remove_existing - Boolean (default: false)
30
+ def self.create_service_dir(service_instance, opts = {})
31
+ path = "#{base_path(:service)}/#{service_instance}"
32
+ if File.exists?(path)
33
+ if opts[:remove_existing]
34
+ FileUtils.rm_rf(path)
35
+ else
36
+ # TODO: put back in after referenced methods are ported over
37
+ # if local copy of module exists then move that module to backups location
38
+ # if opts[:backup_if_exist]
39
+ # backup_dir = backup_dir(type, module_ref)
40
+ # FileUtils.mv(target_repo_dir, backup_dir)
41
+ # OsUtil.print_warning("Backup of existing module directory moved to '#{backup_dir}'")
42
+ # else
43
+ # raise Error::Usage, "Directory '#{path}' is not empty; it must be deleted or removed before retrying the command"
44
+ #end
45
+ raise Error::Usage, "Directory '#{path}' is not empty; it must be deleted or removed before retrying the command"
46
+ end
47
+ end
48
+ FileUtils.mkdir_p(path)
49
+ path
50
+ end
51
+
52
+ def self.create_module_dir(module_type, module_name, opts = {})
53
+ path = opts[:path]
54
+
55
+ unless path
56
+ base_module_path = base_path(module_type)
57
+
58
+ path_parts =
59
+ if (module_name.match(/(.*)#{NAMESPACE_SEPERATOR}(.*)/))
60
+ [base_module_path, "#{$1}", "#{$2}"]
61
+ else
62
+ [base_module_path, "#{module_name}"]
63
+ end
64
+
65
+ path = path_parts.compact.join('/')
66
+ end
67
+
68
+ if File.exists?(path)
69
+ if opts[:remove_existing]
70
+ FileUtils.rm_rf(path)
71
+ else
72
+ raise Error::Usage, "Directory '#{path}' is not empty; it must be deleted or removed before retrying the command" unless (Dir.entries(path) - %w{ . .. }).empty?
73
+ return path
74
+ end
75
+ end
76
+
77
+ FileUtils.mkdir_p(path)
78
+ path
79
+ end
80
+
81
+ def self.create_module_dir_from_path(path, opts = {})
82
+ if File.exists?(path)
83
+ if opts[:remove_existing]
84
+ FileUtils.rm_rf(path)
85
+ else
86
+ raise Error::Usage, "Directory '#{path}' is not empty; it must be deleted or removed before retrying the command" unless (Dir.entries(path) - %w{ . .. }).empty?
87
+ return path
88
+ end
89
+ end
90
+
91
+ FileUtils.mkdir_p(path)
92
+ path
93
+ end
94
+
95
+ def self.local_dir_exists?(type, name, opts = {})
96
+ File.exists?("#{base_path(type)}/#{name}")
97
+ end
98
+
99
+ def self.ret_base_path(type, name)
100
+ "#{base_path(type)}/#{name}"
101
+ end
102
+
103
+ def self.ret_path_with_current_dir(name)
104
+ "#{OsUtil.current_dir}/#{name.gsub(':','/')}"
105
+ end
106
+
107
+ def self.purge_service_instance_dir(dir_path)
108
+ FileUtils.rm_rf(dir_path)
109
+ end
110
+
111
+ def self.delete_directory_content(path)
112
+ FileUtils.rm_rf(Dir.glob("#{path}/*"))
113
+ end
114
+
115
+ def self.create_file_with_content(file_path, content)
116
+ File.open(file_path, 'w') { |f| f << content }
117
+ end
118
+
119
+ private
120
+
121
+ def self.base_path(type)
122
+ path =
123
+ case type.to_sym
124
+ when :service_module then Config[:service_location]
125
+ when :component_module then Config[:module_location]
126
+ when :service then Config[:instance_location]
127
+ else raise Error, "Unexpected type (#{type}) when determining base path"
128
+ end
129
+
130
+ # see if path is relative or not
131
+ final_path = path && path.start_with?('/') ? path : "#{OsUtil.dtk_local_folder}/#{path}"
132
+ # remove last slash if set in configuration by mistake
133
+ final_path.gsub(/\/$/,'')
134
+ end
135
+ end
136
+ end
137
+ end
138
+
@@ -0,0 +1,52 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ class Operation::Module
20
+ class CloneModule < self
21
+ def self.execute(args = Args.new)
22
+ wrap_operation(args) do |args|
23
+ module_ref = args.required(:module_ref)
24
+ module_name = args.required(:module_name)
25
+ target_directory = args[:target_directory]
26
+
27
+ unless module_info = module_exists?(module_ref, :type => :common_module)
28
+ raise Error::Usage, "DTK module '#{module_ref.print_form}' does not exist on server."
29
+ end
30
+
31
+ branch = module_info.required(:branch, :name)
32
+ repo_url = module_info.required(:repo, :url)
33
+ repo_name = module_info.required(:repo, :name)
34
+
35
+ clone_args = {
36
+ :module_type => :common_module,
37
+ :repo_url => module_info.required(:repo, :url),
38
+ :branch => module_info.required(:branch, :name),
39
+ :module_name => module_name,
40
+ :repo_dir => target_directory || ClientModuleDir.ret_path_with_current_dir(module_name)
41
+ # :remove_existing => remove_existing
42
+ }
43
+
44
+ ret = ClientModuleDir::GitRepo.clone_module_repo(clone_args)
45
+ OsUtil.print_info("DTK module '#{module_ref.print_form}' has been successfully cloned into '#{ret.required(:target_repo_dir)}'")
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+
@@ -0,0 +1,58 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ class Operation::Module::Install
20
+ class CommonModule < self
21
+ BaseRoute = 'modules'
22
+
23
+ def self.install(module_ref, file_obj)
24
+ post_body = PostBody.new(
25
+ :module_name => module_ref.module_name,
26
+ :namespace => module_ref.namespace,
27
+ :version? => module_ref.version
28
+ )
29
+
30
+ response = rest_post("#{BaseRoute}/create_empty_module", post_body)
31
+
32
+ branch = response.required(:branch, :name)
33
+ repo_url = response.required(:repo, :url)
34
+ repo_name = response.required(:repo, :name)
35
+
36
+ # making repo dir to be directory that directly holds the base file object file_obj
37
+ repo_dir = file_obj.parent_dir
38
+
39
+ args = {
40
+ :repo_dir => repo_dir,
41
+ :repo_url => repo_url,
42
+ :branch => branch
43
+ }
44
+
45
+ git_response = ClientModuleDir::GitRepo.fetch_merge_and_push(args)
46
+
47
+ post_body.merge!(
48
+ :repo_name => repo_name,
49
+ :commit_sha => git_response.data(:head_sha)
50
+ )
51
+
52
+ rest_post("#{BaseRoute}/update_from_repo", post_body)
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+