dtk-client 0.5.10 → 0.5.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,5 @@
1
1
  #TODO: putting in version as hidden coption that can be enabled when code ready
2
2
  #TODO: may be consistent on whether service module id or service module name used as params
3
- dtk_require_from_base('command_helpers/ssh_processing')
4
3
  dtk_require_from_base('command_helpers/service_importer')
5
4
  dtk_require_common_commands('thor/clone')
6
5
  dtk_require_common_commands('thor/push_to_remote')
@@ -14,6 +13,7 @@ dtk_require_from_base("commands/thor/assembly")
14
13
  dtk_require_common_commands('thor/task_status')
15
14
  dtk_require_common_commands('thor/set_required_params')
16
15
  dtk_require_common_commands('thor/purge_clone')
16
+ dtk_require_common_commands('thor/common')
17
17
 
18
18
  module DTK::Client
19
19
  class ServiceModule < CommandBaseThor
@@ -49,8 +49,8 @@ module DTK::Client
49
49
  PPColumns.get(:service_module)
50
50
  end
51
51
 
52
- def self.whoami()
53
- return :service_module, "service_module/list", nil
52
+ def self.validation_list(context_params)
53
+ get_cached_response(:service_module, "service_module/list", {})
54
54
  end
55
55
 
56
56
  def self.override_allowed_methods()
@@ -84,7 +84,6 @@ module DTK::Client
84
84
  ##MERGE-QUESTION: need to add options of what info is about
85
85
  desc "SERVICE-MODULE-NAME/ID info", "Provides information about specified service module"
86
86
  def info(context_params)
87
- #TODO Aldin
88
87
  if context_params.is_there_identifier?(:assembly)
89
88
  response = DTK::Client::ContextRouter.routeTask("assembly", "info", context_params, @conn)
90
89
  else
@@ -131,8 +130,7 @@ module DTK::Client
131
130
  # If user is on service level, list task can't have about value set
132
131
  if (context_params.last_entity_name == :"service-module") and about.nil?
133
132
  action = options.remote? ? "list_remote" : "list"
134
- # post_body = (options.remote? ? { :rsa_pub_key => SshProcessing.rsa_pub_key_content() } : {:detail_to_include => ["remotes","versions"]})
135
- post_body = (options.remote? ? { :rsa_pub_key => SshProcessing.rsa_pub_key_content() } : {:detail_to_include => ["remotes"]})
133
+ post_body = (options.remote? ? { :rsa_pub_key => SSHUtil.rsa_pub_key_content() } : {:detail_to_include => ["remotes"]})
136
134
  post_body[:diff] = options.diff? ? options.diff : {}
137
135
 
138
136
  response = post rest_url("service_module/#{action}"), post_body
@@ -180,7 +178,7 @@ module DTK::Client
180
178
  # post_body = {
181
179
  # :service_module_id => service_module_id,
182
180
  # :detail_to_include => ["remotes"],
183
- # :rsa_pub_key => SshProcessing.rsa_pub_key_content()
181
+ # :rsa_pub_key => SSHUtil.rsa_pub_key_content()
184
182
  # }
185
183
  # response = post rest_url("service_module/versions"), post_body
186
184
 
@@ -207,7 +205,7 @@ module DTK::Client
207
205
  post_body = {
208
206
  :remote_module_name => remote_module_name,
209
207
  :local_module_name => local_module_name,
210
- :rsa_pub_key => SshProcessing.rsa_pub_key_content()
208
+ :rsa_pub_key => SSHUtil.rsa_pub_key_content()
211
209
  }
212
210
 
213
211
  response = post rest_url("service_module/import"), post_body
@@ -216,8 +214,10 @@ module DTK::Client
216
214
  if (response.ok? && (missing_components = response.data(:missing_module_components)))
217
215
  opts = {:do_not_raise=>true}
