Module: DTK::Client::ModuleMixin
- Includes:
- AccessControlMixin, CloneMixin, EditMixin, ListDiffsMixin, PullFromRemoteMixin, PuppetForgeMixin, PurgeCloneMixin, PushCloneChangesMixin, PushToRemoteMixin, RemotesMixin, ReparseMixin, ServiceImporter
- Defined in:
- lib/commands/common/thor/module.rb
Constant Summary
collapse
- REQ_MODULE_ID =
[:service_module_id!, :component_module_id!, :test_module_id!]
- REQ_MODULE_NAME =
[:service_module_name!, :component_module_name!, :test_module_name!]
- PushCatalogs =
["origin", "dtkn"]
ReparseMixin::YamlDTKMetaFiles
CommandHelperMixin::Loaded
PushToRemoteMixin::NO_PUSH_CHANGES_MSG
PuppetForgeMixin::NAME_REGEX
Instance Method Summary
collapse
-
#add_collaborators_module_aux(context_params) ⇒ Object
-
#check_version_format(version) ⇒ Object
-
#chmod_module_aux(context_params) ⇒ Object
-
#clone_module_aux(context_params, internal_trigger = false) ⇒ Object
-
#create_new_version_aux(context_params, internal_trigger = false) ⇒ Object
-
#create_test_module_aux(context_params) ⇒ Object
-
#delete_assembly_aux(context_params) ⇒ Object
-
#delete_from_catalog_aux(context_params) ⇒ Object
-
#delete_module_aux(context_params, method_opts = {}) ⇒ Object
-
#delete_module_sub_aux(context_params, module_id, method_opts = {}) ⇒ Object
-
#edit_module_aux(context_params) ⇒ Object
-
#fork_aux(context_params) ⇒ Object
-
#forward_namespace?(module_name, input_remote_name, context_params) ⇒ Boolean
-
#get_module_type(context_params) ⇒ Object
-
#import_git_module_aux(context_params) ⇒ Object
-
#import_module_aux(context_params) ⇒ Object
-
#install_base_version_aux?(context_params, post_body, module_type, version) ⇒ Boolean
-
#install_module_aux(context_params, internal_trigger = false) ⇒ Object
-
#list_collaborators_module_aux(context_params) ⇒ Object
-
#list_diffs_module_aux(context_params) ⇒ Object
-
#list_instances_aux(context_params) ⇒ Object
-
#list_remote_module_diffs(context_params) ⇒ Object
-
#list_remote_versions_aux(context_params) ⇒ Object
-
#list_versions_aux(context_params) ⇒ Object
-
#make_private_module_aux(context_params) ⇒ Object
-
#make_public_module_aux(context_params) ⇒ Object
-
#module_info_about(context_params, about, data_type) ⇒ Object
-
#module_info_aux(context_params) ⇒ Object
-
#print_ambiguous(ambiguous) ⇒ Object
-
#print_dependencies(dependencies) ⇒ Object
-
#print_using_dependencies(component_refs) ⇒ Object
-
#publish_module_aux(context_params) ⇒ Object
-
#pull_dtkn_aux(context_params) ⇒ Object
DTK::Client::RemoteDependencyUtil.print_dependency_warnings(response, “Module has been successfully published to ‘#ServiceImporter#full_module_name’!”) Response::Ok.new() end end.
-
#push_dtkn_module_aux(context_params, internal_trigger = false) ⇒ Object
-
#push_module_aux(context_params, internal_trigger = false, opts = {}) ⇒ Object
-
#push_remote_module_aux(context_params) ⇒ Object
-
#remove_collaborators_module_aux(context_params) ⇒ Object
-
#set_attribute_module_aux(context_params) ⇒ Object
#remote_add_aux, #remote_list_aux, #remote_remove_aux
#chmod_aux, #chown_aux, #collaboration_aux, #collaboration_list_aux
#create_missing_clone_dirs, error_message, #resolve_missing_components, #trigger_module_auto_import, #trigger_module_auto_pull
#list_component_module_diffs, #list_diffs_aux, #list_remote_diffs_aux, #print_diffs
#check_if_unsaved_assembly_changes, #check_if_unsaved_cmp_module_changes, #purge_clone_aux
#reparse_aux
Methods included from EditMixin
#attributes_editor, #edit_aux
#pull_clone_changes?
#push_clone_changes_aux
Methods included from CloneMixin
#clone_aux, #clone_base_aux, #create_context_for_module
Methods included from Console
confirmation_prompt, confirmation_prompt_additional_options, confirmation_prompt_multiple_choice, confirmation_prompt_simple, unix_shell, wait_animation
#Helper
#get, #get_connection, handle_argument_error, #post, #post_file, #rest_url, #rotate_args
#pull_from_remote_aux
#push_to_git_remote_aux, #push_to_git_remote_location_aux, #push_to_remote_aux
#puppet_forge_install_aux
Instance Method Details
#add_collaborators_module_aux(context_params) ⇒ Object
618
619
620
621
|
# File 'lib/commands/common/thor/module.rb', line 618
def add_collaborators_module_aux(context_params)
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
collaboration_aux(:add, module_id, options.users, options.groups, options.namespace)
end
|
1004
1005
1006
1007
1008
|
# File 'lib/commands/common/thor/module.rb', line 1004
def check_version_format(version)
unless version.match(/\A\d{1,2}\.\d{1,2}\.\d{1,2}\Z/)
raise DtkValidationError, "Version has an illegal value '#{version}', format needed: '##.##.##'"
end
end
|
#chmod_module_aux(context_params) ⇒ Object
603
604
605
606
|
# File 'lib/commands/common/thor/module.rb', line 603
def chmod_module_aux(context_params)
module_id, permission_selector = context_params.retrieve_arguments([REQ_MODULE_ID, :option_1!], method_argument_names)
chmod_aux(module_id, permission_selector, options.namespace)
end
|
#clone_module_aux(context_params, internal_trigger = false) ⇒ Object
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
|
# File 'lib/commands/common/thor/module.rb', line 635
def clone_module_aux(context_params, internal_trigger = false)
module_type = get_module_type(context_params)
forward_options = context_params.get_forwarded_options()
thor_options = forward_options.empty? ? options : forward_options
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
module_name = context_params.retrieve_arguments(["#{module_type}_name".to_sym],method_argument_names)
version = thor_options["version"]||options.version
internal_trigger = true if thor_options['skip_edit']
response = clone_aux(module_type.to_sym, module_id, version, internal_trigger, thor_options['omit_output'], :use_latest => true)
if !response.ok? && response.is_a?(Response::Error::Usage) && !forward_options[:service_importer]
if errors = response['errors']
if error_msg = errors.first['message']
OsUtil.print_warning(errors.first['message'])
return
end
end
end
response
end
|
#create_new_version_aux(context_params, internal_trigger = false) ⇒ Object
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
|
# File 'lib/commands/common/thor/module.rb', line 916
def create_new_version_aux(context_params, internal_trigger = false)
module_type = get_module_type(context_params)
module_id, version = context_params.retrieve_arguments([REQ_MODULE_ID, :option_1!], method_argument_names)
version = (context_params.get_forwarded_options()['version'] || options.version) if internal_trigger
module_name = context_params.retrieve_arguments(["#{module_type}_name".to_sym],method_argument_names)
namespace, name = get_namespace_and_name(module_name,':')
do_not_raise_if_exist = context_params.get_forwarded_options()['do_not_raise_if_exist']
module_location = OsUtil.module_location(module_type, module_name, nil)
unless File.directory?(module_location)
if Console.confirmation_prompt("Module '#{module_name}' has not been cloned. Would you like to clone module now"+'?')
response = clone_aux(module_type.to_sym, module_id, nil, true)
return response unless response.ok?
end
end
opts = {:do_not_raise_if_exist => do_not_raise_if_exist} if do_not_raise_if_exist
m_name, m_namespace, repo_url, branch, not_ok_response = workspace_branch_info(module_type, module_id, nil)
resp = Helper(:git_repo).create_new_version(module_type, branch, name, namespace, version, repo_url, opts||{})
post_body = get_workspace_branch_info_post_body(module_type, module_id, version)
post_body.merge!(:do_not_raise_if_exist => do_not_raise_if_exist) if do_not_raise_if_exist
create_response = post(rest_url("#{module_type}/create_new_version"), post_body)
unless create_response.ok?
FileUtils.rm_rf("#{resp['module_directory']}") unless resp['exist_already']
return create_response
end
if version_exist = create_response.data(:version_exist)
return create_response if do_not_raise_if_exist
end
if error = create_response.data(:dsl_parse_error)
dsl_parsed_message = ServiceImporter.error_message(module_name, error)
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
end
if external_dependencies = create_response.data(:external_dependencies)
print_dependencies(external_dependencies)
end
if component_module_refs = create_response.data(:component_module_refs)
print_using_dependencies(component_module_refs)
end
Response::Ok.new()
end
|
#create_test_module_aux(context_params) ⇒ Object
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
# File 'lib/commands/common/thor/module.rb', line 236
def create_test_module_aux(context_params)
test_module_name = context_params.retrieve_arguments([:option_1!], method_argument_names)
module_type = get_module_type(context_params)
response = DTK::Client::TestModuleCreator.create_clone(module_type.to_sym, test_module_name)
return response unless response.ok?
create_response = import(context_params)
unless create_response.ok?
error_msg = create_response['errors'].select { |er| er['message'].include? 'cannot be created since it exists already' }
if error_msg.empty?
delete(context_params, :force_delete => true, :no_error_msg => true)
end
FileUtils.rm_rf("#{response['data']['module_directory']}")
return create_response
end
end
|
#delete_assembly_aux(context_params) ⇒ Object
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
|
# File 'lib/commands/common/thor/module.rb', line 820
def delete_assembly_aux(context_params)
module_type = get_module_type(context_params)
module_id, assembly_template_id = context_params.retrieve_arguments([REQ_MODULE_ID,:option_1!], method_argument_names)
module_name = context_params.retrieve_arguments([:service_module_name],method_argument_names)
assembly_template_name = (assembly_template_id.to_s =~ /^[0-9]+$/) ? DTK::Client::Assembly.get_assembly_template_name_for_service(assembly_template_id, module_name) : assembly_template_id
assembly_template_id = DTK::Client::Assembly.get_assembly_template_id_for_service(assembly_template_id, module_name) unless assembly_template_id.to_s =~ /^[0-9]+$/
return unless Console.confirmation_prompt("Are you sure you want to delete assembly '#{assembly_template_name||assembly_template_id}'"+'?') unless options.force?
post_body = {
"#{module_type}_id".to_sym => module_id,
:assembly_id => assembly_template_id,
:subtype => :template
}
response = post rest_url("#{module_type}/delete_assembly_template"), post_body
return response unless response.ok?
module_location = OsUtil.module_location(module_type, module_name)
if (module_location && assembly_template_name)
assembly_template_location = "#{module_location}/assemblies/#{assembly_template_name}"
base_file = "#{module_location}/assemblies/#{assembly_template_name}.dtk.assembly"
assembly_file_location =
if File.exists?("#{base_file}.yaml")
"#{base_file}.yaml"
elsif File.exists?("#{base_file}.json")
"#{base_file}.json"
else
nil
end
end
FileUtils.rm("#{assembly_file_location}") if assembly_file_location
if File.directory?(assembly_template_location)
unless (assembly_template_location.nil? || ("#{module_location}/assemblies/" == assembly_template_location))
FileUtils.rm_rf("#{assembly_template_location}")
end
end
version = nil
commit_msg = "Deleting assembly template #{assembly_template_name.to_s}"
internal_trigger = true
push_clone_changes_aux(module_type.to_sym, module_id, version, commit_msg, internal_trigger, :skip_cloning => true)
Response::Ok.new()
end
|
#delete_from_catalog_aux(context_params) ⇒ Object
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
|
# File 'lib/commands/common/thor/module.rb', line 409
def delete_from_catalog_aux(context_params)
module_type = get_module_type(context_params)
remote_module_name = context_params.retrieve_arguments([:option_1!], method_argument_names)
version = options.version
rsa_pub_key = SSHUtil.rsa_pub_key_content()
remote_namespace, remote_module_name = get_namespace_and_name(remote_module_name, ':')
if version
check_version_format(version)
else
list_post_body = {
"#{module_type}_id".to_sym => "#{remote_namespace}:#{remote_module_name}",
:rsa_pub_key => rsa_pub_key,
:include_base => true
}
versions_response = post rest_url("#{module_type}/list_remote"), list_post_body
return versions_response unless versions_response.ok?
selected_module = versions_response.data.find{ |vr| vr['display_name'].eql?("#{remote_namespace}/#{remote_module_name}") }
raise DtkError, "Module '#{remote_namespace}/#{remote_module_name}'' does not exist on repo manager!" unless selected_module
versions = selected_module['versions']
if versions.size > 2
versions << "all"
ret_version = Console.confirmation_prompt_multiple_choice("\nSelect version to delete:", versions)
return unless ret_version
raise DtkError, "You are not allowed to delete 'base' version while other versions exist!" if ret_version.eql?('base')
version = ret_version
end
end
unless options.force? || options.confirmed?
msg = "Are you sure you want to delete remote #{module_type} '#{remote_namespace.nil? ? '' : remote_namespace + '/'}#{remote_module_name}'"
msg += " version '#{version}'" if version
msg += " and all items contained in it"
return unless Console.confirmation_prompt(msg + '?')
end
post_body = {
:rsa_pub_key => rsa_pub_key,
:remote_module_name => remote_module_name,
:remote_module_namespace => remote_namespace,
:force_delete => options.force?
}
post_body.merge!(:version => version) if version
response = post rest_url("#{module_type}/delete_remote"), post_body
return response unless response.ok?
full_module_name, version = response.data(:module_full_name, :version)
msg = "Module '#{full_module_name}' "
msg << "version '#{version}'" if version && !version.eql?('master')
msg << " has been deleted successfully."
OsUtil.print(msg, :yellow)
Response::Ok.new()
end
|
#delete_module_aux(context_params, method_opts = {}) ⇒ Object
107
108
109
110
111
112
|
# File 'lib/commands/common/thor/module.rb', line 107
def delete_module_aux(context_params, method_opts = {})
module_location, modules_path = nil, nil
module_id = context_params.retrieve_arguments([:option_1!], method_argument_names)
delete_module_sub_aux(context_params, module_id, method_opts)
end
|
#delete_module_sub_aux(context_params, module_id, method_opts = {}) ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/commands/common/thor/module.rb', line 114
def delete_module_sub_aux(context_params, module_id, method_opts = {})
version = options.version
module_name = get_name_from_id_helper(module_id)
module_type = get_module_type(context_params)
version = 'delete_all' if method_opts[:delete_all]
unless (options.force? || method_opts[:force_delete])
msg = "Are you sure you want to delete module '#{module_name}'"
msg += " version '#{version}'" if version
is_go = Console.confirmation_prompt("#{msg}"+"?")
return nil unless is_go
end
post_body = { "#{module_type}_id".to_sym => module_id }
opts = { :module_name => module_name }
unless version
versions_response = post rest_url("#{module_type}/list_versions"), post_body
return versions_response unless versions_response.ok?
versions = versions_response.data.first['versions']
if versions.size > 0
versions << "all" unless versions.size == 1
ret_version = Console.confirmation_prompt_multiple_choice("\nSelect version to delete:", versions)
return unless ret_version
raise DtkError, "You are not allowed to delete 'base' version while other versions exist!" if ret_version.eql?('base')
version = ret_version
else
raise DtkError, "There are no versions created for #{module_type} '#{module_name}'!" unless method_opts[:no_error_msg]
end
end
if version
if version.eql?('all')
post_body.merge!(:all_except_base => true)
opts.merge!(:all_except_base => true)
elsif version.eql?('delete_all')
post_body.merge!(:delete_all_versions => true)
opts.merge!(:delete_all_versions => true)
else
post_body.merge!(:version => version)
opts.merge!(:version => version)
end
end
response = post(rest_url("#{module_type}/delete"), post_body)
return response unless response.ok?
unless version
version = response.data(:version)
opts.merge!(:version => version)
end
response =
if options.purge? || method_opts[:purge]
purge_clone_aux(module_type.to_sym, opts)
else
Helper(:git_repo).unlink_local_clone?(module_type.to_sym, module_name, version)
end
return response unless response.ok?
unless method_opts[:no_error_msg]
if version && version.eql?('all')
OsUtil.print("All versions (except base) of '#{module_name}' module have been deleted.", :yellow)
elsif version && version.eql?('delete_all')
OsUtil.print("All versions of '#{module_name}' module have been deleted.", :yellow)
else
msg = "Module '#{module_name}' "
if version then msg << "version '#{version}' has been deleted successfully."
else msg << "has been deleted successfully."; end
OsUtil.print(msg, :yellow)
end
end
Response::Ok.new()
end
|
#edit_module_aux(context_params) ⇒ Object
659
660
661
662
663
664
665
666
667
668
669
670
671
|
# File 'lib/commands/common/thor/module.rb', line 659
def edit_module_aux(context_params)
module_type = get_module_type(context_params)
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
module_name = context_params.retrieve_arguments(["#{module_type}_name".to_sym], method_argument_names)
version = options.version||context_params.retrieve_arguments([:option_1], method_argument_names)
edit_dsl = context_params.get_forwarded_options()[:edit_dsl] if context_params.get_forwarded_options()
opts = {}
base_file_name = "dtk.model"
opts.merge!(:edit_file => {:base_file_name => base_file_name}) if edit_dsl
edit_aux(module_type.to_sym, module_id, module_name, version, opts)
end
|
#fork_aux(context_params) ⇒ Object
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
|
# File 'lib/commands/common/thor/module.rb', line 883
def fork_aux(context_params)
module_type = get_module_type(context_params)
module_id, fork_namespace = context_params.retrieve_arguments([REQ_MODULE_ID, :option_1!], method_argument_names)
raise DtkValidationError, "Namespace '#{fork_namespace}' contains invalid characters. Valid characters are letters, numbers, dash and underscore." unless fork_namespace.to_s =~ /^[0-9a-zA-Z\_\-]*$/
module_name = context_params.retrieve_arguments(["#{module_type}_name".to_sym],method_argument_names)
namespace, name = get_namespace_and_name(module_name,':')
module_location = OsUtil.module_location(module_type, module_name, nil)
unless File.directory?(module_location)
if Console.confirmation_prompt("Module '#{module_name}' has not been cloned. Would you like to clone module now"+'?')
response = clone_aux(module_type.to_sym, module_id, nil, true)
return response unless response.ok?
end
end
response = Helper(:git_repo).cp_r_to_new_namespace(module_type, name, namespace, fork_namespace)
return response unless response.ok?
new_context_params = DTK::Shell::ContextParams.new
new_context_params.add_context_to_params(module_type, module_type)
new_context_params.method_arguments = ["#{fork_namespace}:#{name}"]
create_response = DTK::Client::ContextRouter.routeTask(module_type, "import", new_context_params, @conn)
unless create_response.ok?
FileUtils.rm_rf("#{response['data']['module_directory']}")
return create_response
end
Response::Ok.new()
end
|
#forward_namespace?(module_name, input_remote_name, context_params) ⇒ Boolean
970
971
972
973
974
975
|
# File 'lib/commands/common/thor/module.rb', line 970
def forward_namespace?(module_name, input_remote_name, context_params)
return unless input_remote_name
local_namespace, local_name = get_namespace_and_name(module_name,':')
remote_namespace, remote_name = get_namespace_and_name(input_remote_name,'/')
context_params.forward_options('namespace' => remote_namespace) unless local_namespace.eql?(remote_namespace)
end
|
#get_module_type(context_params) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/commands/common/thor/module.rb', line 64
def get_module_type(context_params)
forwarded_type = context_params.get_forwarded_options() ? context_params.get_forwarded_options()[:module_type] : nil
if context_params.root_command_name || forwarded_type
module_type = (context_params.root_command_name||forwarded_type).gsub(/\-/, "_")
else
module_type = resolve_module_type
end
module_type
end
|
#import_git_module_aux(context_params) ⇒ Object
259
260
261
|
# File 'lib/commands/common/thor/module.rb', line 259
def import_git_module_aux(context_params)
CommonModule::Import.new(self, context_params).from_git(context_params.get_forwarded_options()[:internal_trigger])
end
|
#import_module_aux(context_params) ⇒ Object
263
264
265
|
# File 'lib/commands/common/thor/module.rb', line 263
def import_module_aux(context_params)
CommonModule::Import.new(self, context_params).from_file()
end
|
#install_base_version_aux?(context_params, post_body, module_type, version) ⇒ Boolean
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
# File 'lib/commands/common/thor/module.rb', line 383
def install_base_version_aux?(context_params, post_body, module_type, version)
master_response = post rest_url("#{module_type}/prepare_for_install_module"), post_body
return master_response unless master_response.ok?
head_installed = master_response.data(:head_installed)
latest_version = master_response.data(:latest_version)
remote_module_name, param_version = context_params.retrieve_arguments([:option_1!, :option_2], method_argument_names)
if version
versions = master_response.data(:versions)
raise DtkError, "Module '#{remote_module_name}' version '#{version}' does not exist on repo manager!" unless versions.include?(version)
end
base_response = nil
if !head_installed && !latest_version.eql?('master')
new_context_params = DTK::Shell::ContextParams.new
new_context_params.add_context_to_params(module_type, module_type)
new_context_params.method_arguments = [remote_module_name]
new_context_params.forward_options('skip_base' => true, 'version' => 'master')
base_response = install_module_aux(new_context_params)
end
return base_response if base_response && (options.version? && options.version.eql?('master'))
master_response
end
|
#install_module_aux(context_params, internal_trigger = false) ⇒ Object
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
# File 'lib/commands/common/thor/module.rb', line 267
def install_module_aux(context_params, internal_trigger = false)
create_missing_clone_dirs()
resolve_direct_access(::DTK::Client::Configurator.check_direct_access)
remote_module_name, version = context_params.retrieve_arguments([:option_1!, :option_2], method_argument_names)
forwarded_version = context_params.get_forwarded_options()['version']
add_version = false
master_only = (options.version? && options.version.eql?('master'))
version ||= forwarded_version || options.version
version = nil if version.eql?('master')
if version
check_version_format(version)
add_version = true
end
skip_cloning = context_params.get_forwarded_options()['skip_cloning'] if context_params.get_forwarded_options()
do_not_raise = context_params.get_forwarded_options()[:do_not_raise] if context_params.get_forwarded_options()
skip_ainstall = context_params.get_forwarded_options() ? context_params.get_forwarded_options()[:skip_auto_install] : false
skip_base = context_params.get_forwarded_options()['skip_base']
module_type = get_module_type(context_params)
ignore_component_error = context_params.get_forwarded_options().empty? ? options.ignore? : context_params.get_forwarded_options()[:ignore_component_error]
additional_message = context_params.get_forwarded_options()[:additional_message] if context_params.get_forwarded_options()
remote_namespace, local_module_name = get_namespace_and_name(remote_module_name, ':')
post_body = {
:remote_module_name => remote_module_name.sub(':', '/'),
:local_module_name => local_module_name,
:rsa_pub_key => SSHUtil.rsa_pub_key_content()
}
post_body.merge!(:do_not_raise => do_not_raise) if do_not_raise
post_body.merge!(:ignore_component_error => ignore_component_error) if ignore_component_error
post_body.merge!(:additional_message => additional_message) if additional_message
post_body.merge!(:skip_auto_install => skip_ainstall) if skip_ainstall
unless skip_base
master_response = install_base_version_aux?(context_params, post_body, module_type, version)
return master_response if !master_response.ok? || master_only
latest_version = master_response.data(:latest_version)
unless version
version = latest_version.eql?('master') ? nil : latest_version
end
post_body.merge!(:hard_reset_on_pull_version => true) if version
end
if version
add_version = true
post_body.merge!(:version => version)
end
if clone_dir = Helper(:git_repo).local_clone_dir_exists?(module_type.to_sym, local_module_name, :namespace => remote_namespace, :version => version)
message = "Module's directory (#{clone_dir}) exists on client. To install this needs to be renamed or removed."
raise DtkError, message unless ignore_component_error
end
response = post rest_url("#{module_type}/import"), post_body
unless skip_base
are_there_warnings = RemoteDependencyUtil.check_permission_warnings(response)
are_there_warnings ||= RemoteDependencyUtil.print_dependency_warnings(response, nil, :ignore_permission_warnings => true)
if are_there_warnings
return false unless Console.confirmation_prompt('Do you still want to proceed with import' + '?')
end
end
if response.ok? && !skip_ainstall && (missing_components = response.data(:missing_module_components))
required_components = response.data(:required_modules)
opts = { :do_not_raise => true }
module_opts = ignore_component_error ? opts.merge(:ignore_component_error => true) : opts.merge(:additional_message => true)
module_opts.merge!(:update_none => true) if options.update_none?
module_opts.merge!(:hide_output => true) if skip_base && !master_only
continue = trigger_module_auto_import(missing_components, required_components, module_opts)
return unless continue
print_remote_name = add_version ? "#{remote_module_name}(#{version})" : remote_module_name
print "Resuming DTK Network import for #{module_type} '#{print_remote_name}' ..." unless skip_base
post_body.merge!(opts)
response = post rest_url("#{module_type}/import"), post_body
puts ' Done' unless skip_base
end
return response if !response.ok? || response.data(:does_not_exist)
module_id, module_name, namespace, repo_url, branch, version = response.data(:module_id, :module_name, :namespace, :repo_url, :workspace_branch, :version)
if error = response.data(:dsl_parse_error)
dsl_parsed_message = ServiceImporter.error_message(module_name, error)
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
end
unless skip_cloning
response = Helper(:git_repo).create_clone_with_branch(module_type.to_sym, module_name, repo_url, branch, version, remote_namespace)
end
resolve_missing_components(module_id, module_name, namespace, options.force?) if module_type.to_s.eql?('service_module')
response
end
|
#list_collaborators_module_aux(context_params) ⇒ Object
628
629
630
631
632
633
|
# File 'lib/commands/common/thor/module.rb', line 628
def list_collaborators_module_aux(context_params)
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
response = collaboration_list_aux(module_id, options.namespace)
response.render_table(:module_collaborators)
response
end
|
#list_diffs_module_aux(context_params) ⇒ Object
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
|
# File 'lib/commands/common/thor/module.rb', line 766
def list_diffs_module_aux(context_params)
module_type = get_module_type(context_params)
module_id = context_params.retrieve_arguments([REQ_MODULE_ID],method_argument_names)
module_name = context_params.retrieve_arguments(["#{module_type}_name".to_sym],method_argument_names)
version = options["version"]
module_location = OsUtil.module_location(module_type, module_name, version)
if File.directory?(module_location)
list_diffs_aux(module_type.to_sym, module_id, options.remote?, version)
else
if Console.confirmation_prompt("Module '#{module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
response = clone_aux(module_type.to_sym, module_id, version, true)
unless response.ok?
return response
end
else
return
end
end
end
|
#list_instances_aux(context_params) ⇒ Object
870
871
872
873
874
875
876
877
878
879
880
881
|
# File 'lib/commands/common/thor/module.rb', line 870
def list_instances_aux(context_params)
module_type = get_module_type(context_params)
module_id = context_params.retrieve_arguments([REQ_MODULE_ID],method_argument_names)
post_body = {
"#{module_type}_id".to_sym => module_id,
}
response = post rest_url("#{module_type}/list_instances"), post_body
response.render_table(:assembly)
end
|
#list_remote_module_diffs(context_params) ⇒ Object
791
792
793
794
795
|
# File 'lib/commands/common/thor/module.rb', line 791
def list_remote_module_diffs(context_params)
module_type = get_module_type(context_params)
module_id = context_params.retrieve_arguments([REQ_MODULE_ID],method_argument_names)
list_remote_diffs_aux(module_type.to_sym, module_id)
end
|
#list_remote_versions_aux(context_params) ⇒ Object
808
809
810
811
812
813
814
815
816
817
818
|
# File 'lib/commands/common/thor/module.rb', line 808
def list_remote_versions_aux(context_params)
module_type = get_module_type(context_params)
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
post_body = {
"#{module_type}_id".to_sym => module_id,
:rsa_pub_key => SSHUtil.rsa_pub_key_content()
}
response = post rest_url("#{module_type}/list_remote_versions"), post_body
end
|
#list_versions_aux(context_params) ⇒ Object
797
798
799
800
801
802
803
804
805
806
|
# File 'lib/commands/common/thor/module.rb', line 797
def list_versions_aux(context_params)
module_type = get_module_type(context_params)
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
include_base = context_params.get_forwarded_options()['include_base']
post_body = { "#{module_type}_id".to_sym => module_id }
post_body.merge!(:include_base => include_base) if include_base
response = post rest_url("#{module_type}/list_versions"), post_body
end
|
#make_private_module_aux(context_params) ⇒ Object
613
614
615
616
|
# File 'lib/commands/common/thor/module.rb', line 613
def make_private_module_aux(context_params)
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
chmod_aux(module_id, "o-rwd", options.namespace, :make_private)
end
|
#make_public_module_aux(context_params) ⇒ Object
608
609
610
611
|
# File 'lib/commands/common/thor/module.rb', line 608
def make_public_module_aux(context_params)
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
chmod_aux(module_id, "o+r", options.namespace, :make_public)
end
|
#module_info_about(context_params, about, data_type) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/commands/common/thor/module.rb', line 76
def module_info_about(context_params, about, data_type)
module_id, component_template_id = context_params.retrieve_arguments([REQ_MODULE_ID, :component_id],method_argument_names)
module_type = get_module_type(context_params)
post_body = {
"#{module_type}_id".to_sym => module_id,
:component_template_id => component_template_id,
:about => about
}
response = post rest_url("#{module_type}/info_about"), post_body
data_type = data_type
response.render_table(data_type) unless options.list?
end
|
#module_info_aux(context_params) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/commands/common/thor/module.rb', line 91
def module_info_aux(context_params)
module_type = get_module_type(context_params)
if context_params.is_there_identifier?(:assembly)
response = DTK::Client::ContextRouter.routeTask("assembly", "info", context_params, @conn)
else
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
post_body = {
"#{module_type}_id".to_sym => module_id
}
response = post rest_url("#{module_type}/info"), post_body
response.render_custom_info("module")
end
end
|
#print_ambiguous(ambiguous) ⇒ Object
967
968
|
# File 'lib/commands/common/thor/module.rb', line 967
def print_ambiguous(ambiguous)
end
|
#print_dependencies(dependencies) ⇒ Object
977
978
979
980
981
982
983
984
985
986
|
# File 'lib/commands/common/thor/module.rb', line 977
def print_dependencies(dependencies)
ambiguous = dependencies["ambiguous"]||[]
amb_sorted = ambiguous.map { |k,v| "#{k.split('/').last} (#{v.join(', ')})" }
inconsistent = dependencies["inconsistent"]||[]
possibly_missing = dependencies["possibly_missing"]||[]
OsUtil.print("There are inconsistent module dependencies mentioned in dtk.model.yaml: #{inconsistent.join(', ')}", :red) unless inconsistent.empty?
OsUtil.print("There are missing module dependencies mentioned in dtk.model.yaml: #{possibly_missing.join(', ')}", :yellow) unless possibly_missing.empty?
OsUtil.print("There are ambiguous module dependencies mentioned in dtk.model.yaml: '#{amb_sorted.join(', ')}'. One of the namespaces should be selected by editing the module_refs file", :yellow) if ambiguous && !ambiguous.empty?
end
|
#print_using_dependencies(component_refs) ⇒ Object
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
|
# File 'lib/commands/common/thor/module.rb', line 988
def print_using_dependencies(component_refs)
unless component_refs.empty?
puts 'Using component modules:'
names = []
component_refs.values.each do |cmp_ref|
version = cmp_ref['version_info']
name = "#{cmp_ref['namespace_info']}:#{cmp_ref['module_name']}"
name << "(#{version})" if version
names << name
end
names.sort.each do |name|
puts " #{name}"
end
end
end
|
#publish_module_aux(context_params) ⇒ Object
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
|
# File 'lib/commands/common/thor/module.rb', line 470
def publish_module_aux(context_params)
module_type = get_module_type(context_params)
module_id, module_name, input_remote_name = context_params.retrieve_arguments([REQ_MODULE_ID, REQ_MODULE_NAME, :option_1], method_argument_names)
raise DtkValidationError, "You have to provide version you want to publish!" unless options.version
unless input_remote_name
input_remote_name = module_name.gsub(":","/")
context_params.method_arguments << input_remote_name
end
skip_base = context_params.get_forwarded_options()['skip_base']
forwarded_version = context_params.get_forwarded_options()['version']
version = forwarded_version||options.version
version = nil if version.eql?('master')
forward_namespace?(module_name, input_remote_name, context_params)
post_body = {
"#{module_type}_id".to_sym => module_id,
:remote_component_name => input_remote_name,
:rsa_pub_key => SSHUtil.rsa_pub_key_content(),
}
unless skip_base
check_response = post rest_url("#{module_type}/check_remote_exist"), post_body
return check_response unless check_response.ok?
remote_exist = check_response.data(:remote_exist)
unless remote_exist
context_params.forward_options('skip_base' => true, 'version' => 'master')
resp = publish_module_aux(context_params)
return resp unless resp.ok?
end
context_params.forward_options('do_not_raise_if_exist' => true, 'version' => version)
create_response = create_new_version_aux(context_params, true)
return create_response unless create_response.ok?
end
post_body.merge!(:version => version) if version
response = post rest_url("#{module_type}/export"), post_body
return response unless response.ok?
unless skip_base
full_module_name = "#{response.data['remote_repo_namespace']}/#{response.data['remote_repo_name']}"
DTK::Client::RemoteDependencyUtil.print_dependency_warnings(response, "Module has been successfully published to '#{full_module_name}' version '#{version}'!")
end
Response::Ok.new()
end
|
#pull_dtkn_aux(context_params) ⇒ Object
DTK::Client::RemoteDependencyUtil.print_dependency_warnings(response, “Module has been successfully published to ‘#ServiceImporter#full_module_name’!”)
Response::Ok.new()
end
end
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
|
# File 'lib/commands/common/thor/module.rb', line 568
def pull_dtkn_aux(context_params)
module_id, module_name = context_params.retrieve_arguments([REQ_MODULE_ID,REQ_MODULE_NAME,:option_1],method_argument_names)
catalog = 'dtkn'
version = options.version||context_params.get_forwarded_options()[:version]
module_type = get_module_type(context_params)
skip_recursive_pull = context_params.get_forwarded_options()[:skip_recursive_pull]
ignore_dependency_merge_conflict = context_params.get_forwarded_options()[:skip_recursive_pull]
raise DtkValidationError, "You have to provide valid catalog to pull changes from! Valid catalogs: #{PULL_CATALOGS}" unless catalog
module_location = OsUtil.module_location(resolve_module_type(), module_name, version)
if catalog.to_s.eql?("dtkn")
clone_aux(module_type.to_sym, module_id, version, true, true) unless File.directory?(module_location)
opts = {
:force => options.force?,
:version => version,
:remote_namespace => options.namespace,
:skip_recursive_pull => skip_recursive_pull,
:ignore_dependency_merge_conflict => ignore_dependency_merge_conflict
}
opts.merge!(:do_not_raise => true) if (context_params.get_forwarded_options()||{})[:do_not_raise]
response = pull_from_remote_aux(module_type.to_sym, module_id, opts)
return response unless response.ok?
push_clone_changes_aux(module_type.to_sym, module_id, version, nil, true, {:update_from_includes => true}) if File.directory?(module_location)
response.skip_render = true
response
else
raise DtkValidationError, "You have to provide valid catalog to pull changes from! Valid catalogs: #{PULL_CATALOGS}"
end
end
|
#push_dtkn_module_aux(context_params, internal_trigger = false) ⇒ Object
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
|
# File 'lib/commands/common/thor/module.rb', line 729
def push_dtkn_module_aux(context_params, internal_trigger=false)
module_id, module_name = context_params.retrieve_arguments([REQ_MODULE_ID, REQ_MODULE_NAME],method_argument_names)
catalog = 'dtkn'
version = options["version"]||context_params.get_forwarded_thor_option('version')
module_type = get_module_type(context_params)
raise DtkValidationError, "You have to provide valid catalog to push changes to! Valid catalogs: #{PushCatalogs}" unless catalog
module_location = OsUtil.module_location(resolve_module_type(), module_name, version)
reparse_aux(module_location) unless internal_trigger
local_namespace, local_module_name = get_namespace_and_name(module_name,':')
if catalog.to_s.eql?("dtkn")
module_refs_content = RemoteDependencyUtil.module_ref_content(module_location)
options_namespace = options["namespace"]||context_params.get_forwarded_thor_option('namespace')
remote_module_info = get_remote_module_info_aux(module_type.to_sym, module_id, options_namespace, version, module_refs_content, local_namespace)
return remote_module_info unless remote_module_info.ok?
unless File.directory?(module_location)
response = clone_aux(module_type.to_sym, module_id, version, true, true)
if(response.nil? || response.ok?)
reparse_aux(module_location)
response = push_to_remote_aux(remote_module_info, module_type.to_sym)
end
return response
end
push_to_remote_aux(remote_module_info, module_type.to_sym, options.force?)
else
raise DtkValidationError, "You have to provide valid catalog to push changes to! Valid catalogs: #{PushCatalogs}"
end
end
|
#push_module_aux(context_params, internal_trigger = false, opts = {}) ⇒ Object
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
# File 'lib/commands/common/thor/module.rb', line 220
def push_module_aux(context_params, internal_trigger = false, opts = {})
module_type = get_module_type(context_params)
module_id, module_name = context_params.retrieve_arguments([REQ_MODULE_ID, "#{module_type}_name".to_sym], method_argument_names)
version = options['version']
module_location = OsUtil.module_location(module_type, module_name, version)
git_import = opts[:git_import]
opts.merge!(:update_from_includes => true, :force_parse => true) unless git_import
opts.merge!(:force => options.force?)
opts.merge!(:generate_docs => options.docs?)
reparse_aux(module_location)
push_clone_changes_aux(module_type.to_sym, module_id, version, options['message'] || DEFAULT_COMMIT_MSG, internal_trigger, opts)
end
|
#push_remote_module_aux(context_params) ⇒ Object
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
|
# File 'lib/commands/common/thor/module.rb', line 673
def push_remote_module_aux(context_params)
module_id, module_name, remote_name = context_params.retrieve_arguments([REQ_MODULE_ID, REQ_MODULE_NAME, :option_1],method_argument_names)
version = options["version"]
module_type = get_module_type(context_params)
post_body = {
"#{module_type}_id".to_sym => module_id
}
response = post rest_url("#{module_type}/info_git_remote"), post_body
remotes_list = response.data
raise DtkError, "There are no registered remotes, aborting action" if remotes_list.empty?
if remote_name
target_remote = remotes_list.find { |r| remote_name.eql?(r['display_name']) }
raise DtkError, "Not able to find remote '#{remote_name}'" unless target_remote
end
unless target_remote
if remotes_list.size == 1
target_remote = remotes_list.first
else
remote_names = remotes_list.collect { |r| r['display_name'] }
raise DtkError, "Call is ambiguous, please provide remote name. Remotes: #{remote_names.join(', ')} "
end
end
module_location = OsUtil.module_location(resolve_module_type(), module_name, version)
unless File.directory?(module_location)
response = clone_aux(module_type.to_sym, module_id, version, true, true)
return response unless response.ok?
end
if target_remote['base_git_location']
OsUtil.print("Pushing local content to remote #{target_remote['base_git_url']} in folder #{target_remote['base_git_location']} ...")
return push_to_git_remote_location_aux(module_name, module_type.to_sym, version, {
:remote_repo_url => target_remote['base_git_url'],
:remote_repo_location => target_remote['base_git_location'],
:remote_branch => 'master',
:remote_repo => "#{target_remote['display_name']}--remote"
}, options.force?)
else
OsUtil.print("Pushing local content to remote #{target_remote['repo_url']} ... ", :yellow)
return push_to_git_remote_aux(module_name, module_type.to_sym, version, {
:remote_repo_url => target_remote['repo_url'],
:remote_branch => 'master',
:remote_repo => "#{target_remote['display_name']}--remote"
}, options.force?)
end
end
|
#remove_collaborators_module_aux(context_params) ⇒ Object
623
624
625
626
|
# File 'lib/commands/common/thor/module.rb', line 623
def remove_collaborators_module_aux(context_params)
module_id = context_params.retrieve_arguments([REQ_MODULE_ID], method_argument_names)
collaboration_aux(:remove, module_id, options.users, options.groups, options.namespace)
end
|
#set_attribute_module_aux(context_params) ⇒ Object
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/commands/common/thor/module.rb', line 200
def set_attribute_module_aux(context_params)
if context_params.is_there_identifier?(:attribute)
mapping = [REQ_MODULE_ID, :attribute_id!, :option_1]
else
mapping = [REQ_MODULE_ID, :option_1!, :option_2]
end
module_id, attribute_id, value = context_params.retrieve_arguments(mapping, method_argument_names)
module_type = get_module_type(context_params)
post_body = {
:attribute_id => attribute_id,
:attribute_value => value,
:attribute_type => module_type,
"#{module_type}_id".to_sym => module_id
}
post rest_url('attribute/set'), post_body
end
|