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
@@ -0,0 +1,106 @@
|
|
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 'singleton'
|
19
|
+
|
20
|
+
module DTK::Client
|
21
|
+
##
|
22
|
+
# Singleton patern to hold configuration for dtk client.
|
23
|
+
#
|
24
|
+
class Config < Hash
|
25
|
+
include Singleton
|
26
|
+
|
27
|
+
def self.[](k)
|
28
|
+
instance[k.to_s]
|
29
|
+
end
|
30
|
+
|
31
|
+
CLIENT_CONF = 'client.conf'
|
32
|
+
DEFAULT_CONF_FILE_PATH = File.expand_path('config/default.conf', File.dirname(__FILE__))
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def initialize
|
37
|
+
set_defaults!
|
38
|
+
load_config_file_values!
|
39
|
+
validate
|
40
|
+
end
|
41
|
+
|
42
|
+
def set_defaults!
|
43
|
+
merge_config_file_content_into_hash!(DEFAULT_CONF_FILE_PATH)
|
44
|
+
end
|
45
|
+
|
46
|
+
def load_config_file_values!
|
47
|
+
client_config_path = Configurator.client_config_path
|
48
|
+
merge_config_file_content_into_hash!(client_config_path) if File.exist?(client_config_path)
|
49
|
+
end
|
50
|
+
|
51
|
+
REQUIRED_KEYS = ['server_host']
|
52
|
+
def validate
|
53
|
+
# TODO: along with checking for missing keys should check for legal values
|
54
|
+
missing_keys = REQUIRED_KEYS - keys
|
55
|
+
unless missing_keys.empty?
|
56
|
+
raise Error::Usage, "Missing config keys (#{missing_keys.join(", ")}) in client config file '#{Configurator.client_config_path}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def merge_config_file_content_into_hash!(path)
|
61
|
+
merge!(parse_string_content(File.read(path)))
|
62
|
+
end
|
63
|
+
|
64
|
+
# returns a hash
|
65
|
+
def parse_string_content(string)
|
66
|
+
ret = {}
|
67
|
+
string.each_line do |line|
|
68
|
+
line.strip!
|
69
|
+
# strip off comment
|
70
|
+
line.gsub!(/#.+$/,'')
|
71
|
+
# remove control characters
|
72
|
+
line.gsub!(/\t/,'')
|
73
|
+
# below strips blanks after and before '='
|
74
|
+
if line =~ /(^[^=]+)[ ]*=[ ]*(.+$)/
|
75
|
+
attr = $1
|
76
|
+
val_string = $2
|
77
|
+
ret.merge!(attr => parse_value_string(val_string))
|
78
|
+
else
|
79
|
+
# skipping any line that does not parse
|
80
|
+
end
|
81
|
+
end
|
82
|
+
ret
|
83
|
+
end
|
84
|
+
|
85
|
+
def parse_value_string(val_string)
|
86
|
+
# remove trailing blanks
|
87
|
+
val_string = val_string.gsub(/[ ]+$/,'')
|
88
|
+
convert_data_types(val_string)
|
89
|
+
end
|
90
|
+
|
91
|
+
def convert_data_types(val_string)
|
92
|
+
case val_string
|
93
|
+
when /^(true|false)$/
|
94
|
+
val_string.eql?('true') ? true : false
|
95
|
+
when /^[0-9]+$/
|
96
|
+
val_string.to_i
|
97
|
+
when /^[0-9\.]+$/
|
98
|
+
# making sure dont do something like '10.0.0.1'.to_f
|
99
|
+
val_string.split('.').size == 2 ? val_string.to_f : val_string
|
100
|
+
else
|
101
|
+
val_string
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
@@ -0,0 +1,182 @@
|
|
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
|
+
module DTK::Client
|
20
|
+
module Configurator
|
21
|
+
CONFIG_FILE = File.join(DtkPath.base_dir, 'client.conf')
|
22
|
+
CRED_FILE = File.join(DtkPath.base_dir, '.connection')
|
23
|
+
DIRECT_ACCESS = File.join(DtkPath.base_dir, '.add_direct_access')
|
24
|
+
NODE_SSH_CREDENTIALS = File.join(DtkPath.base_dir, 'ssh_credentials.yaml')
|
25
|
+
|
26
|
+
def self.client_config_path
|
27
|
+
CONFIG_FILE
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_credentials
|
31
|
+
cred_file = CRED_FILE
|
32
|
+
raise Error, "Authorization configuration file (#{cred_file}) does not exist" unless File.exists?(cred_file)
|
33
|
+
ret = parse_key_value_file(cred_file)
|
34
|
+
[:username, :password].each{ |k| raise Error, "cannot find #{k}" unless ret[k] }
|
35
|
+
ret
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.create_missing_client_dirs
|
39
|
+
base_dir = DtkPath.base_dir
|
40
|
+
FileUtils.mkdir(base_dir) unless File.directory?(base_dir)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.check_config_exists
|
44
|
+
exists = true
|
45
|
+
if !File.exists?(client_config_path)
|
46
|
+
puts "", "Please enter the DTK server address (example: instance.dtk.io)"
|
47
|
+
header = File.read(Config::DEFAULT_CONF_FILE_PATH)
|
48
|
+
generate_conf_file(client_config_path, [['server_host', 'Server address']], header)
|
49
|
+
exists = false
|
50
|
+
end
|
51
|
+
if !File.exists?(CRED_FILE)
|
52
|
+
puts "", "Please enter your DTK login details"
|
53
|
+
generate_conf_file(CRED_FILE, [['username', 'Username'], ['password', 'Password']], '')
|
54
|
+
exists = false
|
55
|
+
end
|
56
|
+
|
57
|
+
exists
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.check_git
|
61
|
+
if OsUtil.which('git') == nil
|
62
|
+
OsUtil.put_warning "[WARNING]", "Can't find the 'git' command in you path. Please make sure git is installed in order to use all features of DTK Client.", :yellow
|
63
|
+
else
|
64
|
+
OsUtil.put_warning "[WARNING]", 'Git username not set. This can cause issues while using DTK Client. To set it, run `git config --global user.name "User Name"`', :yellow if `git config --get user.name` == ""
|
65
|
+
OsUtil.put_warning "[WARNING]", 'Git email not set. This can cause issues while using DTK Client. To set it, run `git config --global user.email "me@here.com"`', :yellow if `git config --get user.email` == ""
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# return true/false, .add_direct_access file location and ssk key file location
|
70
|
+
def self.check_direct_access
|
71
|
+
username_exists = check_for_username_entry(client_username)
|
72
|
+
ssh_key_path = SSHUtil.default_rsa_pub_key_path
|
73
|
+
|
74
|
+
{:username_exists => username_exists, :file_path => DIRECT_ACCESS, :ssh_key_path => ssh_key_path}
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.regenerate_conf_file(file_path, properties, header)
|
78
|
+
File.open(file_path, 'w') do |f|
|
79
|
+
f.puts(header)
|
80
|
+
properties.each do |prop|
|
81
|
+
f.puts("#{prop[0]}=#{prop[1]}")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.parse_key_value_file(file)
|
87
|
+
# adapted from mcollective config
|
88
|
+
ret = Hash.new
|
89
|
+
raise Error,"Config file (#{file}) does not exists" unless File.exists?(file)
|
90
|
+
File.open(file).each do |line|
|
91
|
+
# strip blank spaces, tabs etc off the end of all lines
|
92
|
+
line.gsub!(/\s*$/, "")
|
93
|
+
unless line =~ /^#|^$/
|
94
|
+
if (line =~ /(.+?)\s*=\s*(.+)/)
|
95
|
+
key = $1
|
96
|
+
val = $2
|
97
|
+
ret[key.to_sym] = val
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
ret
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.add_current_user_to_direct_access
|
105
|
+
username = client_username
|
106
|
+
|
107
|
+
File.open(DIRECT_ACCESS, 'a') do |file|
|
108
|
+
file.puts(username)
|
109
|
+
end
|
110
|
+
|
111
|
+
true
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.client_username
|
115
|
+
parse_key_value_file(CRED_FILE)[:username]
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# Method will check if there is username entry in DIRECT_ACCESS file
|
120
|
+
#
|
121
|
+
def self.check_for_username_entry(username)
|
122
|
+
if File.exists?(DIRECT_ACCESS)
|
123
|
+
File.open(DIRECT_ACCESS).each do |line|
|
124
|
+
if line.strip.eql?(username)
|
125
|
+
return true
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
false
|
131
|
+
end
|
132
|
+
|
133
|
+
def self.ask_catalog_credentials
|
134
|
+
are_there_creds = Console.prompt_yes_no("Do you have DTK catalog credentials?", :add_options => true)
|
135
|
+
property_template = {}
|
136
|
+
if are_there_creds
|
137
|
+
property_template = self.enter_catalog_credentials
|
138
|
+
end
|
139
|
+
|
140
|
+
property_template
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.enter_catalog_credentials
|
144
|
+
property_template = {}
|
145
|
+
# needed to preserve the order for ruby 1.8.7
|
146
|
+
# ruby 1.8 does not preserve order of insertation
|
147
|
+
wizard_values = { :username => 'Catalog Username', :password => 'Catalog Password' }
|
148
|
+
[:username, :password].each do |p|
|
149
|
+
value = ask("#{wizard_values[p]}: ") { |q| q.echo = false if p == :password }
|
150
|
+
property_template.store(p, value)
|
151
|
+
end
|
152
|
+
property_template
|
153
|
+
end
|
154
|
+
|
155
|
+
private
|
156
|
+
|
157
|
+
def self.generate_conf_file(file_path, properties, header)
|
158
|
+
require 'highline/import'
|
159
|
+
property_template = []
|
160
|
+
|
161
|
+
properties.each do |p,d|
|
162
|
+
begin
|
163
|
+
trap("INT") {
|
164
|
+
puts "", "Exiting..."
|
165
|
+
abort
|
166
|
+
}
|
167
|
+
end
|
168
|
+
value = ask("#{d}: ") { |q| q.echo = false if p == 'password'}
|
169
|
+
property_template << [p,value]
|
170
|
+
end
|
171
|
+
|
172
|
+
File.open(file_path, 'w') do |f|
|
173
|
+
f.puts(header)
|
174
|
+
property_template.each do |prop|
|
175
|
+
f.puts("#{prop[0]}=#{prop[1]}")
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
end
|
182
|
+
end
|
data/lib/client/conn.rb
ADDED
@@ -0,0 +1,197 @@
|
|
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 Conn
|
21
|
+
def initialize
|
22
|
+
@cookies = {}
|
23
|
+
@connection_error = nil
|
24
|
+
login
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :connection_error, :cookies
|
28
|
+
|
29
|
+
def self.get_timeout
|
30
|
+
default_rest_opts[:timeout]
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.set_timeout(timeout_sec)
|
34
|
+
default_rest_opts[:timeout] = timeout_sec
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_username
|
38
|
+
get_credentials[:username]
|
39
|
+
end
|
40
|
+
|
41
|
+
def get(route, query_string_hash = {})
|
42
|
+
url = rest_url(route)
|
43
|
+
ap "GET #{url}" if verbose_mode_on?
|
44
|
+
|
45
|
+
check_and_wrap_response { json_parse_if_needed(get_raw(url, query_string_hash)) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def post(route, post_body = {})
|
49
|
+
url = rest_url(route)
|
50
|
+
if verbose_mode_on?
|
51
|
+
ap "POST (REST) #{url}"
|
52
|
+
ap "params: "
|
53
|
+
ap post_body
|
54
|
+
end
|
55
|
+
|
56
|
+
check_and_wrap_response { json_parse_if_needed(post_raw(url, post_body)) }
|
57
|
+
end
|
58
|
+
|
59
|
+
def post_file(route, post_body = {})
|
60
|
+
url = rest_url(route)
|
61
|
+
if verbose_mode_on?
|
62
|
+
ap "POST (FILE) #{url}"
|
63
|
+
ap "params: "
|
64
|
+
ap post_body
|
65
|
+
end
|
66
|
+
|
67
|
+
check_and_wrap_response { json_parse_if_needed(post_raw(url,post_body,{:content_type => 'avro/binary'})) }
|
68
|
+
end
|
69
|
+
|
70
|
+
def connection_error?
|
71
|
+
!@connection_error.nil?
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# Method will warn user that connection could not be established. User should check configuration
|
76
|
+
# to make sure that connection is properly set.
|
77
|
+
#
|
78
|
+
def print_warning
|
79
|
+
creds = get_credentials
|
80
|
+
puts "[ERROR] Unable to connect to server, please check you configuration."
|
81
|
+
puts "========================== Configuration =========================="
|
82
|
+
printf "%15s %s\n", "REST endpoint:", rest_url
|
83
|
+
printf "%15s %s\n", "Username:", "#{creds[:username]}"
|
84
|
+
printf "%15s %s\n", "Password:", "#{creds[:password] ? creds[:password].gsub(/./,'*') : 'No password set'}"
|
85
|
+
puts "==================================================================="
|
86
|
+
|
87
|
+
if connection_error['errors'].first['errors']
|
88
|
+
error_code = self.connection_error['errors'].first['errors'].first['code']
|
89
|
+
OsUtil.print_error("Error code: #{error_code}")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
REST_VERSION = 'v1'
|
96
|
+
REST_PREFIX = "rest/api/#{REST_VERSION}"
|
97
|
+
# REST_PREFIX = "rest"
|
98
|
+
|
99
|
+
def rest_url(route = nil)
|
100
|
+
"#{rest_url_base}/#{REST_PREFIX}/#{route}"
|
101
|
+
end
|
102
|
+
|
103
|
+
def rest_url_base
|
104
|
+
@@rest_url_base ||= get_rest_url_base
|
105
|
+
end
|
106
|
+
|
107
|
+
def get_rest_url_base
|
108
|
+
protocol, port =
|
109
|
+
if "#{Config[:secure_connection]}" == 'true'
|
110
|
+
['https', Config[:secure_connection_server_port].to_s]
|
111
|
+
else
|
112
|
+
['http', Config[:server_port].to_s]
|
113
|
+
end
|
114
|
+
"#{protocol}://#{Config[:server_host]}:#{port}"
|
115
|
+
end
|
116
|
+
|
117
|
+
# method will repeat request in case session has expired
|
118
|
+
def check_and_wrap_response(&rest_method_func)
|
119
|
+
response = rest_method_func.call
|
120
|
+
|
121
|
+
if Response::ErrorHandler.check_for_session_expiried(response)
|
122
|
+
# re-logging user and repeating request
|
123
|
+
OsUtil.print_warning("Session expired: re-establishing session & re-trying request ...")
|
124
|
+
@cookies = Session.re_initialize
|
125
|
+
response = rest_method_func.call
|
126
|
+
end
|
127
|
+
|
128
|
+
response_obj = Response.new(response)
|
129
|
+
|
130
|
+
# queue messages from server to be displayed later
|
131
|
+
#TODO: DTK-2554: put in processing of messages Shell::MessageQueue.process_response(response_obj)
|
132
|
+
response_obj
|
133
|
+
end
|
134
|
+
|
135
|
+
def verbose_mode_on?
|
136
|
+
if @verbose_mode_on.nil?
|
137
|
+
if @verbose_mode_on ||= !!Config[:verbose_rest_calls]
|
138
|
+
require 'ap'
|
139
|
+
end
|
140
|
+
end
|
141
|
+
@verbose_mode_on
|
142
|
+
end
|
143
|
+
|
144
|
+
def login
|
145
|
+
response = post_raw rest_url('auth/login'), get_credentials
|
146
|
+
if response.kind_of?(::DTK::Common::Response) and ! response.ok?
|
147
|
+
@connection_error = response
|
148
|
+
else
|
149
|
+
@cookies = response.cookies
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def logout
|
154
|
+
response = get_raw rest_url('auth/logout')
|
155
|
+
# TODO: see if response can be nil
|
156
|
+
raise Error, "Failed to logout, and terminate session!" unless response
|
157
|
+
@cookies = nil
|
158
|
+
end
|
159
|
+
|
160
|
+
def set_credentials(username, password)
|
161
|
+
@parsed_credentials = { :username => username, :password => password}
|
162
|
+
end
|
163
|
+
|
164
|
+
def get_credentials
|
165
|
+
@parsed_credentials ||= Configurator.get_credentials
|
166
|
+
end
|
167
|
+
|
168
|
+
def default_rest_opts
|
169
|
+
@default_rest_opts ||= get_default_rest_opts
|
170
|
+
end
|
171
|
+
|
172
|
+
def get_default_rest_opts
|
173
|
+
# In development mode we want bigger timeout allowing us to debbug on server while still
|
174
|
+
# keeping connection alive and receivinga response
|
175
|
+
timeout = Config[:development_mode] ? 2000 : 150
|
176
|
+
{
|
177
|
+
:timeout => timeout,
|
178
|
+
:open_timeout => 10,
|
179
|
+
:verify_ssl => OpenSSL::SSL::VERIFY_PEER,
|
180
|
+
:ssl_ca_file => File.expand_path('../client/config/cacert.pem', File.dirname(__FILE__)),
|
181
|
+
}
|
182
|
+
end
|
183
|
+
|
184
|
+
def get_raw(url, query_string_hash = {})
|
185
|
+
Response::RestClientWrapper.get_raw(url, query_string_hash, default_rest_opts.merge(:cookies => @cookies))
|
186
|
+
end
|
187
|
+
|
188
|
+
def post_raw(url, post_body, params = {})
|
189
|
+
Response::RestClientWrapper.post_raw(url, post_body, default_rest_opts.merge(:cookies => @cookies).merge(params))
|
190
|
+
end
|
191
|
+
|
192
|
+
def json_parse_if_needed(item)
|
193
|
+
Response::RestClientWrapper.json_parse_if_needed(item)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
@@ -0,0 +1,127 @@
|
|
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 'yaml'
|
19
|
+
|
20
|
+
module DTK::Client
|
21
|
+
# Abstract class that holds classes and methods for xecuting commands by
|
22
|
+
# make calls to server and performing client side operations
|
23
|
+
class ContentGenerator
|
24
|
+
def initialize(content_dir, module_ref, version)
|
25
|
+
@content_dir = content_dir
|
26
|
+
@module_ref = module_ref
|
27
|
+
@version = version
|
28
|
+
@directory_content = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def generate_module_content
|
32
|
+
module_hash = {
|
33
|
+
'dsl_version' => '1.0.0',
|
34
|
+
'module' => "#{@module_ref.namespace}/#{@module_ref.module_name}",
|
35
|
+
'version' => @version || 'master'
|
36
|
+
}
|
37
|
+
|
38
|
+
if dependencies = ret_dependencies_hash
|
39
|
+
module_hash.merge!('dependencies' => dependencies)
|
40
|
+
end
|
41
|
+
|
42
|
+
if assemblies = ret_assemblies_hash
|
43
|
+
module_hash.merge!('assemblies' => assemblies)
|
44
|
+
end
|
45
|
+
|
46
|
+
module_hash
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def get_raw_content?(file_path)
|
52
|
+
File.open(file_path).read if file_path and File.exists?(file_path)
|
53
|
+
end
|
54
|
+
|
55
|
+
def convert_file_content_to_hash(file_path)
|
56
|
+
begin
|
57
|
+
YAML.load(get_raw_content?(file_path))
|
58
|
+
rescue Exception => e
|
59
|
+
yaml_err_msg = e.message.gsub(/\(<unknown>\): /,'').capitalize
|
60
|
+
raise Error::Usage, "YAML parsing error in '#{file_path}':\n#{yaml_err_msg}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_directory_content
|
65
|
+
@directory_content ||= Dir.glob("#{@content_dir}/**/*")
|
66
|
+
end
|
67
|
+
|
68
|
+
def invalidate_directory_content
|
69
|
+
@directory_content = Dir.glob("#{@content_dir}/**/*")
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_assembly_files
|
73
|
+
get_directory_content.select { |f| f =~ AssemblyRegexp[:regexp] || f =~ AssemblyRegexp[:legacy_regexp] }
|
74
|
+
end
|
75
|
+
AssemblyRegexp = {
|
76
|
+
:regexp => Regexp.new("assemblies/(.*)\.dtk\.assembly\.(yml|yaml)$"),
|
77
|
+
:legacy_regexp => Regexp.new("assemblies/([^/]+)/assembly\.(yml|yaml)$")
|
78
|
+
}
|
79
|
+
|
80
|
+
def get_module_refs_file
|
81
|
+
get_directory_content.find { |f| f =~ ModuleRefsRegexp[:regexp] }
|
82
|
+
end
|
83
|
+
ModuleRefsRegexp = {
|
84
|
+
:regexp => Regexp.new("module_refs\.(yml|yaml)$")
|
85
|
+
}
|
86
|
+
|
87
|
+
def ret_assemblies_hash
|
88
|
+
assemblies = {}
|
89
|
+
|
90
|
+
get_assembly_files.each do |assembly|
|
91
|
+
content_hash = convert_file_content_to_hash(assembly)
|
92
|
+
name = content_hash['name']
|
93
|
+
assembly_content = content_hash['assembly']
|
94
|
+
workflows = ret_workflows_hash(content_hash['workflow'])
|
95
|
+
|
96
|
+
assembly_content.merge!('workflows' => workflows) if workflows
|
97
|
+
assemblies.merge!(name => assembly_content)
|
98
|
+
end
|
99
|
+
|
100
|
+
assemblies.empty? ? nil : assemblies
|
101
|
+
end
|
102
|
+
|
103
|
+
def ret_workflows_hash(workflow)
|
104
|
+
return if workflow.nil? || workflow.empty?
|
105
|
+
workflow_name = workflow.delete('assembly_action')
|
106
|
+
{
|
107
|
+
workflow_name => workflow
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
def ret_dependencies_hash
|
112
|
+
if file_path = get_module_refs_file
|
113
|
+
module_refs_content = convert_file_content_to_hash(file_path)
|
114
|
+
dependencies = []
|
115
|
+
|
116
|
+
if cmp_dependencies = module_refs_content['component_modules']
|
117
|
+
cmp_dependencies.each_pair do |name, namespace_h|
|
118
|
+
dependencies << "#{namespace_h['namespace']}/#{name}"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
dependencies
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|