dtk-shell 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/Gemfile_dev +13 -0
- data/README.md +121 -0
- data/bin/dtk-execute +32 -0
- data/bin/dtk-run +92 -0
- data/bin/dtk-shell +31 -0
- data/dtk-shell.gemspec +50 -0
- data/lib/auxiliary.rb +61 -0
- data/lib/bundler_monkey_patch.rb +26 -0
- data/lib/client.rb +58 -0
- data/lib/command_helper.rb +33 -0
- data/lib/command_helpers/git_repo.rb +589 -0
- data/lib/command_helpers/git_repo/merge.rb +153 -0
- data/lib/command_helpers/jenkins_client.rb +106 -0
- data/lib/command_helpers/jenkins_client/config_xml.rb +288 -0
- data/lib/command_helpers/service_importer.rb +251 -0
- data/lib/command_helpers/service_link.rb +33 -0
- data/lib/command_helpers/test_module_creator.rb +69 -0
- data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +10 -0
- data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +10 -0
- data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +5 -0
- data/lib/commands.rb +57 -0
- data/lib/commands/common/thor/access_control.rb +133 -0
- data/lib/commands/common/thor/action_result_handler.rb +74 -0
- data/lib/commands/common/thor/assembly_template.rb +92 -0
- data/lib/commands/common/thor/assembly_workspace.rb +1801 -0
- data/lib/commands/common/thor/base_command_helper.rb +59 -0
- data/lib/commands/common/thor/clone.rb +82 -0
- data/lib/commands/common/thor/common.rb +88 -0
- data/lib/commands/common/thor/common_base.rb +49 -0
- data/lib/commands/common/thor/create_target.rb +70 -0
- data/lib/commands/common/thor/edit.rb +255 -0
- data/lib/commands/common/thor/inventory_parser.rb +98 -0
- data/lib/commands/common/thor/list_diffs.rb +128 -0
- data/lib/commands/common/thor/module.rb +1011 -0
- data/lib/commands/common/thor/module/import.rb +210 -0
- data/lib/commands/common/thor/node.rb +53 -0
- data/lib/commands/common/thor/poller.rb +65 -0
- data/lib/commands/common/thor/pull_clone_changes.rb +28 -0
- data/lib/commands/common/thor/pull_from_remote.rb +152 -0
- data/lib/commands/common/thor/puppet_forge.rb +72 -0
- data/lib/commands/common/thor/purge_clone.rb +101 -0
- data/lib/commands/common/thor/push_clone_changes.rb +162 -0
- data/lib/commands/common/thor/push_to_remote.rb +94 -0
- data/lib/commands/common/thor/remotes.rb +71 -0
- data/lib/commands/common/thor/reparse.rb +40 -0
- data/lib/commands/common/thor/set_required_attributes.rb +46 -0
- data/lib/commands/thor/account.rb +239 -0
- data/lib/commands/thor/assembly.rb +356 -0
- data/lib/commands/thor/attribute.rb +79 -0
- data/lib/commands/thor/component.rb +70 -0
- data/lib/commands/thor/component_module.rb +501 -0
- data/lib/commands/thor/component_template.rb +174 -0
- data/lib/commands/thor/dependency.rb +34 -0
- data/lib/commands/thor/developer.rb +144 -0
- data/lib/commands/thor/dtk.rb +152 -0
- data/lib/commands/thor/library.rb +125 -0
- data/lib/commands/thor/node.rb +504 -0
- data/lib/commands/thor/node_template.rb +94 -0
- data/lib/commands/thor/project.rb +34 -0
- data/lib/commands/thor/provider.rb +233 -0
- data/lib/commands/thor/remotes.rb +49 -0
- data/lib/commands/thor/service.rb +941 -0
- data/lib/commands/thor/service_module.rb +914 -0
- data/lib/commands/thor/state_change.rb +25 -0
- data/lib/commands/thor/target.rb +250 -0
- data/lib/commands/thor/task.rb +116 -0
- data/lib/commands/thor/test_module.rb +310 -0
- data/lib/commands/thor/utils.rb +21 -0
- data/lib/commands/thor/workspace.rb +685 -0
- data/lib/config/cacert.pem +3785 -0
- data/lib/config/client.conf.header +20 -0
- data/lib/config/configuration.rb +99 -0
- data/lib/config/default.conf +16 -0
- data/lib/config/disk_cacher.rb +80 -0
- data/lib/configurator.rb +176 -0
- data/lib/context_router.rb +44 -0
- data/lib/core.rb +497 -0
- data/lib/domain/git_adapter.rb +412 -0
- data/lib/domain/git_error_handler.rb +64 -0
- data/lib/domain/response.rb +285 -0
- data/lib/domain/response/error_handler.rb +86 -0
- data/lib/dtk-shell/version.rb +20 -0
- data/lib/dtk_constants.rb +40 -0
- data/lib/dtk_error.rb +114 -0
- data/lib/dtk_logger.rb +126 -0
- data/lib/dtk_shell.rb +31 -0
- data/lib/error.rb +85 -0
- data/lib/execute.rb +29 -0
- data/lib/execute/cli_pure/cli_rerouter.rb +102 -0
- data/lib/execute/command.rb +40 -0
- data/lib/execute/command/api_call.rb +60 -0
- data/lib/execute/command/api_call/map.rb +60 -0
- data/lib/execute/command/api_call/service.rb +91 -0
- data/lib/execute/command/api_call/translation_term.rb +119 -0
- data/lib/execute/command/rest_call.rb +37 -0
- data/lib/execute/command_processor.rb +30 -0
- data/lib/execute/command_processor/rest_call.rb +59 -0
- data/lib/execute/error_usage.rb +21 -0
- data/lib/execute/execute_context.rb +86 -0
- data/lib/execute/execute_context/result_store.rb +37 -0
- data/lib/execute/script.rb +64 -0
- data/lib/execute/script/add_tenant.rb +121 -0
- data/lib/git-logs/git.log +0 -0
- data/lib/parser/adapters/option_parser.rb +70 -0
- data/lib/parser/adapters/thor.rb +555 -0
- data/lib/parser/adapters/thor/common_option_defs.rb +40 -0
- data/lib/require_first.rb +104 -0
- data/lib/search_hash.rb +44 -0
- data/lib/shell.rb +261 -0
- data/lib/shell/context.rb +1065 -0
- data/lib/shell/context_aux.rb +46 -0
- data/lib/shell/domain/active_context.rb +186 -0
- data/lib/shell/domain/context_entity.rb +89 -0
- data/lib/shell/domain/context_params.rb +223 -0
- data/lib/shell/domain/override_tasks.rb +88 -0
- data/lib/shell/domain/shadow_entity.rb +76 -0
- data/lib/shell/header_shell.rb +44 -0
- data/lib/shell/help_monkey_patch.rb +283 -0
- data/lib/shell/interactive_wizard.rb +225 -0
- data/lib/shell/message_queue.rb +63 -0
- data/lib/shell/parse_monkey_patch.rb +39 -0
- data/lib/shell/status_monitor.rb +124 -0
- data/lib/task_status.rb +83 -0
- data/lib/task_status/refresh_mode.rb +77 -0
- data/lib/task_status/snapshot_mode.rb +28 -0
- data/lib/task_status/stream_mode.rb +48 -0
- data/lib/task_status/stream_mode/element.rb +101 -0
- data/lib/task_status/stream_mode/element/format.rb +101 -0
- data/lib/task_status/stream_mode/element/hierarchical_task.rb +100 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result.rb +72 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result/action.rb +93 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result/components.rb +26 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result/node_level.rb +26 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps.rb +34 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps/action.rb +53 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps/components.rb +53 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps/node_level.rb +42 -0
- data/lib/task_status/stream_mode/element/no_results.rb +26 -0
- data/lib/task_status/stream_mode/element/render.rb +59 -0
- data/lib/task_status/stream_mode/element/stage.rb +84 -0
- data/lib/task_status/stream_mode/element/stage/render.rb +76 -0
- data/lib/task_status/stream_mode/element/task_end.rb +35 -0
- data/lib/task_status/stream_mode/element/task_start.rb +37 -0
- data/lib/util/common_util.rb +37 -0
- data/lib/util/console.rb +235 -0
- data/lib/util/dtk_puppet.rb +65 -0
- data/lib/util/module_util.rb +66 -0
- data/lib/util/os_util.rb +385 -0
- data/lib/util/permission_util.rb +31 -0
- data/lib/util/remote_dependency_util.rb +84 -0
- data/lib/util/ssh_util.rb +94 -0
- data/lib/view_processor.rb +129 -0
- data/lib/view_processor/augmented_simple_list.rb +44 -0
- data/lib/view_processor/hash_pretty_print.rb +123 -0
- data/lib/view_processor/simple_list.rb +156 -0
- data/lib/view_processor/table_print.rb +309 -0
- data/lib/violation.rb +86 -0
- data/lib/violation/attribute.rb +76 -0
- data/lib/violation/fix.rb +26 -0
- data/lib/violation/fix/result.rb +73 -0
- data/lib/violation/fix/result/error.rb +34 -0
- data/lib/violation/fix/set_attribute.rb +41 -0
- data/lib/violation/sub_classes.rb +60 -0
- data/puppet/manifests/init.pp +72 -0
- data/puppet/manifests/params.pp +16 -0
- data/puppet/r8meta.puppet.yml +35 -0
- data/puppet/templates/bash_profile.erb +2 -0
- data/puppet/templates/client.conf.erb +1 -0
- data/puppet/templates/dtkclient.erb +2 -0
- data/spec/component_module_spec.rb +34 -0
- data/spec/dependency_spec.rb +6 -0
- data/spec/dtk_shell_spec.rb +13 -0
- data/spec/dtk_spec.rb +33 -0
- data/spec/lib/spec_helper.rb +10 -0
- data/spec/lib/spec_thor.rb +108 -0
- data/spec/node_template_spec.rb +24 -0
- data/spec/project_spec.rb +6 -0
- data/spec/repo_spec.rb +7 -0
- data/spec/response_spec.rb +52 -0
- data/spec/service_module_spec.rb +38 -0
- data/spec/service_spec.rb +50 -0
- data/spec/state_change_spec.rb +7 -0
- data/spec/table_print_spec.rb +48 -0
- data/spec/target_spec.rb +57 -0
- data/spec/task_spec.rb +28 -0
- data/views/assembly/augmented_simple_list.rb +12 -0
- data/views/assembly_template/augmented_simple_list.rb +12 -0
- data/views/list_task/augmented_simple_list.rb +12 -0
- metadata +421 -0
@@ -0,0 +1,251 @@
|
|
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_from_base('configurator')
|
19
|
+
module DTK::Client
|
20
|
+
#
|
21
|
+
# Main purpose of this module is to recognize which local modules are missing based on
|
22
|
+
# name, namespace, version and for those missing component module module will call
|
23
|
+
# module#clone and module#import_dtkn method to get missing component modules
|
24
|
+
#
|
25
|
+
module ServiceImporter
|
26
|
+
def create_missing_clone_dirs()
|
27
|
+
Configurator.create_missing_clone_dirs
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.error_message(name, errors, opts = {})
|
31
|
+
prefix = ''
|
32
|
+
unless opts[:module_type] == :service_module
|
33
|
+
prefix = "Module '#{name}' has errors:\n "
|
34
|
+
end
|
35
|
+
command = opts[:command] || 'edit'
|
36
|
+
"#{prefix}#{errors.to_s}\nYou can fix errors by invoking the '#{command}' command.\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# Method will trigger pull from dtkn for each existing module
|
41
|
+
#
|
42
|
+
def trigger_module_auto_pull(required_modules, opts = {})
|
43
|
+
return if required_modules.empty?
|
44
|
+
hide_output = opts[:hide_output]
|
45
|
+
|
46
|
+
# options[:force] means this command is triggered from trigger_module_auto_import method bellow
|
47
|
+
unless opts[:force]
|
48
|
+
update_none = RemoteDependencyUtil.check_for_frozen_modules(required_modules)
|
49
|
+
|
50
|
+
if update_none
|
51
|
+
print "All dependent modules are frozen and will not be updated!\n" unless hide_output
|
52
|
+
print "Resuming pull ... " unless hide_output
|
53
|
+
return Response::Ok.new()
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
if opts[:force] || Console.confirmation_prompt("Do you want to update in addition to this module its dependent modules from the catalog?")
|
58
|
+
required_modules.uniq.each do |r_module|
|
59
|
+
module_name = full_module_name(r_module)
|
60
|
+
module_type = r_module['type']
|
61
|
+
version = r_module['version']
|
62
|
+
full_name = (version && !version.eql?('master')) ? "#{module_name}(#{version})" : module_name
|
63
|
+
|
64
|
+
# No op for frozen modules
|
65
|
+
next if r_module['frozen']
|
66
|
+
|
67
|
+
print "Pulling #{module_type.gsub('_',' ')} content for '#{full_name}' ... " unless hide_output
|
68
|
+
|
69
|
+
new_context_params = DTK::Shell::ContextParams.new
|
70
|
+
new_context_params.add_context_to_params(module_type, module_type)
|
71
|
+
new_context_params.add_context_name_to_params(module_type, module_type, module_name)
|
72
|
+
|
73
|
+
forwarded_opts = { :skip_recursive_pull => true, :ignore_dependency_merge_conflict => true }
|
74
|
+
forwarded_opts.merge!(:do_not_raise => true) if opts[:do_not_raise]
|
75
|
+
forwarded_opts.merge!(:version => version) if version && !version.eql?('master')
|
76
|
+
new_context_params.forward_options(forwarded_opts)
|
77
|
+
|
78
|
+
response = ContextRouter.routeTask(module_type, "pull_dtkn", new_context_params, @conn)
|
79
|
+
|
80
|
+
unless response.ok?
|
81
|
+
if opts[:do_not_raise]
|
82
|
+
OsUtil.print("#{response.error_message}", :red)
|
83
|
+
else
|
84
|
+
raise DtkError, response.error_message
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
print "Resuming pull ... " unless opts[:force]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# Method will trigger import for each missing module component
|
95
|
+
#
|
96
|
+
def trigger_module_auto_import(modules_to_import, required_modules, opts = {})
|
97
|
+
hide_output = opts[:hide_output]
|
98
|
+
|
99
|
+
puts 'Auto-installing missing module(s)' unless hide_output
|
100
|
+
update_all = false
|
101
|
+
update_none = RemoteDependencyUtil.check_for_frozen_modules(required_modules)
|
102
|
+
|
103
|
+
# Print out or update installed modules from catalog
|
104
|
+
required_modules.uniq.each do |r_module|
|
105
|
+
module_name = full_module_name(r_module)
|
106
|
+
module_type = r_module['type']
|
107
|
+
version = r_module['version']
|
108
|
+
full_name = (version && !version.eql?('master')) ? "#{module_name}(#{version})" : module_name
|
109
|
+
|
110
|
+
unless hide_output
|
111
|
+
print "Using #{module_type.gsub('_', ' ')} '#{full_name}'\n" unless update_all
|
112
|
+
end
|
113
|
+
|
114
|
+
next if update_none || opts[:update_none]
|
115
|
+
|
116
|
+
pull_opts = {:force => true, :do_not_raise => true}
|
117
|
+
pull_opts.merge!(:hide_output => hide_output) if hide_output
|
118
|
+
|
119
|
+
if update_all
|
120
|
+
trigger_module_auto_pull([r_module], pull_opts)
|
121
|
+
else
|
122
|
+
options = required_modules.size > 1 ? %w(all none) : []
|
123
|
+
update = Console.confirmation_prompt_additional_options("Do you want to update dependent #{module_type.gsub('_', ' ')} '#{full_name}' from the catalog?", options) unless hide_output
|
124
|
+
next unless update
|
125
|
+
|
126
|
+
if update.to_s.eql?('all')
|
127
|
+
update_all = true
|
128
|
+
trigger_module_auto_pull([r_module], pull_opts)
|
129
|
+
elsif update.to_s.eql?('none')
|
130
|
+
update_none = true
|
131
|
+
else
|
132
|
+
trigger_module_auto_pull([r_module], pull_opts)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# Trigger import/install for missing modules
|
138
|
+
modules_to_import.uniq.each do |m_module|
|
139
|
+
module_name = full_module_name(m_module)
|
140
|
+
module_type = m_module['type']
|
141
|
+
version = m_module['version']
|
142
|
+
full_name = (version && !version.eql?('master')) ? "#{module_name}(#{version})" : module_name
|
143
|
+
|
144
|
+
# we check if there is module_url if so we install from git
|
145
|
+
module_url = m_module['module_url']
|
146
|
+
|
147
|
+
# descriptive message
|
148
|
+
importing = module_url ? "Importing" : "Installing"
|
149
|
+
import_msg = "#{importing} #{module_type.gsub('_', ' ')} '#{full_name}'"
|
150
|
+
import_msg += " from git source #{module_url}" if module_url
|
151
|
+
print "#{import_msg} ... " unless hide_output
|
152
|
+
|
153
|
+
if module_url
|
154
|
+
# import from Git source
|
155
|
+
new_context_params = ::DTK::Shell::ContextParams.new([module_url, module_name])
|
156
|
+
new_context_params.forward_options(:internal_trigger => true)
|
157
|
+
response = ContextRouter.routeTask(module_type, 'import_git', new_context_params, @conn)
|
158
|
+
else
|
159
|
+
# import from Repo Manager
|
160
|
+
new_context_params = ::DTK::Shell::ContextParams.new([module_name])
|
161
|
+
new_context_params.override_method_argument!('option_2', version) if version && !version.eql?('master')
|
162
|
+
new_context_params.forward_options(:skip_cloning => false, :skip_auto_install => true, :module_type => module_type, :ignore_component_error => true).merge!(opts)
|
163
|
+
response = ContextRouter.routeTask(module_type, 'install', new_context_params, @conn)
|
164
|
+
end
|
165
|
+
|
166
|
+
ignore_component_error = (new_context_params.get_forwarded_options() || {})[:ignore_component_error] && module_type.eql?('component_module')
|
167
|
+
puts(response.data(:does_not_exist) ? response.data(:does_not_exist) : 'Done.') unless hide_output
|
168
|
+
raise DtkError, response.error_message if !response.ok? && !ignore_component_error
|
169
|
+
end
|
170
|
+
|
171
|
+
Response::Ok.new()
|
172
|
+
end
|
173
|
+
|
174
|
+
def resolve_missing_components(service_module_id, service_module_name, namespace_to_use, force_clone=false)
|
175
|
+
# Get dependency component modules and cross reference them with local component modules
|
176
|
+
module_component_list = post rest_url("service_module/list_component_modules"), { :service_module_id => service_module_id }
|
177
|
+
|
178
|
+
local_modules, needed_modules = OsUtil.local_component_module_list(), Array.new
|
179
|
+
|
180
|
+
if module_component_list
|
181
|
+
module_component_list.data.each do |cmp_module|
|
182
|
+
with_namespace = ModuleUtil.resolve_name(cmp_module["display_name"],cmp_module["namespace_name"])
|
183
|
+
formated_name = add_version?(with_namespace, cmp_module['version'])
|
184
|
+
unless local_modules.include?(formated_name)
|
185
|
+
needed_modules << cmp_module.merge({'formated_name' => formated_name})
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
unless needed_modules.empty?
|
191
|
+
# puts "Service '#{service_module_name}' does not have the following component modules dependencies on the client machine: \n\n"
|
192
|
+
# needed_modules.each { |m| puts " - #{m['formated_name']}" }
|
193
|
+
is_install_dependencies = true
|
194
|
+
# is_install_dependencies = Console.confirmation_prompt("\nDo you want to clone these missing component modules to the client machine?") unless force_clone
|
195
|
+
|
196
|
+
# we get list of modules available on server
|
197
|
+
|
198
|
+
new_context_params = nil
|
199
|
+
|
200
|
+
if is_install_dependencies
|
201
|
+
needed_modules.each do |m|
|
202
|
+
formated_name = m['formated_name']
|
203
|
+
# print "Cloning component module '#{formated_name}' from server ... "
|
204
|
+
thor_options = {}
|
205
|
+
thor_options["version"] = m['version'] unless m['version'].eql?('base')
|
206
|
+
thor_options["skip_edit"] = true
|
207
|
+
thor_options["omit_output"] = true
|
208
|
+
thor_options.merge!(:module_type => 'component-module')
|
209
|
+
thor_options.merge!(:service_importer => true)
|
210
|
+
new_context_params = ::DTK::Shell::ContextParams.new
|
211
|
+
new_context_params.forward_options(thor_options)
|
212
|
+
new_context_params.add_context_to_params(formated_name, :"component-module", m['id'])
|
213
|
+
|
214
|
+
begin
|
215
|
+
response = ContextRouter.routeTask("component_module", "clone", new_context_params, @conn)
|
216
|
+
rescue DtkValidationError => e
|
217
|
+
# ignoring this
|
218
|
+
end
|
219
|
+
# puts "Done."
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
private
|
226
|
+
#
|
227
|
+
# As the result we can have multiple version so we need to resolve them
|
228
|
+
#
|
229
|
+
# Returns: Array<String>
|
230
|
+
def resolve_module_names(e)
|
231
|
+
versions = (e['version'] ? e['version'].split(',') : ['CURRENT'])
|
232
|
+
|
233
|
+
versions.collect { |version| add_version?(e['display_name'], version)}
|
234
|
+
end
|
235
|
+
|
236
|
+
# Resolves local module name
|
237
|
+
#
|
238
|
+
# Returns: String
|
239
|
+
def add_version?(display_name, version)
|
240
|
+
version = nil if 'CURRENT'.eql?(version) || 'base'.eql?(version)
|
241
|
+
(version ? "#{display_name}-#{version.strip}" : "#{display_name}")
|
242
|
+
end
|
243
|
+
|
244
|
+
private
|
245
|
+
|
246
|
+
def full_module_name(module_hash)
|
247
|
+
ModuleUtil.join_name(module_hash['name'], module_hash['namespace'])
|
248
|
+
end
|
249
|
+
|
250
|
+
end
|
251
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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; module Client; class CommandHelper
|
19
|
+
class ServiceLink < self; class << self
|
20
|
+
def post_body_with_id_keys(context_params,method_argument_names)
|
21
|
+
assembly_or_workspace_id = context_params.retrieve_arguments([[:service_id!,:workspace_id!]])
|
22
|
+
ret = {:assembly_id => assembly_or_workspace_id}
|
23
|
+
if context_params.is_last_command_eql_to?(:component)
|
24
|
+
component_id,service_type = context_params.retrieve_arguments([:component_id!,:option_1!],method_argument_names)
|
25
|
+
ret.merge(:input_component_id => component_id,:service_type => service_type)
|
26
|
+
else
|
27
|
+
service_link_id = context_params.retrieve_arguments([:option_1!],method_argument_names)
|
28
|
+
ret.merge(:service_link_id => service_link_id)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end; end
|
33
|
+
end; end; end
|
@@ -0,0 +1,69 @@
|
|
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
|
+
require 'erubis'
|
20
|
+
|
21
|
+
module DTK::Client
|
22
|
+
class TestModuleCreator
|
23
|
+
class << self
|
24
|
+
def create_clone(type, module_name)
|
25
|
+
Response.wrap_helper_actions do
|
26
|
+
modules_dir = OsUtil.test_clone_location()
|
27
|
+
FileUtils.mkdir_p(modules_dir) unless File.directory?(modules_dir)
|
28
|
+
target_repo_dir = OsUtil.module_location(type,module_name)
|
29
|
+
|
30
|
+
begin
|
31
|
+
FileUtils.mkdir_p(target_repo_dir)
|
32
|
+
generate_model(module_name, target_repo_dir)
|
33
|
+
generate_serverspec_files(module_name, target_repo_dir)
|
34
|
+
rescue => e
|
35
|
+
additional_error_msg = ""
|
36
|
+
error_msg = "Create of directory (#{target_repo_dir}) failed."
|
37
|
+
additional_error_msg = "Directory already exists" if e.message.include? "File exists"
|
38
|
+
raise DTK::ErrorUsage.new(error_msg + " " + additional_error_msg,:log_error=>false)
|
39
|
+
end
|
40
|
+
{"module_directory" => target_repo_dir}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def generate_model(module_name, target_repo_dir)
|
45
|
+
input = File.expand_path('test_module_templates/dtk.model.yaml.eruby', File.dirname(__FILE__))
|
46
|
+
eruby = Erubis::Eruby.new(File.read(input))
|
47
|
+
content = eruby.result(:module_name => module_name)
|
48
|
+
File.open(target_repo_dir + "/dtk.model.yaml", "w") { |f| f.write(content) }
|
49
|
+
end
|
50
|
+
|
51
|
+
def generate_serverspec_files(module_name, target_repo_dir)
|
52
|
+
template_location = File.expand_path('test_module_templates', File.dirname(__FILE__))
|
53
|
+
spec_helper_template = Erubis::Eruby.new(File.read(template_location + "/spec_helper.rb.eruby")).result
|
54
|
+
spec_template = Erubis::Eruby.new(File.read(template_location + "/temp_component_spec.rb.eruby")).result
|
55
|
+
|
56
|
+
begin
|
57
|
+
#Create standard serverspec structure
|
58
|
+
FileUtils.mkdir_p(target_repo_dir + "/serverspec/spec/localhost")
|
59
|
+
File.open(target_repo_dir + "/serverspec/spec/spec_helper.rb", "w") { |f| f.write(spec_helper_template) }
|
60
|
+
File.open(target_repo_dir + "/serverspec/spec/localhost/temp_component_spec.rb", "w") { |f| f.write(spec_template) }
|
61
|
+
rescue => e
|
62
|
+
error_msg = "Generating serverspec files failed."
|
63
|
+
DtkLogger.instance.error_pp(e.message, e.backtrace)
|
64
|
+
raise DTK::ErrorUsage.new(error_msg,:log_error=>false)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/commands.rb
ADDED
@@ -0,0 +1,57 @@
|
|
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
|
19
|
+
module Client
|
20
|
+
module CommandBase
|
21
|
+
#TODO: temp workaround
|
22
|
+
def rotate_args(rotated_args)
|
23
|
+
[rotated_args.last] + rotated_args[0..rotated_args.size-2]
|
24
|
+
end
|
25
|
+
|
26
|
+
def get(url)
|
27
|
+
get_connection.get(self.class,url)
|
28
|
+
end
|
29
|
+
def post(url,body=nil)
|
30
|
+
get_connection.post(self.class,url,body)
|
31
|
+
end
|
32
|
+
|
33
|
+
def post_file(url,body=nil)
|
34
|
+
get_connection.post_file(self.class,url,body)
|
35
|
+
end
|
36
|
+
|
37
|
+
def rest_url(route)
|
38
|
+
get_connection.rest_url(route)
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_connection
|
42
|
+
DTK::Client::Session.get_connection()
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.handle_argument_error(task, error)
|
46
|
+
super
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def pretty_print_cols()
|
52
|
+
self.class.pretty_print_cols()
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,133 @@
|
|
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
|
+
module AccessControlMixin
|
20
|
+
|
21
|
+
def chmod_aux(module_id, permission_string, namespace = nil, chmod_action = :chmod)
|
22
|
+
permission_selector = PermissionUtil.validate_permissions!(permission_string.downcase)
|
23
|
+
post_body = {
|
24
|
+
:module_id => module_id,
|
25
|
+
:permission_selector => permission_selector,
|
26
|
+
:chmod_action => chmod_action,
|
27
|
+
:rsa_pub_key => SSHUtil.rsa_pub_key_content(),
|
28
|
+
:remote_module_namespace => namespace
|
29
|
+
}
|
30
|
+
response = post rest_url("#{resolve_module_type}/remote_chmod"), post_body
|
31
|
+
return response unless response.ok?
|
32
|
+
|
33
|
+
if response.data(:simple_flow)
|
34
|
+
puts "Module is now public."
|
35
|
+
else
|
36
|
+
# in case there are dependencies
|
37
|
+
main_module_name = response.data(:main_module)['full_name']
|
38
|
+
puts "Main module '#{main_module_name}' has dependencies that are not public: "
|
39
|
+
unless response.data(:missing_modules).empty?
|
40
|
+
missing = response.data(:missing_modules).collect { |a| a['full_name'] }
|
41
|
+
OsUtil.print(" These modules are missing on repository: #{missing.join(', ')}", :red)
|
42
|
+
end
|
43
|
+
unless response.data(:no_permission).empty?
|
44
|
+
no_permission = response.data(:no_permission).collect { |a| a['full_name'] }
|
45
|
+
OsUtil.print(" You cannot change permissions for dependencies: #{no_permission.join(', ')}", :yellow)
|
46
|
+
end
|
47
|
+
unless response.data(:with_permission).empty?
|
48
|
+
with_permission = response.data(:with_permission)
|
49
|
+
with_permission_names = with_permission.collect { |a| a['full_name'] }
|
50
|
+
OsUtil.print(" You can change permissions for dependencies: #{with_permission_names.join(', ')}", :white)
|
51
|
+
|
52
|
+
# fix for bug in comments for DTK-1959
|
53
|
+
# need to send hash instead of array to be able to parse properly in rest_request_params
|
54
|
+
with_permission_hash = {}
|
55
|
+
with_permission.each do |wp|
|
56
|
+
with_permission_hash.merge!("#{wp['name']}" => wp)
|
57
|
+
end
|
58
|
+
|
59
|
+
response.data["with_permission"] = with_permission_hash
|
60
|
+
end
|
61
|
+
|
62
|
+
puts "How should we resolve these dependencies: "
|
63
|
+
input = Shell::InteractiveWizard.text_input("(A)ll / (M)ain Module / (N)one ", true, /M|A|N/i)
|
64
|
+
if 'N'.eql?(input)
|
65
|
+
return nil
|
66
|
+
else
|
67
|
+
puts "Sending input information ... "
|
68
|
+
post_body = {
|
69
|
+
:module_id => module_id,
|
70
|
+
:module_info => response.data,
|
71
|
+
:public_action => 'A'.eql?(input) ? :all : :one,
|
72
|
+
:rsa_pub_key => SSHUtil.rsa_pub_key_content(),
|
73
|
+
:remote_module_namespace => namespace
|
74
|
+
}
|
75
|
+
|
76
|
+
response = post rest_url("#{resolve_module_type}/confirm_make_public"), post_body
|
77
|
+
return response unless response.ok?
|
78
|
+
puts "Modules are now public."
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
nil
|
83
|
+
end
|
84
|
+
|
85
|
+
def chown_aux(module_id, remote_user, namespace = nil)
|
86
|
+
post_body = {
|
87
|
+
:module_id => module_id,
|
88
|
+
:remote_user => remote_user,
|
89
|
+
:rsa_pub_key => SSHUtil.rsa_pub_key_content(),
|
90
|
+
:remote_module_namespace => namespace
|
91
|
+
}
|
92
|
+
post rest_url("#{resolve_module_type}/remote_chown"), post_body
|
93
|
+
end
|
94
|
+
|
95
|
+
def collaboration_aux(action, module_id, users, groups, namespace = nil)
|
96
|
+
raise DtkValidationError, "You must provide --users or --groups to this command" if users.nil? && groups.nil?
|
97
|
+
post_body = {
|
98
|
+
:module_id => module_id,
|
99
|
+
:users => users,
|
100
|
+
:groups => groups,
|
101
|
+
:action => action,
|
102
|
+
:remote_module_namespace => namespace,
|
103
|
+
:rsa_pub_key => SSHUtil.rsa_pub_key_content()
|
104
|
+
}
|
105
|
+
post rest_url("#{resolve_module_type}/remote_collaboration"), post_body
|
106
|
+
end
|
107
|
+
|
108
|
+
def collaboration_list_aux(module_id, namespace = nil)
|
109
|
+
post_body = {
|
110
|
+
:module_id => module_id,
|
111
|
+
:remote_module_namespace => namespace,
|
112
|
+
:rsa_pub_key => SSHUtil.rsa_pub_key_content()
|
113
|
+
}
|
114
|
+
post rest_url("#{resolve_module_type}/list_remote_collaboration"), post_body
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def resolve_module_type
|
120
|
+
case self
|
121
|
+
when ComponentModule
|
122
|
+
return :component_module
|
123
|
+
when ServiceModule
|
124
|
+
return :service_module
|
125
|
+
when TestModule
|
126
|
+
return :test_module
|
127
|
+
else
|
128
|
+
raise DtkError, "Module type cannot be resolved for this class (#{self})"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|