218
216
  module_opts = ignore_component_error ? opts.merge(:ignore_component_error => true) : opts.merge(:additional_message=>true)
219
- trigger_module_component_import(missing_components,module_opts)
220
- puts "Resuming DTK network import for service module '#{remote_module_name}' ..."
217
+ continue = trigger_module_component_import(missing_components,module_opts)
218
+ return unless continue
219
+
220
+ puts "Resuming DTK Network import for service module '#{remote_module_name}' ..."
221
221
  # repeat import call for service
222
222
  post_body.merge!(opts)
223
223
  response = post rest_url("service_module/import"), post_body
@@ -289,7 +289,7 @@ module DTK::Client
289
289
  # post_body = {
290
290
  # :service_module_id => service_module_id,
291
291
  # :remote_component_name => input_remote_name,
292
- # :rsa_pub_key => SshProcessing.rsa_pub_key_content()
292
+ # :rsa_pub_key => SSHUtil.rsa_pub_key_content()
293
293
  # }
294
294
 
295
295
  # post rest_url("service_module/export"), post_body
@@ -302,7 +302,7 @@ module DTK::Client
302
302
  post_body = {
303
303
  :service_module_id => service_module_id,
304
304
  :remote_component_name => input_remote_name,
305
- :rsa_pub_key => SshProcessing.rsa_pub_key_content()
305
+ :rsa_pub_key => SSHUtil.rsa_pub_key_content()
306
306
  }
307
307
 
308
308
  post rest_url("service_module/export"), post_body
@@ -347,34 +347,13 @@ module DTK::Client
347
347
  # push_to_remote_aux(:service_module, service_module_id, service_module_name, options["namespace"], options["version"])
348
348
  # end
349
349
 
350
- # desc "SERVICE-MODULE-NAME/ID pull-from-dtkn [-v VERSION]", "Update local service module from remote repository."
351
- # version_method_option
352
- # desc "SERVICE-MODULE-NAME/ID pull-from-dtkn", "Update local service module from remote repository."
353
- # def pull_from_dtkn(context_params)
354
- # service_module_id, service_module_name = context_params.retrieve_arguments([:service_module_id!,:service_module_name],method_argument_names)
355
- # version = options["version"]
356
-
357
- # response = pull_from_remote_aux(:service_module,service_module_id,version)
358
- # return response unless response.ok?
359
-
360
- # if service_module_name.to_s =~ /^[0-9]+$/
361
- # service_module_id = service_module_name
362
- # service_module_name = get_service_module_name(service_module_id)
363
- # end
364
-
365
- # modules_path = OsUtil.service_clone_location()
366
- # module_location = "#{modules_path}/#{service_module_name}#{version && "-#{version}"}"
367
-
368
- # # server repo needs to be sync with local clone, so we will use push-clone-changes when pull changes from remote to local
369
- # # to automatically sync local with server repo
370
- # push_clone_changes_aux(:service_module,service_module_id,version,nil,true) if File.directory?(module_location)
371
- # Response::Ok.new()
372
- # end
373
-
374
- # desc "SERVICE-MODULE-NAME/ID pull dtkn", "Update local service module from remote repository."
375
- desc "SERVICE-MODULE-NAME/ID pull-dtkn", "Update local service module from remote repository."
350
+ # desc "SERVICE-MODULE-NAME/ID pull-from-dtkn [-n NAMESPACE] [-v VERSION]", "Update local service module from remote repository."
351
+ desc "SERVICE-MODULE-NAME/ID pull-dtkn [-n NAMESPACE]", "Update local service module from remote repository."
352
+ method_option "namespace",:aliases => "-n",
353
+ :type => :string,
354
+ :banner => "NAMESPACE",
355
+ :desc => "Remote namespace"
376
356
  def pull_dtkn(context_params)
377
- # service_module_id, service_module_name, catalog = context_params.retrieve_arguments([:service_module_id!,:service_module_name, :option_1],method_argument_names)
378
357
  service_module_id, service_module_name = context_params.retrieve_arguments([:service_module_id!,:service_module_name],method_argument_names)
