dtk-shell 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +5 -0
  3. data/Gemfile_dev +13 -0
  4. data/README.md +121 -0
  5. data/bin/dtk-execute +32 -0
  6. data/bin/dtk-run +92 -0
  7. data/bin/dtk-shell +31 -0
  8. data/dtk-shell.gemspec +50 -0
  9. data/lib/auxiliary.rb +61 -0
  10. data/lib/bundler_monkey_patch.rb +26 -0
  11. data/lib/client.rb +58 -0
  12. data/lib/command_helper.rb +33 -0
  13. data/lib/command_helpers/git_repo.rb +589 -0
  14. data/lib/command_helpers/git_repo/merge.rb +153 -0
  15. data/lib/command_helpers/jenkins_client.rb +106 -0
  16. data/lib/command_helpers/jenkins_client/config_xml.rb +288 -0
  17. data/lib/command_helpers/service_importer.rb +251 -0
  18. data/lib/command_helpers/service_link.rb +33 -0
  19. data/lib/command_helpers/test_module_creator.rb +69 -0
  20. data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +10 -0
  21. data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +10 -0
  22. data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +5 -0
  23. data/lib/commands.rb +57 -0
  24. data/lib/commands/common/thor/access_control.rb +133 -0
  25. data/lib/commands/common/thor/action_result_handler.rb +74 -0
  26. data/lib/commands/common/thor/assembly_template.rb +92 -0
  27. data/lib/commands/common/thor/assembly_workspace.rb +1801 -0
  28. data/lib/commands/common/thor/base_command_helper.rb +59 -0
  29. data/lib/commands/common/thor/clone.rb +82 -0
  30. data/lib/commands/common/thor/common.rb +88 -0
  31. data/lib/commands/common/thor/common_base.rb +49 -0
  32. data/lib/commands/common/thor/create_target.rb +70 -0
  33. data/lib/commands/common/thor/edit.rb +255 -0
  34. data/lib/commands/common/thor/inventory_parser.rb +98 -0
  35. data/lib/commands/common/thor/list_diffs.rb +128 -0
  36. data/lib/commands/common/thor/module.rb +1011 -0
  37. data/lib/commands/common/thor/module/import.rb +210 -0
  38. data/lib/commands/common/thor/node.rb +53 -0
  39. data/lib/commands/common/thor/poller.rb +65 -0
  40. data/lib/commands/common/thor/pull_clone_changes.rb +28 -0
  41. data/lib/commands/common/thor/pull_from_remote.rb +152 -0
  42. data/lib/commands/common/thor/puppet_forge.rb +72 -0
  43. data/lib/commands/common/thor/purge_clone.rb +101 -0
  44. data/lib/commands/common/thor/push_clone_changes.rb +162 -0
  45. data/lib/commands/common/thor/push_to_remote.rb +94 -0
  46. data/lib/commands/common/thor/remotes.rb +71 -0
  47. data/lib/commands/common/thor/reparse.rb +40 -0
  48. data/lib/commands/common/thor/set_required_attributes.rb +46 -0
  49. data/lib/commands/thor/account.rb +239 -0
  50. data/lib/commands/thor/assembly.rb +356 -0
  51. data/lib/commands/thor/attribute.rb +79 -0
  52. data/lib/commands/thor/component.rb +70 -0
  53. data/lib/commands/thor/component_module.rb +501 -0
  54. data/lib/commands/thor/component_template.rb +174 -0
  55. data/lib/commands/thor/dependency.rb +34 -0
  56. data/lib/commands/thor/developer.rb +144 -0
  57. data/lib/commands/thor/dtk.rb +152 -0
  58. data/lib/commands/thor/library.rb +125 -0
  59. data/lib/commands/thor/node.rb +504 -0
  60. data/lib/commands/thor/node_template.rb +94 -0
  61. data/lib/commands/thor/project.rb +34 -0
  62. data/lib/commands/thor/provider.rb +233 -0
  63. data/lib/commands/thor/remotes.rb +49 -0
  64. data/lib/commands/thor/service.rb +941 -0
  65. data/lib/commands/thor/service_module.rb +914 -0
  66. data/lib/commands/thor/state_change.rb +25 -0
  67. data/lib/commands/thor/target.rb +250 -0
  68. data/lib/commands/thor/task.rb +116 -0
  69. data/lib/commands/thor/test_module.rb +310 -0
  70. data/lib/commands/thor/utils.rb +21 -0
  71. data/lib/commands/thor/workspace.rb +685 -0
  72. data/lib/config/cacert.pem +3785 -0
  73. data/lib/config/client.conf.header +20 -0
  74. data/lib/config/configuration.rb +99 -0
  75. data/lib/config/default.conf +16 -0
  76. data/lib/config/disk_cacher.rb +80 -0
  77. data/lib/configurator.rb +176 -0
  78. data/lib/context_router.rb +44 -0
  79. data/lib/core.rb +497 -0
  80. data/lib/domain/git_adapter.rb +412 -0
  81. data/lib/domain/git_error_handler.rb +64 -0
  82. data/lib/domain/response.rb +285 -0
  83. data/lib/domain/response/error_handler.rb +86 -0
  84. data/lib/dtk-shell/version.rb +20 -0
  85. data/lib/dtk_constants.rb +40 -0
  86. data/lib/dtk_error.rb +114 -0
  87. data/lib/dtk_logger.rb +126 -0
  88. data/lib/dtk_shell.rb +31 -0
  89. data/lib/error.rb +85 -0
  90. data/lib/execute.rb +29 -0
  91. data/lib/execute/cli_pure/cli_rerouter.rb +102 -0
  92. data/lib/execute/command.rb +40 -0
  93. data/lib/execute/command/api_call.rb +60 -0
  94. data/lib/execute/command/api_call/map.rb +60 -0
  95. data/lib/execute/command/api_call/service.rb +91 -0
  96. data/lib/execute/command/api_call/translation_term.rb +119 -0
  97. data/lib/execute/command/rest_call.rb +37 -0
  98. data/lib/execute/command_processor.rb +30 -0
  99. data/lib/execute/command_processor/rest_call.rb +59 -0
  100. data/lib/execute/error_usage.rb +21 -0
  101. data/lib/execute/execute_context.rb +86 -0
  102. data/lib/execute/execute_context/result_store.rb +37 -0
  103. data/lib/execute/script.rb +64 -0
  104. data/lib/execute/script/add_tenant.rb +121 -0
  105. data/lib/git-logs/git.log +0 -0
  106. data/lib/parser/adapters/option_parser.rb +70 -0
  107. data/lib/parser/adapters/thor.rb +555 -0
  108. data/lib/parser/adapters/thor/common_option_defs.rb +40 -0
  109. data/lib/require_first.rb +104 -0
  110. data/lib/search_hash.rb +44 -0
  111. data/lib/shell.rb +261 -0
  112. data/lib/shell/context.rb +1065 -0
  113. data/lib/shell/context_aux.rb +46 -0
  114. data/lib/shell/domain/active_context.rb +186 -0
  115. data/lib/shell/domain/context_entity.rb +89 -0
  116. data/lib/shell/domain/context_params.rb +223 -0
  117. data/lib/shell/domain/override_tasks.rb +88 -0
  118. data/lib/shell/domain/shadow_entity.rb +76 -0
  119. data/lib/shell/header_shell.rb +44 -0
  120. data/lib/shell/help_monkey_patch.rb +283 -0
  121. data/lib/shell/interactive_wizard.rb +225 -0
  122. data/lib/shell/message_queue.rb +63 -0
  123. data/lib/shell/parse_monkey_patch.rb +39 -0
  124. data/lib/shell/status_monitor.rb +124 -0
  125. data/lib/task_status.rb +83 -0
  126. data/lib/task_status/refresh_mode.rb +77 -0
  127. data/lib/task_status/snapshot_mode.rb +28 -0
  128. data/lib/task_status/stream_mode.rb +48 -0
  129. data/lib/task_status/stream_mode/element.rb +101 -0
  130. data/lib/task_status/stream_mode/element/format.rb +101 -0
  131. data/lib/task_status/stream_mode/element/hierarchical_task.rb +100 -0
  132. data/lib/task_status/stream_mode/element/hierarchical_task/result.rb +72 -0
  133. data/lib/task_status/stream_mode/element/hierarchical_task/result/action.rb +93 -0
  134. data/lib/task_status/stream_mode/element/hierarchical_task/result/components.rb +26 -0
  135. data/lib/task_status/stream_mode/element/hierarchical_task/result/node_level.rb +26 -0
  136. data/lib/task_status/stream_mode/element/hierarchical_task/steps.rb +34 -0
  137. data/lib/task_status/stream_mode/element/hierarchical_task/steps/action.rb +53 -0
  138. data/lib/task_status/stream_mode/element/hierarchical_task/steps/components.rb +53 -0
  139. data/lib/task_status/stream_mode/element/hierarchical_task/steps/node_level.rb +42 -0
  140. data/lib/task_status/stream_mode/element/no_results.rb +26 -0
  141. data/lib/task_status/stream_mode/element/render.rb +59 -0
  142. data/lib/task_status/stream_mode/element/stage.rb +84 -0
  143. data/lib/task_status/stream_mode/element/stage/render.rb +76 -0
  144. data/lib/task_status/stream_mode/element/task_end.rb +35 -0
  145. data/lib/task_status/stream_mode/element/task_start.rb +37 -0
  146. data/lib/util/common_util.rb +37 -0
  147. data/lib/util/console.rb +235 -0
  148. data/lib/util/dtk_puppet.rb +65 -0
  149. data/lib/util/module_util.rb +66 -0
  150. data/lib/util/os_util.rb +385 -0
  151. data/lib/util/permission_util.rb +31 -0
  152. data/lib/util/remote_dependency_util.rb +84 -0
  153. data/lib/util/ssh_util.rb +94 -0
  154. data/lib/view_processor.rb +129 -0
  155. data/lib/view_processor/augmented_simple_list.rb +44 -0
  156. data/lib/view_processor/hash_pretty_print.rb +123 -0
  157. data/lib/view_processor/simple_list.rb +156 -0
  158. data/lib/view_processor/table_print.rb +309 -0
  159. data/lib/violation.rb +86 -0
  160. data/lib/violation/attribute.rb +76 -0
  161. data/lib/violation/fix.rb +26 -0
  162. data/lib/violation/fix/result.rb +73 -0
  163. data/lib/violation/fix/result/error.rb +34 -0
  164. data/lib/violation/fix/set_attribute.rb +41 -0
  165. data/lib/violation/sub_classes.rb +60 -0
  166. data/puppet/manifests/init.pp +72 -0
  167. data/puppet/manifests/params.pp +16 -0
  168. data/puppet/r8meta.puppet.yml +35 -0
  169. data/puppet/templates/bash_profile.erb +2 -0
  170. data/puppet/templates/client.conf.erb +1 -0
  171. data/puppet/templates/dtkclient.erb +2 -0
  172. data/spec/component_module_spec.rb +34 -0
  173. data/spec/dependency_spec.rb +6 -0
  174. data/spec/dtk_shell_spec.rb +13 -0
  175. data/spec/dtk_spec.rb +33 -0
  176. data/spec/lib/spec_helper.rb +10 -0
  177. data/spec/lib/spec_thor.rb +108 -0
  178. data/spec/node_template_spec.rb +24 -0
  179. data/spec/project_spec.rb +6 -0
  180. data/spec/repo_spec.rb +7 -0
  181. data/spec/response_spec.rb +52 -0
  182. data/spec/service_module_spec.rb +38 -0
  183. data/spec/service_spec.rb +50 -0
  184. data/spec/state_change_spec.rb +7 -0
  185. data/spec/table_print_spec.rb +48 -0
  186. data/spec/target_spec.rb +57 -0
  187. data/spec/task_spec.rb +28 -0
  188. data/views/assembly/augmented_simple_list.rb +12 -0
  189. data/views/assembly_template/augmented_simple_list.rb +12 -0
  190. data/views/list_task/augmented_simple_list.rb +12 -0
  191. metadata +421 -0
