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.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/Gemfile +1 -3
- data/README.md +2 -121
- data/Rakefile +44 -0
- data/bin/dtk +10 -88
- data/dtk-client.gemspec +21 -44
- data/examples/simple/dtk.module.yaml +32 -0
- data/{lib/git-logs/git.log → examples/simple/test/README.md} +0 -0
- data/examples/spark/dtk.module.yaml +120 -0
- data/examples/with_repo_content/deploy/puppet/manifests/hostname.pp +54 -0
- data/examples/with_repo_content/dtk.module.yaml +49 -0
- data/examples/with_repo_content/test/README.txt +0 -0
- data/features/dtk.feature +8 -0
- data/features/step_definitions/dtk_steps.rb +6 -0
- data/features/support/env.rb +15 -0
- data/lib/cli/command/mixin.rb +101 -0
- data/lib/cli/command/module/clone.rb +42 -0
- data/lib/cli/command/module/install.rb +52 -0
- data/lib/cli/command/module/list.rb +31 -0
- data/lib/cli/command/module/list_assemblies.rb +39 -0
- data/lib/cli/command/module/push.rb +34 -0
- data/lib/cli/command/module/uninstall.rb +46 -0
- data/lib/cli/command/module.rb +33 -0
- data/lib/cli/command/options.rb +33 -0
- data/lib/cli/command/service/cancel_task.rb +33 -0
- data/lib/cli/command/service/converge.rb +37 -0
- data/lib/{parser/adapters/thor/common_option_defs.rb → cli/command/service/create_workspace.rb} +13 -17
- data/lib/cli/command/service/destroy.rb +47 -0
- data/lib/cli/command/service/edit.rb +47 -0
- data/lib/cli/command/service/exec.rb +42 -0
- data/lib/cli/command/service/exec_sync.rb +53 -0
- data/lib/cli/command/service/list.rb +30 -0
- data/lib/cli/command/service/list_actions.rb +39 -0
- data/lib/cli/command/service/list_attributes.rb +44 -0
- data/lib/cli/command/service/list_component_links.rb +33 -0
- data/lib/cli/command/service/list_components.rb +39 -0
- data/lib/cli/command/service/list_dependent_modules.rb +33 -0
- data/lib/cli/command/service/list_nodes.rb +33 -0
- data/lib/cli/command/service/list_violations.rb +33 -0
- data/lib/cli/command/service/pull.rb +32 -0
- data/lib/cli/command/service/push.rb +37 -0
- data/lib/{shell/parse_monkey_patch.rb → cli/command/service/set_default_target.rb} +9 -17
- data/lib/cli/command/service/set_required_attributes.rb +32 -0
- data/lib/cli/command/service/ssh.rb +42 -0
- data/lib/cli/command/service/stage.rb +55 -0
- data/lib/cli/command/service/start.rb +33 -0
- data/lib/{shell/context_aux.rb → cli/command/service/stop.rb} +10 -23
- data/lib/cli/command/service/task_status.rb +39 -0
- data/lib/cli/command/service.rb +55 -0
- data/lib/{commands.rb → cli/command/subcommand.rb} +22 -25
- data/lib/{bundler_monkey_patch.rb → cli/command/token/arg.rb} +6 -6
- data/lib/cli/command/token/class_mixin.rb +96 -0
- data/lib/cli/command/token/flag.rb +42 -0
- data/lib/{execute/command/rest_call.rb → cli/command/token/mixin.rb} +23 -14
- data/lib/cli/command/token/switch.rb +35 -0
- data/lib/cli/command/token.rb +76 -0
- data/lib/cli/command.rb +46 -0
- data/lib/cli/context/attributes.rb +50 -0
- data/lib/cli/context/type/module.rb +34 -0
- data/lib/{commands/thor/state_change.rb → cli/context/type/service.rb} +11 -5
- data/lib/cli/context/type/top.rb +32 -0
- data/lib/cli/context/type.rb +42 -0
- data/lib/cli/context.rb +174 -0
- data/lib/cli/directory_parser/file_system.rb +105 -0
- data/lib/{execute/command.rb → cli/directory_parser.rb} +14 -17
- data/lib/{execute.rb → cli/file_obj.rb} +13 -9
- data/lib/cli/processor/plugin/gli.rb +70 -0
- data/lib/cli/processor.rb +60 -0
- data/lib/cli/runner/dtkn_access.rb +75 -0
- data/lib/cli/runner.rb +58 -0
- data/lib/cli/version.rb +8 -0
- data/lib/{config → client/config}/cacert.pem +0 -0
- data/lib/client/config/default.conf +20 -0
- data/lib/client/config.rb +106 -0
- data/lib/client/configurator.rb +182 -0
- data/lib/client/conn.rb +197 -0
- data/lib/client/content_generator.rb +127 -0
- data/lib/client/error/subclasses.rb +105 -0
- data/lib/client/error.rb +98 -0
- data/lib/client/git_repo/adapter/git_gem/error_handler.rb +70 -0
- data/lib/client/git_repo/adapter/git_gem.rb +179 -0
- data/lib/client/git_repo.rb +122 -0
- data/lib/client/logger.rb +136 -0
- data/lib/client/operation/account.rb +66 -0
- data/lib/client/operation/client_module_dir/git_repo.rb +286 -0
- data/lib/client/operation/client_module_dir.rb +138 -0
- data/lib/client/operation/module/clone_module.rb +52 -0
- data/lib/client/operation/module/install/common_module.rb +58 -0
- data/lib/client/operation/module/install/external_module.rb +122 -0
- data/lib/client/operation/module/install.rb +91 -0
- data/lib/client/operation/module/install_from_catalog.rb +76 -0
- data/lib/client/operation/module/list.rb +34 -0
- data/lib/client/operation/module/list_assemblies.rb +35 -0
- data/lib/client/operation/module/push.rb +62 -0
- data/lib/client/operation/module/uninstall.rb +44 -0
- data/lib/client/operation/module.rb +58 -0
- data/lib/{commands/common/thor/reparse.rb → client/operation/module_service_common.rb} +27 -16
- data/lib/client/operation/service/cancel_task.rb +29 -0
- data/lib/client/operation/service/commit_and_push.rb +128 -0
- data/lib/client/operation/service/converge.rb +50 -0
- data/lib/{util/common_util.rb → client/operation/service/create_workspace.rb} +13 -13
- data/lib/client/operation/service/destroy.rb +42 -0
- data/lib/client/operation/service/edit.rb +54 -0
- data/lib/client/operation/service/exec.rb +73 -0
- data/lib/client/operation/service/list.rb +32 -0
- data/lib/client/operation/service/list_actions.rb +34 -0
- data/lib/{commands/thor/dependency.rb → client/operation/service/list_attributes.rb} +16 -12
- data/lib/client/operation/service/list_component_links.rb +29 -0
- data/lib/{commands/common/thor/pull_clone_changes.rb → client/operation/service/list_components.rb} +13 -7
- data/lib/client/operation/service/list_dependent_modules.rb +29 -0
- data/lib/client/operation/service/list_nodes.rb +29 -0
- data/lib/{commands/thor/project.rb → client/operation/service/list_violations.rb} +8 -13
- data/lib/client/operation/service/pull.rb +37 -0
- data/lib/client/operation/service/set_default_target.rb +31 -0
- data/lib/client/operation/service/set_required_attributes.rb +41 -0
- data/lib/client/operation/service/ssh.rb +118 -0
- data/lib/client/operation/service/stage.rb +54 -0
- data/lib/client/operation/service/start.rb +29 -0
- data/lib/client/operation/service/stop.rb +30 -0
- data/lib/{task_status → client/operation/service/task_status}/refresh_mode.rb +15 -25
- data/lib/{task_status → client/operation/service/task_status}/snapshot_mode.rb +4 -5
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/format.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/action.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/components.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/node_level.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result.rb +4 -4
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/action.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/components.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/node_level.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps.rb +4 -4
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task.rb +3 -3
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/no_results.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/render.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/stage/render.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/stage.rb +3 -3
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/task_end.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/task_start.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element.rb +13 -13
- data/lib/{task_status → client/operation/service/task_status}/stream_mode.rb +5 -9
- data/lib/client/operation/service/task_status.rb +77 -0
- data/lib/client/operation/service.rb +54 -0
- data/lib/client/operation.rb +67 -0
- data/lib/client/operation_args.rb +40 -0
- data/lib/{execute/execute_context/result_store.rb → client/render/view/simple.rb} +15 -14
- data/lib/client/render/view/table/processor.rb +248 -0
- data/lib/client/render/view/table.rb +75 -0
- data/lib/client/render.rb +113 -0
- data/lib/client/response/error_handler.rb +97 -0
- data/lib/client/response/render_helper.rb +78 -0
- data/lib/client/response/subclasses.rb +62 -0
- data/lib/client/response.rb +83 -0
- data/lib/client/session.rb +62 -0
- data/lib/client/util/auxiliary.rb +34 -0
- data/lib/client/util/console.rb +81 -0
- data/lib/client/util/disk_cacher.rb +66 -0
- data/lib/client/util/dtk_path.rb +28 -0
- data/lib/{search_hash.rb → client/util/hash_with_optional_keys.rb} +29 -21
- data/lib/client/util/interactive_wizard.rb +84 -0
- data/lib/client/util/module_ref.rb +92 -0
- data/lib/client/util/os_util/print.rb +121 -0
- data/lib/client/util/os_util.rb +122 -0
- data/lib/{commands/thor/utils.rb → client/util/post_body.rb} +1 -1
- data/lib/{execute/error_usage.rb → client/util/query_string_hash.rb} +2 -2
- data/lib/client/util/remote_dependency.rb +67 -0
- data/lib/client/util/ssh_util.rb +89 -0
- data/lib/client/util/validation.rb +28 -0
- data/lib/client/util.rb +18 -0
- data/lib/{util/permission_util.rb → dtk_cli.rb} +10 -9
- data/lib/dtk_client.rb +18 -14
- data/test/default_test.rb +14 -0
- data/test/test_helper.rb +9 -0
- metadata +196 -307
- data/Gemfile_dev +0 -13
- data/bin/dtk-execute +0 -32
- data/bin/dtk-shell +0 -31
- data/lib/auxiliary.rb +0 -61
- data/lib/client.rb +0 -58
- data/lib/command_helper.rb +0 -33
- data/lib/command_helpers/git_repo/merge.rb +0 -153
- data/lib/command_helpers/git_repo.rb +0 -589
- data/lib/command_helpers/jenkins_client/config_xml.rb +0 -288
- data/lib/command_helpers/jenkins_client.rb +0 -106
- data/lib/command_helpers/service_importer.rb +0 -251
- data/lib/command_helpers/service_link.rb +0 -33
- data/lib/command_helpers/test_module_creator.rb +0 -69
- data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +0 -10
- data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +0 -10
- data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +0 -5
- data/lib/commands/common/thor/access_control.rb +0 -133
- data/lib/commands/common/thor/action_result_handler.rb +0 -74
- data/lib/commands/common/thor/assembly_template.rb +0 -92
- data/lib/commands/common/thor/assembly_workspace.rb +0 -1638
- data/lib/commands/common/thor/base_command_helper.rb +0 -59
- data/lib/commands/common/thor/clone.rb +0 -82
- data/lib/commands/common/thor/common.rb +0 -88
- data/lib/commands/common/thor/common_base.rb +0 -49
- data/lib/commands/common/thor/create_target.rb +0 -70
- data/lib/commands/common/thor/edit.rb +0 -255
- data/lib/commands/common/thor/inventory_parser.rb +0 -98
- data/lib/commands/common/thor/list_diffs.rb +0 -128
- data/lib/commands/common/thor/module/import.rb +0 -215
- data/lib/commands/common/thor/module.rb +0 -1011
- data/lib/commands/common/thor/node.rb +0 -53
- data/lib/commands/common/thor/poller.rb +0 -65
- data/lib/commands/common/thor/pull_from_remote.rb +0 -152
- data/lib/commands/common/thor/puppet_forge.rb +0 -72
- data/lib/commands/common/thor/purge_clone.rb +0 -101
- data/lib/commands/common/thor/push_clone_changes.rb +0 -162
- data/lib/commands/common/thor/push_to_remote.rb +0 -94
- data/lib/commands/common/thor/remotes.rb +0 -71
- data/lib/commands/common/thor/set_required_attributes.rb +0 -46
- data/lib/commands/thor/account.rb +0 -239
- data/lib/commands/thor/assembly.rb +0 -361
- data/lib/commands/thor/attribute.rb +0 -79
- data/lib/commands/thor/component.rb +0 -70
- data/lib/commands/thor/component_module.rb +0 -501
- data/lib/commands/thor/component_template.rb +0 -174
- data/lib/commands/thor/developer.rb +0 -144
- data/lib/commands/thor/dtk.rb +0 -152
- data/lib/commands/thor/library.rb +0 -125
- data/lib/commands/thor/node.rb +0 -504
- data/lib/commands/thor/node_group.rb +0 -203
- data/lib/commands/thor/node_template.rb +0 -94
- data/lib/commands/thor/provider.rb +0 -233
- data/lib/commands/thor/remotes.rb +0 -49
- data/lib/commands/thor/service.rb +0 -932
- data/lib/commands/thor/service_module.rb +0 -900
- data/lib/commands/thor/target.rb +0 -250
- data/lib/commands/thor/task.rb +0 -116
- data/lib/commands/thor/test_module.rb +0 -310
- data/lib/commands/thor/workspace.rb +0 -698
- data/lib/config/client.conf.header +0 -20
- data/lib/config/configuration.rb +0 -99
- data/lib/config/default.conf +0 -16
- data/lib/config/disk_cacher.rb +0 -80
- data/lib/configurator.rb +0 -176
- data/lib/context_router.rb +0 -44
- data/lib/core.rb +0 -489
- data/lib/domain/git_adapter.rb +0 -412
- data/lib/domain/git_error_handler.rb +0 -64
- data/lib/domain/response/error_handler.rb +0 -86
- data/lib/domain/response.rb +0 -285
- data/lib/dtk-client/version.rb +0 -20
- data/lib/dtk_constants.rb +0 -40
- data/lib/dtk_error.rb +0 -114
- data/lib/dtk_logger.rb +0 -113
- data/lib/error.rb +0 -85
- data/lib/execute/cli_pure/cli_rerouter.rb +0 -102
- data/lib/execute/command/api_call/map.rb +0 -60
- data/lib/execute/command/api_call/service.rb +0 -91
- data/lib/execute/command/api_call/translation_term.rb +0 -119
- data/lib/execute/command/api_call.rb +0 -60
- data/lib/execute/command_processor/rest_call.rb +0 -59
- data/lib/execute/command_processor.rb +0 -30
- data/lib/execute/execute_context.rb +0 -86
- data/lib/execute/script/add_tenant.rb +0 -121
- data/lib/execute/script.rb +0 -64
- data/lib/parser/adapters/option_parser.rb +0 -70
- data/lib/parser/adapters/thor.rb +0 -555
- data/lib/require_first.rb +0 -104
- data/lib/shell/context.rb +0 -1064
- data/lib/shell/domain/active_context.rb +0 -186
- data/lib/shell/domain/context_entity.rb +0 -89
- data/lib/shell/domain/context_params.rb +0 -223
- data/lib/shell/domain/override_tasks.rb +0 -88
- data/lib/shell/domain/shadow_entity.rb +0 -76
- data/lib/shell/header_shell.rb +0 -44
- data/lib/shell/help_monkey_patch.rb +0 -283
- data/lib/shell/interactive_wizard.rb +0 -256
- data/lib/shell/message_queue.rb +0 -63
- data/lib/shell/status_monitor.rb +0 -124
- data/lib/shell.rb +0 -261
- data/lib/task_status.rb +0 -83
- data/lib/util/console.rb +0 -235
- data/lib/util/dtk_puppet.rb +0 -65
- data/lib/util/module_util.rb +0 -66
- data/lib/util/os_util.rb +0 -385
- data/lib/util/remote_dependency_util.rb +0 -84
- data/lib/util/ssh_util.rb +0 -94
- data/lib/view_processor/augmented_simple_list.rb +0 -44
- data/lib/view_processor/hash_pretty_print.rb +0 -123
- data/lib/view_processor/simple_list.rb +0 -156
- data/lib/view_processor/table_print.rb +0 -309
- data/lib/view_processor.rb +0 -129
- data/puppet/manifests/init.pp +0 -72
- data/puppet/manifests/params.pp +0 -16
- data/puppet/r8meta.puppet.yml +0 -35
- data/puppet/templates/bash_profile.erb +0 -2
- data/puppet/templates/client.conf.erb +0 -1
- data/puppet/templates/dtkclient.erb +0 -2
- data/spec/component_module_spec.rb +0 -34
- data/spec/dependency_spec.rb +0 -6
- data/spec/dtk_shell_spec.rb +0 -13
- data/spec/dtk_spec.rb +0 -33
- data/spec/lib/spec_helper.rb +0 -10
- data/spec/lib/spec_thor.rb +0 -108
- data/spec/node_template_spec.rb +0 -24
- data/spec/project_spec.rb +0 -6
- data/spec/repo_spec.rb +0 -7
- data/spec/response_spec.rb +0 -52
- data/spec/service_module_spec.rb +0 -38
- data/spec/service_spec.rb +0 -50
- data/spec/state_change_spec.rb +0 -7
- data/spec/table_print_spec.rb +0 -48
- data/spec/target_spec.rb +0 -57
- data/spec/task_spec.rb +0 -28
- data/views/assembly/augmented_simple_list.rb +0 -12
- data/views/assembly_template/augmented_simple_list.rb +0 -12
- data/views/list_task/augmented_simple_list.rb +0 -12
@@ -1,283 +0,0 @@
|
|
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
|
-
class Thor
|
19
|
-
class << self
|
20
|
-
# NOTE: Class is loaded automaticly in dtk-shell
|
21
|
-
|
22
|
-
@@shell_context = nil
|
23
|
-
HIDE_FROM_BASE_CONTEXT_HELP = "HIDE_FROM_BASE"
|
24
|
-
|
25
|
-
def set_context(context)
|
26
|
-
@@shell_context = context
|
27
|
-
end
|
28
|
-
|
29
|
-
def match_help_item_changes(help_item, entity_name)
|
30
|
-
help_item.first.match(/^\[?#{entity_name.upcase}.?(NAME\/ID|ID\/NAME|ID|NAME)(\-?PATTERN)?\]?/)
|
31
|
-
end
|
32
|
-
|
33
|
-
def replace_if_matched!(help_item, matched)
|
34
|
-
# change by reference
|
35
|
-
help_item.first.gsub!(matched[0],'') if matched
|
36
|
-
|
37
|
-
return help_item
|
38
|
-
end
|
39
|
-
|
40
|
-
# Method returns alternative providers
|
41
|
-
def get_alternative_identifiers(command_name)
|
42
|
-
# we check for alternate identifiers
|
43
|
-
command_clazz = ::DTK::Client::OsUtil.get_dtk_class(command_name)
|
44
|
-
|
45
|
-
if (command_clazz && command_clazz.respond_to?(:alternate_identifiers))
|
46
|
-
return command_clazz.alternate_identifiers()
|
47
|
-
end
|
48
|
-
|
49
|
-
return []
|
50
|
-
end
|
51
|
-
|
52
|
-
# Monkey path of printable task methods to include name as well
|
53
|
-
# Returns tasks ready to be printed.
|
54
|
-
def printable_tasks(all = true, subcommand = false)
|
55
|
-
(all ? all_tasks : tasks).map do |_, task|
|
56
|
-
# using HIDE_FROM_BASE to hide command from base context help (e.g from dtk:/assembly>help) ...
|
57
|
-
# but show that command in other context help (e.g in dtk:/assembly/assembly_id/utils>help)
|
58
|
-
# added (task.name.eql?('help')) to hide help from command list
|
59
|
-
next if (task.hidden? || (task.name.eql?("help")) || (task.usage.include?(HIDE_FROM_BASE_CONTEXT_HELP) && (@@shell_context ? !@@shell_context.active_context.is_n_context? : '')))
|
60
|
-
item = []
|
61
|
-
item << banner(task, false, subcommand)
|
62
|
-
item << (task.description ? "# #{task.description.gsub(/\s+/m,' ')}" : "")
|
63
|
-
item << task.name
|
64
|
-
item
|
65
|
-
end.compact
|
66
|
-
end
|
67
|
-
|
68
|
-
# method will check if help is overriden and if so it will replace help description,
|
69
|
-
# with overriden one, override_tasks => class => OverrideTasks
|
70
|
-
def overriden_help(override_tasks, help_item, is_command)
|
71
|
-
return (override_tasks && override_tasks.are_there_self_override_tasks?) ? override_tasks.check_help_item(help_item, is_command) : help_item
|
72
|
-
end
|
73
|
-
|
74
|
-
def help(shell, subcommand = false)
|
75
|
-
list = printable_tasks(true, subcommand)
|
76
|
-
|
77
|
-
Thor::Util.thor_classes_in(self).each do |klass|
|
78
|
-
list += klass.printable_tasks(false)
|
79
|
-
end
|
80
|
-
|
81
|
-
list.sort!{ |a,b| a[0] <=> b[0] }
|
82
|
-
|
83
|
-
# monkey patching here => START
|
84
|
-
if @@shell_context
|
85
|
-
unless @@shell_context.root?
|
86
|
-
|
87
|
-
active_context = @@shell_context.active_context
|
88
|
-
|
89
|
-
# first command we are using:
|
90
|
-
# e.g. dtk:\assembly\assembly1\node\node123> => command would be :assembly
|
91
|
-
command = active_context.first_command_name.upcase
|
92
|
-
|
93
|
-
# is there identifier for given commands (first)
|
94
|
-
# e.g. dtk:\assembly\assembly1\node\node123> => identifier here would be 'assembly1'
|
95
|
-
is_there_identifier = active_context.is_there_identifier_for_first_context?
|
96
|
-
|
97
|
-
# alternative providers
|
98
|
-
alt_identifiers = get_alternative_identifiers(command)
|
99
|
-
|
100
|
-
|
101
|
-
filtered_list = []
|
102
|
-
|
103
|
-
# case when we are not on first level and it is not identifier we skip help
|
104
|
-
# since it needs to be empty
|
105
|
-
# e.g. assembly/bootstrap1/node> ... HELP IS EMPTY FOR THIS
|
106
|
-
|
107
|
-
|
108
|
-
# override objects are special cases defined in Thor classes
|
109
|
-
# base on level there will be included in help context, help content is calculated by:
|
110
|
-
#
|
111
|
-
# 1) Matching help items with Regex (see bellow)
|
112
|
-
# 2) Adding help items from override_methods
|
113
|
-
#
|
114
|
-
#
|
115
|
-
override_tasks_obj = self.respond_to?(:override_allowed_methods) ? self.override_allowed_methods.dup : nil
|
116
|
-
|
117
|
-
shadow_list = ::DTK::Shell::ShadowEntity.resolve(active_context.last_context)
|
118
|
-
# N-LEVEL-CONTEXT - context that has at least 2 commands and 1 or more identifiers
|
119
|
-
# e.g. dtk:\assembly\assembly1\node> THIS IS N-LEVEL CONTEXT
|
120
|
-
# e.g. dtk:\assembly\assembly1\node\node123> THIS IS N-LEVEL CONTEXT
|
121
|
-
# e.g. dtk:\assembly\assembly1> THIS IS NOT N-LEVEL CONTEXT
|
122
|
-
#
|
123
|
-
unless shadow_list
|
124
|
-
if (!active_context.is_n_context? || active_context.current_identifier?)
|
125
|
-
|
126
|
-
list.each do |help_item|
|
127
|
-
help_item.first.gsub!("^^", '') if help_item.first.include?("^^")
|
128
|
-
|
129
|
-
# this will match entity_name (command) and alternative identifiers
|
130
|
-
identifers = [command] + alt_identifiers
|
131
|
-
|
132
|
-
# matches identifiers for ID/NAME
|
133
|
-
matched_data = help_item.first.match(/^\s\[?(#{identifers.join('|')}).?(NAME\/ID|ID\/NAME)\]?\s/)
|
134
|
-
alt_matched_data = help_item.first.match(/^\s\[?(#{alt_identifiers.join('|')}).?(NAME\/ID|ID\/NAME)\]?\s/)
|
135
|
-
|
136
|
-
if matched_data.nil?
|
137
|
-
# not found and tier 1 we add it to help list
|
138
|
-
filtered_list << overriden_help(override_tasks_obj, help_item, true) if @@shell_context.current_command?
|
139
|
-
else
|
140
|
-
# for help we only care about first context name / identifier
|
141
|
-
if !is_there_identifier
|
142
|
-
# if it contains [] it is optional and will be available on both tiers
|
143
|
-
if matched_data[0].include?('[')
|
144
|
-
# we remove it, since there is no need to use it
|
145
|
-
help_item.first.gsub!(matched_data[0],' ') unless help_item.nil?
|
146
|
-
filtered_list << overriden_help(override_tasks_obj, help_item, true)
|
147
|
-
end
|
148
|
-
else
|
149
|
-
# Adding alt identifiers here
|
150
|
-
if alt_matched_data
|
151
|
-
if active_context.current_alt_identifier?
|
152
|
-
help_item.first.gsub!(matched_data[0],'') unless help_item.nil?
|
153
|
-
filtered_list << overriden_help(override_tasks_obj, help_item, false)
|
154
|
-
end
|
155
|
-
else
|
156
|
-
unless active_context.current_alt_identifier?
|
157
|
-
help_item.first.gsub!(matched_data[0],'') unless help_item.nil?
|
158
|
-
filtered_list << overriden_help(override_tasks_obj, help_item, false)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
# This will return commands that have identifiers
|
167
|
-
# e.g. dtk:\assembly\assembly1\node\node123> => ['assembly','node']
|
168
|
-
commands_that_have_identifiers = active_context.commands_that_have_identifiers()
|
169
|
-
is_n_level_context = active_context.command_list.size > 1
|
170
|
-
|
171
|
-
# first one does not count
|
172
|
-
if is_n_level_context
|
173
|
-
# additional filter list for n-context
|
174
|
-
n_filter_list = []
|
175
|
-
# we do not need first one, since above code takes care of that one
|
176
|
-
filtered_list = filtered_list.select do |filtered_help_item|
|
177
|
-
#next unless filtered_help_item
|
178
|
-
unless commands_that_have_identifiers.empty?
|
179
|
-
commands_that_have_identifiers[1..-1].each_with_index do |entity,i|
|
180
|
-
matched = match_help_item_changes(filtered_help_item, entity)
|
181
|
-
filtered_help_item = replace_if_matched!(filtered_help_item, matched)
|
182
|
-
|
183
|
-
# if it is last command, and there were changes
|
184
|
-
if (i == (commands_that_have_identifiers.size - 2) && matched)
|
185
|
-
n_filter_list << filtered_help_item
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
if override_tasks_obj && is_n_level_context
|
192
|
-
last_entity_name = active_context.last_context_entity_name.to_sym
|
193
|
-
|
194
|
-
# special case for node_id/utils (we don't want to use utils from service context)
|
195
|
-
command_list = active_context.command_list
|
196
|
-
if (command_list.size > 2) && command_list.last.eql?('utils')
|
197
|
-
last_entity_name = command_list.last(2).join('_').to_sym
|
198
|
-
end
|
199
|
-
|
200
|
-
# we get commands task, and identifier tasks for given entity (e.g. :assembly)
|
201
|
-
command_o_tasks, identifier_o_tasks = override_tasks_obj.get_all_tasks(last_entity_name)
|
202
|
-
|
203
|
-
if active_context.current_identifier?
|
204
|
-
identifier_o_tasks.each do |o_task|
|
205
|
-
n_filter_list << [o_task[1],o_task[2]]
|
206
|
-
end
|
207
|
-
else
|
208
|
-
command_o_tasks.each do |o_task|
|
209
|
-
n_filter_list << [o_task[1],o_task[2]]
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
# we have just filtered those methods that have attribute for given entity
|
215
|
-
# and also are last in the list
|
216
|
-
filtered_list = n_filter_list
|
217
|
-
end
|
218
|
-
|
219
|
-
# remove double spaces
|
220
|
-
list = filtered_list.each { |e| e.first.gsub!(/ /,' ') }
|
221
|
-
else
|
222
|
-
list = shadow_list
|
223
|
-
end
|
224
|
-
end
|
225
|
-
else
|
226
|
-
# no dtk-shell just dtk, we make sure that underscore is not used '_'
|
227
|
-
list = list.collect do |item|
|
228
|
-
|
229
|
-
#
|
230
|
-
# e.g.
|
231
|
-
# dtk assembly_template info
|
232
|
-
# dtk assembly-template info
|
233
|
-
#
|
234
|
-
item[0] = item[0].gsub(/^dtk ([a-zA-Z]+)_([a-zA-Z]+) /,'dtk \1-\2 ')
|
235
|
-
item
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
if list.empty?
|
240
|
-
shell.say ""
|
241
|
-
shell.say "No tasks for current context '#{@@shell_context.active_context.full_path}'."
|
242
|
-
end
|
243
|
-
|
244
|
-
# remove helper 3. element in help item list
|
245
|
-
list = list.collect { |e| e[0..1] }
|
246
|
-
|
247
|
-
# monkey patching here => END
|
248
|
-
shell.print_table(list, :indent => 2, :truncate => true)
|
249
|
-
shell.say
|
250
|
-
|
251
|
-
|
252
|
-
# print sub context information
|
253
|
-
sub_children = []
|
254
|
-
|
255
|
-
# current active context clazz
|
256
|
-
if @@shell_context
|
257
|
-
last_command_name = @@shell_context.active_context.last_command_name
|
258
|
-
command_clazz = DTK::Shell::Context.get_command_class(last_command_name)
|
259
|
-
|
260
|
-
if @@shell_context && @@shell_context.active_context.current_identifier?
|
261
|
-
sub_children += command_clazz.valid_children() if command_clazz.respond_to?(:valid_children)
|
262
|
-
sub_children += command_clazz.invisible_context_list()
|
263
|
-
# remove utils subcontext from help in service/service_name/node_group only
|
264
|
-
if @@shell_context.active_context.last_context_is_shadow_entity? && @@shell_context.active_context.shadow_entity().eql?('node_group')
|
265
|
-
sub_children.delete(:utils)
|
266
|
-
end
|
267
|
-
else
|
268
|
-
if command_clazz.respond_to?(:validation_list)
|
269
|
-
sub_children += ["#{last_command_name}-identifier"]
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
unless sub_children.empty?
|
274
|
-
shell.say(" Change context (cc) to: #{sub_children.join(', ')}", :BOLD)
|
275
|
-
shell.say
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
|
280
|
-
class_options_help(shell)
|
281
|
-
end
|
282
|
-
end
|
283
|
-
end
|
@@ -1,256 +0,0 @@
|
|
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 'colorize'
|
19
|
-
require 'readline'
|
20
|
-
require 'highline/import'
|
21
|
-
|
22
|
-
module DTK
|
23
|
-
module Shell
|
24
|
-
|
25
|
-
|
26
|
-
# we use interactive wizard to give user opertunity
|
27
|
-
class InteractiveWizard
|
28
|
-
|
29
|
-
PP_LINE_HEAD = '--------------------------------- DATA ---------------------------------'
|
30
|
-
PP_LINE = '------------------------------------------------------------------------'
|
31
|
-
INVALID_INPUT = Client::OsUtil.colorize(" Input is not valid. ", :yellow)
|
32
|
-
EC2_REGIONS = ['us-east-1','us-west-1','us-west-2','eu-west-1','sa-east-1','ap-northeast-1','ap-southeast-1','ap-southeast-2' ]
|
33
|
-
|
34
|
-
|
35
|
-
def initialize
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.validate_region(region)
|
39
|
-
unless EC2_REGIONS.include? region
|
40
|
-
raise ::DTK::Client::DtkValidationError.new("Region '#{region}' is not EC2 region, use one of: #{EC2_REGIONS.join(',')}")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# Generic wizard which will return hash map based on metadata input
|
45
|
-
#
|
46
|
-
# Example provided bellow
|
47
|
-
#
|
48
|
-
def self.interactive_user_input(wizard_dsl, recursion_call = false)
|
49
|
-
results = {}
|
50
|
-
wizard_dsl = [wizard_dsl].flatten
|
51
|
-
begin
|
52
|
-
wizard_dsl.each do |meta_input|
|
53
|
-
input_name = meta_input.keys.first
|
54
|
-
display_name = input_name.to_s.gsub(/_/,' ').capitalize
|
55
|
-
metadata = meta_input.values.first
|
56
|
-
|
57
|
-
# default values
|
58
|
-
output = display_name
|
59
|
-
validation = metadata[:validation]
|
60
|
-
is_password = false
|
61
|
-
is_required = metadata[:requried]
|
62
|
-
|
63
|
-
case metadata[:type]
|
64
|
-
when nil
|
65
|
-
when :email
|
66
|
-
validation = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
|
67
|
-
when :question
|
68
|
-
output = "#{metadata[:question]}"
|
69
|
-
validation = metadata[:validation]
|
70
|
-
when :password
|
71
|
-
is_password = true
|
72
|
-
is_required = true
|
73
|
-
when :repeat_password
|
74
|
-
is_password = true
|
75
|
-
is_required = true
|
76
|
-
validation = /^#{results[:password]}$/
|
77
|
-
when :selection
|
78
|
-
options = ""
|
79
|
-
display_field = metadata[:display_field]
|
80
|
-
metadata[:options].each_with_index do |o,i|
|
81
|
-
if display_field
|
82
|
-
options += "\t#{i+1}. #{o[display_field]}\n"
|
83
|
-
else
|
84
|
-
options += "\t#{i+1}. #{o}\n"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
options += DTK::Client::OsUtil.colorize("\t0. Skip\n", :yellow) if metadata[:skip_option]
|
88
|
-
output = "Select '#{display_name}': \n\n #{options} \n "
|
89
|
-
validation_range_start = metadata[:skip_option] ? 0 : 1
|
90
|
-
validation = (validation_range_start..metadata[:options].size).to_a
|
91
|
-
when :group
|
92
|
-
# recursion call to populate second level of hash params
|
93
|
-
puts " Enter '#{display_name}': "
|
94
|
-
results[input_name] = self.interactive_user_input(metadata[:options], true)
|
95
|
-
next
|
96
|
-
end
|
97
|
-
|
98
|
-
input = text_input(output, is_required, validation, is_password)
|
99
|
-
|
100
|
-
if metadata[:required_options] && !metadata[:required_options].include?(input)
|
101
|
-
# case where we have to give explicit permission, if answer is not affirmative
|
102
|
-
# we terminate rest of the wizard
|
103
|
-
DTK::Client::OsUtil.print(" #{metadata[:explanation]}", :red)
|
104
|
-
return nil
|
105
|
-
end
|
106
|
-
|
107
|
-
# post processing
|
108
|
-
if metadata[:type] == :selection
|
109
|
-
input = input.to_i == 0 ? nil : metadata[:options][input.to_i - 1]
|
110
|
-
end
|
111
|
-
|
112
|
-
results[input_name] = input
|
113
|
-
end
|
114
|
-
|
115
|
-
return results
|
116
|
-
rescue Interrupt => e
|
117
|
-
puts
|
118
|
-
raise DTK::Client::DtkValidationError, "Exiting the wizard ..."
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def self.text_input(output, is_required = false, validation_regex = nil, is_password = false)
|
123
|
-
while line = ask("#{output}: ") { |q| q.echo = !is_password }
|
124
|
-
if is_required && line.strip.empty?
|
125
|
-
puts Client::OsUtil.colorize("Field '#{output}' is required field. ", :red)
|
126
|
-
next
|
127
|
-
end
|
128
|
-
|
129
|
-
if validation_regex && !validation_regex.match(line)
|
130
|
-
puts Client::OsUtil.colorize("Input is not valid, please enter it again. ", :red)
|
131
|
-
next
|
132
|
-
end
|
133
|
-
|
134
|
-
return line
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
|
139
|
-
# takes hash maps with description of missing params and
|
140
|
-
# returns array of hash map with key, value for each missed param
|
141
|
-
def self.resolve_missing_params(param_list, additional_message = nil)
|
142
|
-
begin
|
143
|
-
user_provided_params, checkup_hash = [], {}
|
144
|
-
|
145
|
-
puts "\nPlease fill in missing data.\n"
|
146
|
-
param_list.each do |param_info|
|
147
|
-
description =
|
148
|
-
if param_info['display_name'] =~ Regexp.new(param_info['description'])
|
149
|
-
param_info['display_name']
|
150
|
-
else
|
151
|
-
"#{param_info['display_name']} (#{param_info['description']})"
|
152
|
-
end
|
153
|
-
datatype_info = (param_info['datatype'] ? DTK::Client::OsUtil.colorize(" [#{param_info['datatype'].upcase}]", :yellow) : '')
|
154
|
-
string_identifier = DTK::Client::OsUtil.colorize(description, :green) + datatype_info
|
155
|
-
|
156
|
-
puts "Please enter #{string_identifier}:"
|
157
|
-
while line = Readline.readline(": ", true)
|
158
|
-
id = param_info['id']
|
159
|
-
user_provided_params << {:id => id, :value => line, :display_name => param_info['display_name']}
|
160
|
-
checkup_hash[id] = {:value => line, :description => description}
|
161
|
-
break
|
162
|
-
end
|
163
|
-
|
164
|
-
end
|
165
|
-
|
166
|
-
# pp print for provided parameters
|
167
|
-
pretty_print_provided_user_info(checkup_hash)
|
168
|
-
|
169
|
-
# make sure this is satisfactory
|
170
|
-
while line = Readline.readline("Is provided information ok? (yes|no) ", true)
|
171
|
-
# start all over again
|
172
|
-
return resolve_missing_params(param_list) if 'no'.eql? line
|
173
|
-
# continue with the code
|
174
|
-
break if 'yes'.eql? line
|
175
|
-
end
|
176
|
-
|
177
|
-
rescue Interrupt => e
|
178
|
-
puts
|
179
|
-
# TODO: Provide original error here
|
180
|
-
raise DTK::Client::DtkError::InteractiveWizardError, "You have decided to skip correction wizard.#{additional_message}"
|
181
|
-
end
|
182
|
-
|
183
|
-
return user_provided_params
|
184
|
-
end
|
185
|
-
|
186
|
-
private
|
187
|
-
|
188
|
-
def self.pretty_print_provided_user_info(user_information)
|
189
|
-
puts PP_LINE_HEAD
|
190
|
-
user_information.each do |key,info|
|
191
|
-
description = info[:description]
|
192
|
-
value = info[:value]
|
193
|
-
printf "%48s : %s\n", DTK::Client::OsUtil.colorize(description, :green), DTK::Client::OsUtil.colorize(value, :yellow)
|
194
|
-
end
|
195
|
-
puts PP_LINE
|
196
|
-
puts
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
## EXAMPLE OF USAGE
|
203
|
-
|
204
|
-
# Example 1. Creating target via wizard
|
205
|
-
=begin
|
206
|
-
desc "create","Wizard that will guide you trough creation of target and target-template"
|
207
|
-
def create(context_params)
|
208
|
-
|
209
|
-
# we get existing templates
|
210
|
-
target_templates = post rest_url("target/list"), { :subtype => :template }
|
211
|
-
|
212
|
-
# ask user to select target template
|
213
|
-
wizard_params = [{:target_template => { :type => :selection, :options => target_templates['data'], :display_field => 'display_name', :skip_option => true }}]
|
214
|
-
target_template_selected = DTK::Shell::InteractiveWizard.interactive_user_input(wizard_params)
|
215
|
-
target_template_id = (target_template_selected[:target_template]||{})['id']
|
216
|
-
|
217
|
-
wizard_params = [
|
218
|
-
{:target_name => {}},
|
219
|
-
{:description => {:optional => true }}
|
220
|
-
]
|
221
|
-
|
222
|
-
if target_template_id.nil?
|
223
|
-
# in case user has not selected template id we will needed information to create target
|
224
|
-
wizard_params.concat([
|
225
|
-
{:iaas_type => { :type => :selection, :options => [:ec2] }},
|
226
|
-
{:aws_install => { :type => :question,
|
227
|
-
:question => "Do we have your permission to add necessery 'key-pair' and 'security-group' to your EC2 account?",
|
228
|
-
:options => ["yes","no"],
|
229
|
-
:required_options => ["yes"],
|
230
|
-
:explanation => "This permission is necessary for creation of a custom target."
|
231
|
-
}},
|
232
|
-
{:iaas_properties => { :type => :group, :options => [
|
233
|
-
{:key => {}},
|
234
|
-
{:secret => {}},
|
235
|
-
{:region => {:type => :selection, :options => DTK::Shell::InteractiveWizard::EC2_REGIONS}},
|
236
|
-
]}},
|
237
|
-
])
|
238
|
-
end
|
239
|
-
|
240
|
-
post_body = DTK::Shell::InteractiveWizard.interactive_user_input(wizard_params)
|
241
|
-
post_body ||= {}
|
242
|
-
|
243
|
-
# this means that user has not given permission so we skip request
|
244
|
-
return unless (target_template_id || post_body[:aws_install])
|
245
|
-
|
246
|
-
# in case user chose target ID
|
247
|
-
post_body.merge!(:target_template_id => target_template_id) if target_template_id
|
248
|
-
|
249
|
-
|
250
|
-
response = post rest_url("target/create"), post_body
|
251
|
-
# when changing context send request for getting latest targets instead of getting from cache
|
252
|
-
@@invalidate_map << :target
|
253
|
-
|
254
|
-
return response
|
255
|
-
end
|
256
|
-
=end
|
data/lib/shell/message_queue.rb
DELETED
@@ -1,63 +0,0 @@
|
|
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
|
-
# TODO-REMOVE: Check if we need this anymore
|
19
|
-
|
20
|
-
dtk_require_from_base('util/os_util')
|
21
|
-
|
22
|
-
module DTK
|
23
|
-
module Shell
|
24
|
-
class MessageQueue
|
25
|
-
include Singleton
|
26
|
-
|
27
|
-
MESSAGE_TYPES = [:info, :warn, :error]
|
28
|
-
|
29
|
-
def initialize
|
30
|
-
@queue = {}
|
31
|
-
init_or_clear()
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.process_response(response_obj)
|
35
|
-
self.instance.process_response(response_obj)
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.print_messages()
|
39
|
-
self.instance.print_messages()
|
40
|
-
end
|
41
|
-
|
42
|
-
def init_or_clear()
|
43
|
-
MESSAGE_TYPES.each { |msg_type| @queue[msg_type] = [] }
|
44
|
-
end
|
45
|
-
|
46
|
-
def print_messages()
|
47
|
-
@queue[:info].each { |msg| DTK::Client::OsUtil.print(msg, :white) }
|
48
|
-
@queue[:warn].each { |msg| DTK::Client::OsUtil.print(msg, :yellow) }
|
49
|
-
@queue[:error].each { |msg| DTK::Client::OsUtil.print(msg, :red) }
|
50
|
-
|
51
|
-
init_or_clear()
|
52
|
-
end
|
53
|
-
|
54
|
-
def process_response(response_obj)
|
55
|
-
MESSAGE_TYPES.each do |msg_type|
|
56
|
-
msg = response_obj[msg_type.to_s] || response_obj[msg_type]
|
57
|
-
@queue[msg_type] << msg if msg
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|