dtk-client 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/command_helpers/git_repo.rb +20 -11
- data/lib/command_helpers/service_importer.rb +1 -1
- data/lib/commands/common/thor/assembly_workspace.rb +11 -3
- data/lib/commands/common/thor/common.rb +2 -1
- data/lib/commands/common/thor/module.rb +38 -8
- data/lib/commands/common/thor/push_clone_changes.rb +4 -3
- data/lib/commands/thor/account.rb +11 -0
- data/lib/commands/thor/assembly.rb +23 -23
- data/lib/commands/thor/component_module.rb +2 -2
- data/lib/commands/thor/provider.rb +23 -6
- data/lib/commands/thor/service_module.rb +25 -4
- data/lib/commands/thor/target.rb +20 -4
- data/lib/commands/thor/test_module.rb +1 -1
- data/lib/configurator.rb +147 -129
- data/lib/core.rb +19 -5
- data/lib/domain/git_adapter.rb +39 -4
- data/lib/domain/response.rb +0 -3
- data/lib/dtk-client/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ae387fa3ef1b1ab77afa462b3de70d85dc091d9
|
4
|
+
data.tar.gz: 28a1fbd9f0f73e2e4d8b3a4071f50610957e5f35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4c9d5be56fcdacca8fe807b471217ad2ea5a8a85ffa20b875d73b21b1adfcdb7ddf7225a1c08297210eb51efbc1d4c744ce465757a4b75fd7a9970ecad6fe61
|
7
|
+
data.tar.gz: ba9ea50cf712535d0aa4b95cddf9ad11b1f5c451ee7a57e82b8cff7185645abd98043eba12a8e8235cd6f7e47ce5944583b0389515b5ff52218043d97b5ab868
|
@@ -28,7 +28,7 @@ module DTK; module Client; class CommandHelper
|
|
28
28
|
|
29
29
|
target_repo_dir = local_repo_dir(type,full_name,version,opts)
|
30
30
|
if File.exists?(target_repo_dir)
|
31
|
-
raise ErrorUsage.new("Directory '#{target_repo_dir}' is not empty; it must be deleted or removed before retrying the command")
|
31
|
+
raise ErrorUsage.new("Directory '#{target_repo_dir}' is not empty; it must be deleted or removed before retrying the command")
|
32
32
|
end
|
33
33
|
|
34
34
|
begin
|
@@ -60,13 +60,13 @@ module DTK; module Client; class CommandHelper
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
#opts can have the following keys
|
63
|
+
# opts can have the following keys
|
64
64
|
#
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
# :remote_repo
|
66
|
+
# :remote_branch
|
67
|
+
# :remote_repo_url
|
68
|
+
# :local_branch
|
69
|
+
# :no_fetch
|
70
70
|
#
|
71
71
|
def push_changes(type,full_module_name,version,opts={})
|
72
72
|
Response.wrap_helper_actions() do
|
@@ -152,7 +152,7 @@ module DTK; module Client; class CommandHelper
|
|
152
152
|
local_repo_dir = local_repo_dir(type,full_module_name,version)
|
153
153
|
|
154
154
|
unless File.directory?(local_repo_dir)
|
155
|
-
raise ErrorUsage.new("The content for module (#{full_module_name}) should be put in directory (#{local_repo_dir})")
|
155
|
+
raise ErrorUsage.new("The content for module (#{full_module_name}) should be put in directory (#{local_repo_dir})",:log_error=>false)
|
156
156
|
end
|
157
157
|
|
158
158
|
# transfered this part to initialize_client_clone_and_push because if we remove .git folder and
|
@@ -175,7 +175,6 @@ module DTK; module Client; class CommandHelper
|
|
175
175
|
end
|
176
176
|
|
177
177
|
def rename_and_initialize_clone_and_push(type, module_name, new_module_name, branch, repo_url, local_repo_dir, version = nil)
|
178
|
-
|
179
178
|
# check to see if the new dir has proper naming e.g. (~/dtk/component_modules/dtk::java)
|
180
179
|
unless local_repo_dir.match(/\/#{new_module_name.gsub(ModuleUtil::NAMESPACE_SEPERATOR,'/')}$/)
|
181
180
|
old_dir = local_repo_dir
|
@@ -185,13 +184,23 @@ module DTK; module Client; class CommandHelper
|
|
185
184
|
parent_path = new_dir.gsub(/(\/\w+)$/,'')
|
186
185
|
FileUtils::mkdir_p(parent_path) unless File.directory?(parent_path)
|
187
186
|
# raise ErrorUsage.new("Destination folder already exists '#{new_dir}', aborting initialization.") if File.directory?(new_dir)
|
188
|
-
|
187
|
+
if File.directory?(new_dir)
|
188
|
+
# return empty response if user does not want to overwrite current directory
|
189
|
+
return unless Console.confirmation_prompt("Destination directory #{new_dir} exists already. Do you want to overwrite it with content from #{old_dir}"+'?')
|
190
|
+
FileUtils.rm_rf(new_dir)
|
191
|
+
end
|
192
|
+
# FileUtils.mv(old_dir, new_dir)
|
193
|
+
FileUtils.cp_r(old_dir, new_dir)
|
189
194
|
else
|
190
195
|
new_dir = local_repo_dir
|
191
196
|
end
|
192
197
|
|
193
198
|
# Continue push
|
194
|
-
initialize_client_clone_and_push(type, new_module_name, branch, repo_url, new_dir, version)
|
199
|
+
response = initialize_client_clone_and_push(type, new_module_name, branch, repo_url, new_dir, version)
|
200
|
+
return response unless response.ok?
|
201
|
+
|
202
|
+
response.data.merge!(:old_dir => old_dir)
|
203
|
+
response
|
195
204
|
end
|
196
205
|
|
197
206
|
# makes repo_dir (determined from type and module_name) into a git dir, pulls, adds, content and then pushes
|
@@ -40,7 +40,7 @@ module DTK::Client
|
|
40
40
|
print "Importing component module '#{module_name}' ... "
|
41
41
|
new_context_params = ::DTK::Shell::ContextParams.new([module_name])
|
42
42
|
new_context_params.override_method_argument!('option_2', m_module['version'])
|
43
|
-
new_context_params.forward_options( { "skip_cloning" =>
|
43
|
+
new_context_params.forward_options( { "skip_cloning" => false}).merge!(opts)
|
44
44
|
|
45
45
|
response = ContextRouter.routeTask("component_module", "install", new_context_params, @conn)
|
46
46
|
puts(response.data(:does_not_exist) ? response.data(:does_not_exist) : "Done.")
|
@@ -67,9 +67,12 @@ module DTK::Client
|
|
67
67
|
end
|
68
68
|
|
69
69
|
namespace ||= opts[:default_namespace]
|
70
|
+
local_clone_dir_exists = Helper(:git_repo).local_clone_dir_exists?(:service_module, service_module_name, :namespace => namespace)
|
71
|
+
|
70
72
|
if namespace
|
71
73
|
post_body.merge!(:namespace => namespace)
|
72
|
-
post_body.merge!(:local_clone_dir_exists => true) if
|
74
|
+
post_body.merge!(:local_clone_dir_exists => true) if local_clone_dir_exists
|
75
|
+
# post_body.merge!(:local_clone_dir_exists => true) if Helper(:git_repo).local_clone_dir_exists?(:service_module, service_module_name, :namespace => namespace)
|
73
76
|
end
|
74
77
|
|
75
78
|
post_body.merge!(:assembly_template_name => assembly_template_name) if assembly_template_name
|
@@ -78,10 +81,15 @@ module DTK::Client
|
|
78
81
|
return response unless response.ok?()
|
79
82
|
|
80
83
|
#synchronize_clone will load new assembly template into service clone on workspace (if it exists)
|
81
|
-
commit_sha,workspace_branch,namespace,full_module_name = response.data(:commit_sha,:workspace_branch,:module_namespace,:full_module_name)
|
84
|
+
commit_sha,workspace_branch,namespace,full_module_name,repo_url,version = response.data(:commit_sha,:workspace_branch,:module_namespace,:full_module_name,:repo_url,:version)
|
82
85
|
service_module_name ||= response.data(:module_name)
|
83
86
|
opts = {:local_branch=>workspace_branch, :namespace => namespace}
|
84
|
-
|
87
|
+
|
88
|
+
if local_clone_dir_exists
|
89
|
+
response = Helper(:git_repo).synchronize_clone(:service_module,service_module_name,commit_sha,opts)
|
90
|
+
else
|
91
|
+
response = Helper(:git_repo).create_clone_with_branch(:service_module, service_module_name, repo_url, workspace_branch, version, namespace)
|
92
|
+
end
|
85
93
|
return response unless response.ok?
|
86
94
|
|
87
95
|
DTK::Client::OsUtil.print("New assembly template '#{assembly_template_name}' created in service module '#{full_module_name}'.", :yellow) if mode == :create
|
@@ -38,7 +38,7 @@ module DTK::Client
|
|
38
38
|
post_body
|
39
39
|
end
|
40
40
|
|
41
|
-
def get_remote_module_info_aux(module_type, module_id, remote_namespace, version=nil, module_refs_content=nil)
|
41
|
+
def get_remote_module_info_aux(module_type, module_id, remote_namespace, version=nil, module_refs_content=nil, local_namespace=nil)
|
42
42
|
id_field = "#{module_type}_id"
|
43
43
|
rsa_pub_value = SSHUtil.rsa_pub_key_content()
|
44
44
|
|
@@ -50,6 +50,7 @@ module DTK::Client
|
|
50
50
|
}
|
51
51
|
post_body.merge!(:version => version) if version
|
52
52
|
post_body.merge!(:remote_namespace => remote_namespace) if remote_namespace
|
53
|
+
post_body.merge!(:local_namespace => local_namespace) if local_namespace
|
53
54
|
post_body.merge!(:module_ref_content => module_refs_content) if module_refs_content && !module_refs_content.empty?
|
54
55
|
|
55
56
|
response = post(rest_url("#{module_type}/get_remote_module_info"),post_body)
|
@@ -241,9 +241,11 @@ module DTK::Client
|
|
241
241
|
|
242
242
|
repo_url,repo_id,module_id,branch,new_module_name = response.data(:repo_url,:repo_id,:module_id,:workspace_branch,:full_module_name)
|
243
243
|
response = Helper(:git_repo).rename_and_initialize_clone_and_push(module_type.to_sym, local_module_name, new_module_name, branch, repo_url, module_directory)
|
244
|
-
return response unless response.ok?
|
245
|
-
|
244
|
+
return response unless (response && response.ok?)
|
245
|
+
|
246
|
+
repo_obj,commit_sha = response.data(:repo_obj, :commit_sha)
|
246
247
|
module_final_dir = repo_obj.repo_dir
|
248
|
+
old_dir = response.data[:old_dir]
|
247
249
|
|
248
250
|
post_body = {
|
249
251
|
:repo_id => repo_id,
|
@@ -255,6 +257,9 @@ module DTK::Client
|
|
255
257
|
|
256
258
|
unless response.ok?
|
257
259
|
response.set_data_hash({ :full_module_name => new_module_name })
|
260
|
+
# remove new directory if import failed
|
261
|
+
# DTK-1768: removed below; TODO: see if there is any case where applicable
|
262
|
+
# FileUtils.rm_rf(module_final_dir) unless (namespace && git_import)
|
258
263
|
return response
|
259
264
|
end
|
260
265
|
|
@@ -277,9 +282,31 @@ module DTK::Client
|
|
277
282
|
context_params.add_context_to_params(local_module_name, module_type.to_s.gsub!(/\_/,'-').to_sym, module_id)
|
278
283
|
response = push_module_aux(context_params, true)
|
279
284
|
|
285
|
+
unless response.ok?
|
286
|
+
# remove new directory if import failed
|
287
|
+
# DTK-1768: removed below; TODO: see if there is any case where applicable
|
288
|
+
# Also think what should be done is if failure then move the directory back to old dir position
|
289
|
+
# (if it has been moved)
|
290
|
+
# FileUtils.rm_rf(module_final_dir) unless (namespace && git_import)
|
291
|
+
return response
|
292
|
+
end
|
293
|
+
|
294
|
+
# remove the old one if no errors while importing
|
295
|
+
# DTK-1768: removed below; and replaced by removing old dir if unequal to final dir
|
296
|
+
# was not sure why clause namespace && git_import was in so kept this condition
|
297
|
+
# FileUtils.rm_rf(old_dir) unless (namespace && git_import)
|
298
|
+
# New:
|
299
|
+
if old_dir and (old_dir != module_final_dir)
|
300
|
+
FileUtils.rm_rf(old_dir) unless (namespace && git_import)
|
301
|
+
end
|
302
|
+
|
280
303
|
if git_import
|
281
304
|
response[:module_id] = module_id
|
282
305
|
response.add_data_value!(:external_dependencies, external_dependencies) if external_dependencies
|
306
|
+
else
|
307
|
+
# if not git-import and user do import from default directory (e.g. import ntp - without namespace) print message
|
308
|
+
# module directory moved from (~/dtk/component_module/<module_name>) to (~/dtk/component_module/<default_namespace>/<module_name>)
|
309
|
+
DTK::Client::OsUtil.print("Module '#{new_module_name}' has been created and module directory moved to #{module_final_dir}",:yellow) unless namespace
|
283
310
|
end
|
284
311
|
|
285
312
|
response
|
@@ -298,7 +325,7 @@ module DTK::Client
|
|
298
325
|
ignore_component_error = context_params.get_forwarded_options() ? context_params.get_forwarded_options()[:ignore_component_error] : options.ignore?
|
299
326
|
additional_message = context_params.get_forwarded_options()[:additional_message] if context_params.get_forwarded_options()
|
300
327
|
|
301
|
-
remote_namespace, local_module_name = get_namespace_and_name(remote_module_name,'
|
328
|
+
remote_namespace, local_module_name = get_namespace_and_name(remote_module_name,':')
|
302
329
|
|
303
330
|
if clone_dir = Helper(:git_repo).local_clone_dir_exists?(module_type.to_sym, local_module_name, :namespace => remote_namespace, :version => version)
|
304
331
|
message = "Module's directory (#{clone_dir}) exists on client. To install this needs to be renamed or removed"
|
@@ -308,7 +335,7 @@ module DTK::Client
|
|
308
335
|
end
|
309
336
|
|
310
337
|
post_body = {
|
311
|
-
:remote_module_name => remote_module_name,
|
338
|
+
:remote_module_name => remote_module_name.sub(':','/'),
|
312
339
|
:local_module_name => local_module_name,
|
313
340
|
:rsa_pub_key => SSHUtil.rsa_pub_key_content()
|
314
341
|
}
|
@@ -386,7 +413,9 @@ module DTK::Client
|
|
386
413
|
response = post rest_url("#{module_type}/export"), post_body
|
387
414
|
return response unless response.ok?
|
388
415
|
|
389
|
-
|
416
|
+
full_module_name = "#{response.data['remote_repo_namespace']}/#{response.data['remote_repo_name']}"
|
417
|
+
|
418
|
+
DTK::Client::RemoteDependencyUtil.print_dependency_warnings(response, "Module has been successfully published to '#{full_module_name}'!")
|
390
419
|
Response::Ok.new()
|
391
420
|
end
|
392
421
|
|
@@ -486,14 +515,14 @@ module DTK::Client
|
|
486
515
|
raise DtkValidationError, "You have to provide valid catalog to push changes to! Valid catalogs: #{PushCatalogs}" unless catalog
|
487
516
|
|
488
517
|
module_location = OsUtil.module_location(resolve_module_type(), module_name, version)
|
489
|
-
|
490
518
|
reparse_aux(module_location) unless internal_trigger
|
519
|
+
local_namespace, local_module_name = get_namespace_and_name(module_name,':')
|
491
520
|
|
492
521
|
# if catalog.to_s.eql?("origin")
|
493
522
|
# push_clone_changes_aux(:component_module,component_module_id,version,options["message"]||DEFAULT_COMMIT_MSG,internal_trigger)
|
494
523
|
if catalog.to_s.eql?("dtkn")
|
495
524
|
module_refs_content = RemoteDependencyUtil.module_ref_content(module_location) if module_type == :service_module
|
496
|
-
remote_module_info = get_remote_module_info_aux(module_type.to_sym, module_id, options["namespace"], version, module_refs_content)
|
525
|
+
remote_module_info = get_remote_module_info_aux(module_type.to_sym, module_id, options["namespace"], version, module_refs_content, local_namespace)
|
497
526
|
return remote_module_info unless remote_module_info.ok?
|
498
527
|
|
499
528
|
unless File.directory?(module_location)
|
@@ -541,6 +570,7 @@ module DTK::Client
|
|
541
570
|
|
542
571
|
def delete_assembly_aux(context_params)
|
543
572
|
module_type = get_module_type(context_params)
|
573
|
+
|
544
574
|
module_id, assembly_template_id = context_params.retrieve_arguments([REQ_MODULE_ID,:option_1!], method_argument_names)
|
545
575
|
module_name = context_params.retrieve_arguments([:service_module_name],method_argument_names)
|
546
576
|
|
@@ -584,7 +614,7 @@ module DTK::Client
|
|
584
614
|
version = nil
|
585
615
|
commit_msg = "Deleting assembly template #{assembly_template_name.to_s}"
|
586
616
|
internal_trigger = true
|
587
|
-
push_clone_changes_aux(module_type.to_sym, module_id, version, commit_msg, internal_trigger)
|
617
|
+
push_clone_changes_aux(module_type.to_sym, module_id, version, commit_msg, internal_trigger, :skip_cloning => true)
|
588
618
|
|
589
619
|
Response::Ok.new()
|
590
620
|
end
|
@@ -15,6 +15,7 @@ module DTK::Client
|
|
15
15
|
module_location = OsUtil.module_location(module_type,full_module_name,version,opts)
|
16
16
|
|
17
17
|
unless File.directory?(module_location)
|
18
|
+
return if opts[:skip_cloning]
|
18
19
|
if Console.confirmation_prompt("Push not possible, module '#{module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
|
19
20
|
clone_aux(module_type,module_id, version, true, true, opts)
|
20
21
|
else
|
@@ -46,11 +47,11 @@ module DTK::Client
|
|
46
47
|
ret = Response::NoOp.new()
|
47
48
|
end
|
48
49
|
end
|
49
|
-
|
50
|
+
|
50
51
|
# check if server pushed anything that needs to be pulled
|
51
52
|
dsl_updated_info = response.data(:dsl_updated_info)
|
52
53
|
if dsl_updated_info and !dsl_updated_info.empty?
|
53
|
-
if msg = dsl_updated_info["msg"]
|
54
|
+
if msg = dsl_updated_info["msg"]
|
54
55
|
DTK::Client::OsUtil.print(msg,:yellow)
|
55
56
|
end
|
56
57
|
new_commit_sha = dsl_updated_info[:commit_sha]
|
@@ -67,7 +68,7 @@ module DTK::Client
|
|
67
68
|
path = dsl_created_info["path"]
|
68
69
|
content = dsl_created_info["content"]
|
69
70
|
if path and content
|
70
|
-
msg = "A #{path} file has been created for you, located at #{repo_obj.repo_dir}"
|
71
|
+
msg = "A #{path} file has been created for you, located at #{repo_obj.repo_dir}"
|
71
72
|
response = Helper(:git_repo).add_file(repo_obj,path,content,msg)
|
72
73
|
return response unless response.ok?
|
73
74
|
end
|
@@ -154,6 +154,17 @@ module DTK::Client
|
|
154
154
|
nil
|
155
155
|
end
|
156
156
|
|
157
|
+
desc "set-catalog-credentials", "Sets catalog credentials"
|
158
|
+
def set_catalog_credentials(context_params)
|
159
|
+
creds = DTK::Client::Configurator.enter_catalog_credentials()
|
160
|
+
|
161
|
+
response = post rest_url("account/set_catalog_credentials"), { :username => creds[:username], :password => creds[:password] }
|
162
|
+
return response unless response.ok?
|
163
|
+
|
164
|
+
OsUtil.print("Your catalog credentials have been set!", :yellow)
|
165
|
+
nil
|
166
|
+
end
|
167
|
+
|
157
168
|
|
158
169
|
|
159
170
|
# Will leave this commented for now until we check if above commands work as expected
|
@@ -22,7 +22,7 @@ module DTK::Client
|
|
22
22
|
if response.ok?
|
23
23
|
unless response['data'].nil?
|
24
24
|
response['data'].each do |module_item|
|
25
|
-
if ("#{service_name.to_s}
|
25
|
+
if ("#{service_name.to_s}/#{assembly_template_name.to_s}" == (module_item['display_name']) && service_namespace == module_item['namespace'])
|
26
26
|
assembly_template_id = module_item['id']
|
27
27
|
break
|
28
28
|
end
|
@@ -31,7 +31,7 @@ module DTK::Client
|
|
31
31
|
end
|
32
32
|
|
33
33
|
raise DTK::Client::DtkError, "Illegal name (#{assembly_template_name}) for assembly." if assembly_template_id.nil?
|
34
|
-
|
34
|
+
|
35
35
|
return assembly_template_id
|
36
36
|
end
|
37
37
|
|
@@ -74,13 +74,13 @@ module DTK::Client
|
|
74
74
|
assembly_list = []
|
75
75
|
response = get_cached_response(:service, "assembly/list", {})
|
76
76
|
raise DTK::Client::DtkError, "Unable to retreive service list." unless (response.nil? || response.ok?)
|
77
|
-
|
77
|
+
|
78
78
|
if assemblies = response.data
|
79
79
|
assemblies.each do |assembly|
|
80
80
|
assembly_list << assembly["display_name"]
|
81
81
|
end
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
assembly_list
|
85
85
|
end
|
86
86
|
|
@@ -89,19 +89,19 @@ module DTK::Client
|
|
89
89
|
def info(context_params)
|
90
90
|
assembly_template_id = context_params.retrieve_arguments([:assembly_id!],method_argument_names)
|
91
91
|
data_type = :assembly_template
|
92
|
-
|
92
|
+
|
93
93
|
post_body = {
|
94
94
|
:assembly_id => assembly_template_id,
|
95
95
|
:subtype => 'template',
|
96
96
|
}
|
97
|
-
|
97
|
+
|
98
98
|
post rest_url("assembly/info"), post_body
|
99
99
|
end
|
100
100
|
|
101
101
|
desc "ASSEMBLY-NAME/ID list-nodes [--service SERVICE-NAME]", "List all nodes for given assembly."
|
102
102
|
method_option :list, :type => :boolean, :default => false
|
103
103
|
method_option "service",:aliases => "-s" ,
|
104
|
-
:type => :string,
|
104
|
+
:type => :string,
|
105
105
|
:banner => "SERVICE-LIST-FILTER",
|
106
106
|
:desc => "Service list filter"
|
107
107
|
def list_nodes(context_params)
|
@@ -112,7 +112,7 @@ module DTK::Client
|
|
112
112
|
desc "ASSEMBLY-NAME/ID list-components [--service SERVICE-NAME]", "List all components for given assembly."
|
113
113
|
method_option :list, :type => :boolean, :default => false
|
114
114
|
method_option "service",:aliases => "-s" ,
|
115
|
-
:type => :string,
|
115
|
+
:type => :string,
|
116
116
|
:banner => "SERVICE-LIST-FILTER",
|
117
117
|
:desc => "Service list filter"
|
118
118
|
def list_components(context_params)
|
@@ -133,7 +133,7 @@ module DTK::Client
|
|
133
133
|
context_params_for_service = DTK::Shell::ContextParams.new
|
134
134
|
context_params_for_service.add_context_to_params("service_module", "service_module", service_id)
|
135
135
|
context_params_for_service.method_arguments = ['assembly',"#{service_id}"]
|
136
|
-
|
136
|
+
|
137
137
|
response = DTK::Client::ContextRouter.routeTask("service_module", "list", context_params_for_service, @conn)
|
138
138
|
else
|
139
139
|
response = post rest_url("assembly/list"), {:subtype => 'template', :detail_level => 'nodes'}
|
@@ -143,7 +143,7 @@ module DTK::Client
|
|
143
143
|
end
|
144
144
|
|
145
145
|
else
|
146
|
-
|
146
|
+
|
147
147
|
post_body = {
|
148
148
|
:subtype => 'template',
|
149
149
|
:assembly_id => assembly_template_id,
|
@@ -153,7 +153,7 @@ module DTK::Client
|
|
153
153
|
case about
|
154
154
|
when 'nodes'
|
155
155
|
response = post rest_url("assembly/info_about"), post_body
|
156
|
-
data_type = :
|
156
|
+
data_type = :assembly_node_template
|
157
157
|
when 'components'
|
158
158
|
response = post rest_url("assembly/info_about"), post_body
|
159
159
|
data_type = :component
|
@@ -186,12 +186,12 @@ module DTK::Client
|
|
186
186
|
|
187
187
|
desc "ASSEMBLY-NAME/ID stage [INSTANCE-NAME] [-t TARGET-NAME/ID] [--settings SETTINGS-NAME1[,..]]", "Stage assembly in target."
|
188
188
|
method_option "in-target",:aliases => "-t" ,
|
189
|
-
:type => :string,
|
189
|
+
:type => :string,
|
190
190
|
:banner => "TARGET-NAME/ID",
|
191
|
-
:desc => "Target (id) to create assembly in"
|
191
|
+
:desc => "Target (id) to create assembly in"
|
192
192
|
#hidden option
|
193
193
|
method_option "instance-bindings",
|
194
|
-
:type => :string
|
194
|
+
:type => :string
|
195
195
|
method_option :settings, :type => :string, :aliases => '-s'
|
196
196
|
def stage(context_params)
|
197
197
|
assembly_template_id, name = context_params.retrieve_arguments([:assembly_id!, :option_1],method_argument_names)
|
@@ -202,7 +202,7 @@ module DTK::Client
|
|
202
202
|
# using this to make sure cache will be invalidated after new assembly is created from other commands e.g.
|
203
203
|
# 'assembly-create', 'install' etc.
|
204
204
|
@@invalidate_map << :assembly
|
205
|
-
|
205
|
+
|
206
206
|
assembly_template_name = get_assembly_name(assembly_template_id)
|
207
207
|
if assembly_template_name
|
208
208
|
assembly_template_name.gsub!(/(::)|(\/)/,'-')
|
@@ -218,7 +218,7 @@ module DTK::Client
|
|
218
218
|
else
|
219
219
|
name = get_assembly_stage_name(assembly_list,assembly_template_name)
|
220
220
|
end
|
221
|
-
|
221
|
+
|
222
222
|
post_body.merge!(:target_id => in_target) if in_target
|
223
223
|
post_body.merge!(:name => name) if name
|
224
224
|
post_body.merge!(:instance_bindings => instance_bindings) if instance_bindings
|
@@ -239,13 +239,13 @@ module DTK::Client
|
|
239
239
|
desc "ASSEMBLY-NAME/ID deploy [INSTANCE-NAME] [--settings SETTINGS-NAME1[,..]] [-m COMMIT-MSG]", "Stage and deploy assembly in target."
|
240
240
|
#hidden option
|
241
241
|
method_option "instance-bindings",
|
242
|
-
:type => :string
|
242
|
+
:type => :string
|
243
243
|
# method_option "in-target",:aliases => "-t" ,
|
244
244
|
# :type => :string,
|
245
245
|
# :banner => "TARGET-NAME/ID",
|
246
|
-
# :desc => "Target (id) to create assembly in"
|
246
|
+
# :desc => "Target (id) to create assembly in"
|
247
247
|
method_option "commit_msg",:aliases => "-m" ,
|
248
|
-
:type => :string,
|
248
|
+
:type => :string,
|
249
249
|
:banner => "COMMIT-MSG",
|
250
250
|
:desc => "Commit message"
|
251
251
|
method_option :settings, :type => :string, :aliases => '-s'
|
@@ -262,7 +262,7 @@ module DTK::Client
|
|
262
262
|
# using this to make sure cache will be invalidated after new assembly is created from other commands e.g.
|
263
263
|
# 'assembly-create', 'install' etc.
|
264
264
|
@@invalidate_map << :assembly
|
265
|
-
|
265
|
+
|
266
266
|
assembly_template_name = get_assembly_name(assembly_template_id)
|
267
267
|
if assembly_template_name
|
268
268
|
assembly_template_name.gsub!(/(::)|(\/)/,'-')
|
@@ -279,7 +279,7 @@ module DTK::Client
|
|
279
279
|
else
|
280
280
|
name = get_assembly_stage_name(assembly_list,assembly_template_name)
|
281
281
|
end
|
282
|
-
|
282
|
+
|
283
283
|
post_body.merge!(:target_id => in_target) if in_target
|
284
284
|
post_body.merge!(:name => name) if name
|
285
285
|
post_body.merge!(:instance_bindings => instance_bindings) if instance_bindings
|
@@ -292,7 +292,7 @@ module DTK::Client
|
|
292
292
|
@@invalidate_map << :assembly
|
293
293
|
response
|
294
294
|
end
|
295
|
-
|
295
|
+
|
296
296
|
|
297
297
|
desc "delete ASSEMBLY-ID", "Delete assembly"
|
298
298
|
method_option :force, :aliases => '-y', :type => :boolean, :default => false
|
@@ -308,7 +308,7 @@ module DTK::Client
|
|
308
308
|
:subtype => :template
|
309
309
|
}
|
310
310
|
response = post rest_url("assembly/delete"), post_body
|
311
|
-
|
311
|
+
|
312
312
|
# when changing context send request for getting latest assemblies instead of getting from cache
|
313
313
|
@@invalidate_map << :assembly
|
314
314
|
return response unless response.ok?
|
@@ -130,7 +130,7 @@ TODO: might deprecate
|
|
130
130
|
|
131
131
|
post_body = (remote ? { :rsa_pub_key => SSHUtil.rsa_pub_key_content() } : {:detail_to_include => ["remotes"]})
|
132
132
|
post_body[:diff] = options.diff? ? options.diff : {}
|
133
|
-
post_body.merge!(:module_namespace => options.namespace)
|
133
|
+
post_body.merge!(:module_namespace => options.namespace) if options.namespace
|
134
134
|
|
135
135
|
response = post rest_url("component_module/#{action}"),post_body
|
136
136
|
|
@@ -176,7 +176,7 @@ TODO: might deprecate
|
|
176
176
|
desc "import [NAMESPACE:]COMPONENT-MODULE-NAME", "Create new component module from local clone"
|
177
177
|
def import(context_params)
|
178
178
|
response = import_module_aux(context_params)
|
179
|
-
@@invalidate_map << :component_module
|
179
|
+
@@invalidate_map << :component_module
|
180
180
|
|
181
181
|
response
|
182
182
|
end
|
@@ -52,10 +52,10 @@ module DTK::Client
|
|
52
52
|
raise ::DTK::Client::DtkValidationError.new("Multiple security groups should be separated with ',' and without spaces between them (e.g. --security_groups gr1,gr2,gr3,...) ") if security_group.end_with?(',')
|
53
53
|
|
54
54
|
security_groups = security_group.split(',')
|
55
|
-
iaas_properties.merge!(:keypair_name => keypair)
|
55
|
+
iaas_properties.merge!(:keypair_name => keypair)
|
56
56
|
|
57
57
|
if (security_groups.empty? || security_groups.size==1)
|
58
|
-
iaas_properties.merge!(:security_group => security_group)
|
58
|
+
iaas_properties.merge!(:security_group => security_group)
|
59
59
|
else
|
60
60
|
iaas_properties.merge!(:security_group_set => security_groups)
|
61
61
|
end
|
@@ -108,18 +108,35 @@ module DTK::Client
|
|
108
108
|
end
|
109
109
|
|
110
110
|
|
111
|
-
desc "PROVIDER-ID/NAME create-target [TARGET-NAME] --region REGION", "Create target based on given provider"
|
111
|
+
desc "PROVIDER-ID/NAME create-target [TARGET-NAME] --region REGION --keypair KEYPAIR --security-group SECURITY-GROUP(S)", "Create target based on given provider"
|
112
112
|
method_option :region, :type => :string
|
113
|
+
method_option :keypair, :type => :string
|
114
|
+
method_option :security_group, :type => :string, :aliases => '--security-groups'
|
113
115
|
def create_target(context_params)
|
114
116
|
# we use :target_id but that will retunr provider_id (another name for target template ID)
|
115
|
-
provider_id, target_name = context_params.retrieve_arguments([:provider_id
|
116
|
-
region = context_params.retrieve_thor_options([:region!], options)
|
117
|
+
provider_id, target_name = context_params.retrieve_arguments([:provider_id!, :option_1],method_argument_names)
|
118
|
+
region, keypair, security_group = context_params.retrieve_thor_options([:region!, :keypair!, :security_group!], options)
|
117
119
|
|
120
|
+
#TODO: data-driven check if legal provider type and then what options needed depending on provider type
|
121
|
+
iaas_properties = Hash.new
|
118
122
|
DTK::Shell::InteractiveWizard.validate_region(region)
|
119
123
|
|
124
|
+
security_groups = []
|
125
|
+
raise ::DTK::Client::DtkValidationError.new("Multiple security groups should be separated with ',' and without spaces between them (e.g. --security_groups gr1,gr2,gr3,...) ") if security_group.end_with?(',')
|
126
|
+
|
127
|
+
security_groups = security_group.split(',')
|
128
|
+
iaas_properties.merge!(:keypair => keypair)
|
129
|
+
|
130
|
+
if (security_groups.empty? || security_groups.size==1)
|
131
|
+
iaas_properties.merge!(:security_group => security_group)
|
132
|
+
else
|
133
|
+
iaas_properties.merge!(:security_group_set => security_groups)
|
134
|
+
end
|
135
|
+
|
120
136
|
post_body = {
|
121
137
|
:provider_id => provider_id,
|
122
|
-
:region => region
|
138
|
+
:region => region,
|
139
|
+
:iaas_properties => iaas_properties
|
123
140
|
}
|
124
141
|
post_body.merge!(:target_name => target_name) if target_name
|
125
142
|
response = post rest_url("target/create"), post_body
|
@@ -121,7 +121,7 @@ module DTK::Client
|
|
121
121
|
action = options.remote? ? "list_remote" : "list"
|
122
122
|
post_body = (options.remote? ? { :rsa_pub_key => SSHUtil.rsa_pub_key_content() } : {:detail_to_include => ["remotes"]})
|
123
123
|
post_body[:diff] = options.diff? ? options.diff : {}
|
124
|
-
post_body.merge!(:module_namespace => options.namespace)
|
124
|
+
post_body.merge!(:module_namespace => options.namespace) if options.namespace
|
125
125
|
|
126
126
|
response = post rest_url("service_module/#{action}"), post_body
|
127
127
|
# If user is on service identifier level, list task can't have '--remote' option.
|
@@ -421,12 +421,33 @@ module DTK::Client
|
|
421
421
|
repo_url,repo_id,module_id,branch,new_module_name = [:repo_url,:repo_id,:module_id,:workspace_branch,:full_module_name].map { |k| repo_info[k.to_s] }
|
422
422
|
|
423
423
|
response = Helper(:git_repo).rename_and_initialize_clone_and_push(:service_module, local_module_name, new_module_name,branch,repo_url,service_directory)
|
424
|
-
return response unless response.ok?
|
424
|
+
return response unless (response && response.ok?)
|
425
425
|
|
426
|
-
repo_obj,commit_sha =
|
426
|
+
repo_obj,commit_sha = response.data(:repo_obj,:commit_sha)
|
427
|
+
module_final_dir = repo_obj.repo_dir
|
428
|
+
old_dir = response.data[:old_dir]
|
427
429
|
|
428
430
|
context_params.add_context_to_params(local_module_name, :"service-module", module_id)
|
429
|
-
push(context_params,true)
|
431
|
+
response = push(context_params,true)
|
432
|
+
|
433
|
+
unless response.ok?
|
434
|
+
# remove new directory if import failed
|
435
|
+
# DTK-1768: removed below; TODO: see if need to put a variant back in
|
436
|
+
# was not sure why clause namespace is there
|
437
|
+
# FileUtils.rm_rf(module_final_dir) unless namespace
|
438
|
+
return response
|
439
|
+
end
|
440
|
+
|
441
|
+
# remove the old one if no errors while importing
|
442
|
+
# DTK-1768: removed below; and replaced by removing old dir if unequal to final dir
|
443
|
+
# was not sure why clause namespace was in so kept this condition
|
444
|
+
#FileUtils.rm_rf(old_dir) unless namespace
|
445
|
+
if old_dir and (old_dir != module_final_dir)
|
446
|
+
FileUtils.rm_rf(old_dir) unless namespace
|
447
|
+
end
|
448
|
+
DTK::Client::OsUtil.print("Module '#{new_module_name}' has been created and module directory moved to #{repo_obj.repo_dir}",:yellow) unless namespace
|
449
|
+
|
450
|
+
response
|
430
451
|
end
|
431
452
|
|
432
453
|
|
data/lib/commands/thor/target.rb
CHANGED
@@ -84,19 +84,35 @@ module DTK::Client
|
|
84
84
|
post rest_url("target/install_agents"), post_body
|
85
85
|
end
|
86
86
|
|
87
|
-
desc "create-target [TARGET-NAME] --provider PROVIDER --region REGION", "Create target based on given provider"
|
87
|
+
desc "create-target [TARGET-NAME] --provider PROVIDER --region REGION --keypair KEYPAIR --security-group SECURITY-GROUP(S)", "Create target based on given provider"
|
88
88
|
method_option :provider, :type => :string
|
89
89
|
method_option :region, :type => :string
|
90
|
+
method_option :keypair, :type => :string
|
91
|
+
method_option :security_group, :type => :string, :aliases => '--security-groups'
|
90
92
|
def create_target(context_params)
|
91
93
|
# we use :target_id but that will retunr provider_id (another name for target template ID)
|
92
94
|
target_name = context_params.retrieve_arguments([:option_1],method_argument_names)
|
93
|
-
provider
|
94
|
-
region = context_params.retrieve_thor_options([:region], options)
|
95
|
+
provider, region, keypair, security_group = context_params.retrieve_thor_options([:provider!, :region, :keypair!, :security_group!], options)
|
95
96
|
|
97
|
+
#TODO: data-driven check if legal provider type and then what options needed depending on provider type
|
98
|
+
iaas_properties = Hash.new
|
96
99
|
DTK::Shell::InteractiveWizard.validate_region(region) if region
|
97
100
|
|
101
|
+
security_groups = []
|
102
|
+
raise ::DTK::Client::DtkValidationError.new("Multiple security groups should be separated with ',' and without spaces between them (e.g. --security_groups gr1,gr2,gr3,...) ") if security_group.end_with?(',')
|
103
|
+
|
104
|
+
security_groups = security_group.split(',')
|
105
|
+
iaas_properties.merge!(:keypair => keypair)
|
106
|
+
|
107
|
+
if (security_groups.empty? || security_groups.size==1)
|
108
|
+
iaas_properties.merge!(:security_group => security_group)
|
109
|
+
else
|
110
|
+
iaas_properties.merge!(:security_group_set => security_groups)
|
111
|
+
end
|
112
|
+
|
98
113
|
post_body = {
|
99
|
-
:provider_id => provider
|
114
|
+
:provider_id => provider,
|
115
|
+
:iaas_properties => iaas_properties
|
100
116
|
}
|
101
117
|
post_body.merge!(:target_name => target_name) if target_name
|
102
118
|
post_body.merge!(:region => region) if region
|
@@ -89,7 +89,7 @@ module DTK::Client
|
|
89
89
|
desc "import [NAMESPACE:]TEST-MODULE-NAME", "Create new test module from local clone"
|
90
90
|
def import(context_params)
|
91
91
|
response = import_module_aux(context_params)
|
92
|
-
@@invalidate_map << :test_module
|
92
|
+
@@invalidate_map << :test_module
|
93
93
|
|
94
94
|
response
|
95
95
|
end
|
data/lib/configurator.rb
CHANGED
@@ -1,138 +1,156 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
|
2
|
+
require 'fileutils'
|
3
3
|
dtk_require_from_base('util/os_util')
|
4
4
|
|
5
5
|
module DTK
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
def self.client_username()
|
6
|
+
module Client
|
7
|
+
class Configurator
|
8
|
+
|
9
|
+
CONFIG_FILE = File.join(OsUtil.dtk_local_folder, "client.conf")
|
10
|
+
CRED_FILE = File.join(OsUtil.dtk_local_folder, ".connection")
|
11
|
+
DIRECT_ACCESS = File.join(OsUtil.dtk_local_folder, ".add_direct_access")
|
12
|
+
NODE_SSH_CREDENTIALS = File.join(OsUtil.dtk_local_folder, "ssh_credentials.yaml")
|
13
|
+
|
14
|
+
FileUtils.mkdir(OsUtil.dtk_local_folder) unless File.directory?(OsUtil.dtk_local_folder)
|
15
|
+
|
16
|
+
def self.check_config_exists
|
17
|
+
exists = true
|
18
|
+
if !File.exists?(CONFIG_FILE)
|
19
|
+
puts "", "Please enter the DTK server address (example: instance.dtk.io)"
|
20
|
+
header = File.read(File.expand_path('../lib/config/client.conf.header', File.dirname(__FILE__)))
|
21
|
+
generate_conf_file(CONFIG_FILE, [['server_host', 'Server address']], header)
|
22
|
+
exists = false
|
23
|
+
end
|
24
|
+
if !File.exists?(CRED_FILE)
|
25
|
+
puts "", "Please enter your DTK login details"
|
26
|
+
generate_conf_file(CRED_FILE, [['username', 'Username'], ['password', 'Password']], '')
|
27
|
+
exists = false
|
28
|
+
end
|
29
|
+
|
30
|
+
exists
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.check_git
|
34
|
+
if OsUtil.which('git') == nil
|
35
|
+
OsUtil.put_warning "[WARNING]", "Can't find the 'git' command in you path. Please make sure git is installed in order to use all features of DTK Client.", :yellow
|
36
|
+
else
|
37
|
+
OsUtil.put_warning "[WARNING]", 'Git username not set. This can cause issues while using DTK Client. To set it, run `git config --global user.name "User Name"`', :yellow if `git config --get user.name` == ""
|
38
|
+
OsUtil.put_warning "[WARNING]", 'Git email not set. This can cause issues while using DTK Client. To set it, run `git config --global user.email "me@here.com"`', :yellow if `git config --get user.email` == ""
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# return true/false, .add_direct_access file location and ssk key file location
|
43
|
+
def self.check_direct_access
|
44
|
+
username_exists = check_for_username_entry(client_username())
|
45
|
+
ssh_key_path = SSHUtil.default_rsa_pub_key_path()
|
46
|
+
|
47
|
+
{:username_exists => username_exists, :file_path => DIRECT_ACCESS, :ssh_key_path => ssh_key_path}
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.generate_conf_file(file_path, properties, header)
|
51
|
+
require 'highline/import'
|
52
|
+
property_template = []
|
53
|
+
|
54
|
+
properties.each do |p,d|
|
55
|
+
begin
|
56
|
+
trap("INT") {
|
57
|
+
puts "", "Exiting..."
|
58
|
+
abort
|
59
|
+
}
|
60
|
+
end
|
61
|
+
value = ask("#{d}: ") { |q| q.echo = false if p == 'password'}
|
62
|
+
property_template << [p,value]
|
63
|
+
end
|
64
|
+
|
65
|
+
File.open(file_path, 'w') do |f|
|
66
|
+
f.puts(header)
|
67
|
+
property_template.each do |prop|
|
68
|
+
f.puts("#{prop[0]}=#{prop[1]}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.regenerate_conf_file(file_path, properties, header)
|
74
|
+
File.open(file_path, 'w') do |f|
|
75
|
+
f.puts(header)
|
76
|
+
properties.each do |prop|
|
77
|
+
f.puts("#{prop[0]}=#{prop[1]}")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.create_missing_clone_dirs
|
83
|
+
FileUtils.mkdir(OsUtil.component_clone_location) unless File.directory?(OsUtil.component_clone_location)
|
84
|
+
FileUtils.mkdir(OsUtil.service_clone_location) unless File.directory?(OsUtil.service_clone_location)
|
85
|
+
FileUtils.mkdir(OsUtil.test_clone_location) unless File.directory?(OsUtil.test_clone_location)
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
def self.parse_key_value_file(file)
|
90
|
+
# adapted from mcollective config
|
91
|
+
ret = Hash.new
|
92
|
+
raise DTK::Client::DtkError,"Config file (#{file}) does not exists" unless File.exists?(file)
|
93
|
+
File.open(file).each do |line|
|
94
|
+
# strip blank spaces, tabs etc off the end of all lines
|
95
|
+
line.gsub!(/\s*$/, "")
|
96
|
+
unless line =~ /^#|^$/
|
97
|
+
if (line =~ /(.+?)\s*=\s*(.+)/)
|
98
|
+
key = $1
|
99
|
+
val = $2
|
100
|
+
ret[key.to_sym] = val
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
ret
|
105
|
+
end
|
106
|
+
def self.add_current_user_to_direct_access()
|
107
|
+
username = client_username()
|
108
|
+
|
109
|
+
File.open(DIRECT_ACCESS, 'a') do |file|
|
110
|
+
file.puts(username)
|
111
|
+
end
|
112
|
+
|
113
|
+
true
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.client_username()
|
118
117
|
parse_key_value_file(CRED_FILE)[:username]
|
119
118
|
end
|
120
119
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
120
|
+
#
|
121
|
+
# Method will check if there is username entry in DIRECT_ACCESS file
|
122
|
+
#
|
123
|
+
def self.check_for_username_entry(username)
|
124
|
+
if File.exists?(DIRECT_ACCESS)
|
125
|
+
File.open(DIRECT_ACCESS).each do |line|
|
126
|
+
if line.strip.eql?(username)
|
127
|
+
return true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
return false
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.ask_catalog_credentials()
|
136
|
+
are_there_creds = Console.confirmation_prompt("Do you have DTK catalog credentials", true)
|
137
|
+
property_template = {}
|
138
|
+
if are_there_creds
|
139
|
+
property_template = self.enter_catalog_credentials()
|
140
|
+
end
|
141
|
+
|
142
|
+
property_template
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.enter_catalog_credentials()
|
146
|
+
property_template = {}
|
147
|
+
{ :username => 'Catalog Username', :password => 'Catalog Password' }.each do |p, v|
|
148
|
+
value = ask("#{v}: ") { |q| q.echo = false if p == :password }
|
149
|
+
property_template.store(p, value)
|
150
|
+
end
|
151
|
+
property_template
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
137
155
|
end
|
138
156
|
|
data/lib/core.rb
CHANGED
@@ -121,6 +121,19 @@ def resolve_direct_access(params, config_exists=nil)
|
|
121
121
|
return if params[:username_exists]
|
122
122
|
|
123
123
|
puts "Processing..." if config_exists
|
124
|
+
# check to see if catalog credentials are set
|
125
|
+
conn = DTK::Client::Session.get_connection()
|
126
|
+
response = conn.post DTK::Client::CommandBase.class, conn.rest_url("account/check_catalog_credentials"), {}
|
127
|
+
|
128
|
+
# set catalog credentails
|
129
|
+
if response.ok? && !response.data['catalog_credentials_set']
|
130
|
+
# setting up catalog credentials
|
131
|
+
catalog_creds = DTK::Client::Configurator.ask_catalog_credentials()
|
132
|
+
unless catalog_creds.empty?
|
133
|
+
response = conn.post DTK::Client::CommandBase.class, conn.rest_url("account/set_catalog_credentials"), { :username => catalog_creds[:username], :password => catalog_creds[:password]}
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
124
137
|
# response = DTK::Client::Account.add_access(params[:ssh_key_path])
|
125
138
|
response, matched_pub_key, matched_username = DTK::Client::Account.add_key(params[:ssh_key_path])
|
126
139
|
|
@@ -138,7 +151,6 @@ def resolve_direct_access(params, config_exists=nil)
|
|
138
151
|
DTK::Client::Configurator.add_current_user_to_direct_access()
|
139
152
|
end
|
140
153
|
|
141
|
-
|
142
154
|
response
|
143
155
|
end
|
144
156
|
|
@@ -389,17 +401,19 @@ module DTK
|
|
389
401
|
# to make sure that connection is properly set.
|
390
402
|
#
|
391
403
|
def print_warning
|
404
|
+
creds = get_credentials
|
392
405
|
puts "[WARNING] Unable to connect to server, please check you configuration."
|
393
406
|
puts "========================== Configuration =========================="
|
394
407
|
printf "%15s %s\n", "REST endpoint:", rest_url
|
395
|
-
creds = get_credentials
|
396
408
|
printf "%15s %s\n", "Username:", "#{creds[:username]}"
|
397
409
|
printf "%15s %s\n", "Password:", "#{creds[:password] ? creds[:password].gsub(/./,'*') : 'No password set'}"
|
398
410
|
puts "==================================================================="
|
399
|
-
error_code = self.connection_error['errors'].first['errors'].first['code']
|
400
|
-
print " Error code: "
|
401
|
-
DTK::Client::OsUtil.print(error_code, :red)
|
402
411
|
|
412
|
+
if self.connection_error['errors'].first['errors']
|
413
|
+
error_code = self.connection_error['errors'].first['errors'].first['code']
|
414
|
+
print " Error code: "
|
415
|
+
DTK::Client::OsUtil.print(error_code, :red)
|
416
|
+
end
|
403
417
|
end
|
404
418
|
|
405
419
|
private
|
data/lib/domain/git_adapter.rb
CHANGED
@@ -15,9 +15,11 @@ module DTK
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def stage_changes()
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
handle_git_error do
|
19
|
+
@git_repo.add(untracked())
|
20
|
+
@git_repo.add(added())
|
21
|
+
@git_repo.add(changed())
|
22
|
+
end
|
21
23
|
deleted().each do |file|
|
22
24
|
begin
|
23
25
|
@git_repo.remove(file)
|
@@ -190,7 +192,8 @@ module DTK
|
|
190
192
|
end
|
191
193
|
|
192
194
|
def self.clone(repo_url, target_path, branch, opts={})
|
193
|
-
git_base = Git.clone(repo_url, target_path)
|
195
|
+
git_base = handle_git_error{Git.clone(repo_url, target_path)}
|
196
|
+
|
194
197
|
unless branch.nil?
|
195
198
|
if opts[:track_remote_branch]
|
196
199
|
# This just tracks remote branch
|
@@ -256,6 +259,38 @@ module DTK
|
|
256
259
|
end
|
257
260
|
|
258
261
|
private
|
262
|
+
def handle_git_error(&block)
|
263
|
+
self.class.handle_git_error(&block)
|
264
|
+
end
|
265
|
+
def self.handle_git_error(&block)
|
266
|
+
ret = nil
|
267
|
+
begin
|
268
|
+
ret = yield
|
269
|
+
rescue => e
|
270
|
+
unless e.respond_to?(:message)
|
271
|
+
raise e
|
272
|
+
else
|
273
|
+
err_msg = e.message
|
274
|
+
lines = err_msg.split("\n")
|
275
|
+
if lines.last =~ GitErrorPattern
|
276
|
+
err_msg = error_msg_when_git_error(lines)
|
277
|
+
end
|
278
|
+
raise DtkError.new(err_msg)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
ret
|
282
|
+
end
|
283
|
+
GitErrorPattern = /^fatal:/
|
284
|
+
def self.error_msg_when_git_error(lines)
|
285
|
+
ret = lines.last.gsub(GitErrorPattern,'').strip()
|
286
|
+
# TODO start putting in special cases here
|
287
|
+
if ret =~ /adding files failed/
|
288
|
+
if lines.first =~ /\.git/
|
289
|
+
ret = "Cannot add files that are in a .git directory; remove any nested .git directory"
|
290
|
+
end
|
291
|
+
end
|
292
|
+
ret
|
293
|
+
end
|
259
294
|
|
260
295
|
# Method bellow show different behavior when working with 1.8.7
|
261
296
|
# so based on Hash response we know it it is:
|
data/lib/domain/response.rb
CHANGED
@@ -36,9 +36,6 @@ module DTK
|
|
36
36
|
Ok.new(results)
|
37
37
|
rescue ErrorUsage => e
|
38
38
|
Error::Usage.new("message"=> e.to_s)
|
39
|
-
#rescue ::Grit::Git::CommandFailed => e
|
40
|
-
# remove grit internal error handler
|
41
|
-
# Error::Usage.new("message"=> "Grit Error: #{e.err.gsub(/^.*:/,'').strip.capitalize}")
|
42
39
|
rescue => e
|
43
40
|
error_hash = {
|
44
41
|
"message"=> e.message,
|
data/lib/dtk-client/version.rb
CHANGED
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.6.
|
4
|
+
version: 0.6.3
|
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-10-
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -338,7 +338,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
338
338
|
version: '0'
|
339
339
|
requirements: []
|
340
340
|
rubyforge_project:
|
341
|
-
rubygems_version: 2.
|
341
|
+
rubygems_version: 2.2.2
|
342
342
|
signing_key:
|
343
343
|
specification_version: 4
|
344
344
|
summary: DTK CLI client for DTK server interaction.
|