@@ -0,0 +1,79 @@
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
+
19
+ module DTK::Client
20
+ class Attribute < CommandBaseThor
21
+
22
+ no_tasks do
23
+
24
+ def self.assembly_validation_list(context_params)
25
+ assembly_or_worspace_id, node_id, component_id = context_params.retrieve_arguments([[:service_id!, :workspace_id!], :node_id!, :component_id!])
26
+
27
+ post_body = {
28
+ :assembly_id => assembly_or_worspace_id,
29
+ :node_id => node_id,
30
+ :component_id => component_id,
31
+ :subtype => 'instance',
32
+ :about => 'attributes',
33
+ :filter => nil
34
+ }
35
+
36
+ response = get_cached_response(:service_node_component_attribute, "assembly/info_about", post_body)
37
+ modified_response = response.clone_me()
38
+
39
+ modified_response['data'].each { |e| e['display_name'] = e['display_name'].split('/').last }
40
+
41
+ return modified_response
42
+ end
43
+
44
+ def self.module_validation_list(context_params)
45
+ component_module_id = context_params.retrieve_arguments([:module_id!])
46
+
47
+ post_body = {
48
+ :component_module_id => component_module_id,
49
+ :about => :attributes
50
+ }
51
+ response = post rest_url("component_module/info_about"), post_body
52
+
53
+ modified_response = response.clone_me()
54
+ modified_response['data'].each { |e| e['display_name'] = e['display_name'].split('/').last }
55
+ #modified_response['data'].each { |e| e['display_name'] = e['display_name'].match(/.+\[.+::(.*)\]/)[1] }
56
+
57
+ return modified_response
58
+ end
59
+
60
+ end
61
+
62
+ def self.validation_list(context_params)
63
+ command_name = context_params.root_command_name
64
+
65
+ case command_name
66
+ when 'service'
67
+ return assembly_validation_list(context_params)
68
+ when 'workspace'
69
+ return assembly_validation_list(context_params)
70
+ when 'module'
71
+ return module_validation_list(context_params)
72
+ else
73
+ raise DTK::Client::DtkError,"Attribute 'validation_list' not supported for #{command_name}, implementation nedeed."
74
+ end
75
+ end
76
+
77
+
78
+ end
79
+ end
@@ -0,0 +1,70 @@
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 Component < CommandBaseThor
20
+
21
+ def self.valid_children()
22
+ # [:attribute]
23
+ []
24
+ end
25
+
26
+ def self.valid_child?(name_of_sub_context)
27
+ return Component.valid_children().include?(name_of_sub_context.to_sym)
28
+ end
29
+
30
+ def self.validation_list(context_params)
31
+ if context_params.is_there_identifier?("component-module")
32
+ component_module_id = context_params.retrieve_arguments([:component_module_id!])
33
+ res = get_cached_response(:component_template, "component_module/info_about", { :component_module_id => component_module_id, :about => :components})
34
+ else
35
+ assembly_or_worspace_id, node_id, node_name = context_params.retrieve_arguments([[:service_id, :workspace_id], :node_id!, :node_name!])
36
+
37
+ post_body = {
38
+ :assembly_id => assembly_or_worspace_id,
39
+ :node_id => node_id,
40
+ :subtype => 'instance',
41
+ :about => 'components',
42
+ :filter => nil
43
+ }
44
+
45
+ if assembly_or_worspace_id
46
+ response = get_cached_response(:service_node_component, "assembly/info_about", post_body)
47
+ else
48
+ response = get_cached_response(:node_component, "node/info_about", post_body)
49
+ end
50
+
51
+ modified_response = response.clone_me()
52
+ modified_response['data'].each { |e| e['display_name'] = e['display_name'].split('/').last }
53
+
54
+ return modified_response
55
+ end
56
+ end
57
+
58
+ desc "SERVICE-NAME/ID set ATTRIBUTE-PATTERN VALUE", "Set target component attributes"
59
+ def set(context_params)
60
+ assembly_id, node_id, component_id, pattern, value = context_params.retrieve_arguments([:service_id, :node_id, :component_id, :option_1,:option_2],method_argument_names)
61
+ post_body = {
62
+ :assembly_id => assembly_id,
63
+ :pattern => pattern,
64
+ :value => value
65
+ }
66
+ post rest_url("assembly/set_attributes"), post_body
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,501 @@
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
+ dtk_require_common_commands('thor/module')
19
+ require 'fileutils'
20
+
21
+ module DTK::Client
22
+ class ComponentModule < CommandBaseThor
23
+
24
+ no_tasks do
25
+ include ModuleMixin
26
+ end
27
+
28
+ def self.valid_children()
29
+ [:component, :remotes]
30
+ end
31
+
32
+ # this includes children of children - has to be sorted by n-level access
33
+ def self.all_children()
34
+ [:component]
35
+ end
36
+
37
+ def self.multi_context_children()
38
+ [[:component], [:remotes], [:component, :remotes]]
39
+ end
40
+
41
+ def self.valid_child?(name_of_sub_context)
42
+ return ComponentModule.valid_children().include?(name_of_sub_context.to_sym)
43
+ end
44
+
45
+ def self.validation_list(context_params)
46
+ get_cached_response(:component_module, "component_module/list", {})
47
+ end
48
+
49
+ def self.override_allowed_methods()
50
+ return DTK::Shell::OverrideTasks.new(
51
+ {
52
+ :command_only => {
53
+ :self => [
54
+ ["list"," list [--remote] [--diff] [-n NAMESPACE]","# List loaded or remote component modules. Use --diff to compare loaded and remote component modules."]
55
+ ],
56
+ :component => [
57
+ ["list","list","# List all component templates."],
58
+ ["list-attributes","list-attributes", "# List all attributes for given component."]
59
+ ],
60
+ :remotes => [
61
+ ["push-remote", "push-remote [REMOTE-NAME] [--force]", "# Push local changes to remote git repository"],
62
+ ["list-remotes", "list-remotes", "# List git remotes for given module"],
63
+ ["add-remote", "add-remote REMOTE-NAME REMOTE-URL", "# Add git remote for given module"],
64
+ ["remove-remote", "remove-remote REPO-NAME [-y]", "# Remove git remote for given module"]
65
+ ]
66
+ },
67
+ :identifier_only => {
68
+ :component => [
69
+ ["list-attributes","list-attributes", "# List all attributes for given component."]
70
+ ]
71
+ }
72
+
73
+ })
74
+ end
75
+
76
+ def self.whoami()
77
+ return :component_module, "component_module/list", nil
78
+ end
79
+
80
+ desc "delete-version COMPONENT-MODULE-NAME [-y] [-p] [-v VERSION]", "Delete component module version and all items contained in it. Optional parameter [-p] is to delete local directory."
81
+ method_option :force, :aliases => '-y', :type => :boolean, :default => false
82
+ method_option :purge, :aliases => '-p', :type => :boolean, :default => false
83
+ version_method_option
84
+ def delete_version(context_params, method_opts = {})
85
+ response = delete_module_aux(context_params, method_opts)
86
+ @@invalidate_map << :component_module if response && response.ok?
87
+
88
+ response
89
+ end
90
+
91
+ desc "delete COMPONENT-MODULE-NAME [-y] [-p]", "Delete component module and all items contained in it. Optional parameter [-p] is to delete local directory."
92
+ method_option :force, :aliases => '-y', :type => :boolean, :default => false
93
+ method_option :purge, :aliases => '-p', :type => :boolean, :default => false
94
+ # version_method_option
95
+ def delete(context_params, method_opts = {})
96
+ response = delete_module_aux(context_params, method_opts.merge!(:delete_all => true))
97
+ @@invalidate_map << :component_module if response && response.ok?
98
+
99
+ response
100
+ end
101
+
102
+ desc "COMPONENT-MODULE-NAME/ID set-attribute ATTRIBUTE-ID VALUE", "Set value of component module attributes"
103
+ def set_attribute(context_params)
104
+ set_attribute_module_aux(context_params)
105
+ end
106
+
107
+ desc "list [--remote] [--diffs] [-n NAMESPACE]", "List loaded or remote component modules. Use --diff to compare loaded and remote component modules."
108
+ method_option :remote, :type => :boolean, :default => false
109
+ method_option :diffs, :type => :boolean, :default => false, :aliases => "--diff"
110
+ method_option :namespace, :aliases => "-n" ,
111
+ :type => :string,
112
+ :banner => "NAMESPACE",
113
+ :desc => "List modules only in specific namespace."
114
+ # method_option :with_versions, :type => :boolean, :default => false, :aliases => "with-versions"
115
+ def list(context_params)
116
+ return module_info_about(context_params, :components, :component) if context_params.is_there_command?(:"component")
117
+
118
+ forwarded_remote = context_params.get_forwarded_options()["remote"] if context_params.get_forwarded_options()
119
+ remote = options.remote? || forwarded_remote
120
+ action = (remote ? "list_remote" : "list")
121
+
122
+ post_body = (remote ? { :rsa_pub_key => SSHUtil.rsa_pub_key_content() } : {:detail_to_include => ["remotes"]})
123
+ post_body[:diff] = options.diffs? ? options.diffs : {}
124
+
125
+ if post_body[:detail_to_include]
126
+ post_body[:detail_to_include] << 'versions' # if options.with_versions?
127
+ else
128
+ post_body[:detail_to_include]
129
+ end
130
+
131
+ post_body.merge!(:module_namespace => options.namespace) if options.namespace
132
+
133
+ response = post rest_url("component_module/#{action}"), post_body
134
+
135
+ return response unless response.ok?
136
+
137
+ if options.with_versions?
138
+ response.render_table(:module_with_versions, true)
139
+ else
140
+ response.render_table()
141
+ end
142
+ end
143
+
144
+ desc "COMPONENT-MODULE-NAME/ID list-components", "List all components for given component module."
145
+ def list_components(context_params)
146
+ module_info_about(context_params, :components, :component)
147
+ end
148
+
149
+ desc "COMPONENT-MODULE-NAME/ID list-attributes", "List all attributes for given component module."
150
+ def list_attributes(context_params)
151
+ module_info_about(context_params, :attributes, :attribute_without_link)
152
+ end
153
+
154
+ desc "COMPONENT-MODULE-NAME/ID list-instances", "List all instances for given component module."
155
+ def list_instances(context_params)
156
+ module_info_about(context_params, :instances, :component_instances)
157
+ end
158
+
159
+ desc "COMPONENT-MODULE-NAME/ID list-versions","List all versions associated with this component module."
160
+ def list_versions(context_params)
161
+ response = list_versions_aux(context_params)
162
+ return response unless response.ok?
163
+ response.render_table(:list_versions, true)
164
+ end
165
+
166
+ desc "COMPONENT-MODULE-NAME/ID list-remote-versions","List all remote versions associated with this component module."
167
+ def list_remote_versions(context_params)
168
+ response = list_remote_versions_aux(context_params)
169
+ return response unless response.ok?
170
+ response.render_table(:list_versions, true)
171
+ end
172
+
173
+ desc "import [NAMESPACE:]COMPONENT-MODULE-NAME", "Create new component module from local clone"
174
+ def import(context_params)
175
+ response = import_module_aux(context_params)
176
+ @@invalidate_map << :component_module
177
+ response
178
+ end
179
+
180
+ desc "import-puppet-forge PUPPET-MODULE-NAME [[NAMESPACE:]COMPONENT-MODULE-NAME]", "Install puppet module from puppet forge"
181
+ def import_puppet_forge(context_params)
182
+ pf_module_name, full_module_name = context_params.retrieve_arguments([:option_1!, :option_2],method_argument_names)
183
+ namespace, module_name = get_namespace_and_name(full_module_name, ModuleUtil::NAMESPACE_SEPERATOR)
184
+ module_type = get_module_type(context_params)
185
+
186
+ OsUtil.print('Retrieving puppet module metadata, please wait ...')
187
+ response = puppet_forge_install_aux(context_params, pf_module_name, module_name, namespace, nil, module_type)
188
+
189
+ @@invalidate_map << :component_module
190
+ response
191
+ end
192
+
193
+ #
194
+ # Creates component module from input git repo, removing .git dir to rid of pointing to user github, and creates component module
195
+ #
196
+ method_option :branch, :aliases => '-b'
197
+ desc "import-git GIT-SSH-REPO-URL [NAMESPACE:]COMPONENT-MODULE-NAME [-b BRANCH/TAG]", "Create new local component module by importing from provided git repo URL"
198
+ def import_git(context_params)
199
+ response = import_git_module_aux(context_params)
200
+ @@invalidate_map << :component_module
201
+ response
202
+ end
203
+
204
+ =begin
205
+ # desc "COMPONENT-MODULE-NAME/ID validate-model [-v VERSION]", "Check the DSL model for errors"
206
+ # version_method_option
207
+ desc "COMPONENT-MODULE-NAME/ID validate-model", "Check the DSL model for errors"
208
+ def validate_model(context_params)
209
+ module_id, module_name = context_params.retrieve_arguments([:component_module_id!, :component_module_name],method_argument_names)
210
+ version = options["version"]
211
+
212
+ if module_name.to_s =~ /^[0-9]+$/
213
+ module_id = module_name
214
+ module_name = get_module_name(module_id)
215
+ end
216
+
217
+ modules_path = OsUtil.component_clone_location()
218
+ module_location = "#{modules_path}/#{module_name}#{version && "-#{version}"}"
219
+
220
+ raise DTK::Client::DtkValidationError, "Unable to parse module '#{module_name}#{version && "-#{version}"}' that doesn't exist on your local machine!" unless File.directory?(module_location)
221
+
222
+ reparse_aux(module_location)
223
+ end
224
+ =end
225
+
226
+ # TODO: put in back support for:desc "import REMOTE-MODULE[,...] [LIBRARY-NAME/ID]", "Import remote component module(s) into library"
227
+ # TODO: put in doc REMOTE-MODULE havs namespace and optionally version information; e.g. r8/hdp or r8/hdp/v1.1
228
+ # if multiple items and failire; stops on first failure
229
+ # desc "install [NAMESPACE/]REMOTE-COMPONENT-MODULE-NAME [-r DTK-REPO-MANAGER]","Install remote component module into local environment"
230
+ desc "install NAMESPACE/REMOTE-COMPONENT-MODULE-NAME [-v VERSION]","Install remote component module into local environment"
231
+ method_option "repo-manager",:aliases => "-r" ,
232
+ :type => :string,
233
+ :banner => "REPO-MANAGER",
234
+ :desc => "DTK Repo Manager from which to resolve requested module."
235
+ version_method_option
236
+ def install(context_params)
237
+ response = install_module_aux(context_params)
238
+ if response && response.ok?
239
+ @@invalidate_map << :component_module
240
+ # TODO: hack before clean up way to indicate to better format what is passed as hash; these lines print the created module,
241
+ # not the module_directory
242
+ if module_directory = response.data(:module_directory)
243
+ split = module_directory.split('/')
244
+ if split.size > 2
245
+ installed_module = split[split.size-2..split.size-1].join(':')
246
+ response = Response::Ok.new('installed_module' => installed_module)
247
+ end
248
+ end
249
+ end
250
+ response
251
+ end
252
+
253
+
254
+ =begin
255
+ => DUE TO DEPENDENCY TO PUPPET GEM WE OMIT THIS <=
256
+ desc "import-puppet-forge PUPPET-FORGE-MODULE-NAME", "Imports puppet module from puppet forge via puppet gem"
257
+ def import_puppet_forge(context_params)
258
+ module_name = context_params.retrieve_arguments([:option_1!],method_argument_names)
259
+ # this call will throw exception if error occurs
260
+ module_dir_name = DtkPuppet.install_module(module_name)
261
+
262
+ # we change module name to be dir name
263
+ context_params.override_method_argument!(:option_1, module_dir_name)
264
+
265
+ # process will take some time adding friendly message
266
+ puts "Cloning to remote repo, please wait ..."
267
+
268
+ # rest of reponsabilty is given to import method
269
+ import(context_params)
270
+ end
271
+ =end
272
+ =begin
273
+ desc "COMPONENT-MODULE-NAME/ID import-version VERSION", "Import a specfic version from a linked component module"
274
+ def import_version(context_params)
275
+ component_module_id,version = context_params.retrieve_arguments([:component_module_id!,:option_1!],method_argument_names)
276
+ post_body = {
277
+ :component_module_id => component_module_id,
278
+ :version => version
279
+ }
280
+ response = post rest_url("component_module/import_version"), post_body
281
+ @@invalidate_map << :component_module
282
+
283
+ return response unless response.ok?
284
+ module_name,repo_url,branch,version = response.data(:module_name,:repo_url,:workspace_branch,:version)
285
+
286
+ if error = response.data(:dsl_parse_error)
287
+ dsl_parsed_message = ServiceImporter.error_message(module_name, error)
288
+ DTK::Client::OsUtil.print(dsl_parsed_message, :red)
289
+ end
290
+
291
+ #TODO: need to check if local clone directory exists
292
+ Helper(:git_repo).create_clone_with_branch(:component_module,module_name,repo_url,branch,version)
293
+ end
294
+ =end
295
+
296
+ desc "delete-from-catalog NAMESPACE/REMOTE-COMPONENT-MODULE-NAME [-y] [--force] [-v VERSION]", "Delete the component module from the DTK Network catalog"
297
+ method_option :confirmed, :aliases => '-y', :type => :boolean, :default => false
298
+ method_option :force, :type => :boolean, :default => false
299
+ version_method_option
300
+ def delete_from_catalog(context_params)
301
+ delete_from_catalog_aux(context_params)
302
+ end
303
+
304
+ # renamed to 'publish' but didn't delete this in case we run into issues with 'publish'
305
+ # desc "COMPONENT-MODULE-NAME/ID create-on-dtkn [[NAMESPACE/]REMOTE-COMPONENT-MODULE-NAME]", "Export component module to remote repository."
306
+ # def create_on_dtkn(context_params)
307
+ # component_module_id, input_remote_name = context_params.retrieve_arguments([:component_module_id!, :option_1],method_argument_names)
308
+
309
+ # post_body = {
310
+ # :component_module_id => component_module_id,
311
+ # :remote_component_name => input_remote_name,
312
+ # :rsa_pub_key => SSHUtil.rsa_pub_key_content()
313
+ # }
314
+
315
+ # response = post rest_url("component_module/export"), post_body
316
+
317
+ # return response
318
+ # end
319
+
320
+ desc "COMPONENT-MODULE-NAME/ID publish [[NAMESPACE/]REMOTE-COMPONENT-MODULE-NAME] -v VERSION [--force]", "Publish component module to remote repository."
321
+ version_method_option
322
+ method_option :force, :type => :boolean, :default => false, :aliases => '-f'
323
+ def publish(context_params)
324
+ publish_module_aux(context_params)
325
+ end
326
+
327
+ desc "COMPONENT-MODULE-NAME/ID pull-dtkn [-n NAMESPACE] [--force]", "Update local component module from remote repository."
328
+ method_option :namespace,:aliases => '-n',
329
+ :type => :string,
330
+ :banner => "NAMESPACE",
331
+ :desc => "Remote namespace"
332
+ method_option :force,:aliases => '-f',
333
+ :type => :boolean,
334
+ :desc => "Force pull",
335
+ :default => false
336
+ def pull_dtkn(context_params)
337
+ pull_dtkn_aux(context_params)
338
+ end
339
+
340
+ =begin
341
+ desc "COMPONENT-MODULE-NAME/ID chown REMOTE-USER", "Set remote module owner"
342
+ method_option "namespace", :aliases => "-n", :type => :string, :banner => "NAMESPACE", :desc => "Remote namespace"
343
+ def chown(context_params)
344
+ component_module_id, remote_user = context_params.retrieve_arguments([:component_module_id!,:option_1!],method_argument_names)
345
+ chown_aux(component_module_id, remote_user, options.namespace)
346
+ end
347
+ =end
348
+
349
+ desc "COMPONENT-MODULE-NAME/ID chmod PERMISSION-SELECTOR", "Update remote permissions e.g. ug+rw , user and group get RW permissions"
350
+ method_option "namespace", :aliases => "-n", :type => :string, :banner => "NAMESPACE", :desc => "Remote namespace"
351
+ def chmod(context_params)
352
+ chmod_module_aux(context_params)
353
+ end
354
+
355
+ desc "COMPONENT-MODULE-NAME/ID make-public", "Make this module public"
356
+ method_option "namespace", :aliases => "-n", :type => :string, :banner => "NAMESPACE", :desc => "Remote namespace"
357
+ def make_public(context_params)
358
+ make_public_module_aux(context_params)
359
+ end
360
+
361
+ desc "COMPONENT-MODULE-NAME/ID make-private", "Make this module private"
362
+ method_option "namespace", :aliases => "-n", :type => :string, :banner => "NAMESPACE", :desc => "Remote namespace"
363
+ def make_private(context_params)
364
+ make_private_module_aux(context_params)
365
+ end
366
+
367
+ desc "COMPONENT-MODULE-NAME/ID add-collaborators", "Add collabrators users or groups comma seperated (--users or --groups)"
368
+ method_option "namespace", :aliases => "-n", :type => :string, :banner => "NAMESPACE", :desc => "Remote namespace"
369
+ method_option "users", :aliases => "-u", :type => :string, :banner => "USERS", :desc => "User collabrators"
370
+ method_option "groups", :aliases => "-g", :type => :string, :banner => "GROUPS", :desc => "Group collabrators"
371
+ def add_collaborators(context_params)
372
+ add_collaborators_module_aux(context_params)
373
+ end
374
+
375
+ desc "COMPONENT-MODULE-NAME/ID remove-collaborators", "Remove collabrators users or groups comma seperated (--users or --groups)"
376
+ method_option "namespace",:aliases => "-n",:type => :string, :banner => "NAMESPACE", :desc => "Remote namespace"
377
+ method_option "users",:aliases => "-u", :type => :string, :banner => "USERS", :desc => "User collabrators"
378
+ method_option "groups",:aliases => "-g", :type => :string, :banner => "GROUPS", :desc => "Group collabrators"
379
+ def remove_collaborators(context_params)
380
+ remove_collaborators_module_aux(context_params)
381
+ end
382
+
383
+ desc "COMPONENT-MODULE-NAME/ID list-collaborators", "List collaborators for given module"
384
+ method_option "namespace",:aliases => "-n",:type => :string, :banner => "NAMESPACE", :desc => "Remote namespace"
385
+ def list_collaborators(context_params)
386
+ list_collaborators_module_aux(context_params)
387
+ end
388
+
389
+ ##
390
+ #
391
+ # internal_trigger: this flag means that other method (internal) has trigger this.
392
+ # This will change behaviour of method in such way that edit will not be
393
+ # triggered after it.
394
+ #
395
+ desc "COMPONENT-MODULE-NAME/ID clone [-n] [-v VERSION]", "Locally clone component module and component files. Use -n to skip edit prompt"
396
+ method_option :skip_edit, :aliases => '-n', :type => :boolean, :default => false
397
+ version_method_option
398
+ def clone(context_params, internal_trigger=true)
399
+ clone_module_aux(context_params, internal_trigger)
400
+ end
401
+
402
+ # desc "COMPONENT-MODULE-NAME/ID edit [-v VERSION]","Switch to unix editing for given component module."
403
+ # version_method_option
404
+ desc "COMPONENT-MODULE-NAME/ID edit","Switch to unix editing for given component module."
405
+ def edit(context_params)
406
+ edit_module_aux(context_params)
407
+ end
408
+
409
+ desc "COMPONENT-MODULE-NAME/ID push [--force] [--docs]", "Push changes from local copy of component module to server"
410
+ method_option "message",:aliases => "-m" ,
411
+ :type => :string,
412
+ :banner => "COMMIT-MSG",
413
+ :desc => "Commit message"
414
+ # hidden option for dev
415
+ method_option :force, :type => :boolean, :default => false, :aliases => '-f'
416
+ method_option :docs, :type => :boolean, :default => false, :aliases => '-d'
417
+ def push(context_params, internal_trigger=false)
418
+ push_module_aux(context_params, internal_trigger)
419
+ end
420
+
421
+ # desc "COMPONENT-MODULE-NAME/ID push-dtkn [-n NAMESPACE] [-m COMMIT-MSG]", "Push changes from local copy of component module to remote repository (dtkn)."
422
+ desc "COMPONENT-MODULE-NAME/ID push-dtkn [-n NAMESPACE] [--force]", "Push changes from local copy of component module to remote repository (dtkn)."
423
+ method_option "message",:aliases => "-m" ,
424
+ :type => :string,
425
+ :banner => "COMMIT-MSG",
426
+ :desc => "Commit message"
427
+ method_option "namespace",:aliases => "-n",
428
+ :type => :string,
429
+ :banner => "NAMESPACE",
430
+ :desc => "Remote namespace"
431
+ #hidden option for dev
432
+ method_option :force, :type => :boolean, :default => false, :aliases => '-f'
433
+ def push_dtkn(context_params, internal_trigger=false)
434
+ push_dtkn_module_aux(context_params, internal_trigger)
435
+ end
436
+ PushCatalogs = ["origin", "dtkn"]
437
+
438
+
439
+ # desc "COMPONENT-MODULE-NAME/ID list-diffs [-v VERSION] [--remote]", "List diffs"
440
+ # version_method_option
441
+ desc "COMPONENT-MODULE-NAME/ID list-diffs", "List diffs between module on server and remote repo"
442
+ method_option :remote, :type => :boolean, :default => false
443
+ def list_diffs(context_params)
444
+ list_remote_module_diffs(context_params)
445
+ # list_diffs_module_aux(context_params)
446
+ end
447
+
448
+ # REMOTE INTERACTION
449
+
450
+ desc "HIDE_FROM_BASE push-remote [REMOTE-NAME] [--force]", "Push local changes to remote git repository"
451
+ method_option :force, :type => :boolean, :default => false
452
+ def push_remote(context_params)
453
+ push_remote_module_aux(context_params)
454
+ end
455
+
456
+ desc "HIDE_FROM_BASE list-remotes", "List git remotes for given module"
457
+ def list_remotes(context_params)
458
+ remote_list_aux(context_params)
459
+ end
460
+
461
+ desc "HIDE_FROM_BASE add-remote REMOTE-NAME REMOTE-URL", "Add git remote for given module"
462
+ def add_remote(context_params)
463
+ remote_add_aux(context_params)
464
+ end
465
+
466
+ desc "HIDE_FROM_BASE remove-remote REPO-NAME [-y]", "Remove git remote for given module"
467
+ method_option :force, :aliases => '-y', :type => :boolean, :default => false
468
+ def remove_remote(context_params)
469
+ remote_remove_aux(context_params)
470
+ end
471
+
472
+ desc "COMPONENT-MODULE-NAME/ID fork NAMESPACE", "Fork component module to new namespace"
473
+ def fork(context_params)
474
+ fork_aux(context_params)
475
+ end
476
+
477
+ desc "COMPONENT-MODULE-NAME/ID create-new-version VERSION", "Create new component module version"
478
+ def create_new_version(context_params)
479
+ create_new_version_aux(context_params)
480
+ end
481
+
482
+ #
483
+ # DEVELOPMENT MODE METHODS
484
+ #
485
+ if DTK::Configuration.get(:development_mode)
486
+
487
+ desc "delete-all","Delete all service modules"
488
+ def delete_all(context_params)
489
+ return unless Console.confirmation_prompt("This will DELETE ALL component modules, are you sure"+'?')
490
+ response = list(context_params)
491
+
492
+ response.data().each do |e|
493
+ run_shell_command("delete #{e['display_name']} -y -p")
494
+ end
495
+ end
496
+
497
+ end
498
+
499
+ #### end: commands related to cloning to and pushing from local clone
500
+ end
501
+ end