379
358
  catalog = 'dtkn'
380
359
  version = options["version"]
@@ -382,7 +361,8 @@ module DTK::Client
382
361
  raise DtkValidationError, "You have to provide valid catalog to pull changes from! Valid catalogs: #{PullCatalogs}" unless catalog
383
362
 
384
363
  if catalog.to_s.eql?("dtkn")
385
- response = pull_from_remote_aux(:service_module,service_module_id,version)
364
+ opts = {:version => version, :remote_namespace => options.namespace}
365
+ response = pull_from_remote_aux(:service_module,service_module_id,opts)
386
366
  return response unless response.ok?
387
367
 
388
368
  if service_module_name.to_s =~ /^[0-9]+$/
@@ -453,7 +433,7 @@ module DTK::Client
453
433
  # service_module_id,version = context_params.retrieve_arguments([:service_module_id!,:option_1!],method_argument_names)
454
434
  # post_body = {
455
435
  # :service_module_id => service_module_id,
456
- # :rsa_pub_key => SshProcessing.rsa_pub_key_content()
436
+ # :rsa_pub_key => SSHUtil.rsa_pub_key_content()
457
437
  # }
458
438
  # response = post rest_url("service_module/versions"), post_body
459
439
  # return response unless response.ok?
@@ -632,24 +612,23 @@ module DTK::Client
632
612
  modules_path = OsUtil.service_clone_location()
633
613
  module_location = "#{modules_path}/#{service_module_name}#{version && "-#{version}"}"
634
614
  reparse_aux(module_location) unless internal_trigger
615
+
635
616
  if catalog.to_s.eql?("dtkn")
617
+ remote_module_info = get_remote_module_info_aux(:service_module, service_module_id, options["namespace"], version)
618
+ return remote_module_info unless remote_module_info.ok?
619
+
636
620
  unless File.directory?(module_location)
637
- if Console.confirmation_prompt("Unable to push to remote because module '#{service_module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
638
- response = clone_aux(:service_module,service_module_id,version,false)
639
-
640
- if(response.nil? || response.ok?)
641
- reparse_aux(module_location)
642
- push_to_remote_aux(:service_module, service_module_id, service_module_name, options["namespace"], version) if Console.confirmation_prompt("Would you like to push changes to remote"+'?')
643
- end
621
+ response = clone_aux(:service_module, service_module_id, version, true, true)
644
622
 
645
- return response
646
- else
647
- # user choose not to clone needed module
648
- return
623
+ if(response.nil? || response.ok?)
624
+ reparse_aux(module_location)
625
+ response = push_to_remote_aux(remote_module_info, :service_module)
649
626
  end
627
+
628
+ return response
650
629
  end
651
630
 
652
- push_to_remote_aux(:service_module, service_module_id, service_module_name, options["namespace"], options["version"])
631
+ push_to_remote_aux(remote_module_info, :service_module)
653
632
  else
654
633
  raise DtkValidationError, "You have to provide valid catalog to push changes to!"
655
634
  end
@@ -719,7 +698,7 @@ module DTK::Client
719
698
 
720
699
  post_body = {
721
700
  :remote_service_name => remote_service_name,
722
- :rsa_pub_key => SshProcessing.rsa_pub_key_content()
701
+ :rsa_pub_key => SSHUtil.rsa_pub_key_content()
723
702
  }
724
703
  response = post rest_url("service_module/delete_remote"), post_body
725
704
  @@invalidate_map << :module_service
@@ -134,8 +134,9 @@ module DTK::Client
134
134
  ['set-attribute',"set-attribute ATTRIBUTE-NAME [VALUE] [-u]","# (Un)Set attribute value. The option -u will unset the attribute's value."],
135
135
  ['start', "start", "# Start node instance."],
136
136
  ['stop', "stop", "# Stop node instance."],
137
- ['ssh', "ssh [--keypair] [--remote-user]", "# SSH into node, optional parameters are path to keypair and remote user."]
137
+ ['ssh', "ssh REMOTE-USER [--keypair PATH-TO-PEM]", "# SSH into node, optional parameters are path to keypair and remote user."]
138
138
  ],
