dtk-client 0.5.10 → 0.5.12
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 +8 -8
- data/bin/dtk +2 -3
- data/bin/dtk-shell +2 -3
- data/dtk-client.gemspec +1 -1
- data/lib/auxiliary.rb +32 -0
- data/lib/command_helpers/service_importer.rb +46 -6
- data/lib/commands/common/thor/action_result_handler.rb +52 -0
- data/lib/commands/common/thor/assembly_workspace.rb +21 -12
- data/lib/commands/common/thor/common.rb +17 -0
- data/lib/commands/common/thor/list_diffs.rb +1 -1
- data/lib/commands/common/thor/pull_from_remote.rb +39 -32
- data/lib/commands/common/thor/push_to_remote.rb +22 -20
- data/lib/commands/thor/account.rb +10 -19
- data/lib/commands/thor/component.rb +2 -1
- data/lib/commands/thor/component_module.rb +36 -48
- data/lib/commands/thor/developer.rb +1 -1
- data/lib/commands/thor/node.rb +31 -15
- data/lib/commands/thor/node_template.rb +4 -4
- data/lib/commands/thor/provider.rb +4 -4
- data/lib/commands/thor/service.rb +64 -64
- data/lib/commands/thor/service_module.rb +33 -54
- data/lib/commands/thor/workspace.rb +2 -1
- data/lib/configurator.rb +6 -1
- data/lib/core.rb +5 -5
- data/lib/domain/git_error_handler.rb +2 -0
- data/lib/domain/response.rb +2 -1
- data/lib/dtk-client/version.rb +1 -1
- data/lib/parser/adapters/thor.rb +1 -2
- data/lib/shell/domain.rb +8 -1
- data/lib/shell/help_monkey_patch.rb +33 -15
- data/lib/util/console.rb +2 -1
- data/lib/util/os_util.rb +1 -0
- data/lib/util/ssh_util.rb +76 -0
- metadata +7 -6
- data/lib/command_helpers/ssh_processing.rb +0 -43
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTZhMDBlMWM1ZWUzYjFiNWFlNTg2NDJmZTE2MjQ2ZGU4YmFjYmZiMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWNkODg5NjU2NWJmN2Q4YzkzNDZmZTE1NzU1OTE5YWExZmJhNzVmZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzQ0ZmVmYmM0NmY4NmJlMGZiYWFmODY0NWYyOTI5YWFmYmJjZWViZDliNGY5
|
10
|
+
YTFlMjRmZTZlZTI0NWI3OTFlNDIyZGNkZmIyYTZlODgyMWZhNGRmZDNlNDZj
|
11
|
+
NzRmMzMyYzgzMTllOWMyOTZlZTFhMWJkNGQwM2VhZjI1NmIyZGQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTUwYzA1Y2E0NzEwY2Y0ZGZkMDcwNzRkNTVlOWNmZDBkZTkwY2M5NjQ3NzUz
|
14
|
+
MWY5ZTEzMmNlOGQ5NGNlY2EwYzg3ZTU3ZjQ2M2ExNTcyNzA0YmZmOGY5ZmIy
|
15
|
+
YTkxNzQ0OGVkMTYxZmI3MDZiZmRkYzk1Y2I3YjM5M2M3N2RkYTQ=
|
data/bin/dtk
CHANGED
@@ -9,7 +9,6 @@ require File.expand_path('../lib/parser/adapters/thor', File.dirname(__FILE__
|
|
9
9
|
require File.expand_path('../lib/shell/context', File.dirname(__FILE__))
|
10
10
|
require File.expand_path('../lib/shell/domain', File.dirname(__FILE__))
|
11
11
|
require File.expand_path('../lib/commands/thor/account', File.dirname(__FILE__))
|
12
|
-
require File.expand_path('../lib/command_helpers/ssh_processing', File.dirname(__FILE__))
|
13
12
|
require File.expand_path('../lib/shell/parse_monkey_patch', File.dirname(__FILE__))
|
14
13
|
require File.expand_path('../lib/shell/help_monkey_patch', File.dirname(__FILE__))
|
15
14
|
|
@@ -18,13 +17,13 @@ require 'shellwords'
|
|
18
17
|
|
19
18
|
$: << "/usr/lib/ruby/1.8/" #TODO: put in to get around path problem in rvm 1.9.2 environment
|
20
19
|
|
21
|
-
::DTK::Client::Configurator.check_config_exists
|
20
|
+
config_exists = ::DTK::Client::Configurator.check_config_exists
|
22
21
|
::DTK::Client::Configurator.check_git
|
23
22
|
::DTK::Client::Configurator.create_missing_clone_dirs
|
24
23
|
|
25
24
|
|
26
25
|
# check if .add_direct_access file exists, if not then add direct access and create .add_direct_access file
|
27
|
-
resolve_direct_access(::DTK::Client::Configurator.check_direct_access)
|
26
|
+
resolve_direct_access(::DTK::Client::Configurator.check_direct_access, config_exists)
|
28
27
|
entries = []
|
29
28
|
|
30
29
|
if ARGV.size > 0
|
data/bin/dtk-shell
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require File.expand_path('../lib/shell', File.dirname(__FILE__))
|
3
3
|
require File.expand_path('../lib/commands/thor/account', File.dirname(__FILE__))
|
4
|
-
require File.expand_path('../lib/command_helpers/ssh_processing', File.dirname(__FILE__))
|
5
4
|
|
6
5
|
trap("INT", "SIG_IGN")
|
7
6
|
|
8
|
-
::DTK::Client::Configurator.check_config_exists
|
7
|
+
config_exists = ::DTK::Client::Configurator.check_config_exists
|
9
8
|
::DTK::Client::Configurator.check_git
|
10
9
|
::DTK::Client::Configurator.create_missing_clone_dirs
|
11
10
|
|
12
11
|
# check if .add_direct_access file exists, if not then add direct access and create .add_direct_access file
|
13
|
-
resolve_direct_access(::DTK::Client::Configurator.check_direct_access)
|
12
|
+
resolve_direct_access(::DTK::Client::Configurator.check_direct_access, config_exists)
|
14
13
|
|
15
14
|
run_shell_command()
|
data/dtk-client.gemspec
CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |gem|
|
|
29
29
|
gem.add_dependency 'hirb','~> 0.7.0'
|
30
30
|
gem.add_dependency 'thor','~> 0.15.4'
|
31
31
|
gem.add_dependency 'erubis','~> 2.7.0'
|
32
|
-
gem.add_dependency 'dtk-common-core','~> 0.5.
|
32
|
+
gem.add_dependency 'dtk-common-core','~> 0.5.10'
|
33
33
|
gem.add_dependency 'git','~> 1.2.6'
|
34
34
|
gem.add_dependency 'colorize','~> 0.5.8'
|
35
35
|
gem.add_dependency 'highline', '1.6.16'
|
data/lib/auxiliary.rb
CHANGED
@@ -9,5 +9,37 @@ module DTK
|
|
9
9
|
command_class.to_s.gsub(/^.*::/, '').gsub(/Command$/,'').scan(/[A-Z][a-z]+/).map{|w|w.downcase}.join(seperator)
|
10
10
|
end
|
11
11
|
end
|
12
|
+
|
13
|
+
#TODO: probably move this
|
14
|
+
class PostBody < Hash
|
15
|
+
def initialize(raw={})
|
16
|
+
super()
|
17
|
+
unless raw.empty?
|
18
|
+
replace(convert(raw))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
def merge(raw)
|
22
|
+
super(convert(raw))
|
23
|
+
end
|
24
|
+
def merge!(raw)
|
25
|
+
super(convert(raw))
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def convert(raw)
|
30
|
+
raw.inject(Hash.new) do |h,(k,v)|
|
31
|
+
if non_null_var = is_only_non_null_var?(k)
|
32
|
+
v.nil? ? h : h.merge(non_null_var => v)
|
33
|
+
else
|
34
|
+
h.merge(k => v)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
def is_only_non_null_var?(k)
|
39
|
+
if k.to_s =~ /\?$/
|
40
|
+
k.to_s.gsub(/\?$/,'').to_sym
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
12
44
|
end
|
13
45
|
end
|
@@ -20,11 +20,18 @@ module DTK::Client
|
|
20
20
|
#
|
21
21
|
def trigger_module_component_import(missing_component_list,opts={})
|
22
22
|
puts "Auto-importing missing component module(s)"
|
23
|
+
does_not_exist, modules_to_import = validate_missing_components(missing_component_list)
|
23
24
|
|
24
|
-
|
25
|
-
|
25
|
+
unless does_not_exist.empty?
|
26
|
+
module_names = does_not_exist.collect{|x| "#{x['namespace']}/#{x['name']}"}
|
27
|
+
OsUtil.print("Component modules '#{module_names}' required by service module does not exist on repo manager and will not be imported!", :yellow)
|
28
|
+
return false unless Console.confirmation_prompt("Do you want to continue with import of available component modules and service module"+'?')
|
29
|
+
end
|
30
|
+
|
31
|
+
modules_to_import.each do |m_module|
|
26
32
|
module_name = "#{m_module['namespace']}/#{m_module['name']}"
|
27
|
-
module_name += "
|
33
|
+
module_name += "-#{m_module['version']}" if m_module['version']
|
34
|
+
print "Importing component module '#{module_name}' ... "
|
28
35
|
new_context_params = ::DTK::Shell::ContextParams.new([module_name])
|
29
36
|
new_context_params.override_method_argument!('option_2', m_module['version'])
|
30
37
|
new_context_params.forward_options( { "skip_cloning" => true}).merge!(opts)
|
@@ -37,14 +44,47 @@ module DTK::Client
|
|
37
44
|
Response::Ok.new()
|
38
45
|
end
|
39
46
|
|
47
|
+
# check if component modules dependencies specified in service module exist on repo manager
|
48
|
+
def validate_missing_components(missing_component_list)
|
49
|
+
thor_options = {}
|
50
|
+
thor_options["remote"] = true
|
51
|
+
new_context_params = ::DTK::Shell::ContextParams.new
|
52
|
+
new_context_params.forward_options(thor_options)
|
53
|
+
new_context_params.add_context_to_params(:"component-module", :"component-module")
|
54
|
+
response = ContextRouter.routeTask("component_module", "list", new_context_params, @conn)
|
55
|
+
return response unless response.ok?
|
56
|
+
|
57
|
+
does_not_exist, modules_to_import = [], []
|
58
|
+
|
59
|
+
missing_component_list.each do |missing_cmp|
|
60
|
+
cmp = response.data.select{|x| x['display_name'].eql?("#{missing_cmp['namespace']}/#{missing_cmp['name']}")}
|
61
|
+
if cmp.empty?
|
62
|
+
does_not_exist << missing_cmp
|
63
|
+
else
|
64
|
+
cmp = cmp.first
|
65
|
+
if remote_version = cmp['versions']
|
66
|
+
missing_version = missing_cmp['version']||'CURRENT'
|
67
|
+
does_not_exist << missing_cmp unless (remote_version.include?(missing_version))
|
68
|
+
else
|
69
|
+
does_not_exist << missing_cmp if missing_cmp['version']
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
modules_to_import = missing_component_list - does_not_exist
|
75
|
+
return does_not_exist, modules_to_import
|
76
|
+
end
|
77
|
+
|
40
78
|
def resolve_missing_components(service_module_id, service_module_name, namespace_to_use, force_clone=false)
|
41
79
|
# Get dependency component modules and cross reference them with local component modules
|
42
80
|
module_component_list = post rest_url("service_module/list_component_modules"), { :service_module_id => service_module_id }
|
43
81
|
local_modules, needed_modules = OsUtil.local_component_module_list(), Array.new
|
44
82
|
|
45
|
-
module_component_list
|
46
|
-
|
47
|
-
|
83
|
+
if module_component_list
|
84
|
+
module_component_list.data.each do |dependency_module|
|
85
|
+
unless local_modules.include?(formated_name = formulate_module_name(dependency_module['display_name'], dependency_module['version']))
|
86
|
+
needed_modules << dependency_module.merge({'formated_name' => formated_name})
|
87
|
+
end
|
48
88
|
end
|
49
89
|
end
|
50
90
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module DTK
|
2
|
+
module Client
|
3
|
+
module ActionResultHandler
|
4
|
+
|
5
|
+
def print_action_results(action_results_id, number_of_retries=8)
|
6
|
+
response = action_results(action_results_id, number_of_retries)
|
7
|
+
|
8
|
+
if response.ok? && response.data['results']
|
9
|
+
response.data['results'].each do |k,v|
|
10
|
+
if v['error']
|
11
|
+
OsUtil.print("#{v['error']} (#{k})", :red)
|
12
|
+
else
|
13
|
+
OsUtil.print("#{v['message']} (#{k})", :yellow)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
else
|
17
|
+
OsUtil.print("Not able to process given request, we apologise for inconvenience", :red)
|
18
|
+
end
|
19
|
+
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def action_results(action_results_id, number_of_retries=8)
|
24
|
+
action_body = {
|
25
|
+
:action_results_id => action_results_id,
|
26
|
+
:return_only_if_complete => true,
|
27
|
+
:disable_post_processing => true
|
28
|
+
}
|
29
|
+
response = nil
|
30
|
+
|
31
|
+
number_of_retries.times do
|
32
|
+
response = post(rest_url("assembly/get_action_results"),action_body)
|
33
|
+
|
34
|
+
# server has found an error
|
35
|
+
unless response.data(:results).nil?
|
36
|
+
if response.data(:results)['error']
|
37
|
+
raise DTK::Client::DtkError, response.data(:results)['error']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
break if response.data(:is_complete)
|
42
|
+
|
43
|
+
sleep(1.5)
|
44
|
+
end
|
45
|
+
|
46
|
+
response
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -722,8 +722,8 @@ module DTK::Client
|
|
722
722
|
end
|
723
723
|
|
724
724
|
def execute_tests_aux(context_params)
|
725
|
-
execute_test_tries =
|
726
|
-
execute_test_sleep =
|
725
|
+
execute_test_tries = 10
|
726
|
+
execute_test_sleep = 1
|
727
727
|
|
728
728
|
assembly_or_workspace_id,node_id = context_params.retrieve_arguments([REQ_ASSEMBLY_OR_WS_ID,:node_id],method_argument_names)
|
729
729
|
|
@@ -738,13 +738,28 @@ module DTK::Client
|
|
738
738
|
response = post(rest_url("assembly/info_about"),post_body)
|
739
739
|
|
740
740
|
components = []
|
741
|
-
|
742
741
|
if !response['data'].nil?
|
743
742
|
response['data'].each do |c|
|
744
743
|
components << c['display_name']
|
745
744
|
end
|
746
745
|
end
|
747
746
|
|
747
|
+
#Filter out request per specific component
|
748
|
+
#Filter works for two types of component notation provided: node/component and component
|
749
|
+
if !options["component"].nil?
|
750
|
+
components.reject! do |c|
|
751
|
+
if options["component"].include? "/"
|
752
|
+
c != options["component"]
|
753
|
+
else
|
754
|
+
c.split("/").last != options["component"]
|
755
|
+
end
|
756
|
+
end
|
757
|
+
end
|
758
|
+
|
759
|
+
if components.empty?
|
760
|
+
components = nil
|
761
|
+
end
|
762
|
+
|
748
763
|
post_body = {
|
749
764
|
:assembly_id => assembly_or_workspace_id,
|
750
765
|
:node_id => node_id,
|
@@ -752,6 +767,7 @@ module DTK::Client
|
|
752
767
|
}
|
753
768
|
|
754
769
|
response = post(rest_url("assembly/initiate_execute_tests"),post_body)
|
770
|
+
raise DTK::Client::DtkValidationError, response.data(:errors).first if response.data(:errors)
|
755
771
|
return response unless response.ok?
|
756
772
|
|
757
773
|
action_results_id = response.data(:action_results_id)
|
@@ -776,16 +792,8 @@ module DTK::Client
|
|
776
792
|
sleep execute_test_sleep
|
777
793
|
end
|
778
794
|
end
|
779
|
-
filtered = response.data(:results)
|
780
|
-
|
781
|
-
#Filter out results per specific component
|
782
|
-
if !options["component"].nil?
|
783
|
-
filtered.reject! do |element|
|
784
|
-
element["component_name"] != options["component"]
|
785
|
-
end
|
786
|
-
end
|
787
795
|
|
788
|
-
response.set_data(*
|
796
|
+
response.set_data(*response.data(:results))
|
789
797
|
response.render_table(:execute_tests_data)
|
790
798
|
end
|
791
799
|
|
@@ -1161,6 +1169,7 @@ module DTK::Client
|
|
1161
1169
|
|
1162
1170
|
post_body[:about] = about
|
1163
1171
|
response = post rest_url(rest_endpoint), post_body
|
1172
|
+
|
1164
1173
|
# set render view to be used
|
1165
1174
|
unless format
|
1166
1175
|
response.render_table(data_type, use_default)
|
@@ -30,5 +30,22 @@ module DTK::Client
|
|
30
30
|
end
|
31
31
|
post_body
|
32
32
|
end
|
33
|
+
|
34
|
+
def get_remote_module_info_aux(module_type,module_id,remote_namespace,version=nil)
|
35
|
+
id_field = "#{module_type}_id"
|
36
|
+
rsa_pub_value = SSHUtil.rsa_pub_key_content()
|
37
|
+
|
38
|
+
post_body = {
|
39
|
+
id_field => module_id,
|
40
|
+
:rsa_pub_key => rsa_pub_value,
|
41
|
+
:access_rights => "rw",
|
42
|
+
:action => "push"
|
43
|
+
}
|
44
|
+
post_body.merge!(:version => version) if version
|
45
|
+
post_body.merge!(:remote_namespace => remote_namespace) if remote_namespace
|
46
|
+
|
47
|
+
post(rest_url("#{module_type}/get_remote_module_info"),post_body)
|
48
|
+
end
|
49
|
+
|
33
50
|
end
|
34
51
|
end
|
@@ -2,7 +2,7 @@ module DTK::Client
|
|
2
2
|
module ListDiffsMixin
|
3
3
|
def list_diffs_aux(module_type,module_id,remote,version=nil)
|
4
4
|
id_field = "#{module_type}_id"
|
5
|
-
path_to_key =
|
5
|
+
path_to_key = SSHUtil.default_rsa_pub_key_path()
|
6
6
|
rsa_pub_key = File.file?(path_to_key) && File.open(path_to_key){|f|f.read}.chomp
|
7
7
|
|
8
8
|
post_body = {
|
@@ -1,39 +1,20 @@
|
|
1
1
|
module DTK::Client
|
2
2
|
module PullFromRemoteMixin
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# module_type: will be :component_module or :service_module
|
7
|
-
def import_module_component_dependencies(module_id)
|
8
|
-
post_body = {
|
9
|
-
:service_module_id => module_id
|
10
|
-
}
|
11
|
-
response = post(rest_url("service_module/resolve_pull_from_remote"),post_body)
|
12
|
-
|
13
|
-
print "Resolving dependencies please wait ... "
|
14
|
-
|
15
|
-
if (response.ok? && !(missing_components = response.data(:missing_modules)).empty?)
|
16
|
-
puts " New dependencies found, Installing."
|
17
|
-
|
18
|
-
trigger_module_component_import(missing_components)
|
19
|
-
puts "Resuming pull from remote ..."
|
20
|
-
else
|
21
|
-
puts 'Done.'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def pull_from_remote_aux(module_type,module_id,version=nil)
|
3
|
+
def pull_from_remote_aux(module_type,module_id,opts={})
|
4
|
+
version = opts[:version]
|
5
|
+
remote_namespace = opts[:remote_namespace]
|
26
6
|
#get remote module info, errors raised if remote is not linked or access errors
|
27
|
-
path_to_key =
|
7
|
+
path_to_key = SSHUtil.default_rsa_pub_key_path()
|
28
8
|
rsa_pub_key = File.file?(path_to_key) && File.open(path_to_key){|f|f.read}.chomp
|
29
9
|
|
30
|
-
post_body =
|
10
|
+
post_body = PostBody.new(
|
31
11
|
PullFromRemote.id_field(module_type) => module_id,
|
32
12
|
:access_rights => "r",
|
33
|
-
:action => "pull"
|
34
|
-
|
35
|
-
|
36
|
-
|
13
|
+
:action => "pull",
|
14
|
+
:version? => version,
|
15
|
+
:remote_namespace? => remote_namespace,
|
16
|
+
:rsa_pub_key? => rsa_pub_key
|
17
|
+
)
|
37
18
|
response = post(rest_url("#{module_type}/get_remote_module_info"),post_body)
|
38
19
|
return response unless response.ok?
|
39
20
|
module_name = response.data(:module_name)
|
@@ -41,8 +22,9 @@ module DTK::Client
|
|
41
22
|
remote_params.merge!(:version => version) if version
|
42
23
|
|
43
24
|
#check and import component module dependencies before importing service itself
|
44
|
-
|
45
|
-
|
25
|
+
if (module_type == :service_module)
|
26
|
+
import_module_component_dependencies(module_id,remote_namespace)
|
27
|
+
end
|
46
28
|
# check whether a local module exists to determine whether pull from local clone or try to pull from server
|
47
29
|
if Helper(:git_repo).local_clone_exists?(module_type,module_name,version)
|
48
30
|
unless rsa_pub_key
|
@@ -53,14 +35,37 @@ module DTK::Client
|
|
53
35
|
PullFromRemote.perform_on_server(self,module_type,module_id,module_name,remote_params)
|
54
36
|
end
|
55
37
|
end
|
38
|
+
|
56
39
|
private
|
40
|
+
|
41
|
+
##
|
42
|
+
#
|
43
|
+
# module_type: will be :component_module or :service_module
|
44
|
+
def import_module_component_dependencies(module_id,remote_namespace=nil)
|
45
|
+
post_body = PostBody.new(
|
46
|
+
:service_module_id => module_id,
|
47
|
+
:remote_namespace? => remote_namespace
|
48
|
+
)
|
49
|
+
response = post(rest_url("service_module/resolve_pull_from_remote"),post_body)
|
50
|
+
|
51
|
+
print "Resolving dependencies please wait ... "
|
52
|
+
|
53
|
+
if (response.ok? && !(missing_components = response.data(:missing_modules)).empty?)
|
54
|
+
puts " New dependencies found, Installing."
|
55
|
+
|
56
|
+
trigger_module_component_import(missing_components)
|
57
|
+
puts "Resuming pull from remote ..."
|
58
|
+
else
|
59
|
+
puts 'Done.'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
57
63
|
module PullFromRemote
|
58
64
|
extend CommandBase
|
59
65
|
def self.perform_locally(cmd_obj,module_type,module_id,module_name,remote_params)
|
60
66
|
opts = remote_params
|
61
67
|
response = cmd_obj.Helper(:git_repo).pull_changes(module_type,module_name,opts)
|
62
68
|
# return response unless response.ok?
|
63
|
-
|
64
69
|
if response.data[:diffs].empty?
|
65
70
|
raise DtkError, "No changes to pull from remote"
|
66
71
|
end
|
@@ -77,6 +82,8 @@ module DTK::Client
|
|
77
82
|
end
|
78
83
|
|
79
84
|
def self.perform_on_server(cmd_obj,module_type,module_id,module_name,remote_params)
|
85
|
+
#TODO: this does not handle different namespaces; so suggesting workaround for now
|
86
|
+
raise DtkError, "Module must be cloned to perform this operation; execute 'clone' command and then retry."
|
80
87
|
post_body = {
|
81
88
|
id_field(module_type) => module_id,
|
82
89
|
:remote_repo => remote_params[:remote_repo],
|
@@ -1,37 +1,39 @@
|
|
1
|
+
dtk_require_common_commands('thor/common')
|
1
2
|
module DTK::Client
|
2
3
|
module PushToRemoteMixin
|
3
4
|
|
4
5
|
##
|
5
6
|
#
|
6
7
|
# module_type: will be :component_module or :service_module
|
8
|
+
# def push_to_remote_aux(module_type,module_id, module_name,remote_namespace,version=nil)
|
9
|
+
def push_to_remote_aux(remote_module_info, module_type)
|
10
|
+
# commented out, because we perform this check before calling 'push_to_remote_aux' from service-module/component-module
|
11
|
+
# id_field = "#{module_type}_id"
|
7
12
|
|
8
|
-
|
9
|
-
id_field = "#{module_type}_id"
|
13
|
+
# rsa_pub_value = SSHUtil.rsa_pub_key_content()
|
10
14
|
|
11
|
-
|
15
|
+
# post_body = {
|
16
|
+
# id_field => module_id,
|
17
|
+
# :rsa_pub_key => rsa_pub_value,
|
18
|
+
# :access_rights => "rw",
|
19
|
+
# :action => "push"
|
20
|
+
# }
|
21
|
+
# post_body.merge!(:version => version) if version
|
22
|
+
# post_body.merge!(:remote_namespace => remote_namespace) if remote_namespace
|
12
23
|
|
13
|
-
|
14
|
-
|
15
|
-
:rsa_pub_key => rsa_pub_value,
|
16
|
-
:access_rights => "rw",
|
17
|
-
:action => "push"
|
18
|
-
}
|
19
|
-
post_body.merge!(:version => version) if version
|
20
|
-
post_body.merge!(:remote_namespace => remote_namespace) if remote_namespace
|
21
|
-
response = post(rest_url("#{module_type}/get_remote_module_info"),post_body)
|
24
|
+
# response = post(rest_url("#{module_type}/get_remote_module_info"),post_body)
|
25
|
+
# return response unless response.ok?
|
22
26
|
|
23
|
-
|
27
|
+
returned_module_name = remote_module_info.data(:module_name)
|
28
|
+
version = remote_module_info.data(:version)
|
24
29
|
|
25
|
-
returned_module_name = response.data(:module_name)
|
26
30
|
opts = {
|
27
|
-
:remote_repo_url =>
|
28
|
-
:remote_repo =>
|
29
|
-
:remote_branch =>
|
30
|
-
:local_branch =>
|
31
|
+
:remote_repo_url => remote_module_info.data(:remote_repo_url),
|
32
|
+
:remote_repo => remote_module_info.data(:remote_repo),
|
33
|
+
:remote_branch => remote_module_info.data(:remote_branch),
|
34
|
+
:local_branch => remote_module_info.data(:workspace_branch)
|
31
35
|
}
|
32
36
|
|
33
|
-
version = response.data(:version)
|
34
|
-
|
35
37
|
response = Helper(:git_repo).push_changes(module_type,returned_module_name,version,opts)
|
36
38
|
return response unless response.ok?
|
37
39
|
if response.data(:diffs).empty?
|
@@ -1,4 +1,3 @@
|
|
1
|
-
dtk_require_from_base('command_helpers/ssh_processing')
|
2
1
|
dtk_require_from_base("dtk_logger")
|
3
2
|
dtk_require_from_base("util/os_util")
|
4
3
|
dtk_require_from_base('configurator')
|
@@ -10,15 +9,6 @@ module DTK::Client
|
|
10
9
|
KEY_EXISTS_ALREADY_CONTENT = 'key exists already'
|
11
10
|
|
12
11
|
no_tasks do
|
13
|
-
def self.is_ssh_key_valid(path_to_key, rsa_pub_key)
|
14
|
-
unless path_to_key.include?(".pub")
|
15
|
-
raise DtkError, "[ERROR] Invalid public key file path (#{path_to_key}). Please provide valid path and try again."
|
16
|
-
end
|
17
|
-
|
18
|
-
if(rsa_pub_key.empty? || !rsa_pub_key.include?("AAAAB3NzaC1yc2EA"))
|
19
|
-
raise DtkError, "[ERROR] SSH public key (#{path_to_key}) does not have valid content. Please check your key and try again."
|
20
|
-
end
|
21
|
-
end
|
22
12
|
|
23
13
|
def password_prompt(message, add_options=true)
|
24
14
|
begin
|
@@ -51,8 +41,7 @@ module DTK::Client
|
|
51
41
|
raise DtkError,"[ERROR] No ssh key file found at (#{path_to_key}). Path is wrong or it is necessary to generate the public rsa key (e.g., run `ssh-keygen -t rsa`)."
|
52
42
|
end
|
53
43
|
|
54
|
-
rsa_pub_key =
|
55
|
-
is_ssh_key_valid(path_to_key, rsa_pub_key)
|
44
|
+
rsa_pub_key = SSHUtil.read_and_validate_pub_key(path_to_key)
|
56
45
|
|
57
46
|
post_body = { :rsa_pub_key => rsa_pub_key.chomp }
|
58
47
|
post_body.merge!(:username => name.chomp) if name
|
@@ -67,9 +56,11 @@ module DTK::Client
|
|
67
56
|
|
68
57
|
if response && !match
|
69
58
|
repo_manager_fingerprint,repo_manager_dns = response.data_ret_and_remove!(:repo_manager_fingerprint,:repo_manager_dns)
|
70
|
-
|
59
|
+
|
60
|
+
SSHUtil.update_ssh_known_hosts(repo_manager_dns,repo_manager_fingerprint)
|
71
61
|
name ||= response.data["new_username"]
|
72
62
|
OsUtil.print("SSH key '#{name}' added successfully!", :yellow)
|
63
|
+
|
73
64
|
end
|
74
65
|
|
75
66
|
return response, match, matched_username
|
@@ -124,7 +115,7 @@ module DTK::Client
|
|
124
115
|
desc "add-ssh-key KEYPAIR-NAME [PATH-TO-RSA-PUB-KEY]","Adds a named ssh key to your user account to access modules from the catalog. Optional parameters is path to a ssh rsa public key and default is <user-home-dir>/.ssh/id_rsa.pub"
|
125
116
|
def add_ssh_key(context_params)
|
126
117
|
name, path_to_key = context_params.retrieve_arguments([:option_1!, :option_2],method_argument_names)
|
127
|
-
path_to_key ||=
|
118
|
+
path_to_key ||= SSHUtil.default_rsa_pub_key_path()
|
128
119
|
|
129
120
|
response, matched, matched_username = Account.add_key(path_to_key, name)
|
130
121
|
|
@@ -136,7 +127,7 @@ module DTK::Client
|
|
136
127
|
DTK::Client::Configurator.add_current_user_to_direct_access() if response.ok?
|
137
128
|
end
|
138
129
|
|
139
|
-
|
130
|
+
nil
|
140
131
|
end
|
141
132
|
|
142
133
|
desc "delete-ssh-key KEYPAIR-NAME ","Deletes the named ssh key from your user account"
|
@@ -148,7 +139,7 @@ module DTK::Client
|
|
148
139
|
return response unless response.ok?
|
149
140
|
|
150
141
|
OsUtil.print("Ssh key '#{name}' removed successfully!", :yellow)
|
151
|
-
|
142
|
+
nil
|
152
143
|
end
|
153
144
|
|
154
145
|
|
@@ -177,7 +168,7 @@ module DTK::Client
|
|
177
168
|
# # if either of request passed we will add to known hosts
|
178
169
|
# if proper_response
|
179
170
|
# repo_manager_fingerprint,repo_manager_dns = proper_response.data_ret_and_remove!(:repo_manager_fingerprint,:repo_manager_dns)
|
180
|
-
#
|
171
|
+
# SSHUtil.update_ssh_known_hosts(repo_manager_dns,repo_manager_fingerprint)
|
181
172
|
# return proper_response
|
182
173
|
# else
|
183
174
|
# nil
|
@@ -188,7 +179,7 @@ module DTK::Client
|
|
188
179
|
# def add_direct_access(context_params)
|
189
180
|
# return
|
190
181
|
# path_to_key = context_params.retrieve_arguments([:option_1],method_argument_names)
|
191
|
-
# path_to_key ||=
|
182
|
+
# path_to_key ||= SSHUtil.default_rsa_pub_key_path()
|
192
183
|
# access_granted = Account.add_access(path_to_key)
|
193
184
|
|
194
185
|
# FileUtils.touch(DTK::Client::Configurator::DIRECT_ACCESS) if access_granted
|
@@ -198,7 +189,7 @@ module DTK::Client
|
|
198
189
|
# desc "remove-direct-access [PATH-TO-RSA-PUB-KEY]","Removes direct access to modules. Optional paramaeters is path to a ssh rsa public key and default is <user-home-dir>/.ssh/id_rsa.pub"
|
199
190
|
# def remove_direct_access(context_params)
|
200
191
|
# path_to_key = context_params.retrieve_arguments([:option_1],method_argument_names)
|
201
|
-
# path_to_key ||=
|
192
|
+
# path_to_key ||= SSHUtil.default_rsa_pub_key_path()
|
202
193
|
|
203
194
|
# # path_to_key ||= "#{ENV['HOME']}/.ssh/id_rsa.pub" #TODO: very brittle
|
204
195
|
# unless File.file?(path_to_key)
|