dtk-shell 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/lib/violation.rb
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
class Violation
|
|
21
|
+
dtk_require('violation/attribute')
|
|
22
|
+
dtk_require('violation/fix')
|
|
23
|
+
|
|
24
|
+
# fix must be before the specific violations
|
|
25
|
+
dtk_require('violation/sub_classes')
|
|
26
|
+
|
|
27
|
+
def initialize(service_id, violation_hash)
|
|
28
|
+
@service_id = service_id
|
|
29
|
+
@description = violation_hash['description']
|
|
30
|
+
end
|
|
31
|
+
private :initialize
|
|
32
|
+
|
|
33
|
+
def self.fix_violations(service_id, violation_hash_array)
|
|
34
|
+
violation_objects = violation_hash_array.map { |violation_hash| Violation.create?(service_id, violation_hash) }.compact
|
|
35
|
+
if violation_objects.empty?
|
|
36
|
+
Fix::Result.ok
|
|
37
|
+
else
|
|
38
|
+
run_fix_wizard(violation_objects)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def self.create?(service_id, violation_hash)
|
|
45
|
+
unless violation_type = violation_hash['type']
|
|
46
|
+
DtkLogger.error "No type in violation hash: #{violation_hash.inspect}"
|
|
47
|
+
return nil
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
case violation_type
|
|
51
|
+
when 'required_unset_attribute'
|
|
52
|
+
RequiredUnsetAttribute.new(service_id, violation_hash)
|
|
53
|
+
when 'illegal_attribute_value'
|
|
54
|
+
IllegalAttributeValue.new(service_id, violation_hash)
|
|
55
|
+
when 'invalid_credentials'
|
|
56
|
+
InvalidCredentials.new(service_id, violation_hash)
|
|
57
|
+
else
|
|
58
|
+
DtkLogger.error "untreated violation type '#{violation_type}'"
|
|
59
|
+
nil
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def self.run_fix_wizard(violation_objects)
|
|
64
|
+
rerun_violation_check = false
|
|
65
|
+
violation_objects.each do |violation|
|
|
66
|
+
result = run_and_repeat_when_error(violation)
|
|
67
|
+
return result if result.skip_all?
|
|
68
|
+
rerun_violation_check = true if result.rerun_violation_check?
|
|
69
|
+
end
|
|
70
|
+
rerun_violation_check ? Fix::Result.rerun_violation_check : Fix::Result.ok
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def self.run_and_repeat_when_error(violation)
|
|
74
|
+
result = violation.get_input_and_apply_fix
|
|
75
|
+
if result.error?
|
|
76
|
+
result.render_error_msg
|
|
77
|
+
run_and_repeat_when_error(violation)
|
|
78
|
+
else
|
|
79
|
+
result
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
|
3
|
+
#
|
|
4
|
+
# This file is part of the dtk project.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
module DTK::Client
|
|
19
|
+
class Violation
|
|
20
|
+
# represents a component, node, or assembly attribute
|
|
21
|
+
class Attribute
|
|
22
|
+
def initialize(attribute_hash)
|
|
23
|
+
# ref is the only key that is guarenteed to be present
|
|
24
|
+
@ref = attribute_hash['ref']
|
|
25
|
+
@datatype = attribute_hash['datatype']
|
|
26
|
+
@hidden = attribute_hash['hidden']
|
|
27
|
+
@legal_values = attribute_hash['legal_values']
|
|
28
|
+
@fix_text = attribute_hash['fix_text']
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def prompt_user_for_value
|
|
32
|
+
Shell::InteractiveWizard.prompt_user_for_value(fix_text)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Returns error message if an error
|
|
36
|
+
def illegal_value?(value)
|
|
37
|
+
value_does_not_match_datatype?(value) or value_not_legal_type?(value)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def set_attribute(service_id, value)
|
|
41
|
+
post_body = {
|
|
42
|
+
:assembly_id => service_id,
|
|
43
|
+
:pattern => @ref,
|
|
44
|
+
:value => value
|
|
45
|
+
}
|
|
46
|
+
response = Session.post('assembly/set_attributes', post_body)
|
|
47
|
+
response.ok? ? Fix::Result.ok : Fix::Result.error
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def fix_text
|
|
53
|
+
@fix_text ||= "Enter value for attribute '#{@ref}'"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def value_does_not_match_datatype?(value)
|
|
57
|
+
if @datatype
|
|
58
|
+
# TODO: put in datatype test
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
LegalValueIdent = 2
|
|
63
|
+
def value_not_legal_type?(value)
|
|
64
|
+
return nil unless @legal_values and ! @legal_values.include?(value)
|
|
65
|
+
error_msg = "Illegal value; value must be one of:"
|
|
66
|
+
@legal_values.each do |legal_value|
|
|
67
|
+
error_msg << "\n#{' ' * LegalValueIdent}#{legal_value}"
|
|
68
|
+
end
|
|
69
|
+
error_msg
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
|
3
|
+
#
|
|
4
|
+
# This file is part of the dtk project.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
module DTK::Client
|
|
19
|
+
class Violation
|
|
20
|
+
module Fix
|
|
21
|
+
dtk_require('fix/result')
|
|
22
|
+
dtk_require('fix/set_attribute')
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
|
3
|
+
#
|
|
4
|
+
# This file is part of the dtk project.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
module DTK::Client
|
|
19
|
+
class Violation
|
|
20
|
+
module Fix
|
|
21
|
+
class Result
|
|
22
|
+
dtk_require('result/error')
|
|
23
|
+
|
|
24
|
+
Types = [:ok, :error, :skip_current, :skip_all, :error, :rerun_violation_check]
|
|
25
|
+
|
|
26
|
+
def self.create(type, *args)
|
|
27
|
+
case type
|
|
28
|
+
when :error then Error.new(*args)
|
|
29
|
+
else new(type)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def initialize(type)
|
|
34
|
+
@type = type
|
|
35
|
+
end
|
|
36
|
+
private :initialize
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def self.method_missing(method, *args)
|
|
40
|
+
is_type?(method) ? create(method, *args) : super
|
|
41
|
+
end
|
|
42
|
+
def self.respond_to?(method)
|
|
43
|
+
!!is_type?(method)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def method_missing(method, *args)
|
|
47
|
+
if type = is_type_with_question_mark?(method)
|
|
48
|
+
type == @type
|
|
49
|
+
else
|
|
50
|
+
super
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
def respond_to?(method)
|
|
54
|
+
!!is_type_with_question_mark?(method)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
private
|
|
58
|
+
|
|
59
|
+
def self.is_type?(method)
|
|
60
|
+
Types.include?(method) ? method : nil
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def is_type_with_question_mark?(method)
|
|
64
|
+
if method.to_s =~ /(^.+)[?]$/
|
|
65
|
+
type = $1.to_sym
|
|
66
|
+
self.class.is_type?(type)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
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 Violation::Fix
|
|
20
|
+
class Result
|
|
21
|
+
class Error < self
|
|
22
|
+
def initialize(opts = {})
|
|
23
|
+
super(:error)
|
|
24
|
+
@error_msg = opts[:error_msg]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def render_error_msg
|
|
28
|
+
OsUtil.print(@error_msg, :red) if @error_msg
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
|
3
|
+
#
|
|
4
|
+
# This file is part of the dtk project.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
module DTK::Client
|
|
19
|
+
class Violation
|
|
20
|
+
module Fix
|
|
21
|
+
module SetAttribute
|
|
22
|
+
def self.get_input_and_apply_fix(service_id, attribute)
|
|
23
|
+
prompt_response = attribute.prompt_user_for_value
|
|
24
|
+
if prompt_response.response_type == :skipped
|
|
25
|
+
# TODO: may distinguish between skip current and skip all; now treating everything as skip all
|
|
26
|
+
return Result.skip_all
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
prompted_value = prompt_response.value
|
|
30
|
+
if error_msg = attribute.illegal_value?(prompted_value)
|
|
31
|
+
Result.error :error_msg => error_msg
|
|
32
|
+
else
|
|
33
|
+
attribute.set_attribute(service_id, prompted_value)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
|
3
|
+
#
|
|
4
|
+
# This file is part of the dtk project.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
module DTK::Client
|
|
19
|
+
class Violation
|
|
20
|
+
class IllegalAttributeValue < self
|
|
21
|
+
def initialize(service_id, violation_hash)
|
|
22
|
+
super
|
|
23
|
+
@attribute = Attribute.new(violation_hash['attribute'])
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def get_input_and_apply_fix
|
|
27
|
+
Fix::SetAttribute.get_input_and_apply_fix(@service_id, @attribute)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class RequiredUnsetAttribute < self
|
|
32
|
+
def initialize(service_id, violation_hash)
|
|
33
|
+
super
|
|
34
|
+
@attribute = Attribute.new(violation_hash['attribute'])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def get_input_and_apply_fix
|
|
38
|
+
Fix::SetAttribute.get_input_and_apply_fix(@service_id, @attribute)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class InvalidCredentials < self
|
|
44
|
+
def initialize(service_id, violation_hash)
|
|
45
|
+
super
|
|
46
|
+
@attributes = violation_hash['fix_hashes'].map { |hash| Attribute.new(hash['attribute']) }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def get_input_and_apply_fix
|
|
50
|
+
result = nil
|
|
51
|
+
@attributes.each do |attribute|
|
|
52
|
+
result = Fix::SetAttribute.get_input_and_apply_fix(@service_id, attribute)
|
|
53
|
+
return result if result.skip_all? or result.error?
|
|
54
|
+
end
|
|
55
|
+
result.ok? ? Fix::Result.rerun_violation_check : result
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
class dtk_client($server_hostname)
|
|
2
|
+
{
|
|
3
|
+
include dtk_client::params
|
|
4
|
+
$repos = $dtk_client::params::repos
|
|
5
|
+
$client_user = $dtk_client::params::client_user
|
|
6
|
+
$client_user_homedir = $dtk_client::params::client_user_homedir
|
|
7
|
+
$dtk_username = $dtk_client::params::dtk_username
|
|
8
|
+
$dtk_password = $dtk_client::params::dtk_password
|
|
9
|
+
$client_src_path = $dtk_client::params::repo_targets['client']
|
|
10
|
+
$dtk_client_bin_path = "${client_user_homedir}/${client_src_path}/bin"
|
|
11
|
+
|
|
12
|
+
package {['thor','activesupport']:
|
|
13
|
+
ensure => 'installed',
|
|
14
|
+
provider => 'gem'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
user { $client_user:
|
|
18
|
+
home => $client_homedir,
|
|
19
|
+
shell => '/bin/bash',
|
|
20
|
+
managehome => true
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
file { "${client_user_homedir}/.bash_profile":
|
|
24
|
+
content => template('dtk_client/bash_profile.erb'),
|
|
25
|
+
owner => $client_user,
|
|
26
|
+
require => User[$client_user]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
file { "${client_user_homedir}/dtk/connection.conf":
|
|
30
|
+
content => template('dtk_client/dtkclient.erb'),
|
|
31
|
+
owner => $client_user,
|
|
32
|
+
require => User[$client_user]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
file { '/etc/dtk/':
|
|
36
|
+
ensure => directory,
|
|
37
|
+
owner => $client_user,
|
|
38
|
+
require => User[$client_user]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
file { '/etc/dtk/client.conf':
|
|
42
|
+
content => template('dtk_client/client.conf.erb'),
|
|
43
|
+
owner => $client_user,
|
|
44
|
+
require => File['/etc/dtk/']
|
|
45
|
+
}
|
|
46
|
+
dtk_client::github_repo { $repos:
|
|
47
|
+
require => User[$client_user]
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
#TODO: change to real app deployment; this only works when right keys already on node
|
|
52
|
+
define dtk_client::github_repo(
|
|
53
|
+
)
|
|
54
|
+
{
|
|
55
|
+
$repo = $name
|
|
56
|
+
include dtk_client::params
|
|
57
|
+
$repo_url = $dtk_client::params::repo_urls[$repo]
|
|
58
|
+
$target = $dtk_client::params::repo_targets[$repo]
|
|
59
|
+
$client_user = $dtk_client::params::client_user
|
|
60
|
+
$client_user_homedir = $dtk_client::params::client_user_homedir
|
|
61
|
+
|
|
62
|
+
$repo_target_dir = "${client_user_homedir}/${target}"
|
|
63
|
+
$git_clone_cmd = "git clone ${repo_url} ${repo_target_dir}"
|
|
64
|
+
$chown_cmd = "chown -R ${client_user} ${repo_target_dir}"
|
|
65
|
+
|
|
66
|
+
exec { "clone ${name}":
|
|
67
|
+
command => "${git_clone_cmd}; ${chown_cmd}",
|
|
68
|
+
path => ['/bin','/usr/bin'],
|
|
69
|
+
logoutput => true,
|
|
70
|
+
creates => $repo_target_dir
|
|
71
|
+
}
|
|
72
|
+
}
|