139
+
139
140
  :component => [
140
141
  ['info',"info","# Return info about component instance belonging to given node."],
141
142
  ['edit',"edit","# Edit component module related to given component."],
data/lib/configurator.rb CHANGED
@@ -22,15 +22,20 @@ module DTK
22
22
  end
23
23
 
24
24
  def self.check_config_exists
25
+ exists = true
25
26
  if !File.exists?(CONFIG_FILE)
26
27
  puts "", "Please enter the DTK server address (example: dtk.r8network.com)"
27
28
  header = File.read(File.expand_path('../lib/config/client.conf.header', File.dirname(__FILE__)))
28
29
  generate_conf_file(CONFIG_FILE, [['server_host', 'Server address']], header)
30
+ exists = false
29
31
  end
30
32
  if !File.exists?(CRED_FILE)
31
33
  puts "", "Please enter your DTK login details"
32
34
  generate_conf_file(CRED_FILE, [['username', 'Username'], ['password', 'Password']], '')
35
+ exists = false
33
36
  end
37
+
38
+ exists
34
39
  end
35
40
 
36
41
  def self.check_git
@@ -45,7 +50,7 @@ module DTK
45
50
  # return true/false, .add_direct_access file location and ssk key file location
46
51
  def self.check_direct_access
47
52
  username_exists = check_for_username_entry(client_username())
48
- ssh_key_path = SshProcessing.default_rsa_pub_key_path()
53
+ ssh_key_path = SSHUtil.default_rsa_pub_key_path()
49
54
 
50
55
  {:username_exists => username_exists, :file_path => DIRECT_ACCESS, :ssh_key_path => ssh_key_path}
51
56
  end
data/lib/core.rb CHANGED
@@ -11,6 +11,7 @@ require 'pp'
11
11
 
12
12
  dtk_require_from_base('domain/response')
13
13
  dtk_require_from_base('util/os_util')
14
+ dtk_require_from_base('util/ssh_util')
14
15
  dtk_require("config/configuration")
15
16
 
16
17
  def top_level_execute(entity_name, method_name, context_params=nil, options_args=nil, shell_execute=false)
@@ -111,15 +112,15 @@ def validate_connection(connection)
111
112
  end
112
113
 
113
114
  # check if .add_direct_access file exists, if not then add direct access and create .add_direct_access file
114
- def resolve_direct_access(params)
115
+ def resolve_direct_access(params, config_exists=nil)
115
116
  return if params[:username_exists]
116
117
 
117
- puts "Adding direct access for current user..."
118
+ puts "Processing..." if config_exists
118
119
  # response = DTK::Client::Account.add_access(params[:ssh_key_path])
119
120
  response, matched_pub_key, matched_username = DTK::Client::Account.add_key(params[:ssh_key_path])
120
121
 
121
122
  if !response.ok?
122
- DTK::Client::OsUtil.print("We were not able to add direct access for current user. #{response.error_message}. In order to properly use dtk-shell you will have to add access manually ('dtk account add-ssh-key').\n", :yellow)
123
+ DTK::Client::OsUtil.print("We were not able to add access for current user. #{response.error_message}. In order to properly use dtk-shell you will have to add access manually ('dtk account add-ssh-key').\n", :yellow)
123
124
  elsif matched_pub_key
124
125
  # message will be displayed by add key # TODO: Refactor this flow
125
126
  DTK::Client::OsUtil.print("Provided SSH PUB key has already been added.", :yellow)
@@ -405,8 +406,7 @@ module DTK
405
406
  response = post_raw rest_url("user/process_login"),creds
406
407
  errors = response['errors']
407
408
 
408
- if response.kind_of?(Common::Response) and not response.ok?
409
- puts errors.first['code']
409
+ if response.kind_of?(Common::Response) and not response.ok?
410
410
  if (errors && errors.first['code']=="pg_error")
411
411
  DTK::Client::OsUtil.print(errors.first['message'].gsub!("403 Forbidden", "[PG_ERROR]"), :red)
412
412
  exit
@@ -35,6 +35,8 @@ module DTK
35
35
  "Destination folder #{$1.strip()} already exists"
36
36
  when /Authentication failed for (.*)$/i
37
37
  "Authentication failed for given repository #{$1.strip()}"
38
+ when /timed out/
39
+ "Timeout - not able to contact remote"
38
40
  else
39
41
  message
40
42
  end
@@ -63,7 +63,8 @@ module DTK
63
63
  "size:" => "SIZE:",
64
64
  "os_type:" => "OS:",
65
65
  "op_status:" => "OP STATUS:",
66
- "dns_name:" => "DNS NAME:"
66
+ "dns_name:" => "DNS NAME:",
67
+ "target:" => "TARGET:"
67
68
  }
