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
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
|
3
|
+
#
|
|
4
|
+
# This file is part of the dtk project.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
dtk_require_from_base('configurator')
|
|
19
|
+
module DTK::Client
|
|
20
|
+
module InventoryParserMixin
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def parse_inventory_file(file_path)
|
|
24
|
+
ssh_creds_path = ::DTK::Client::Configurator::NODE_SSH_CREDENTIALS
|
|
25
|
+
ssh_creds_data = parse_ssh_credentials_file(ssh_creds_path)
|
|
26
|
+
|
|
27
|
+
hash = validate_inventory_data(file_path)
|
|
28
|
+
|
|
29
|
+
ret = Hash.new
|
|
30
|
+
defaults = hash["defaults"]
|
|
31
|
+
|
|
32
|
+
hash["nodes"].each do |node_name, data|
|
|
33
|
+
display_name = data["name"]||node_name
|
|
34
|
+
ssh_credentials = data["ssh_credentials"]||defaults["ssh_credentials"]
|
|
35
|
+
|
|
36
|
+
raise DtkValidationError, "Credentials for '#{ssh_credentials}' does not exist in credentials file '#{ssh_creds_path}'" unless ssh_creds_data.include?(ssh_credentials)
|
|
37
|
+
|
|
38
|
+
ref = "physical--#{display_name}"
|
|
39
|
+
row = ret[ref] = {
|
|
40
|
+
:display_name => display_name,
|
|
41
|
+
:os_type => data["os_type"]||defaults["os_type"],
|
|
42
|
+
:managed => false,
|
|
43
|
+
:external_ref => {:type => "physical", :routable_host_address => node_name, :ssh_credentials => ssh_creds_data["#{ssh_credentials}"]}
|
|
44
|
+
}
|
|
45
|
+
if tags = data["tags"]
|
|
46
|
+
row[:tags] = tags
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
ret
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def parse_ssh_credentials_file(file_path)
|
|
54
|
+
begin
|
|
55
|
+
data = YAML.load_file(file_path)
|
|
56
|
+
rescue SyntaxError => e
|
|
57
|
+
raise DSLParsing::YAMLParsing.new("YAML parsing error #{e.message} in file", file_path)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
data.each do |k,v|
|
|
61
|
+
raise DtkValidationError, "File: '#{file_path}'. Ssh credentials '#{k}' missing required field 'ssh_user'." unless v['ssh_user']
|
|
62
|
+
raise DtkValidationError, "File: '#{file_path}'. Ssh credentials '#{k}' should contain 'ssh_password' or 'sudo_password'." unless (v['ssh_password'] || v['sudo_password'])
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
data
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def validate_inventory_data(file_path)
|
|
69
|
+
begin
|
|
70
|
+
data = YAML.load_file(file_path)
|
|
71
|
+
rescue SyntaxError => e
|
|
72
|
+
raise DSLParsing::YAMLParsing.new("YAML parsing error #{e.message} in file", file_path)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
defaults = data['defaults']||[]
|
|
76
|
+
nodes = data['nodes']||[]
|
|
77
|
+
|
|
78
|
+
nodes.each do |k,v|
|
|
79
|
+
os_type = v['os_type']||defaults['os_type']
|
|
80
|
+
ssh_credentials = v['ssh_credentials']||defaults['ssh_credentials']
|
|
81
|
+
|
|
82
|
+
# os_type is required field and should be set through node specific fields or used from defaults
|
|
83
|
+
raise DtkValidationError, "Missing required field 'os_type' for node '#{k}'." unless os_type
|
|
84
|
+
|
|
85
|
+
# ssh_credentials is required field and should be set through node specific fields or used from defaults
|
|
86
|
+
raise DtkValidationError, "Missing required field 'ssh_credentials' for node '#{k}'." unless ssh_credentials
|
|
87
|
+
|
|
88
|
+
# currently we support 'ubuntu', 'centos, 'redhat' and 'debian' as os types and should be set through node specific field
|
|
89
|
+
# or used from defaults
|
|
90
|
+
raise DtkValidationError, "Os_type '#{os_type}' is not valid for node '#{k}'. Valid os types: #{ValidOsTypes}." unless ValidOsTypes.include?(os_type)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
data
|
|
94
|
+
end
|
|
95
|
+
ValidOsTypes = ['ubuntu', 'centos', 'redhat', 'debian']
|
|
96
|
+
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
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 ListDiffsMixin
|
|
20
|
+
def list_diffs_aux(module_type,module_id,remote,version=nil)
|
|
21
|
+
id_field = "#{module_type}_id"
|
|
22
|
+
path_to_key = SSHUtil.default_rsa_pub_key_path()
|
|
23
|
+
rsa_pub_key = File.file?(path_to_key) && File.open(path_to_key){|f|f.read}.chomp
|
|
24
|
+
|
|
25
|
+
post_body = {
|
|
26
|
+
id_field => module_id,
|
|
27
|
+
:access_rights => "r",
|
|
28
|
+
:action => "pull"
|
|
29
|
+
}
|
|
30
|
+
post_body.merge!(:version => version) if version
|
|
31
|
+
post_body.merge!(:rsa_pub_key => rsa_pub_key) if rsa_pub_key
|
|
32
|
+
|
|
33
|
+
response = post(rest_url("#{module_type}/get_remote_module_info"),post_body)
|
|
34
|
+
return response unless response.ok?
|
|
35
|
+
|
|
36
|
+
module_name = response.data(:full_module_name)
|
|
37
|
+
|
|
38
|
+
opts = {
|
|
39
|
+
:remote_repo_url => response.data(:remote_repo_url),
|
|
40
|
+
:remote_repo => response.data(:remote_repo),
|
|
41
|
+
:remote_branch => response.data(:remote_branch),
|
|
42
|
+
:local_branch => response.data(:workspace_branch)
|
|
43
|
+
}
|
|
44
|
+
version = response.data(:version)
|
|
45
|
+
|
|
46
|
+
# response = Helper(:git_repo).get_diffs(module_type,module_name,version,opts)
|
|
47
|
+
response = Helper(:git_repo).get_remote_diffs(module_type,module_name,version,opts)
|
|
48
|
+
return response unless response.ok?
|
|
49
|
+
|
|
50
|
+
added, deleted, modified = print_diffs(response.data(:status), remote)
|
|
51
|
+
diffs = response.data(:diffs)
|
|
52
|
+
|
|
53
|
+
raise DTK::Client::DtkValidationError, "There are no changes in current workspace!" if(added.empty? && deleted.empty? && modified.empty? && diffs.empty?)
|
|
54
|
+
puts "#{diffs}" unless (diffs||"").empty?
|
|
55
|
+
|
|
56
|
+
unless added.empty?
|
|
57
|
+
puts "\nNew file(s):"
|
|
58
|
+
added.each do |a|
|
|
59
|
+
puts "\t #{a.inspect}"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
unless deleted.empty?
|
|
64
|
+
puts "\nDeleted file(s):"
|
|
65
|
+
deleted.each do |d|
|
|
66
|
+
puts "\t #{d.inspect}"
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def list_remote_diffs_aux(module_type, module_id)
|
|
72
|
+
id_field = "#{module_type}_id"
|
|
73
|
+
|
|
74
|
+
post_body = {
|
|
75
|
+
id_field => module_id
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
response = post(rest_url("#{module_type}/list_remote_diffs"),post_body)
|
|
79
|
+
return response unless response.ok?
|
|
80
|
+
|
|
81
|
+
raise DTK::Client::DtkValidationError, "There are no diffs between module on server and remote repo!" if response.data.empty?
|
|
82
|
+
response
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def list_component_module_diffs(module_id, assembly_name, workspace_branch, commit_sha, module_branch_id, repo_id)
|
|
86
|
+
post_body = {
|
|
87
|
+
:module_id => module_id,
|
|
88
|
+
:assembly_name => assembly_name,
|
|
89
|
+
:workspace_branch => workspace_branch,
|
|
90
|
+
:module_branch_id => module_branch_id,
|
|
91
|
+
:repo_id => repo_id
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
response = post(rest_url("assembly/list_component_module_diffs"),post_body)
|
|
95
|
+
return response unless response.ok?
|
|
96
|
+
|
|
97
|
+
raise DTK::Client::DtkValidationError, "There are no diffs between module in service instance and base module!" if response.data.empty?
|
|
98
|
+
response
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def print_diffs(response, remote)
|
|
102
|
+
added = []
|
|
103
|
+
deleted = []
|
|
104
|
+
modified = []
|
|
105
|
+
|
|
106
|
+
unless response[:files_modified].nil?
|
|
107
|
+
response[:files_modified].each do |file|
|
|
108
|
+
modified << file[:path]
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
unless response[:files_deleted].nil?
|
|
113
|
+
response[:files_deleted].each do |file|
|
|
114
|
+
deleted << file[:path]
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
unless response[:files_added].nil?
|
|
119
|
+
response[:files_added].each do |file|
|
|
120
|
+
added << file[:path]
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
return added, deleted, modified
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,1011 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2010-2016 dtk contributors
|
|
3
|
+
#
|
|
4
|
+
# This file is part of the dtk project.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
dtk_require_common_commands('thor/clone')
|
|
19
|
+
dtk_require_common_commands('thor/list_diffs')
|
|
20
|
+
dtk_require_common_commands('thor/puppet_forge')
|
|
21
|
+
dtk_require_common_commands('thor/push_to_remote')
|
|
22
|
+
dtk_require_common_commands('thor/pull_from_remote')
|
|
23
|
+
dtk_require_common_commands('thor/push_clone_changes')
|
|
24
|
+
dtk_require_common_commands('thor/access_control')
|
|
25
|
+
dtk_require_common_commands('thor/edit')
|
|
26
|
+
dtk_require_common_commands('thor/reparse')
|
|
27
|
+
dtk_require_common_commands('thor/purge_clone')
|
|
28
|
+
dtk_require_common_commands('thor/common')
|
|
29
|
+
dtk_require_common_commands('thor/remotes')
|
|
30
|
+
|
|
31
|
+
dtk_require_from_base('configurator')
|
|
32
|
+
dtk_require_from_base('command_helpers/service_importer')
|
|
33
|
+
dtk_require_from_base('command_helpers/test_module_creator')
|
|
34
|
+
|
|
35
|
+
require 'fileutils'
|
|
36
|
+
|
|
37
|
+
DEFAULT_COMMIT_MSG = "Initial commit."
|
|
38
|
+
PULL_CATALOGS = ["dtkn"]
|
|
39
|
+
|
|
40
|
+
module DTK::Client
|
|
41
|
+
dtk_require_common_commands('thor/base_command_helper')
|
|
42
|
+
class CommonModule
|
|
43
|
+
dtk_require_common_commands('thor/module/import')
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
module ModuleMixin
|
|
47
|
+
|
|
48
|
+
REQ_MODULE_ID = [:service_module_id!, :component_module_id!, :test_module_id!]
|
|
49
|
+
REQ_MODULE_NAME = [:service_module_name!, :component_module_name!, :test_module_name!]
|
|
50
|
+
|
|
51
|
+
include PuppetForgeMixin
|
|
52
|
+
include CloneMixin
|
|
53
|
+
include PushToRemoteMixin
|
|
54
|
+
include PullFromRemoteMixin
|
|
55
|
+
include PushCloneChangesMixin
|
|
56
|
+
include EditMixin
|
|
57
|
+
include ReparseMixin
|
|
58
|
+
include PurgeCloneMixin
|
|
59
|
+
include ListDiffsMixin
|
|
60
|
+
include ServiceImporter
|
|
61
|
+
include AccessControlMixin
|
|
62
|
+
include RemotesMixin
|
|
63
|
+
|
|
64
|
+
def get_module_type(context_params)
|
|
65
|
+
forwarded_type = context_params.get_forwarded_options() ? context_params.get_forwarded_options()[:module_type] : nil
|
|
66
|
+
|
|
67
|
+
if context_params.root_command_name || forwarded_type
|
|
68
|
+
module_type = (context_params.root_command_name||forwarded_type).gsub(/\-/, "_")
|
|
69
|
+
else
|
|
70
|
+
module_type = resolve_module_type
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
module_type
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def module_info_about(context_params, about, data_type)
|
|
77
|
+
module_id, component_template_id = context_params.retrieve_arguments([REQ_MODULE_ID, :component_id],method_argument_names)
|
|
78
|
+
module_type = get_module_type(context_params)
|
|
79
|
+
|
|
80
|
+
post_body = {
|
|
81
|
+
"#{module_type}_id".to_sym => module_id,
|
|
82
|
+
:component_template_id => component_template_id,
|
|
83
|
+
:about => about
|
|
84
|
+
}
|
|
85
|
+
response = post rest_url("#{module_type}/info_about"), post_body
|
|
86
|
+
data_type = data_type
|
|
87
|
+
|
|
88
|
+
response.render_table(data_type) unless options.list?
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def module_info_aux(context_params)
|
|
92
|
+
module_type = get_module_type(context_params)
|
|
93
|
+
|
|
94
|
+
if context_params.is_there_identifier?(:assembly)
|
|
95
|
+
response = DTK::Client::ContextRouter.routeTask("assembly", "info", context_params, @conn)
|
|
96
|
+
else
|
|
97
|
+
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
|
|
98
|
+
|
|
99
|
+
post_body = {
|
|
100
|
+
"#{module_type}_id".to_sym => module_id
|
|
101
|
+
}
|
|
102
|
+
response = post rest_url("#{module_type}/info"), post_body
|
|
103
|
+
response.render_custom_info("module")
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def delete_module_aux(context_params, method_opts = {})
|
|
108
|
+
module_location, modules_path = nil, nil
|
|
109
|
+
module_id = context_params.retrieve_arguments([:option_1!], method_argument_names)
|
|
110
|
+
|
|
111
|
+
delete_module_sub_aux(context_params, module_id, method_opts)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def delete_module_sub_aux(context_params, module_id, method_opts = {})
|
|
115
|
+
version = options.version
|
|
116
|
+
module_name = get_name_from_id_helper(module_id)
|
|
117
|
+
module_type = get_module_type(context_params)
|
|
118
|
+
|
|
119
|
+
# delete all versions
|
|
120
|
+
version = 'delete_all' if method_opts[:delete_all]
|
|
121
|
+
|
|
122
|
+
unless (options.force? || method_opts[:force_delete])
|
|
123
|
+
msg = "Are you sure you want to delete module '#{module_name}'"
|
|
124
|
+
msg += " version '#{version}'" if version
|
|
125
|
+
is_go = Console.confirmation_prompt("#{msg}"+"?")
|
|
126
|
+
return nil unless is_go
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
post_body = { "#{module_type}_id".to_sym => module_id }
|
|
130
|
+
opts = { :module_name => module_name }
|
|
131
|
+
|
|
132
|
+
unless version
|
|
133
|
+
# post_body.merge!(:include_base => true)
|
|
134
|
+
|
|
135
|
+
versions_response = post rest_url("#{module_type}/list_versions"), post_body
|
|
136
|
+
return versions_response unless versions_response.ok?
|
|
137
|
+
|
|
138
|
+
versions = versions_response.data.first['versions']
|
|
139
|
+
if versions.size > 0
|
|
140
|
+
versions << "all" unless versions.size == 1
|
|
141
|
+
ret_version = Console.confirmation_prompt_multiple_choice("\nSelect version to delete:", versions)
|
|
142
|
+
return unless ret_version
|
|
143
|
+
raise DtkError, "You are not allowed to delete 'base' version while other versions exist!" if ret_version.eql?('base')
|
|
144
|
+
version = ret_version
|
|
145
|
+
else
|
|
146
|
+
raise DtkError, "There are no versions created for #{module_type} '#{module_name}'!" unless method_opts[:no_error_msg]
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
if version
|
|
151
|
+
if version.eql?('all')
|
|
152
|
+
# delete only versions (not base)
|
|
153
|
+
post_body.merge!(:all_except_base => true)
|
|
154
|
+
opts.merge!(:all_except_base => true)
|
|
155
|
+
elsif version.eql?('delete_all')
|
|
156
|
+
# this means delete entire module (including all versions + base)
|
|
157
|
+
post_body.merge!(:delete_all_versions => true)
|
|
158
|
+
opts.merge!(:delete_all_versions => true)
|
|
159
|
+
else
|
|
160
|
+
# delete specific version only
|
|
161
|
+
post_body.merge!(:version => version)
|
|
162
|
+
opts.merge!(:version => version)
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
response = post(rest_url("#{module_type}/delete"), post_body)
|
|
167
|
+
return response unless response.ok?
|
|
168
|
+
|
|
169
|
+
# if we do not provide version, server will calculate the latest version which we can use here
|
|
170
|
+
unless version
|
|
171
|
+
version = response.data(:version)
|
|
172
|
+
opts.merge!(:version => version)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
response =
|
|
176
|
+
if options.purge? || method_opts[:purge]
|
|
177
|
+
purge_clone_aux(module_type.to_sym, opts)
|
|
178
|
+
else
|
|
179
|
+
Helper(:git_repo).unlink_local_clone?(module_type.to_sym, module_name, version)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
return response unless response.ok?
|
|
183
|
+
|
|
184
|
+
unless method_opts[:no_error_msg]
|
|
185
|
+
if version && version.eql?('all')
|
|
186
|
+
OsUtil.print("All versions (except base) of '#{module_name}' module have been deleted.", :yellow)
|
|
187
|
+
elsif version && version.eql?('delete_all')
|
|
188
|
+
OsUtil.print("All versions of '#{module_name}' module have been deleted.", :yellow)
|
|
189
|
+
else
|
|
190
|
+
msg = "Module '#{module_name}' "
|
|
191
|
+
if version then msg << "version '#{version}' has been deleted successfully."
|
|
192
|
+
else msg << "has been deleted successfully."; end
|
|
193
|
+
OsUtil.print(msg, :yellow)
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
Response::Ok.new()
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def set_attribute_module_aux(context_params)
|
|
201
|
+
if context_params.is_there_identifier?(:attribute)
|
|
202
|
+
mapping = [REQ_MODULE_ID, :attribute_id!, :option_1]
|
|
203
|
+
else
|
|
204
|
+
mapping = [REQ_MODULE_ID, :option_1!, :option_2]
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
module_id, attribute_id, value = context_params.retrieve_arguments(mapping, method_argument_names)
|
|
208
|
+
module_type = get_module_type(context_params)
|
|
209
|
+
|
|
210
|
+
post_body = {
|
|
211
|
+
:attribute_id => attribute_id,
|
|
212
|
+
:attribute_value => value,
|
|
213
|
+
:attribute_type => module_type,
|
|
214
|
+
"#{module_type}_id".to_sym => module_id
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
post rest_url('attribute/set'), post_body
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def push_module_aux(context_params, internal_trigger = false, opts = {})
|
|
221
|
+
module_type = get_module_type(context_params)
|
|
222
|
+
module_id, module_name = context_params.retrieve_arguments([REQ_MODULE_ID, "#{module_type}_name".to_sym], method_argument_names)
|
|
223
|
+
version = options['version']
|
|
224
|
+
|
|
225
|
+
module_location = OsUtil.module_location(module_type, module_name, version)
|
|
226
|
+
|
|
227
|
+
git_import = opts[:git_import]
|
|
228
|
+
opts.merge!(:update_from_includes => true, :force_parse => true) unless git_import
|
|
229
|
+
opts.merge!(:force => options.force?)
|
|
230
|
+
opts.merge!(:generate_docs => options.docs?)
|
|
231
|
+
|
|
232
|
+
reparse_aux(module_location)
|
|
233
|
+
push_clone_changes_aux(module_type.to_sym, module_id, version, options['message'] || DEFAULT_COMMIT_MSG, internal_trigger, opts)
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def create_test_module_aux(context_params)
|
|
237
|
+
test_module_name = context_params.retrieve_arguments([:option_1!], method_argument_names)
|
|
238
|
+
module_type = get_module_type(context_params)
|
|
239
|
+
|
|
240
|
+
response = DTK::Client::TestModuleCreator.create_clone(module_type.to_sym, test_module_name)
|
|
241
|
+
return response unless response.ok?
|
|
242
|
+
|
|
243
|
+
create_response = import(context_params)
|
|
244
|
+
|
|
245
|
+
unless create_response.ok?
|
|
246
|
+
error_msg = create_response['errors'].select { |er| er['message'].include? 'cannot be created since it exists already' }
|
|
247
|
+
if error_msg.empty?
|
|
248
|
+
# If server response is not ok and module does not exist on server, delete cloned module, invoke delete method
|
|
249
|
+
delete(context_params, :force_delete => true, :no_error_msg => true)
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
# remove temp directory
|
|
253
|
+
FileUtils.rm_rf("#{response['data']['module_directory']}")
|
|
254
|
+
|
|
255
|
+
return create_response
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
def import_git_module_aux(context_params)
|
|
260
|
+
CommonModule::Import.new(self, context_params).from_git(context_params.get_forwarded_options()[:internal_trigger])
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def import_module_aux(context_params)
|
|
264
|
+
CommonModule::Import.new(self, context_params).from_file()
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
def install_module_aux(context_params, internal_trigger = false)
|
|
268
|
+
create_missing_clone_dirs()
|
|
269
|
+
resolve_direct_access(::DTK::Client::Configurator.check_direct_access)
|
|
270
|
+
|
|
271
|
+
remote_module_name, version = context_params.retrieve_arguments([:option_1!, :option_2], method_argument_names)
|
|
272
|
+
forwarded_version = context_params.get_forwarded_options()['version']
|
|
273
|
+
add_version = false
|
|
274
|
+
master_only = (options.version? && options.version.eql?('master'))
|
|
275
|
+
|
|
276
|
+
version ||= forwarded_version || options.version
|
|
277
|
+
version = nil if version.eql?('master')
|
|
278
|
+
if version
|
|
279
|
+
check_version_format(version)
|
|
280
|
+
add_version = true
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
# in case of auto-import via service import, we skip cloning to speed up a process
|
|
284
|
+
skip_cloning = context_params.get_forwarded_options()['skip_cloning'] if context_params.get_forwarded_options()
|
|
285
|
+
do_not_raise = context_params.get_forwarded_options()[:do_not_raise] if context_params.get_forwarded_options()
|
|
286
|
+
skip_ainstall = context_params.get_forwarded_options() ? context_params.get_forwarded_options()[:skip_auto_install] : false
|
|
287
|
+
skip_base = context_params.get_forwarded_options()['skip_base']
|
|
288
|
+
module_type = get_module_type(context_params)
|
|
289
|
+
|
|
290
|
+
# ignore_component_error = context_params.get_forwarded_options()[:ignore_component_error]||options.ignore? if context_params.get_forwarded_options()
|
|
291
|
+
ignore_component_error = context_params.get_forwarded_options().empty? ? options.ignore? : context_params.get_forwarded_options()[:ignore_component_error]
|
|
292
|
+
additional_message = context_params.get_forwarded_options()[:additional_message] if context_params.get_forwarded_options()
|
|
293
|
+
|
|
294
|
+
remote_namespace, local_module_name = get_namespace_and_name(remote_module_name, ':')
|
|
295
|
+
|
|
296
|
+
post_body = {
|
|
297
|
+
:remote_module_name => remote_module_name.sub(':', '/'),
|
|
298
|
+
:local_module_name => local_module_name,
|
|
299
|
+
:rsa_pub_key => SSHUtil.rsa_pub_key_content()
|
|
300
|
+
}
|
|
301
|
+
post_body.merge!(:do_not_raise => do_not_raise) if do_not_raise
|
|
302
|
+
post_body.merge!(:ignore_component_error => ignore_component_error) if ignore_component_error
|
|
303
|
+
post_body.merge!(:additional_message => additional_message) if additional_message
|
|
304
|
+
post_body.merge!(:skip_auto_install => skip_ainstall) if skip_ainstall
|
|
305
|
+
|
|
306
|
+
# we need to install base module version if not installed
|
|
307
|
+
unless skip_base
|
|
308
|
+
master_response = install_base_version_aux?(context_params, post_body, module_type, version)
|
|
309
|
+
# return master_response unless master_response.ok?
|
|
310
|
+
return master_response if !master_response.ok? || master_only
|
|
311
|
+
|
|
312
|
+
latest_version = master_response.data(:latest_version)
|
|
313
|
+
|
|
314
|
+
unless version
|
|
315
|
+
version = latest_version.eql?('master') ? nil : latest_version
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
post_body.merge!(:hard_reset_on_pull_version => true) if version
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
if version
|
|
322
|
+
add_version = true
|
|
323
|
+
post_body.merge!(:version => version)
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
if clone_dir = Helper(:git_repo).local_clone_dir_exists?(module_type.to_sym, local_module_name, :namespace => remote_namespace, :version => version)
|
|
327
|
+
message = "Module's directory (#{clone_dir}) exists on client. To install this needs to be renamed or removed."
|
|
328
|
+
raise DtkError, message unless ignore_component_error
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
response = post rest_url("#{module_type}/import"), post_body
|
|
332
|
+
|
|
333
|
+
# when silently installing base version we don't want to print anything
|
|
334
|
+
unless skip_base
|
|
335
|
+
# print permission warnings and then check for other warnings
|
|
336
|
+
are_there_warnings = RemoteDependencyUtil.check_permission_warnings(response)
|
|
337
|
+
are_there_warnings ||= RemoteDependencyUtil.print_dependency_warnings(response, nil, :ignore_permission_warnings => true)
|
|
338
|
+
|
|
339
|
+
# prompt to see if user is ready to continue with warnings/errors
|
|
340
|
+
if are_there_warnings
|
|
341
|
+
return false unless Console.confirmation_prompt('Do you still want to proceed with import' + '?')
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
# case when we need to import additional components
|
|
346
|
+
if response.ok? && !skip_ainstall && (missing_components = response.data(:missing_module_components))
|
|
347
|
+
required_components = response.data(:required_modules)
|
|
348
|
+
opts = { :do_not_raise => true }
|
|
349
|
+
module_opts = ignore_component_error ? opts.merge(:ignore_component_error => true) : opts.merge(:additional_message => true)
|
|
350
|
+
module_opts.merge!(:update_none => true) if options.update_none?
|
|
351
|
+
module_opts.merge!(:hide_output => true) if skip_base && !master_only
|
|
352
|
+
|
|
353
|
+
continue = trigger_module_auto_import(missing_components, required_components, module_opts)
|
|
354
|
+
return unless continue
|
|
355
|
+
|
|
356
|
+
print_remote_name = add_version ? "#{remote_module_name}(#{version})" : remote_module_name
|
|
357
|
+
print "Resuming DTK Network import for #{module_type} '#{print_remote_name}' ..." unless skip_base
|
|
358
|
+
# repeat import call for service
|
|
359
|
+
post_body.merge!(opts)
|
|
360
|
+
response = post rest_url("#{module_type}/import"), post_body
|
|
361
|
+
|
|
362
|
+
# we set skip cloning since it is already done by import
|
|
363
|
+
puts ' Done' unless skip_base
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
return response if !response.ok? || response.data(:does_not_exist)
|
|
367
|
+
module_id, module_name, namespace, repo_url, branch, version = response.data(:module_id, :module_name, :namespace, :repo_url, :workspace_branch, :version)
|
|
368
|
+
|
|
369
|
+
if error = response.data(:dsl_parse_error)
|
|
370
|
+
dsl_parsed_message = ServiceImporter.error_message(module_name, error)
|
|
371
|
+
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
unless skip_cloning
|
|
375
|
+
# TODO: should we use instead Helper(:git_repo).create_clone_from_optional_branch
|
|
376
|
+
response = Helper(:git_repo).create_clone_with_branch(module_type.to_sym, module_name, repo_url, branch, version, remote_namespace)
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
resolve_missing_components(module_id, module_name, namespace, options.force?) if module_type.to_s.eql?('service_module')
|
|
380
|
+
response
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
def install_base_version_aux?(context_params, post_body, module_type, version)
|
|
384
|
+
master_response = post rest_url("#{module_type}/prepare_for_install_module"), post_body
|
|
385
|
+
return master_response unless master_response.ok?
|
|
386
|
+
|
|
387
|
+
head_installed = master_response.data(:head_installed)
|
|
388
|
+
latest_version = master_response.data(:latest_version)
|
|
389
|
+
remote_module_name, param_version = context_params.retrieve_arguments([:option_1!, :option_2], method_argument_names)
|
|
390
|
+
|
|
391
|
+
if version
|
|
392
|
+
versions = master_response.data(:versions)
|
|
393
|
+
raise DtkError, "Module '#{remote_module_name}' version '#{version}' does not exist on repo manager!" unless versions.include?(version)
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
base_response = nil
|
|
397
|
+
if !head_installed && !latest_version.eql?('master')
|
|
398
|
+
new_context_params = DTK::Shell::ContextParams.new
|
|
399
|
+
new_context_params.add_context_to_params(module_type, module_type)
|
|
400
|
+
new_context_params.method_arguments = [remote_module_name]
|
|
401
|
+
new_context_params.forward_options('skip_base' => true, 'version' => 'master')
|
|
402
|
+
base_response = install_module_aux(new_context_params)
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
return base_response if base_response && (options.version? && options.version.eql?('master'))
|
|
406
|
+
master_response
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
def delete_from_catalog_aux(context_params)
|
|
410
|
+
module_type = get_module_type(context_params)
|
|
411
|
+
remote_module_name = context_params.retrieve_arguments([:option_1!], method_argument_names)
|
|
412
|
+
version = options.version
|
|
413
|
+
rsa_pub_key = SSHUtil.rsa_pub_key_content()
|
|
414
|
+
|
|
415
|
+
# remote_module_name can be namespace:name or namespace/name
|
|
416
|
+
remote_namespace, remote_module_name = get_namespace_and_name(remote_module_name, ':')
|
|
417
|
+
|
|
418
|
+
if version
|
|
419
|
+
check_version_format(version)
|
|
420
|
+
else
|
|
421
|
+
list_post_body = {
|
|
422
|
+
"#{module_type}_id".to_sym => "#{remote_namespace}:#{remote_module_name}",
|
|
423
|
+
:rsa_pub_key => rsa_pub_key,
|
|
424
|
+
:include_base => true
|
|
425
|
+
}
|
|
426
|
+
# versions_response = post rest_url("#{module_type}/list_remote_versions"), list_post_body
|
|
427
|
+
versions_response = post rest_url("#{module_type}/list_remote"), list_post_body
|
|
428
|
+
return versions_response unless versions_response.ok?
|
|
429
|
+
|
|
430
|
+
selected_module = versions_response.data.find{ |vr| vr['display_name'].eql?("#{remote_namespace}/#{remote_module_name}") }
|
|
431
|
+
raise DtkError, "Module '#{remote_namespace}/#{remote_module_name}'' does not exist on repo manager!" unless selected_module
|
|
432
|
+
|
|
433
|
+
versions = selected_module['versions']
|
|
434
|
+
if versions.size > 2
|
|
435
|
+
versions << "all"
|
|
436
|
+
ret_version = Console.confirmation_prompt_multiple_choice("\nSelect version to delete:", versions)
|
|
437
|
+
return unless ret_version
|
|
438
|
+
raise DtkError, "You are not allowed to delete 'base' version while other versions exist!" if ret_version.eql?('base')
|
|
439
|
+
version = ret_version
|
|
440
|
+
end
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
unless options.force? || options.confirmed?
|
|
444
|
+
msg = "Are you sure you want to delete remote #{module_type} '#{remote_namespace.nil? ? '' : remote_namespace + '/'}#{remote_module_name}'"
|
|
445
|
+
msg += " version '#{version}'" if version
|
|
446
|
+
msg += " and all items contained in it"
|
|
447
|
+
return unless Console.confirmation_prompt(msg + '?')
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
post_body = {
|
|
451
|
+
:rsa_pub_key => rsa_pub_key,
|
|
452
|
+
:remote_module_name => remote_module_name,
|
|
453
|
+
:remote_module_namespace => remote_namespace,
|
|
454
|
+
:force_delete => options.force?
|
|
455
|
+
}
|
|
456
|
+
post_body.merge!(:version => version) if version
|
|
457
|
+
|
|
458
|
+
response = post rest_url("#{module_type}/delete_remote"), post_body
|
|
459
|
+
return response unless response.ok?
|
|
460
|
+
|
|
461
|
+
full_module_name, version = response.data(:module_full_name, :version)
|
|
462
|
+
msg = "Module '#{full_module_name}' "
|
|
463
|
+
msg << "version '#{version}'" if version && !version.eql?('master')
|
|
464
|
+
msg << " has been deleted successfully."
|
|
465
|
+
OsUtil.print(msg, :yellow)
|
|
466
|
+
|
|
467
|
+
Response::Ok.new()
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
def publish_module_aux(context_params)
|
|
471
|
+
module_type = get_module_type(context_params)
|
|
472
|
+
module_id, module_name, input_remote_name = context_params.retrieve_arguments([REQ_MODULE_ID, REQ_MODULE_NAME, :option_1], method_argument_names)
|
|
473
|
+
|
|
474
|
+
raise DtkValidationError, "You have to provide version you want to publish!" unless options.version
|
|
475
|
+
|
|
476
|
+
unless input_remote_name
|
|
477
|
+
input_remote_name = module_name.gsub(":","/")
|
|
478
|
+
context_params.method_arguments << input_remote_name
|
|
479
|
+
end
|
|
480
|
+
|
|
481
|
+
skip_base = context_params.get_forwarded_options()['skip_base']
|
|
482
|
+
forwarded_version = context_params.get_forwarded_options()['version']
|
|
483
|
+
|
|
484
|
+
version = forwarded_version||options.version
|
|
485
|
+
version = nil if version.eql?('master')
|
|
486
|
+
|
|
487
|
+
forward_namespace?(module_name, input_remote_name, context_params)
|
|
488
|
+
|
|
489
|
+
post_body = {
|
|
490
|
+
"#{module_type}_id".to_sym => module_id,
|
|
491
|
+
:remote_component_name => input_remote_name,
|
|
492
|
+
:rsa_pub_key => SSHUtil.rsa_pub_key_content(),
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
unless skip_base
|
|
496
|
+
check_response = post rest_url("#{module_type}/check_remote_exist"), post_body
|
|
497
|
+
return check_response unless check_response.ok?
|
|
498
|
+
|
|
499
|
+
remote_exist = check_response.data(:remote_exist)
|
|
500
|
+
unless remote_exist
|
|
501
|
+
context_params.forward_options('skip_base' => true, 'version' => 'master')
|
|
502
|
+
resp = publish_module_aux(context_params)
|
|
503
|
+
return resp unless resp.ok?
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
context_params.forward_options('do_not_raise_if_exist' => true, 'version' => version)
|
|
507
|
+
create_response = create_new_version_aux(context_params, true)
|
|
508
|
+
return create_response unless create_response.ok?
|
|
509
|
+
end
|
|
510
|
+
|
|
511
|
+
post_body.merge!(:version => version) if version
|
|
512
|
+
response = post rest_url("#{module_type}/export"), post_body
|
|
513
|
+
return response unless response.ok?
|
|
514
|
+
|
|
515
|
+
unless skip_base
|
|
516
|
+
full_module_name = "#{response.data['remote_repo_namespace']}/#{response.data['remote_repo_name']}"
|
|
517
|
+
DTK::Client::RemoteDependencyUtil.print_dependency_warnings(response, "Module has been successfully published to '#{full_module_name}' version '#{version}'!")
|
|
518
|
+
end
|
|
519
|
+
|
|
520
|
+
Response::Ok.new()
|
|
521
|
+
end
|
|
522
|
+
|
|
523
|
+
# def publish_module_aux(context_params)
|
|
524
|
+
# module_type = get_module_type(context_params)
|
|
525
|
+
# module_id, module_name, input_remote_name = context_params.retrieve_arguments([REQ_MODULE_ID, REQ_MODULE_NAME, :option_1], method_argument_names)
|
|
526
|
+
|
|
527
|
+
# post_body = {
|
|
528
|
+
# "#{module_type}_id".to_sym => module_id,
|
|
529
|
+
# :remote_component_name => input_remote_name,
|
|
530
|
+
# :rsa_pub_key => SSHUtil.rsa_pub_key_content()
|
|
531
|
+
# }
|
|
532
|
+
# if options.version?
|
|
533
|
+
# post_body.merge!(:version => options.version)
|
|
534
|
+
# else
|
|
535
|
+
# post_body.merge!(:use_latest => true)
|
|
536
|
+
# end
|
|
537
|
+
|
|
538
|
+
# # check if module exist on repo manager and use it to decide if need to push or publish
|
|
539
|
+
# check_response = post rest_url("#{module_type}/check_remote_exist"), post_body
|
|
540
|
+
# return check_response unless check_response.ok?
|
|
541
|
+
|
|
542
|
+
# unless options.version?
|
|
543
|
+
# version = check_response.data(:version)
|
|
544
|
+
# context_params.forward_options('version' => version)
|
|
545
|
+
# post_body.merge!(:version => version)
|
|
546
|
+
# end
|
|
547
|
+
|
|
548
|
+
# # if remote module exist and user call 'publish' we do push-dtkn else we publish it as new module
|
|
549
|
+
# response_data = check_response['data']
|
|
550
|
+
# if response_data["remote_exist"]
|
|
551
|
+
# raise DtkValidationError, "You are not allowed to update #{module_type} versions!" if response_data['frozen']
|
|
552
|
+
|
|
553
|
+
# # if do publish namespace2/module from namespace1/module, forward namespace as option to be used in push_dtkn_module_aux
|
|
554
|
+
# forward_namespace?(module_name, input_remote_name, context_params)
|
|
555
|
+
|
|
556
|
+
# push_dtkn_module_aux(context_params, true)
|
|
557
|
+
# else
|
|
558
|
+
# response = post rest_url("#{module_type}/export"), post_body
|
|
559
|
+
# return response unless response.ok?
|
|
560
|
+
|
|
561
|
+
# full_module_name = "#{response.data['remote_repo_namespace']}/#{response.data['remote_repo_name']}"
|
|
562
|
+
|
|
563
|
+
# DTK::Client::RemoteDependencyUtil.print_dependency_warnings(response, "Module has been successfully published to '#{full_module_name}'!")
|
|
564
|
+
# Response::Ok.new()
|
|
565
|
+
# end
|
|
566
|
+
# end
|
|
567
|
+
|
|
568
|
+
def pull_dtkn_aux(context_params)
|
|
569
|
+
module_id, module_name = context_params.retrieve_arguments([REQ_MODULE_ID,REQ_MODULE_NAME,:option_1],method_argument_names)
|
|
570
|
+
|
|
571
|
+
catalog = 'dtkn'
|
|
572
|
+
version = options.version||context_params.get_forwarded_options()[:version]
|
|
573
|
+
module_type = get_module_type(context_params)
|
|
574
|
+
skip_recursive_pull = context_params.get_forwarded_options()[:skip_recursive_pull]
|
|
575
|
+
ignore_dependency_merge_conflict = context_params.get_forwarded_options()[:skip_recursive_pull]
|
|
576
|
+
|
|
577
|
+
raise DtkValidationError, "You have to provide valid catalog to pull changes from! Valid catalogs: #{PULL_CATALOGS}" unless catalog
|
|
578
|
+
|
|
579
|
+
module_location = OsUtil.module_location(resolve_module_type(), module_name, version)
|
|
580
|
+
|
|
581
|
+
if catalog.to_s.eql?("dtkn")
|
|
582
|
+
clone_aux(module_type.to_sym, module_id, version, true, true) unless File.directory?(module_location)
|
|
583
|
+
opts = {
|
|
584
|
+
:force => options.force?,
|
|
585
|
+
:version => version,
|
|
586
|
+
:remote_namespace => options.namespace,
|
|
587
|
+
:skip_recursive_pull => skip_recursive_pull,
|
|
588
|
+
:ignore_dependency_merge_conflict => ignore_dependency_merge_conflict
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
opts.merge!(:do_not_raise => true) if (context_params.get_forwarded_options()||{})[:do_not_raise]
|
|
592
|
+
response = pull_from_remote_aux(module_type.to_sym, module_id, opts)
|
|
593
|
+
return response unless response.ok?
|
|
594
|
+
|
|
595
|
+
push_clone_changes_aux(module_type.to_sym, module_id, version, nil, true, {:update_from_includes => true}) if File.directory?(module_location)
|
|
596
|
+
response.skip_render = true
|
|
597
|
+
response
|
|
598
|
+
else
|
|
599
|
+
raise DtkValidationError, "You have to provide valid catalog to pull changes from! Valid catalogs: #{PULL_CATALOGS}"
|
|
600
|
+
end
|
|
601
|
+
end
|
|
602
|
+
|
|
603
|
+
def chmod_module_aux(context_params)
|
|
604
|
+
module_id, permission_selector = context_params.retrieve_arguments([REQ_MODULE_ID, :option_1!], method_argument_names)
|
|
605
|
+
chmod_aux(module_id, permission_selector, options.namespace)
|
|
606
|
+
end
|
|
607
|
+
|
|
608
|
+
def make_public_module_aux(context_params)
|
|
609
|
+
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
|
|
610
|
+
chmod_aux(module_id, "o+r", options.namespace, :make_public)
|
|
611
|
+
end
|
|
612
|
+
|
|
613
|
+
def make_private_module_aux(context_params)
|
|
614
|
+
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
|
|
615
|
+
chmod_aux(module_id, "o-rwd", options.namespace, :make_private)
|
|
616
|
+
end
|
|
617
|
+
|
|
618
|
+
def add_collaborators_module_aux(context_params)
|
|
619
|
+
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
|
|
620
|
+
collaboration_aux(:add, module_id, options.users, options.groups, options.namespace)
|
|
621
|
+
end
|
|
622
|
+
|
|
623
|
+
def remove_collaborators_module_aux(context_params)
|
|
624
|
+
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
|
|
625
|
+
collaboration_aux(:remove, module_id, options.users, options.groups, options.namespace)
|
|
626
|
+
end
|
|
627
|
+
|
|
628
|
+
def list_collaborators_module_aux(context_params)
|
|
629
|
+
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
|
|
630
|
+
response = collaboration_list_aux(module_id, options.namespace)
|
|
631
|
+
response.render_table(:module_collaborators)
|
|
632
|
+
response
|
|
633
|
+
end
|
|
634
|
+
|
|
635
|
+
def clone_module_aux(context_params, internal_trigger = false)
|
|
636
|
+
module_type = get_module_type(context_params)
|
|
637
|
+
forward_options = context_params.get_forwarded_options()
|
|
638
|
+
thor_options = forward_options.empty? ? options : forward_options
|
|
639
|
+
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
|
|
640
|
+
module_name = context_params.retrieve_arguments(["#{module_type}_name".to_sym],method_argument_names)
|
|
641
|
+
version = thor_options["version"]||options.version
|
|
642
|
+
internal_trigger = true if thor_options['skip_edit']
|
|
643
|
+
response = clone_aux(module_type.to_sym, module_id, version, internal_trigger, thor_options['omit_output'], :use_latest => true)
|
|
644
|
+
|
|
645
|
+
# if error message 'directory exist on client ...' returned print it here
|
|
646
|
+
# with forward_options[:service_importer] we know it is triggered from auto-importing dependencies so don't want to print
|
|
647
|
+
if !response.ok? && response.is_a?(Response::Error::Usage) && !forward_options[:service_importer]
|
|
648
|
+
if errors = response['errors']
|
|
649
|
+
if error_msg = errors.first['message']
|
|
650
|
+
OsUtil.print_warning(errors.first['message'])
|
|
651
|
+
return
|
|
652
|
+
end
|
|
653
|
+
end
|
|
654
|
+
end
|
|
655
|
+
|
|
656
|
+
response
|
|
657
|
+
end
|
|
658
|
+
|
|
659
|
+
def edit_module_aux(context_params)
|
|
660
|
+
module_type = get_module_type(context_params)
|
|
661
|
+
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
|
|
662
|
+
module_name = context_params.retrieve_arguments(["#{module_type}_name".to_sym], method_argument_names)
|
|
663
|
+
version = options.version||context_params.retrieve_arguments([:option_1], method_argument_names)
|
|
664
|
+
edit_dsl = context_params.get_forwarded_options()[:edit_dsl] if context_params.get_forwarded_options()
|
|
665
|
+
|
|
666
|
+
#TODO: cleanup so dont need :base_file_name and get edit_file from server
|
|
667
|
+
opts = {}
|
|
668
|
+
base_file_name = "dtk.model"
|
|
669
|
+
opts.merge!(:edit_file => {:base_file_name => base_file_name}) if edit_dsl
|
|
670
|
+
edit_aux(module_type.to_sym, module_id, module_name, version, opts)
|
|
671
|
+
end
|
|
672
|
+
|
|
673
|
+
def push_remote_module_aux(context_params)
|
|
674
|
+
module_id, module_name, remote_name = context_params.retrieve_arguments([REQ_MODULE_ID, REQ_MODULE_NAME, :option_1],method_argument_names)
|
|
675
|
+
version = options["version"]
|
|
676
|
+
module_type = get_module_type(context_params)
|
|
677
|
+
|
|
678
|
+
post_body = {
|
|
679
|
+
"#{module_type}_id".to_sym => module_id
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
response = post rest_url("#{module_type}/info_git_remote"), post_body
|
|
683
|
+
remotes_list = response.data
|
|
684
|
+
|
|
685
|
+
# vital information, abort if it does not exist
|
|
686
|
+
raise DtkError, "There are no registered remotes, aborting action" if remotes_list.empty?
|
|
687
|
+
|
|
688
|
+
# check if there is provided remote
|
|
689
|
+
if remote_name
|
|
690
|
+
target_remote = remotes_list.find { |r| remote_name.eql?(r['display_name']) }
|
|
691
|
+
raise DtkError, "Not able to find remote '#{remote_name}'" unless target_remote
|
|
692
|
+
end
|
|
693
|
+
|
|
694
|
+
# if only one take it, else raise ambiguous error
|
|
695
|
+
unless target_remote
|
|
696
|
+
if remotes_list.size == 1
|
|
697
|
+
target_remote = remotes_list.first
|
|
698
|
+
else
|
|
699
|
+
remote_names = remotes_list.collect { |r| r['display_name'] }
|
|
700
|
+
raise DtkError, "Call is ambiguous, please provide remote name. Remotes: #{remote_names.join(', ')} "
|
|
701
|
+
end
|
|
702
|
+
end
|
|
703
|
+
|
|
704
|
+
# clone if necessry
|
|
705
|
+
module_location = OsUtil.module_location(resolve_module_type(), module_name, version)
|
|
706
|
+
unless File.directory?(module_location)
|
|
707
|
+
response = clone_aux(module_type.to_sym, module_id, version, true, true)
|
|
708
|
+
return response unless response.ok?
|
|
709
|
+
end
|
|
710
|
+
|
|
711
|
+
if target_remote['base_git_location']
|
|
712
|
+
OsUtil.print("Pushing local content to remote #{target_remote['base_git_url']} in folder #{target_remote['base_git_location']} ...")
|
|
713
|
+
return push_to_git_remote_location_aux(module_name, module_type.to_sym, version, {
|
|
714
|
+
:remote_repo_url => target_remote['base_git_url'],
|
|
715
|
+
:remote_repo_location => target_remote['base_git_location'],
|
|
716
|
+
:remote_branch => 'master',
|
|
717
|
+
:remote_repo => "#{target_remote['display_name']}--remote"
|
|
718
|
+
}, options.force?)
|
|
719
|
+
else
|
|
720
|
+
OsUtil.print("Pushing local content to remote #{target_remote['repo_url']} ... ", :yellow)
|
|
721
|
+
return push_to_git_remote_aux(module_name, module_type.to_sym, version, {
|
|
722
|
+
:remote_repo_url => target_remote['repo_url'],
|
|
723
|
+
:remote_branch => 'master',
|
|
724
|
+
:remote_repo => "#{target_remote['display_name']}--remote"
|
|
725
|
+
}, options.force?)
|
|
726
|
+
end
|
|
727
|
+
end
|
|
728
|
+
|
|
729
|
+
def push_dtkn_module_aux(context_params, internal_trigger=false)
|
|
730
|
+
module_id, module_name = context_params.retrieve_arguments([REQ_MODULE_ID, REQ_MODULE_NAME],method_argument_names)
|
|
731
|
+
catalog = 'dtkn'
|
|
732
|
+
version = options["version"]||context_params.get_forwarded_thor_option('version')
|
|
733
|
+
module_type = get_module_type(context_params)
|
|
734
|
+
|
|
735
|
+
raise DtkValidationError, "You have to provide valid catalog to push changes to! Valid catalogs: #{PushCatalogs}" unless catalog
|
|
736
|
+
|
|
737
|
+
module_location = OsUtil.module_location(resolve_module_type(), module_name, version)
|
|
738
|
+
reparse_aux(module_location) unless internal_trigger
|
|
739
|
+
local_namespace, local_module_name = get_namespace_and_name(module_name,':')
|
|
740
|
+
|
|
741
|
+
if catalog.to_s.eql?("dtkn")
|
|
742
|
+
module_refs_content = RemoteDependencyUtil.module_ref_content(module_location)
|
|
743
|
+
options_namespace = options["namespace"]||context_params.get_forwarded_thor_option('namespace')
|
|
744
|
+
remote_module_info = get_remote_module_info_aux(module_type.to_sym, module_id, options_namespace, version, module_refs_content, local_namespace)
|
|
745
|
+
return remote_module_info unless remote_module_info.ok?
|
|
746
|
+
|
|
747
|
+
unless File.directory?(module_location)
|
|
748
|
+
response = clone_aux(module_type.to_sym, module_id, version, true, true)
|
|
749
|
+
|
|
750
|
+
if(response.nil? || response.ok?)
|
|
751
|
+
reparse_aux(module_location)
|
|
752
|
+
response = push_to_remote_aux(remote_module_info, module_type.to_sym)
|
|
753
|
+
end
|
|
754
|
+
|
|
755
|
+
return response
|
|
756
|
+
end
|
|
757
|
+
|
|
758
|
+
push_to_remote_aux(remote_module_info, module_type.to_sym, options.force?)
|
|
759
|
+
else
|
|
760
|
+
raise DtkValidationError, "You have to provide valid catalog to push changes to! Valid catalogs: #{PushCatalogs}"
|
|
761
|
+
end
|
|
762
|
+
end
|
|
763
|
+
|
|
764
|
+
PushCatalogs = ["origin", "dtkn"]
|
|
765
|
+
|
|
766
|
+
def list_diffs_module_aux(context_params)
|
|
767
|
+
module_type = get_module_type(context_params)
|
|
768
|
+
module_id = context_params.retrieve_arguments([REQ_MODULE_ID],method_argument_names)
|
|
769
|
+
module_name = context_params.retrieve_arguments(["#{module_type}_name".to_sym],method_argument_names)
|
|
770
|
+
version = options["version"]
|
|
771
|
+
|
|
772
|
+
module_location = OsUtil.module_location(module_type, module_name, version)
|
|
773
|
+
|
|
774
|
+
# check if there is repository cloned
|
|
775
|
+
if File.directory?(module_location)
|
|
776
|
+
list_diffs_aux(module_type.to_sym, module_id, options.remote?, version)
|
|
777
|
+
else
|
|
778
|
+
if Console.confirmation_prompt("Module '#{module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
|
|
779
|
+
response = clone_aux(module_type.to_sym, module_id, version, true)
|
|
780
|
+
# if error return
|
|
781
|
+
unless response.ok?
|
|
782
|
+
return response
|
|
783
|
+
end
|
|
784
|
+
else
|
|
785
|
+
# user choose not to clone needed module
|
|
786
|
+
return
|
|
787
|
+
end
|
|
788
|
+
end
|
|
789
|
+
end
|
|
790
|
+
|
|
791
|
+
def list_remote_module_diffs(context_params)
|
|
792
|
+
module_type = get_module_type(context_params)
|
|
793
|
+
module_id = context_params.retrieve_arguments([REQ_MODULE_ID],method_argument_names)
|
|
794
|
+
list_remote_diffs_aux(module_type.to_sym, module_id)
|
|
795
|
+
end
|
|
796
|
+
|
|
797
|
+
def list_versions_aux(context_params)
|
|
798
|
+
module_type = get_module_type(context_params)
|
|
799
|
+
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
|
|
800
|
+
include_base = context_params.get_forwarded_options()['include_base']
|
|
801
|
+
|
|
802
|
+
post_body = { "#{module_type}_id".to_sym => module_id }
|
|
803
|
+
post_body.merge!(:include_base => include_base) if include_base
|
|
804
|
+
|
|
805
|
+
response = post rest_url("#{module_type}/list_versions"), post_body
|
|
806
|
+
end
|
|
807
|
+
|
|
808
|
+
def list_remote_versions_aux(context_params)
|
|
809
|
+
module_type = get_module_type(context_params)
|
|
810
|
+
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
|
|
811
|
+
|
|
812
|
+
post_body = {
|
|
813
|
+
"#{module_type}_id".to_sym => module_id,
|
|
814
|
+
:rsa_pub_key => SSHUtil.rsa_pub_key_content()
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
response = post rest_url("#{module_type}/list_remote_versions"), post_body
|
|
818
|
+
end
|
|
819
|
+
|
|
820
|
+
def delete_assembly_aux(context_params)
|
|
821
|
+
module_type = get_module_type(context_params)
|
|
822
|
+
|
|
823
|
+
module_id, assembly_template_id = context_params.retrieve_arguments([REQ_MODULE_ID,:option_1!], method_argument_names)
|
|
824
|
+
module_name = context_params.retrieve_arguments([:service_module_name],method_argument_names)
|
|
825
|
+
|
|
826
|
+
assembly_template_name = (assembly_template_id.to_s =~ /^[0-9]+$/) ? DTK::Client::Assembly.get_assembly_template_name_for_service(assembly_template_id, module_name) : assembly_template_id
|
|
827
|
+
assembly_template_id = DTK::Client::Assembly.get_assembly_template_id_for_service(assembly_template_id, module_name) unless assembly_template_id.to_s =~ /^[0-9]+$/
|
|
828
|
+
|
|
829
|
+
return unless Console.confirmation_prompt("Are you sure you want to delete assembly '#{assembly_template_name||assembly_template_id}'"+'?') unless options.force?
|
|
830
|
+
|
|
831
|
+
post_body = {
|
|
832
|
+
"#{module_type}_id".to_sym => module_id,
|
|
833
|
+
:assembly_id => assembly_template_id,
|
|
834
|
+
:subtype => :template
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
response = post rest_url("#{module_type}/delete_assembly_template"), post_body
|
|
838
|
+
return response unless response.ok?
|
|
839
|
+
|
|
840
|
+
module_location = OsUtil.module_location(module_type, module_name)
|
|
841
|
+
|
|
842
|
+
if (module_location && assembly_template_name)
|
|
843
|
+
assembly_template_location = "#{module_location}/assemblies/#{assembly_template_name}"
|
|
844
|
+
base_file = "#{module_location}/assemblies/#{assembly_template_name}.dtk.assembly"
|
|
845
|
+
|
|
846
|
+
assembly_file_location =
|
|
847
|
+
if File.exists?("#{base_file}.yaml")
|
|
848
|
+
"#{base_file}.yaml"
|
|
849
|
+
elsif File.exists?("#{base_file}.json")
|
|
850
|
+
"#{base_file}.json"
|
|
851
|
+
else
|
|
852
|
+
nil
|
|
853
|
+
end
|
|
854
|
+
end
|
|
855
|
+
|
|
856
|
+
FileUtils.rm("#{assembly_file_location}") if assembly_file_location
|
|
857
|
+
if File.directory?(assembly_template_location)
|
|
858
|
+
unless (assembly_template_location.nil? || ("#{module_location}/assemblies/" == assembly_template_location))
|
|
859
|
+
FileUtils.rm_rf("#{assembly_template_location}")
|
|
860
|
+
end
|
|
861
|
+
end
|
|
862
|
+
version = nil
|
|
863
|
+
commit_msg = "Deleting assembly template #{assembly_template_name.to_s}"
|
|
864
|
+
internal_trigger = true
|
|
865
|
+
push_clone_changes_aux(module_type.to_sym, module_id, version, commit_msg, internal_trigger, :skip_cloning => true)
|
|
866
|
+
|
|
867
|
+
Response::Ok.new()
|
|
868
|
+
end
|
|
869
|
+
|
|
870
|
+
def list_instances_aux(context_params)
|
|
871
|
+
module_type = get_module_type(context_params)
|
|
872
|
+
module_id = context_params.retrieve_arguments([REQ_MODULE_ID],method_argument_names)
|
|
873
|
+
|
|
874
|
+
post_body = {
|
|
875
|
+
"#{module_type}_id".to_sym => module_id,
|
|
876
|
+
}
|
|
877
|
+
response = post rest_url("#{module_type}/list_instances"), post_body
|
|
878
|
+
|
|
879
|
+
# response.render_table(:assembly_template)
|
|
880
|
+
response.render_table(:assembly)
|
|
881
|
+
end
|
|
882
|
+
|
|
883
|
+
def fork_aux(context_params)
|
|
884
|
+
module_type = get_module_type(context_params)
|
|
885
|
+
module_id, fork_namespace = context_params.retrieve_arguments([REQ_MODULE_ID, :option_1!], method_argument_names)
|
|
886
|
+
|
|
887
|
+
raise DtkValidationError, "Namespace '#{fork_namespace}' contains invalid characters. Valid characters are letters, numbers, dash and underscore." unless fork_namespace.to_s =~ /^[0-9a-zA-Z\_\-]*$/
|
|
888
|
+
|
|
889
|
+
module_name = context_params.retrieve_arguments(["#{module_type}_name".to_sym],method_argument_names)
|
|
890
|
+
namespace, name = get_namespace_and_name(module_name,':')
|
|
891
|
+
|
|
892
|
+
module_location = OsUtil.module_location(module_type, module_name, nil)
|
|
893
|
+
unless File.directory?(module_location)
|
|
894
|
+
if Console.confirmation_prompt("Module '#{module_name}' has not been cloned. Would you like to clone module now"+'?')
|
|
895
|
+
response = clone_aux(module_type.to_sym, module_id, nil, true)
|
|
896
|
+
return response unless response.ok?
|
|
897
|
+
end
|
|
898
|
+
end
|
|
899
|
+
|
|
900
|
+
response = Helper(:git_repo).cp_r_to_new_namespace(module_type, name, namespace, fork_namespace)
|
|
901
|
+
return response unless response.ok?
|
|
902
|
+
|
|
903
|
+
new_context_params = DTK::Shell::ContextParams.new
|
|
904
|
+
new_context_params.add_context_to_params(module_type, module_type)
|
|
905
|
+
new_context_params.method_arguments = ["#{fork_namespace}:#{name}"]
|
|
906
|
+
|
|
907
|
+
create_response = DTK::Client::ContextRouter.routeTask(module_type, "import", new_context_params, @conn)
|
|
908
|
+
unless create_response.ok?
|
|
909
|
+
FileUtils.rm_rf("#{response['data']['module_directory']}")
|
|
910
|
+
return create_response
|
|
911
|
+
end
|
|
912
|
+
|
|
913
|
+
Response::Ok.new()
|
|
914
|
+
end
|
|
915
|
+
|
|
916
|
+
def create_new_version_aux(context_params, internal_trigger = false)
|
|
917
|
+
module_type = get_module_type(context_params)
|
|
918
|
+
module_id, version = context_params.retrieve_arguments([REQ_MODULE_ID, :option_1!], method_argument_names)
|
|
919
|
+
|
|
920
|
+
version = (context_params.get_forwarded_options()['version'] || options.version) if internal_trigger
|
|
921
|
+
|
|
922
|
+
module_name = context_params.retrieve_arguments(["#{module_type}_name".to_sym],method_argument_names)
|
|
923
|
+
namespace, name = get_namespace_and_name(module_name,':')
|
|
924
|
+
do_not_raise_if_exist = context_params.get_forwarded_options()['do_not_raise_if_exist']
|
|
925
|
+
|
|
926
|
+
module_location = OsUtil.module_location(module_type, module_name, nil)
|
|
927
|
+
unless File.directory?(module_location)
|
|
928
|
+
if Console.confirmation_prompt("Module '#{module_name}' has not been cloned. Would you like to clone module now"+'?')
|
|
929
|
+
response = clone_aux(module_type.to_sym, module_id, nil, true)
|
|
930
|
+
return response unless response.ok?
|
|
931
|
+
end
|
|
932
|
+
end
|
|
933
|
+
|
|
934
|
+
opts = {:do_not_raise_if_exist => do_not_raise_if_exist} if do_not_raise_if_exist
|
|
935
|
+
m_name, m_namespace, repo_url, branch, not_ok_response = workspace_branch_info(module_type, module_id, nil)
|
|
936
|
+
resp = Helper(:git_repo).create_new_version(module_type, branch, name, namespace, version, repo_url, opts||{})
|
|
937
|
+
|
|
938
|
+
post_body = get_workspace_branch_info_post_body(module_type, module_id, version)
|
|
939
|
+
post_body.merge!(:do_not_raise_if_exist => do_not_raise_if_exist) if do_not_raise_if_exist
|
|
940
|
+
create_response = post(rest_url("#{module_type}/create_new_version"), post_body)
|
|
941
|
+
|
|
942
|
+
unless create_response.ok?
|
|
943
|
+
FileUtils.rm_rf("#{resp['module_directory']}") unless resp['exist_already']
|
|
944
|
+
return create_response
|
|
945
|
+
end
|
|
946
|
+
|
|
947
|
+
if version_exist = create_response.data(:version_exist)
|
|
948
|
+
return create_response if do_not_raise_if_exist
|
|
949
|
+
end
|
|
950
|
+
|
|
951
|
+
if error = create_response.data(:dsl_parse_error)
|
|
952
|
+
dsl_parsed_message = ServiceImporter.error_message(module_name, error)
|
|
953
|
+
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
|
954
|
+
end
|
|
955
|
+
|
|
956
|
+
if external_dependencies = create_response.data(:external_dependencies)
|
|
957
|
+
print_dependencies(external_dependencies)
|
|
958
|
+
end
|
|
959
|
+
|
|
960
|
+
if component_module_refs = create_response.data(:component_module_refs)
|
|
961
|
+
print_using_dependencies(component_module_refs)
|
|
962
|
+
end
|
|
963
|
+
|
|
964
|
+
Response::Ok.new()
|
|
965
|
+
end
|
|
966
|
+
|
|
967
|
+
def print_ambiguous(ambiguous)
|
|
968
|
+
end
|
|
969
|
+
|
|
970
|
+
def forward_namespace?(module_name, input_remote_name, context_params)
|
|
971
|
+
return unless input_remote_name
|
|
972
|
+
local_namespace, local_name = get_namespace_and_name(module_name,':')
|
|
973
|
+
remote_namespace, remote_name = get_namespace_and_name(input_remote_name,'/')
|
|
974
|
+
context_params.forward_options('namespace' => remote_namespace) unless local_namespace.eql?(remote_namespace)
|
|
975
|
+
end
|
|
976
|
+
|
|
977
|
+
def print_dependencies(dependencies)
|
|
978
|
+
ambiguous = dependencies["ambiguous"]||[]
|
|
979
|
+
amb_sorted = ambiguous.map { |k,v| "#{k.split('/').last} (#{v.join(', ')})" }
|
|
980
|
+
inconsistent = dependencies["inconsistent"]||[]
|
|
981
|
+
possibly_missing = dependencies["possibly_missing"]||[]
|
|
982
|
+
|
|
983
|
+
OsUtil.print("There are inconsistent module dependencies mentioned in dtk.model.yaml: #{inconsistent.join(', ')}", :red) unless inconsistent.empty?
|
|
984
|
+
OsUtil.print("There are missing module dependencies mentioned in dtk.model.yaml: #{possibly_missing.join(', ')}", :yellow) unless possibly_missing.empty?
|
|
985
|
+
OsUtil.print("There are ambiguous module dependencies mentioned in dtk.model.yaml: '#{amb_sorted.join(', ')}'. One of the namespaces should be selected by editing the module_refs file", :yellow) if ambiguous && !ambiguous.empty?
|
|
986
|
+
end
|
|
987
|
+
|
|
988
|
+
def print_using_dependencies(component_refs)
|
|
989
|
+
unless component_refs.empty?
|
|
990
|
+
puts 'Using component modules:'
|
|
991
|
+
names = []
|
|
992
|
+
component_refs.values.each do |cmp_ref|
|
|
993
|
+
version = cmp_ref['version_info']
|
|
994
|
+
name = "#{cmp_ref['namespace_info']}:#{cmp_ref['module_name']}"
|
|
995
|
+
name << "(#{version})" if version
|
|
996
|
+
names << name
|
|
997
|
+
end
|
|
998
|
+
names.sort.each do |name|
|
|
999
|
+
puts " #{name}"
|
|
1000
|
+
end
|
|
1001
|
+
end
|
|
1002
|
+
end
|
|
1003
|
+
|
|
1004
|
+
def check_version_format(version)
|
|
1005
|
+
unless version.match(/\A\d{1,2}\.\d{1,2}\.\d{1,2}\Z/)
|
|
1006
|
+
raise DtkValidationError, "Version has an illegal value '#{version}', format needed: '##.##.##'"
|
|
1007
|
+
end
|
|
1008
|
+
end
|
|
1009
|
+
|
|
1010
|
+
end
|
|
1011
|
+
end
|