68
69
 
69
70
  mappings[column]
@@ -1,3 +1,3 @@
1
1
  module DtkClient
2
- VERSION="0.5.10"
2
+ VERSION="0.5.12"
3
3
  end
@@ -39,8 +39,7 @@ module DTK
39
39
 
40
40
  def self.execute_from_cli(conn,method_name,context_params,thor_options,shell_execution=false)
41
41
  @@shell_execution = shell_execution
42
-
43
- # I am sorry!
42
+
44
43
  if method_name == 'help'
45
44
  ret = start([method_name] + context_params.method_arguments,:conn => conn)
46
45
  else
data/lib/shell/domain.rb CHANGED
@@ -332,6 +332,14 @@ module DTK
332
332
  @context_list.size > 2
333
333
  end
334
334
 
335
+ def is_base_context?
336
+ @context_list.size == 1
337
+ end
338
+
339
+ def is_root_context?
340
+ @context_list.size == 0
341
+ end
342
+
335
343
  def current_command?
336
344
  return @context_list.empty? ? true : @context_list.last.is_command?
337
345
  end
@@ -388,7 +396,6 @@ module DTK
388
396
  def last_context()
389
397
  return @context_list.empty? ? nil : @context_list.last
390
398
  end
391
-
392
399
  end
393
400
 
394
401
  class CachedTasks < Hash
@@ -67,13 +67,15 @@ class Thor
67
67
  if @@shell_context
68
68
  unless @@shell_context.root?
69
69
 
70
+ active_context = @@shell_context.active_context
71
+
70
72
  # first command we are using:
71
73
  # e.g. dtk:\assembly\assembly1\node\node123> => command would be :assembly
72
- command = @@shell_context.active_context.first_command_name.upcase
74
+ command = active_context.first_command_name.upcase
73
75
 
74
76
  # is there identifier for given commands (first)
75
77
  # e.g. dtk:\assembly\assembly1\node\node123> => identifier here would be 'assembly1'
76
- is_there_identifier = @@shell_context.active_context.is_there_identifier_for_first_context?
78
+ is_there_identifier = active_context.is_there_identifier_for_first_context?
77
79
 
78
80
  # alternative providers
79
81
  alt_identifiers = get_alternative_identifiers(command)
@@ -100,7 +102,7 @@ class Thor
100
102
  # e.g. dtk:\assembly\assembly1\node\node123> THIS IS N-LEVEL CONTEXT
101
103
  # e.g. dtk:\assembly\assembly1> THIS IS NOT N-LEVEL CONTEXT
102
104
  #
103
- if (!@@shell_context.active_context.is_n_context? || @@shell_context.active_context.current_identifier?)
105
+ if (!active_context.is_n_context? || active_context.current_identifier?)
104
106
 
105
107
  list.each do |help_item|
106
108
  help_item.first.gsub!("^^", '') if help_item.first.include?("^^")
@@ -127,12 +129,12 @@ class Thor
127
129
  else
128
130
  # Adding alt identifiers here
129
131
  if alt_matched_data
130
- if @@shell_context.active_context.current_alt_identifier?
132
+ if active_context.current_alt_identifier?
131
133
  help_item.first.gsub!(matched_data[0],'') unless help_item.nil?
132
134
  filtered_list << overriden_help(override_tasks_obj, help_item, false)
133
135
  end
134
136
  else
135
- unless @@shell_context.active_context.current_alt_identifier?
137
+ unless active_context.current_alt_identifier?
136
138
  help_item.first.gsub!(matched_data[0],'') unless help_item.nil?
137
139
  filtered_list << overriden_help(override_tasks_obj, help_item, false)
138
140
  end
@@ -144,8 +146,8 @@ class Thor
144
146
 
145
147
  # This will return commands that have identifiers
146
148
  # e.g. dtk:\assembly\assembly1\node\node123> => ['assembly','node']
147
- commands_that_have_identifiers = @@shell_context.active_context.commands_that_have_identifiers()
148
- is_n_level_context = @@shell_context.active_context.command_list.size > 1
149
+ commands_that_have_identifiers = active_context.commands_that_have_identifiers()
150
+ is_n_level_context = active_context.command_list.size > 1
149
151
 
150
152
  # first one does not count
151
153
  if is_n_level_context
@@ -166,12 +168,12 @@ class Thor
166
168
  end
167
169
 
168
170
  if override_tasks_obj && is_n_level_context
169
- last_entity_name = @@shell_context.active_context.last_context_entity_name.to_sym
171
+ last_entity_name = active_context.last_context_entity_name.to_sym
170
172
 
171
173
  # we get commands task, and identifier tasks for given entity (e.g. :assembly)
172
174
  command_o_tasks, identifier_o_tasks = override_tasks_obj.get_all_tasks(last_entity_name)
173
175
 
174
- if @@shell_context.active_context.current_identifier?
176
+ if active_context.current_identifier?
175
177
  identifier_o_tasks.each do |o_task|
176
178
  n_filter_list << [o_task[1],o_task[2]]
177
179
  end
@@ -216,14 +218,30 @@ class Thor
216
218
  shell.print_table(list, :indent => 2, :truncate => true)
217
219
  shell.say
218
220
 
221
+
219
222
  # print sub context information
220
- # if @@shell_context && @@shell_context.active_context.current_identifier?
221
- # sub_children = self.respond_to?(:valid_children) ? self.valid_children() : []
222
- # sub_children += self.invisible_context_list()
223
+ sub_children = []
224
+
225
+ # current active context clazz
226
+ if @@shell_context
227
+ last_command_name = @@shell_context.active_context.last_command_name
228
+ command_clazz = DTK::Shell::Context.get_command_class(last_command_name)
229
+
230
+ if @@shell_context && @@shell_context.active_context.current_identifier?
231
+ sub_children += command_clazz.valid_children() if command_clazz.respond_to?(:valid_children)
232
+ sub_children += command_clazz.invisible_context_list()
233
+ else
234
+ if command_clazz.respond_to?(:validation_list)
235
+ sub_children += ["#{last_command_name}-identifier"]
236
+ end
237
+ end
238
+
239
+ unless sub_children.empty?
240
+ shell.say(" Change context (cc) to: #{sub_children.join(', ')}", :BOLD)
241
+ shell.say
242
+ end
243
+ end
223
244
 
224
- # shell.say(" Change context (cc) to: #{sub_children.join(', ')}", :BOLD) unless sub_children.empty?
225
- # shell.say
226
- # end
227
245
 
228
246
  class_options_help(shell)
229
247
  end
data/lib/util/console.rb CHANGED
@@ -120,7 +120,8 @@ module DTK::Client
120
120
  reparse_aux(path)
121
121
  push_clone_changes_aux(module_type, module_id, version, commit_msg)
122
122
  else
123
- system(line)
123
+ # we are sending stderr to stdout
124
+ system("#{line} 2>&1")
124
125
  end
125
126
  rescue Exception => e
126
127
  DtkLogger.instance.error_pp(e.message, e.backtrace)
data/lib/util/os_util.rb CHANGED
@@ -233,6 +233,7 @@ module DTK
233
233
  def dev_reload_shell()
234
234
  suspend_output do
235
235
  load File.expand_path('../../lib/util/os_util.rb', File.dirname(__FILE__))
236
+ load File.expand_path('../../lib/util/ssh_util.rb', File.dirname(__FILE__))
236
237
  load File.expand_path('../../lib/shell/help_monkey_patch.rb', File.dirname(__FILE__))
237
238
  load File.expand_path('../../lib/shell/domain.rb', File.dirname(__FILE__))
238
239
  load File.expand_path('../../lib/domain/git_adapter.rb', File.dirname(__FILE__))
@@ -0,0 +1,76 @@
1
+ module DTK
2
+ module Client
3
+ module SSHUtil
4
+
5
+ def self.read_and_validate_pub_key(path_to_pub_key)
6
+ is_ssh_key_path_valid?(path_to_pub_key)
7
+ rsa_pub_key = File.open(path_to_pub_key) { |f| f.read }
8
+ is_ssh_key_content_valid?(rsa_pub_key)
9
+ rsa_pub_key
10
+ end
11
+
12
+ def self.update_ssh_known_hosts(server_dns,server_fingerprint)
13
+ known_hosts_path = ssh_known_hosts_path()
14
+ if File.file?(known_hosts_path)
15
+ `ssh-keygen -f #{known_hosts_path} -R #{server_dns} 2> /dev/null`
16
+ File.open(known_hosts_path,"a"){|f|f << server_fingerprint}
17
+ else
18
+ ssh_base_dir = ssh_base_dir()
19
+ unless File.directory?(ssh_base_dir)
20
+ Dir.mkdir(ssh_base_dir)
21
+ end
22
+ File.open(known_hosts_path,"w"){|f|f << server_fingerprint}
23
+ end
24
+ end
25
+
26
+ def self.default_rsa_pub_key_path()
27
+ "#{ssh_base_dir()}/id_rsa.pub"
28
+ end
29
+
30
+ def self.rsa_pub_key_content()
31
+ path_to_key = self.default_rsa_pub_key_path()
32
+ unless File.file?(path_to_key)
33
+ raise DtkError,"No 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)"
34
+ end
35
+
36
+ content = File.open(path_to_key){ |f| f.read }
37
+ content.chomp
38
+ end
39
+
40
+ def self.ssh_reachable?(user, server, timeout = 3)
41
+ output = `ssh -o ConnectTimeout=#{timeout} -o \"StrictHostKeyChecking no\" -o \"UserKnownHostsFile /dev/null\" -q #{user}@#{server} exit; echo $?`
42
+
43
+ # if response 0 than it is able to connect
44
+ "0".eql?(output.strip())
45
+ end
46
+
47
+
48
+ private
49
+
50
+ def self.ssh_base_dir()
51
+ "#{ENV['HOME']}/.ssh" #TODO: very brittle
52
+ end
53
+
54
+ def self.ssh_known_hosts_path()
55
+ "#{ssh_base_dir()}/known_hosts"
56
+ end
57
+
58
+ def self.is_ssh_key_path_valid?(path_to_key)
59
+ unless path_to_key.include?(".pub")
60
+ raise DtkError, "[ERROR] Invalid public key file path (#{path_to_key}). Please provide valid path and try again."
61
+ end
62
+
63
+ unless File.exists?(path_to_key)
64
+ raise DtkError, "[ERROR] Not able to find provided key (#{path_to_key}). Please provide valid path and try again."
65
+ end
66
+ end
67
+
68
+ def self.is_ssh_key_content_valid?(rsa_pub_key)
69
+ if(rsa_pub_key.empty? || !rsa_pub_key.include?("AAAAB3NzaC1yc2EA"))
70
+ raise DtkError, "[ERROR] SSH public key (#{path_to_key}) does not have valid content. Please check your key and try again."
71
+ end
72
+ end
73
+
74
+ end
75
+ end
76
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dtk-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.10
4
+ version: 0.5.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich PELAVIN
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-17 00:00:00.000000000 Z
11
+ date: 2014-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: 0.5.4
117
+ version: 0.5.10
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ~>
123
123
  - !ruby/object:Gem::Version
124
- version: 0.5.4
124
+ version: 0.5.10
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: git
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -202,7 +202,7 @@ files:
202
202
  - lib/command_helpers/jenkins_client.rb
203
203
  - lib/command_helpers/service_importer.rb
204
204
  - lib/command_helpers/service_link.rb
205
- - lib/command_helpers/ssh_processing.rb
205
+ - lib/commands/common/thor/action_result_handler.rb
206
206
  - lib/commands/common/thor/assembly_workspace.rb
207
207
  - lib/commands/common/thor/clone.rb
208
208
  - lib/commands/common/thor/common.rb
@@ -273,6 +273,7 @@ files:
273
273
  - lib/util/console.rb
274
274
  - lib/util/dtk_puppet.rb
275
275
  - lib/util/os_util.rb
276
+ - lib/util/ssh_util.rb
276
277
  - lib/view_processor/augmented_simple_list.rb
277
278
  - lib/view_processor/hash_pretty_print.rb
278
279
  - lib/view_processor/simple_list.rb
@@ -326,7 +327,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
326
327
  version: '0'
327
328
  requirements: []
328
329
  rubyforge_project:
329
- rubygems_version: 2.1.5
330
+ rubygems_version: 2.1.9
330
331
  signing_key:
331
332
  specification_version: 4
332
333
  summary: DTK CLI client for DTK server interaction.
@@ -1,43 +0,0 @@
1
- module DTK; module Client
2
- class SshProcessing
3
- def self.update_ssh_known_hosts(server_dns,server_fingerprint)
4
- known_hosts_path = ssh_known_hosts_path()
5
- if File.file?(known_hosts_path)
6
- `ssh-keygen -f #{known_hosts_path} -R #{server_dns} 2> /dev/null`
7
- File.open(known_hosts_path,"a"){|f|f << server_fingerprint}
8
- else
9
- ssh_base_dir = ssh_base_dir()
10
- unless File.directory?(ssh_base_dir)
11
- Dir.mkdir(ssh_base_dir)
12
- end
13
- File.open(known_hosts_path,"w"){|f|f << server_fingerprint}
14
- end
15
- end
16
- def self.default_rsa_pub_key_path()
17
- "#{ssh_base_dir()}/id_rsa.pub"
18
- end
19
-
20
- def self.rsa_pub_key_content()
21
- path_to_key = self.default_rsa_pub_key_path()
22
- unless File.file?(path_to_key)
23
- raise DtkError,"No 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)"
24
- end
25
-
26
- content = File.open(path_to_key){ |f| f.read }
27
- content.chomp
28
- end
29
-
30
-
31
- private
32
- def self.ssh_base_dir()
33
- "#{ENV['HOME']}/.ssh" #TODO: very brittle
34
- end
35
-
36
- def self.ssh_known_hosts_path()
37
- "#{ssh_base_dir()}/known_hosts"
38
- end
39
- end
40
- end; end
41
-
42
-
43
-