dtk-client 0.5.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +5 -0
- data/Gemfile_dev +12 -0
- data/README.md +78 -0
- data/bin/dtk +54 -0
- data/bin/dtk-shell +15 -0
- data/dtk-client.gemspec +49 -0
- data/lib/auxiliary.rb +13 -0
- data/lib/bundler_monkey_patch.rb +9 -0
- data/lib/client.rb +48 -0
- data/lib/command_helper.rb +16 -0
- data/lib/command_helpers/git_repo.rb +391 -0
- data/lib/command_helpers/jenkins_client/config_xml.rb +271 -0
- data/lib/command_helpers/jenkins_client.rb +91 -0
- data/lib/command_helpers/service_importer.rb +99 -0
- data/lib/command_helpers/service_link.rb +18 -0
- data/lib/command_helpers/ssh_processing.rb +43 -0
- data/lib/commands/common/thor/assembly_workspace.rb +1089 -0
- data/lib/commands/common/thor/clone.rb +39 -0
- data/lib/commands/common/thor/common.rb +34 -0
- data/lib/commands/common/thor/edit.rb +168 -0
- data/lib/commands/common/thor/list_diffs.rb +84 -0
- data/lib/commands/common/thor/pull_clone_changes.rb +11 -0
- data/lib/commands/common/thor/pull_from_remote.rb +99 -0
- data/lib/commands/common/thor/purge_clone.rb +26 -0
- data/lib/commands/common/thor/push_clone_changes.rb +45 -0
- data/lib/commands/common/thor/push_to_remote.rb +45 -0
- data/lib/commands/common/thor/reparse.rb +36 -0
- data/lib/commands/common/thor/set_required_params.rb +29 -0
- data/lib/commands/common/thor/task_status.rb +81 -0
- data/lib/commands/thor/account.rb +213 -0
- data/lib/commands/thor/assembly.rb +329 -0
- data/lib/commands/thor/attribute.rb +62 -0
- data/lib/commands/thor/component.rb +52 -0
- data/lib/commands/thor/component_module.rb +829 -0
- data/lib/commands/thor/component_template.rb +153 -0
- data/lib/commands/thor/dependency.rb +18 -0
- data/lib/commands/thor/developer.rb +105 -0
- data/lib/commands/thor/dtk.rb +117 -0
- data/lib/commands/thor/library.rb +107 -0
- data/lib/commands/thor/node.rb +411 -0
- data/lib/commands/thor/node_group.rb +211 -0
- data/lib/commands/thor/node_template.rb +88 -0
- data/lib/commands/thor/project.rb +17 -0
- data/lib/commands/thor/provider.rb +155 -0
- data/lib/commands/thor/repo.rb +35 -0
- data/lib/commands/thor/service.rb +656 -0
- data/lib/commands/thor/service_module.rb +806 -0
- data/lib/commands/thor/state_change.rb +10 -0
- data/lib/commands/thor/target.rb +94 -0
- data/lib/commands/thor/task.rb +100 -0
- data/lib/commands/thor/utils.rb +4 -0
- data/lib/commands/thor/workspace.rb +437 -0
- data/lib/commands.rb +40 -0
- data/lib/config/cacert.pem +3785 -0
- data/lib/config/client.conf.header +18 -0
- data/lib/config/configuration.rb +82 -0
- data/lib/config/default.conf +14 -0
- data/lib/config/disk_cacher.rb +60 -0
- data/lib/configurator.rb +92 -0
- data/lib/context_router.rb +23 -0
- data/lib/core.rb +460 -0
- data/lib/domain/git_adapter.rb +221 -0
- data/lib/domain/response.rb +234 -0
- data/lib/dtk-client/version.rb +3 -0
- data/lib/dtk_constants.rb +23 -0
- data/lib/dtk_logger.rb +96 -0
- data/lib/error.rb +74 -0
- data/lib/git-logs/git.log +0 -0
- data/lib/parser/adapters/option_parser.rb +53 -0
- data/lib/parser/adapters/thor/common_option_defs.rb +12 -0
- data/lib/parser/adapters/thor.rb +509 -0
- data/lib/require_first.rb +87 -0
- data/lib/search_hash.rb +27 -0
- data/lib/shell/context.rb +975 -0
- data/lib/shell/context_aux.rb +29 -0
- data/lib/shell/domain.rb +447 -0
- data/lib/shell/header_shell.rb +27 -0
- data/lib/shell/help_monkey_patch.rb +221 -0
- data/lib/shell/interactive_wizard.rb +233 -0
- data/lib/shell/parse_monkey_patch.rb +22 -0
- data/lib/shell/status_monitor.rb +105 -0
- data/lib/shell.rb +219 -0
- data/lib/util/console.rb +143 -0
- data/lib/util/dtk_puppet.rb +46 -0
- data/lib/util/os_util.rb +265 -0
- data/lib/view_processor/augmented_simple_list.rb +27 -0
- data/lib/view_processor/hash_pretty_print.rb +106 -0
- data/lib/view_processor/simple_list.rb +139 -0
- data/lib/view_processor/table_print.rb +277 -0
- data/lib/view_processor.rb +112 -0
- data/puppet/manifests/init.pp +72 -0
- data/puppet/manifests/params.pp +16 -0
- data/puppet/r8meta.puppet.yml +18 -0
- data/puppet/templates/bash_profile.erb +2 -0
- data/puppet/templates/client.conf.erb +1 -0
- data/puppet/templates/dtkclient.erb +2 -0
- data/spec/assembly_spec.rb +50 -0
- data/spec/assembly_template_spec.rb +51 -0
- data/spec/component_template_spec.rb +40 -0
- data/spec/dependency_spec.rb +6 -0
- data/spec/dtk_shell_spec.rb +13 -0
- data/spec/dtk_spec.rb +33 -0
- data/spec/lib/spec_helper.rb +10 -0
- data/spec/lib/spec_thor.rb +105 -0
- data/spec/module_spec.rb +35 -0
- data/spec/node_spec.rb +43 -0
- data/spec/node_template_spec.rb +25 -0
- data/spec/project_spec.rb +6 -0
- data/spec/repo_spec.rb +7 -0
- data/spec/response_spec.rb +52 -0
- data/spec/service_spec.rb +41 -0
- data/spec/state_change_spec.rb +7 -0
- data/spec/table_print_spec.rb +48 -0
- data/spec/target_spec.rb +57 -0
- data/spec/task_spec.rb +28 -0
- data/views/assembly/augmented_simple_list.rb +12 -0
- data/views/assembly_template/augmented_simple_list.rb +12 -0
- data/views/list_task/augmented_simple_list.rb +12 -0
- metadata +351 -0
@@ -0,0 +1,829 @@
|
|
1
|
+
dtk_require_from_base('command_helpers/ssh_processing')
|
2
|
+
dtk_require_common_commands('thor/clone')
|
3
|
+
dtk_require_common_commands('thor/list_diffs')
|
4
|
+
dtk_require_common_commands('thor/push_to_remote')
|
5
|
+
dtk_require_common_commands('thor/pull_from_remote')
|
6
|
+
dtk_require_common_commands('thor/push_clone_changes')
|
7
|
+
dtk_require_common_commands('thor/edit')
|
8
|
+
dtk_require_common_commands('thor/reparse')
|
9
|
+
dtk_require_common_commands('thor/purge_clone')
|
10
|
+
dtk_require_from_base('configurator')
|
11
|
+
dtk_require_from_base('command_helpers/service_importer')
|
12
|
+
|
13
|
+
require 'fileutils'
|
14
|
+
|
15
|
+
module DTK::Client
|
16
|
+
class ComponentModule < CommandBaseThor
|
17
|
+
|
18
|
+
DEFAULT_COMMIT_MSG = "Initial commit."
|
19
|
+
|
20
|
+
def self.valid_children()
|
21
|
+
# [:"component-template"]
|
22
|
+
[:component]
|
23
|
+
end
|
24
|
+
|
25
|
+
# this includes children of children - has to be sorted by n-level access
|
26
|
+
def self.all_children()
|
27
|
+
# [:"component-template", :attribute] # Amar: attribute context commented out per Rich suggeston
|
28
|
+
# [:"component-template"]
|
29
|
+
[:component]
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.valid_child?(name_of_sub_context)
|
33
|
+
return ComponentModule.valid_children().include?(name_of_sub_context.to_sym)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.validation_list(context_params)
|
37
|
+
get_cached_response(:component_module, "component_module/list", {})
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.override_allowed_methods()
|
41
|
+
return DTK::Shell::OverrideTasks.new(
|
42
|
+
{
|
43
|
+
:command_only => {
|
44
|
+
:self => [
|
45
|
+
["list"," list [--remote] [--diff]","# List loaded or remote component modules. Use --diff to compare loaded and remote component modules."]
|
46
|
+
],
|
47
|
+
:"component" => [
|
48
|
+
["list","list","# List all component templates."],
|
49
|
+
["list-attributes","list-attributes", "# List all attributes for given component."]
|
50
|
+
]
|
51
|
+
#:attribute => [
|
52
|
+
# ['list',"list","List attributes for given component"]
|
53
|
+
#]
|
54
|
+
},
|
55
|
+
:identifier_only => {
|
56
|
+
:"component" => [
|
57
|
+
["list-attributes","list-attributes", "# List all attributes for given component."]
|
58
|
+
]
|
59
|
+
}
|
60
|
+
|
61
|
+
})
|
62
|
+
end
|
63
|
+
|
64
|
+
no_tasks do
|
65
|
+
include CloneMixin
|
66
|
+
include PushToRemoteMixin
|
67
|
+
include PullFromRemoteMixin
|
68
|
+
include PushCloneChangesMixin
|
69
|
+
include EditMixin
|
70
|
+
include ReparseMixin
|
71
|
+
include PurgeCloneMixin
|
72
|
+
include ListDiffsMixin
|
73
|
+
include ServiceImporter
|
74
|
+
|
75
|
+
def get_module_name(module_id)
|
76
|
+
get_name_from_id_helper(module_id)
|
77
|
+
end
|
78
|
+
|
79
|
+
def module_info_about(context_params, about, data_type)
|
80
|
+
component_module_id, component_template_id = context_params.retrieve_arguments([:component_module_id!, :component_id],method_argument_names)
|
81
|
+
post_body = {
|
82
|
+
:component_module_id => component_module_id,
|
83
|
+
:component_template_id => component_template_id,
|
84
|
+
:about => about
|
85
|
+
}
|
86
|
+
response = post rest_url("component_module/info_about"), post_body
|
87
|
+
data_type = data_type
|
88
|
+
response.render_table(data_type) unless options.list?
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.whoami()
|
93
|
+
return :component_module, "component_module/list", nil
|
94
|
+
end
|
95
|
+
|
96
|
+
#TODO: in for testing; may remove
|
97
|
+
# desc "MODULE-NAME/ID test-generate-dsl", "Test generating DSL from implementation"
|
98
|
+
# def test_generate_dsl(context_params)
|
99
|
+
# component_module_id = context_params.retrieve_arguments([:module_id!],method_argument_names)
|
100
|
+
# post rest_url("component_module/test_generate_dsl"),{:component_module_id => component_module_id}
|
101
|
+
# end
|
102
|
+
|
103
|
+
# desc "MODULE-NAME/ID dsl-upgrade [UPGRADE-VERSION] [-v MODULE-VERSION]","Component module DSL upgrade"
|
104
|
+
# version_method_option
|
105
|
+
# def dsl_upgrade(context_params)
|
106
|
+
# component_module_id, dsl_version = context_params.retrieve_arguments([:module_id, :option_1],method_argument_names)
|
107
|
+
# dsl_version ||= MostRecentDSLVersion
|
108
|
+
# post_body = {
|
109
|
+
# :component_module_id => component_module_id,
|
110
|
+
# :dsl_version => dsl_version
|
111
|
+
# }
|
112
|
+
# post_body.merge!(:version => options["version"]) if options["version"]
|
113
|
+
# post rest_url("component_module/create_new_dsl_version"),post_body
|
114
|
+
# end
|
115
|
+
# MostRecentDSLVersion = 2
|
116
|
+
### end
|
117
|
+
|
118
|
+
#### create and delete commands ###
|
119
|
+
# desc "delete COMPONENT-MODULE-NAME [-v VERSION] [-y] [-p]", "Delete component module or component module version and all items contained in it. Optional parameter [-p] is to delete local directory."
|
120
|
+
# version_method_option
|
121
|
+
desc "delete COMPONENT-MODULE-NAME [-y] [-p]", "Delete component module and all items contained in it. Optional parameter [-p] is to delete local directory."
|
122
|
+
method_option :force, :aliases => '-y', :type => :boolean, :default => false
|
123
|
+
method_option :purge, :aliases => '-p', :type => :boolean, :default => false
|
124
|
+
def delete(context_params,method_opts={})
|
125
|
+
module_location, modules_path = nil, nil
|
126
|
+
component_module_id = context_params.retrieve_arguments([:option_1!],method_argument_names)
|
127
|
+
version = options.version
|
128
|
+
component_module_name = get_module_name(component_module_id)
|
129
|
+
|
130
|
+
unless (options.force? || method_opts[:force_delete])
|
131
|
+
# Ask user if really want to delete component module and all items contained in it, if not then return to dtk-shell without deleting
|
132
|
+
return unless Console.confirmation_prompt("Are you sure you want to delete component-module #{version.nil? ? '' : 'version '}'#{component_module_name}#{version.nil? ? '' : ('-' + version.to_s)}' and all items contained in it"+'?')
|
133
|
+
end
|
134
|
+
|
135
|
+
response =
|
136
|
+
if options.purge?
|
137
|
+
opts = {:module_name => component_module_name}
|
138
|
+
if version then opts.merge!(:version => version)
|
139
|
+
else opts.merge!(:delete_all_versions => true)
|
140
|
+
end
|
141
|
+
purge_clone_aux(:component_module,opts)
|
142
|
+
else
|
143
|
+
Helper(:git_repo).unlink_local_clone?(:component_module,component_module_name,version)
|
144
|
+
end
|
145
|
+
return response unless response.ok?
|
146
|
+
|
147
|
+
post_body = {
|
148
|
+
:component_module_id => component_module_id
|
149
|
+
}
|
150
|
+
action = (version ? "delete_version" : "delete")
|
151
|
+
post_body[:version] = version if version
|
152
|
+
|
153
|
+
response = post(rest_url("component_module/#{action}"), post_body)
|
154
|
+
return response unless response.ok?
|
155
|
+
|
156
|
+
# when changing context send request for getting latest modules instead of getting from cache
|
157
|
+
@@invalidate_map << :component_module
|
158
|
+
|
159
|
+
unless method_opts[:no_error_msg]
|
160
|
+
msg = "Component module '#{component_module_name}' "
|
161
|
+
if version then msg << "version #{version} has been deleted"
|
162
|
+
else msg << "has been deleted"; end
|
163
|
+
OsUtil.print(msg,:yellow)
|
164
|
+
end
|
165
|
+
Response::Ok.new()
|
166
|
+
end
|
167
|
+
|
168
|
+
=begin
|
169
|
+
desc "COMPONENT-MODULE-NAME/ID set-attribute ATTRIBUTE-ID VALUE", "Set value of component module attributes"
|
170
|
+
def set_attribute(context_params)
|
171
|
+
if context_params.is_there_identifier?(:attribute)
|
172
|
+
mapping = [:component_module_id!,:attribute_id!, :option_1]
|
173
|
+
else
|
174
|
+
mapping = [:component_module_id!,:option_1!,:option_2]
|
175
|
+
end
|
176
|
+
|
177
|
+
component_module_id, attribute_id, value = context_params.retrieve_arguments(mapping,method_argument_names)
|
178
|
+
|
179
|
+
post_body = {
|
180
|
+
:attribute_id => attribute_id,
|
181
|
+
:attribute_value => value
|
182
|
+
}
|
183
|
+
|
184
|
+
post rest_url("attribute/set"), post_body
|
185
|
+
end
|
186
|
+
=end
|
187
|
+
#### end: create and delete commands ###
|
188
|
+
|
189
|
+
=begin
|
190
|
+
TODO: might deprecate
|
191
|
+
#### list and info commands ###
|
192
|
+
desc "COMPONENT-MODULE-NAME/ID info", "Get information about given component module."
|
193
|
+
def info(context_params)
|
194
|
+
component_module_id = context_params.retrieve_arguments([:component_module_id!],method_argument_names)
|
195
|
+
|
196
|
+
post_body = {
|
197
|
+
:component_module_id => component_module_id
|
198
|
+
}
|
199
|
+
|
200
|
+
response = post rest_url("component_module/info"), post_body
|
201
|
+
response.render_custom_info("module")
|
202
|
+
end
|
203
|
+
=end
|
204
|
+
|
205
|
+
desc "list [--remote] [--diff]", "List loaded or remote component modules. Use --diff to compare loaded and remote component modules."
|
206
|
+
method_option :remote, :type => :boolean, :default => false
|
207
|
+
method_option :diff, :type => :boolean, :default => false
|
208
|
+
def list(context_params)
|
209
|
+
# Amar: attribute context commented out per Rich suggeston
|
210
|
+
#if context_params.is_there_command?(:attribute)
|
211
|
+
# return module_info_about(context_params, :attributes, :attribute)
|
212
|
+
#elsif context_params.is_there_command?(:"component-template")
|
213
|
+
# if context_params.is_there_command?(:"component-template")
|
214
|
+
if context_params.is_there_command?(:"component")
|
215
|
+
return module_info_about(context_params, :components, :component)
|
216
|
+
end
|
217
|
+
|
218
|
+
action = (options.remote? ? "list_remote" : "list")
|
219
|
+
# post_body = (options.remote? ? { :rsa_pub_key => SshProcessing.rsa_pub_key_content() } : {:detail_to_include => ["remotes","versions"]})
|
220
|
+
post_body = (options.remote? ? { :rsa_pub_key => SshProcessing.rsa_pub_key_content() } : {:detail_to_include => ["remotes"]})
|
221
|
+
post_body[:diff] = options.diff? ? options.diff : {}
|
222
|
+
response = post rest_url("component_module/#{action}"),post_body
|
223
|
+
|
224
|
+
return response unless response.ok?
|
225
|
+
response.render_table()
|
226
|
+
end
|
227
|
+
|
228
|
+
=begin
|
229
|
+
desc "COMPONENT-MODULE-NAME/ID list-versions","List all versions associated with this component module."
|
230
|
+
def list_versions(context_params)
|
231
|
+
component_module_id = context_params.retrieve_arguments([:component_module_id!],method_argument_names)
|
232
|
+
post_body = {
|
233
|
+
:component_module_id => component_module_id,
|
234
|
+
:detail_to_include => ["remotes"],
|
235
|
+
:rsa_pub_key => SshProcessing.rsa_pub_key_content()
|
236
|
+
}
|
237
|
+
response = post rest_url("component_module/versions"), post_body
|
238
|
+
|
239
|
+
response.render_table(:module_version)
|
240
|
+
end
|
241
|
+
=end
|
242
|
+
|
243
|
+
desc "COMPONENT-MODULE-NAME/ID list-components", "List all components for given component module."
|
244
|
+
def list_components(context_params)
|
245
|
+
module_info_about(context_params, :components, :component)
|
246
|
+
end
|
247
|
+
|
248
|
+
desc "COMPONENT-MODULE-NAME/ID list-attributes", "List all attributes for given component module."
|
249
|
+
def list_attributes(context_params)
|
250
|
+
module_info_about(context_params, :attributes, :attribute_without_link)
|
251
|
+
end
|
252
|
+
|
253
|
+
desc "COMPONENT-MODULE-NAME/ID list-instances", "List all instances for given component module."
|
254
|
+
def list_instances(context_params)
|
255
|
+
module_info_about(context_params, :instances, :component)
|
256
|
+
end
|
257
|
+
|
258
|
+
#### end: list and info commands ###
|
259
|
+
|
260
|
+
#### commands to interact with remote repo ###
|
261
|
+
|
262
|
+
|
263
|
+
desc "import COMPONENT-MODULE-NAME", "Create new component module from local clone"
|
264
|
+
def import(context_params)
|
265
|
+
git_import = context_params.get_forwarded_options()[:git_import] if context_params.get_forwarded_options()
|
266
|
+
name_option = git_import ? :option_2! : :option_1!
|
267
|
+
module_name = context_params.retrieve_arguments([name_option],method_argument_names)
|
268
|
+
|
269
|
+
# first check that there is a directory there and it is not already a git repo, and it ha appropriate content
|
270
|
+
response = Helper(:git_repo).check_local_dir_exists_with_content(:component_module,module_name)
|
271
|
+
return response unless response.ok?
|
272
|
+
module_directory = response.data(:module_directory)
|
273
|
+
|
274
|
+
#check for yaml/json parsing errors before import
|
275
|
+
reparse_aux(module_directory)
|
276
|
+
|
277
|
+
# first make call to server to create an empty repo
|
278
|
+
response = post rest_url("component_module/create"), { :module_name => module_name }
|
279
|
+
return response unless response.ok?
|
280
|
+
@@invalidate_map << :component_module
|
281
|
+
|
282
|
+
repo_url,repo_id,module_id,branch = response.data(:repo_url,:repo_id,:module_id,:workspace_branch)
|
283
|
+
response = Helper(:git_repo).initialize_client_clone_and_push(:component_module,module_name,branch,repo_url,module_directory)
|
284
|
+
|
285
|
+
return response unless response.ok?
|
286
|
+
repo_obj,commit_sha = response.data(:repo_obj,:commit_sha)
|
287
|
+
|
288
|
+
post_body = {
|
289
|
+
:repo_id => repo_id,
|
290
|
+
:component_module_id => module_id,
|
291
|
+
:commit_sha => commit_sha,
|
292
|
+
:scaffold_if_no_dsl => true
|
293
|
+
}
|
294
|
+
response = post(rest_url("component_module/update_from_initial_create"),post_body)
|
295
|
+
return response unless response.ok?
|
296
|
+
|
297
|
+
external_dependencies = response.data(:external_dependencies)
|
298
|
+
|
299
|
+
if error = response.data(:dsl_parsed_info)
|
300
|
+
dsl_parsed_message = ServiceImporter.error_message(module_name, error)
|
301
|
+
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
302
|
+
end
|
303
|
+
|
304
|
+
dsl_created_info = response.data(:dsl_created_info)
|
305
|
+
if dsl_created_info and !dsl_created_info.empty?
|
306
|
+
msg = "A #{dsl_created_info["path"]} file has been created for you, located at #{module_directory}"
|
307
|
+
response = Helper(:git_repo).add_file(repo_obj,dsl_created_info["path"],dsl_created_info["content"],msg)
|
308
|
+
else
|
309
|
+
response = Response::Ok.new("module_created" => module_name)
|
310
|
+
end
|
311
|
+
|
312
|
+
# we push clone changes anyway, user can change and push again
|
313
|
+
context_params.add_context_to_params(module_name, :"component-module", module_id)
|
314
|
+
response = push(context_params, true)
|
315
|
+
response[:module_id] = module_id if git_import
|
316
|
+
response.add_data_value!(:external_dependencies,external_dependencies) if external_dependencies
|
317
|
+
|
318
|
+
return response
|
319
|
+
end
|
320
|
+
|
321
|
+
=begin
|
322
|
+
# desc "COMPONENT-MODULE-NAME/ID validate-model [-v VERSION]", "Check the DSL model for errors"
|
323
|
+
# version_method_option
|
324
|
+
desc "COMPONENT-MODULE-NAME/ID validate-model", "Check the DSL model for errors"
|
325
|
+
def validate_model(context_params)
|
326
|
+
module_id, module_name = context_params.retrieve_arguments([:component_module_id!, :component_module_name],method_argument_names)
|
327
|
+
version = options["version"]
|
328
|
+
|
329
|
+
if module_name.to_s =~ /^[0-9]+$/
|
330
|
+
module_id = module_name
|
331
|
+
module_name = get_module_name(module_id)
|
332
|
+
end
|
333
|
+
|
334
|
+
modules_path = OsUtil.module_clone_location()
|
335
|
+
module_location = "#{modules_path}/#{module_name}#{version && "-#{version}"}"
|
336
|
+
|
337
|
+
raise DTK::Client::DtkValidationError, "Unable to parse module '#{module_name}#{version && "-#{version}"}' that doesn't exist on your local machine!" unless File.directory?(module_location)
|
338
|
+
|
339
|
+
reparse_aux(module_location)
|
340
|
+
end
|
341
|
+
=end
|
342
|
+
|
343
|
+
# TODO: put in back support for:desc "import REMOTE-MODULE[,...] [LIBRARY-NAME/ID]", "Import remote component module(s) into library"
|
344
|
+
# TODO: put in doc REMOTE-MODULE havs namespace and optionally version information; e.g. r8/hdp or r8/hdp/v1.1
|
345
|
+
# if multiple items and failire; stops on first failure
|
346
|
+
# desc "install [NAMESPACE/]REMOTE-COMPONENT-MODULE-NAME [-r DTK-REPO-MANAGER]","Install remote component module into local environment"
|
347
|
+
desc "install [NAMESPACE/]REMOTE-COMPONENT-MODULE-NAME","Install remote component module into local environment"
|
348
|
+
method_option "repo-manager",:aliases => "-r" ,
|
349
|
+
:type => :string,
|
350
|
+
:banner => "REPO-MANAGER",
|
351
|
+
:desc => "DTK Repo Manager from which to resolve requested module."
|
352
|
+
def install(context_params)
|
353
|
+
create_missing_clone_dirs()
|
354
|
+
check_direct_access(::DTK::Client::Configurator.check_direct_access)
|
355
|
+
remote_module_name, version = context_params.retrieve_arguments([:option_1!, :option_2],method_argument_names)
|
356
|
+
# in case of auto-import via service import, we skip cloning to speed up a process
|
357
|
+
skip_cloning = context_params.get_forwarded_options()['skip_cloning'] if context_params.get_forwarded_options()
|
358
|
+
do_not_raise = context_params.get_forwarded_options()[:do_not_raise] if context_params.get_forwarded_options()
|
359
|
+
ignore_component_error = context_params.get_forwarded_options()[:ignore_component_error] if context_params.get_forwarded_options()
|
360
|
+
additional_message = context_params.get_forwarded_options()[:additional_message] if context_params.get_forwarded_options()
|
361
|
+
|
362
|
+
remote_namespace, local_module_name = get_namespace_and_name(remote_module_name)
|
363
|
+
if clone_dir = Helper(:git_repo).local_clone_dir_exists?(:component_module,local_module_name,version)
|
364
|
+
message = "Component module's directory (#{clone_dir}) exists on client. To install this needs to be renamed or removed"
|
365
|
+
message += ". To ignore this conflict and use existing component module please use -i switch (install REMOTE-SERVICE-NAME -i)." if additional_message
|
366
|
+
|
367
|
+
raise DtkError, message unless ignore_component_error
|
368
|
+
end
|
369
|
+
post_body = {
|
370
|
+
:remote_module_name => remote_module_name,
|
371
|
+
:local_module_name => local_module_name,
|
372
|
+
:rsa_pub_key => SshProcessing.rsa_pub_key_content()
|
373
|
+
}
|
374
|
+
post_body.merge!(:do_not_raise => do_not_raise) if do_not_raise
|
375
|
+
post_body.merge!(:ignore_component_error => ignore_component_error) if ignore_component_error
|
376
|
+
post_body.merge!(:additional_message => additional_message) if additional_message
|
377
|
+
|
378
|
+
response = post rest_url("component_module/import"), post_body
|
379
|
+
return response unless response.ok?
|
380
|
+
|
381
|
+
return response if response.data(:does_not_exist)
|
382
|
+
module_name,repo_url,branch,version = response.data(:module_name,:repo_url,:workspace_branch,:version)
|
383
|
+
|
384
|
+
if error = response.data(:dsl_parsed_info)
|
385
|
+
dsl_parsed_message = ServiceImporter.error_message(module_name, error)
|
386
|
+
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
387
|
+
end
|
388
|
+
|
389
|
+
response = ""
|
390
|
+
unless skip_cloning
|
391
|
+
response = Helper(:git_repo).create_clone_with_branch(:component_module,module_name,repo_url,branch,version)
|
392
|
+
end
|
393
|
+
@@invalidate_map << :component_module
|
394
|
+
|
395
|
+
response
|
396
|
+
end
|
397
|
+
|
398
|
+
#
|
399
|
+
# Creates component module from input git repo, removing .git dir to rid of pointing to user github, and creates component module
|
400
|
+
#
|
401
|
+
desc "import-git GIT-SSH-REPO-URL COMPONENT-MODULE-NAME", "Create new local component module by importing from provided git repo URL"
|
402
|
+
def import_git(context_params)
|
403
|
+
git_repo_url, module_name = context_params.retrieve_arguments([:option_1!, :option_2!],method_argument_names)
|
404
|
+
|
405
|
+
# Create component module from user's input git repo
|
406
|
+
response = Helper(:git_repo).create_clone_with_branch(:component_module, module_name, git_repo_url)
|
407
|
+
|
408
|
+
# Raise error if git repository is invalid
|
409
|
+
# raise DtkError,"Git repository URL '#{git_repo_url}' is invalid." unless response.ok?
|
410
|
+
return response unless response.ok?
|
411
|
+
|
412
|
+
# Remove .git directory to rid of git pointing to user's github
|
413
|
+
FileUtils.rm_rf("#{response['data']['module_directory']}/.git")
|
414
|
+
|
415
|
+
context_params.forward_options({:git_import => true})
|
416
|
+
# Reuse module create method to create module from local component_module
|
417
|
+
create_response = import(context_params)
|
418
|
+
|
419
|
+
|
420
|
+
if create_response.ok?
|
421
|
+
if external_dependencies = create_response.data(:external_dependencies)
|
422
|
+
inconsistent = external_dependencies["inconsistent"]
|
423
|
+
possibly_missing = external_dependencies["possibly_missing"]
|
424
|
+
OsUtil.print("There are some inconsistent dependencies: #{inconsistent}", :red) unless inconsistent.empty?
|
425
|
+
OsUtil.print("There are some missing dependencies: #{possibly_missing}", :yellow) unless possibly_missing.empty?
|
426
|
+
end
|
427
|
+
else
|
428
|
+
# If server response is not ok, delete cloned module, invoke delete method
|
429
|
+
FileUtils.rm_rf("#{response['data']['module_directory']}")
|
430
|
+
delete(context_params,:force_delete => true, :no_error_msg => true)
|
431
|
+
return create_response
|
432
|
+
end
|
433
|
+
|
434
|
+
Response::Ok.new()
|
435
|
+
end
|
436
|
+
|
437
|
+
=begin
|
438
|
+
=> DUE TO DEPENDENCY TO PUPPET GEM WE OMMIT THIS <=
|
439
|
+
desc "import-puppet-forge PUPPET-FORGE-MODULE-NAME", "Imports puppet module from puppet forge via puppet gem"
|
440
|
+
def import_puppet_forge(context_params)
|
441
|
+
module_name = context_params.retrieve_arguments([:option_1!],method_argument_names)
|
442
|
+
# this call will throw exception if error occurs
|
443
|
+
module_dir_name = DtkPuppet.install_module(module_name)
|
444
|
+
|
445
|
+
# we change module name to be dir name
|
446
|
+
context_params.override_method_argument!(:option_1, module_dir_name)
|
447
|
+
|
448
|
+
# process will take some time adding friendly message
|
449
|
+
puts "Cloning to remote repo, please wait ..."
|
450
|
+
|
451
|
+
# rest of reponsabilty is given to import method
|
452
|
+
import(context_params)
|
453
|
+
end
|
454
|
+
=end
|
455
|
+
=begin
|
456
|
+
desc "COMPONENT-MODULE-NAME/ID import-version VERSION", "Import a specfic version from a linked component module"
|
457
|
+
def import_version(context_params)
|
458
|
+
component_module_id,version = context_params.retrieve_arguments([:component_module_id!,:option_1!],method_argument_names)
|
459
|
+
post_body = {
|
460
|
+
:component_module_id => component_module_id,
|
461
|
+
:version => version
|
462
|
+
}
|
463
|
+
response = post rest_url("component_module/import_version"), post_body
|
464
|
+
@@invalidate_map << :component_module
|
465
|
+
|
466
|
+
return response unless response.ok?
|
467
|
+
module_name,repo_url,branch,version = response.data(:module_name,:repo_url,:workspace_branch,:version)
|
468
|
+
|
469
|
+
if error = response.data(:dsl_parsed_info)
|
470
|
+
dsl_parsed_message = ServiceImporter.error_message(module_name, error)
|
471
|
+
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
472
|
+
end
|
473
|
+
|
474
|
+
#TODO: need to check if local clone directory exists
|
475
|
+
Helper(:git_repo).create_clone_with_branch(:component_module,module_name,repo_url,branch,version)
|
476
|
+
end
|
477
|
+
=end
|
478
|
+
|
479
|
+
desc "delete-from-catalog [NAMESPACE/]REMOTE-COMPONENT-MODULE-NAME [-y]", "Delete the component module from the DTK Network catalog"
|
480
|
+
method_option :force, :aliases => '-y', :type => :boolean, :default => false
|
481
|
+
def delete_from_catalog(context_params)
|
482
|
+
remote_module_name = context_params.retrieve_arguments([:option_1!],method_argument_names)
|
483
|
+
remote_namespace, remote_name = get_namespace_and_name(remote_module_name)
|
484
|
+
|
485
|
+
unless options.force?
|
486
|
+
# Ask user if really want to delete component module and all items contained in it, if not then return to dtk-shell without deleting
|
487
|
+
return unless Console.confirmation_prompt("Are you sure you want to delete remote component-module '#{remote_namespace.nil? ? '' : remote_namespace+'/'}#{remote_name}' and all items contained in it"+'?')
|
488
|
+
end
|
489
|
+
|
490
|
+
post_body = {
|
491
|
+
:remote_module_name => remote_name,
|
492
|
+
:remote_module_namespace => remote_namespace,
|
493
|
+
:rsa_pub_key => SshProcessing.rsa_pub_key_content()
|
494
|
+
}
|
495
|
+
post rest_url("component_module/delete_remote"), post_body
|
496
|
+
end
|
497
|
+
|
498
|
+
# renamed to 'publish' but didn't delete this in case we run into issues with 'publish'
|
499
|
+
# desc "COMPONENT-MODULE-NAME/ID create-on-dtkn [[NAMESPACE/]REMOTE-COMPONENT-MODULE-NAME]", "Export component module to remote repository."
|
500
|
+
# def create_on_dtkn(context_params)
|
501
|
+
# component_module_id, input_remote_name = context_params.retrieve_arguments([:component_module_id!, :option_1],method_argument_names)
|
502
|
+
|
503
|
+
# post_body = {
|
504
|
+
# :component_module_id => component_module_id,
|
505
|
+
# :remote_component_name => input_remote_name,
|
506
|
+
# :rsa_pub_key => SshProcessing.rsa_pub_key_content()
|
507
|
+
# }
|
508
|
+
|
509
|
+
# response = post rest_url("component_module/export"), post_body
|
510
|
+
|
511
|
+
# return response
|
512
|
+
# end
|
513
|
+
|
514
|
+
desc "COMPONENT-MODULE-NAME/ID publish [[NAMESPACE/]REMOTE-COMPONENT-MODULE-NAME]", "Publish component module to remote repository."
|
515
|
+
def publish(context_params)
|
516
|
+
component_module_id, input_remote_name = context_params.retrieve_arguments([:component_module_id!, :option_1],method_argument_names)
|
517
|
+
|
518
|
+
post_body = {
|
519
|
+
:component_module_id => component_module_id,
|
520
|
+
:remote_component_name => input_remote_name,
|
521
|
+
:rsa_pub_key => SshProcessing.rsa_pub_key_content()
|
522
|
+
}
|
523
|
+
|
524
|
+
response = post rest_url("component_module/export"), post_body
|
525
|
+
|
526
|
+
return response
|
527
|
+
end
|
528
|
+
|
529
|
+
# commented out for now -> changed to push but leaving commented out if run into some issues with push
|
530
|
+
# # desc "COMPONENT-MODULE-NAME/ID push-to-dtkn [-n NAMESPACE] [-v VERSION]", "Push local copy of component module to remote repository."
|
531
|
+
# # version_method_option
|
532
|
+
# desc "COMPONENT-MODULE-NAME/ID push-to-dtkn [-n NAMESPACE]", "Push local copy of component module to remote repository."
|
533
|
+
# method_option "namespace",:aliases => "-n",
|
534
|
+
# :type => :string,
|
535
|
+
# :banner => "NAMESPACE",
|
536
|
+
# :desc => "Remote namespace"
|
537
|
+
# def push_to_dtkn(context_params)
|
538
|
+
# component_module_id, component_module_name = context_params.retrieve_arguments([:component_module_id!, :component_module_name!],method_argument_names)
|
539
|
+
# version = options["version"]
|
540
|
+
|
541
|
+
# if component_module_name.to_s =~ /^[0-9]+$/
|
542
|
+
# component_module_id = component_module_name
|
543
|
+
# component_module_name = get_module_name(component_module_id)
|
544
|
+
# end
|
545
|
+
|
546
|
+
# modules_path = OsUtil.module_clone_location()
|
547
|
+
# module_location = "#{modules_path}/#{component_module_name}#{version && "-#{version}"}"
|
548
|
+
|
549
|
+
# unless File.directory?(module_location)
|
550
|
+
# if Console.confirmation_prompt("Unable to push to remote because module '#{component_module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
|
551
|
+
# response = clone_aux(:component_module,component_module_id,version,false)
|
552
|
+
|
553
|
+
# if(response.nil? || response.ok?)
|
554
|
+
# reparse_aux(module_location)
|
555
|
+
# push_to_remote_aux(:component_module, component_module_id, component_module_name, options["namespace"], version) if Console.confirmation_prompt("Would you like to push changes to remote"+'?')
|
556
|
+
# end
|
557
|
+
|
558
|
+
# return response
|
559
|
+
# else
|
560
|
+
# # user choose not to clone needed module
|
561
|
+
# return
|
562
|
+
# end
|
563
|
+
# end
|
564
|
+
|
565
|
+
# reparse_aux(module_location)
|
566
|
+
# push_to_remote_aux(:component_module, component_module_id, component_module_name, options["namespace"], version)
|
567
|
+
# end
|
568
|
+
|
569
|
+
# desc "COMPONENT-MODULE-NAME/ID pull-from-dtkn [-v VERSION]", "Update local component module from remote repository."
|
570
|
+
# version_method_option
|
571
|
+
# desc "COMPONENT-MODULE-NAME/ID pull-from-dtkn", "Update local component module from remote repository."
|
572
|
+
# def pull_from_dtkn(context_params)
|
573
|
+
# component_module_id, component_module_name = context_params.retrieve_arguments([:component_module_id!,:component_module_name],method_argument_names)
|
574
|
+
# version = options["version"]
|
575
|
+
|
576
|
+
# response = pull_from_remote_aux(:component_module,component_module_id,version)
|
577
|
+
# return response unless response.ok?
|
578
|
+
|
579
|
+
# if component_module_name.to_s =~ /^[0-9]+$/
|
580
|
+
# component_module_id = component_module_name
|
581
|
+
# component_module_name = get_module_name(component_module_id)
|
582
|
+
# end
|
583
|
+
|
584
|
+
# modules_path = OsUtil.module_clone_location()
|
585
|
+
# module_location = "#{modules_path}/#{component_module_name}#{version && "-#{version}"}"
|
586
|
+
|
587
|
+
# push_clone_changes_aux(:component_module,component_module_id,version,nil,true) if File.directory?(module_location)
|
588
|
+
# Response::Ok.new()
|
589
|
+
# end
|
590
|
+
|
591
|
+
desc "COMPONENT-MODULE-NAME/ID pull-dtkn", "Update local component module from remote repository."
|
592
|
+
def pull_dtkn(context_params)
|
593
|
+
# component_module_id, component_module_name, catalog = context_params.retrieve_arguments([:component_module_id!,:component_module_name,:option_1],method_argument_names)
|
594
|
+
component_module_id, component_module_name = context_params.retrieve_arguments([:component_module_id!,:component_module_name,:option_1],method_argument_names)
|
595
|
+
catalog = 'dtkn'
|
596
|
+
version = options["version"]
|
597
|
+
|
598
|
+
raise DtkValidationError, "You have to provide valid catalog to pull changes from! Valid catalogs: #{PullCatalogs}" unless catalog
|
599
|
+
|
600
|
+
if catalog.to_s.eql?("dtkn")
|
601
|
+
response = pull_from_remote_aux(:component_module,component_module_id,version)
|
602
|
+
return response unless response.ok?
|
603
|
+
|
604
|
+
if component_module_name.to_s =~ /^[0-9]+$/
|
605
|
+
component_module_id = component_module_name
|
606
|
+
component_module_name = get_module_name(component_module_id)
|
607
|
+
end
|
608
|
+
|
609
|
+
modules_path = OsUtil.module_clone_location()
|
610
|
+
module_location = "#{modules_path}/#{component_module_name}#{version && "-#{version}"}"
|
611
|
+
|
612
|
+
push_clone_changes_aux(:component_module,component_module_id,version,nil,true) if File.directory?(module_location)
|
613
|
+
Response::Ok.new()
|
614
|
+
#elsif catalog.to_s.eql?("origin")
|
615
|
+
#needs to be implemented
|
616
|
+
else
|
617
|
+
raise DtkValidationError, "You have to provide valid catalog to pull changes from! Valid catalogs: #{PullCatalogs}"
|
618
|
+
end
|
619
|
+
end
|
620
|
+
PullCatalogs = ["dtkn"]
|
621
|
+
|
622
|
+
#### end: commands to interact with remote repo ###
|
623
|
+
|
624
|
+
#### commands to manage workspace and versioning ###
|
625
|
+
=begin
|
626
|
+
desc "COMPONENT-MODULE-NAME/ID create-version VERSION", "Snapshot current state of component module as a new version"
|
627
|
+
def create_version(context_params)
|
628
|
+
component_module_id,version = context_params.retrieve_arguments([:component_module_id!,:option_1!],method_argument_names)
|
629
|
+
|
630
|
+
post_body = {
|
631
|
+
:component_module_id => component_module_id,
|
632
|
+
:rsa_pub_key => SshProcessing.rsa_pub_key_content()
|
633
|
+
}
|
634
|
+
response = post rest_url("component_module/versions"), post_body
|
635
|
+
return response unless response.ok?
|
636
|
+
versions = (response.data.first && response.data.first['versions'])||Array.new
|
637
|
+
if versions.include?(version)
|
638
|
+
return Response::Error::Usage.new("Version #{version} exists already")
|
639
|
+
end
|
640
|
+
|
641
|
+
component_module_name = get_module_name(component_module_id)
|
642
|
+
module_location = OsUtil.module_location(:component_module,component_module_name,version)
|
643
|
+
if File.directory?(module_location)
|
644
|
+
return Response::Error::Usage.new("Target component module directory for version #{version} (#{module_location}) exists already; it must be deleted and this comamnd retried")
|
645
|
+
end
|
646
|
+
|
647
|
+
post_body = {
|
648
|
+
:component_module_id => component_module_id,
|
649
|
+
:version => version
|
650
|
+
}
|
651
|
+
response = post rest_url("component_module/create_new_version"), post_body
|
652
|
+
return response unless response.ok?
|
653
|
+
|
654
|
+
internal_trigger = omit_output = true
|
655
|
+
clone_aux(:component_module,component_module_id,version,internal_trigger,omit_output)
|
656
|
+
end
|
657
|
+
=end
|
658
|
+
|
659
|
+
##
|
660
|
+
#
|
661
|
+
# internal_trigger: this flag means that other method (internal) has trigger this.
|
662
|
+
# This will change behaviour of method in such way that edit will not be
|
663
|
+
# triggered after it.
|
664
|
+
#
|
665
|
+
#desc "COMPONENT-MODULE-NAME/ID clone [-v VERSION] [-n]", "Locally clone component module and component files. Use -n to skip edit prompt"
|
666
|
+
# version_method_option
|
667
|
+
desc "COMPONENT-MODULE-NAME/ID clone [-n]", "Locally clone component module and component files. Use -n to skip edit prompt"
|
668
|
+
method_option :skip_edit, :aliases => '-n', :type => :boolean, :default => false
|
669
|
+
def clone(context_params, internal_trigger=false)
|
670
|
+
thor_options = context_params.get_forwarded_options() || options
|
671
|
+
component_module_id = context_params.retrieve_arguments([:component_module_id!],method_argument_names)
|
672
|
+
module_name = context_params.retrieve_arguments([:component_module_name],method_argument_names)
|
673
|
+
version = thor_options["version"]
|
674
|
+
internal_trigger = true if thor_options['skip_edit']
|
675
|
+
|
676
|
+
# if this is not name it will not work, we need module name
|
677
|
+
if module_name.to_s =~ /^[0-9]+$/
|
678
|
+
component_module_id = module_name
|
679
|
+
module_name = get_module_name(component_module_id)
|
680
|
+
end
|
681
|
+
|
682
|
+
modules_path = OsUtil.module_clone_location()
|
683
|
+
module_location = "#{modules_path}/#{module_name}#{version && "-#{version}"}"
|
684
|
+
|
685
|
+
raise DTK::Client::DtkValidationError, "Trying to clone a component module '#{module_name}#{version && "-#{version}"}' that exists already!" if File.directory?(module_location)
|
686
|
+
clone_aux(:component_module,component_module_id,version,internal_trigger,thor_options['omit_output'])
|
687
|
+
end
|
688
|
+
|
689
|
+
# desc "COMPONENT-MODULE-NAME/ID edit [-v VERSION]","Switch to unix editing for given component module."
|
690
|
+
# version_method_option
|
691
|
+
desc "COMPONENT-MODULE-NAME/ID edit","Switch to unix editing for given component module."
|
692
|
+
def edit(context_params)
|
693
|
+
component_module_id = context_params.retrieve_arguments([:component_module_id!],method_argument_names)
|
694
|
+
module_name = context_params.retrieve_arguments([:component_module_name],method_argument_names)
|
695
|
+
version = options.version||context_params.retrieve_arguments([:option_1],method_argument_names)
|
696
|
+
edit_dsl = context_params.get_forwarded_options()[:edit_dsl] if context_params.get_forwarded_options()
|
697
|
+
|
698
|
+
# if this is not name it will not work, we need module name
|
699
|
+
if module_name.to_s =~ /^[0-9]+$/
|
700
|
+
component_module_id = module_name
|
701
|
+
module_name = get_module_name(component_module_id)
|
702
|
+
end
|
703
|
+
|
704
|
+
#TODO: cleanup so dont need :base_file_name and get edit_file from server
|
705
|
+
opts = {}
|
706
|
+
base_file_name = "dtk.model"
|
707
|
+
opts.merge!(:edit_file => {:base_file_name => base_file_name}) if edit_dsl
|
708
|
+
edit_aux(:component_module,component_module_id,module_name,version,opts)
|
709
|
+
end
|
710
|
+
|
711
|
+
# desc "COMPONENT-MODULE-NAME/ID push [-v VERSION] [-m COMMIT-MSG]", "Push changes from local copy of component module to server"
|
712
|
+
desc "COMPONENT-MODULE-NAME/ID push [-m COMMIT-MSG]", "Push changes from local copy of component module to server"
|
713
|
+
version_method_option
|
714
|
+
method_option "message",:aliases => "-m" ,
|
715
|
+
:type => :string,
|
716
|
+
:banner => "COMMIT-MSG",
|
717
|
+
:desc => "Commit message"
|
718
|
+
# hidden option for dev
|
719
|
+
method_option 'force-parse', :aliases => '-f', :type => :boolean, :default => false
|
720
|
+
def push(context_params, internal_trigger=false)
|
721
|
+
component_module_id, component_module_name = context_params.retrieve_arguments([:component_module_id!, :component_module_name],method_argument_names)
|
722
|
+
version = options["version"]
|
723
|
+
if component_module_name.to_s =~ /^[0-9]+$/
|
724
|
+
component_module_id = component_module_name
|
725
|
+
component_module_name = get_module_name(component_module_id)
|
726
|
+
end
|
727
|
+
|
728
|
+
modules_path = OsUtil.module_clone_location()
|
729
|
+
module_location = "#{modules_path}/#{component_module_name}#{version && "-#{version}"}"
|
730
|
+
|
731
|
+
reparse_aux(module_location)
|
732
|
+
push_clone_changes_aux(:component_module,component_module_id,version,options["message"]||DEFAULT_COMMIT_MSG,internal_trigger)
|
733
|
+
end
|
734
|
+
|
735
|
+
desc "COMPONENT-MODULE-NAME/ID push-dtkn [-n NAMESPACE] [-m COMMIT-MSG]", "Push changes from local copy of component module to remote repository (dtkn)."
|
736
|
+
method_option "message",:aliases => "-m" ,
|
737
|
+
:type => :string,
|
738
|
+
:banner => "COMMIT-MSG",
|
739
|
+
:desc => "Commit message"
|
740
|
+
method_option "namespace",:aliases => "-n",
|
741
|
+
:type => :string,
|
742
|
+
:banner => "NAMESPACE",
|
743
|
+
:desc => "Remote namespace"
|
744
|
+
#hidden option for dev
|
745
|
+
method_option 'force-parse', :aliases => '-f', :type => :boolean, :default => false
|
746
|
+
def push_dtkn(context_params, internal_trigger=false)
|
747
|
+
# component_module_id, component_module_name, catalog = context_params.retrieve_arguments([:component_module_id!, :component_module_name, :option_1],method_argument_names)
|
748
|
+
component_module_id, component_module_name = context_params.retrieve_arguments([:component_module_id!, :component_module_name],method_argument_names)
|
749
|
+
catalog = 'dtkn'
|
750
|
+
version = options["version"]
|
751
|
+
|
752
|
+
raise DtkValidationError, "You have to provide valid catalog to push changes to! Valid catalogs: #{PushCatalogs}" unless catalog
|
753
|
+
|
754
|
+
if component_module_name.to_s =~ /^[0-9]+$/
|
755
|
+
component_module_id = component_module_name
|
756
|
+
component_module_name = get_module_name(component_module_id)
|
757
|
+
end
|
758
|
+
|
759
|
+
modules_path = OsUtil.module_clone_location()
|
760
|
+
module_location = "#{modules_path}/#{component_module_name}#{version && "-#{version}"}"
|
761
|
+
reparse_aux(module_location)
|
762
|
+
|
763
|
+
# if catalog.to_s.eql?("origin")
|
764
|
+
# push_clone_changes_aux(:component_module,component_module_id,version,options["message"]||DEFAULT_COMMIT_MSG,internal_trigger)
|
765
|
+
if catalog.to_s.eql?("dtkn")
|
766
|
+
unless File.directory?(module_location)
|
767
|
+
if Console.confirmation_prompt("Unable to push to remote because module '#{component_module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
|
768
|
+
response = clone_aux(:component_module,component_module_id,version,false)
|
769
|
+
|
770
|
+
if(response.nil? || response.ok?)
|
771
|
+
reparse_aux(module_location)
|
772
|
+
push_to_remote_aux(:component_module, component_module_id, component_module_name, options["namespace"], version) if Console.confirmation_prompt("Would you like to push changes to remote"+'?')
|
773
|
+
end
|
774
|
+
|
775
|
+
return response
|
776
|
+
else
|
777
|
+
# user choose not to clone needed module
|
778
|
+
return
|
779
|
+
end
|
780
|
+
end
|
781
|
+
|
782
|
+
push_to_remote_aux(:component_module, component_module_id, component_module_name, options["namespace"], version)
|
783
|
+
else
|
784
|
+
raise DtkValidationError, "You have to provide valid catalog to push changes to! Valid catalogs: #{PushCatalogs}"
|
785
|
+
end
|
786
|
+
end
|
787
|
+
PushCatalogs = ["origin", "dtkn"]
|
788
|
+
|
789
|
+
|
790
|
+
# desc "COMPONENT-MODULE-NAME/ID list-diffs [-v VERSION] [--remote]", "List diffs"
|
791
|
+
# version_method_option
|
792
|
+
desc "COMPONENT-MODULE-NAME/ID list-diffs [--remote]", "List diffs"
|
793
|
+
method_option :remote, :type => :boolean, :default => false
|
794
|
+
def list_diffs(context_params)
|
795
|
+
component_module_id = context_params.retrieve_arguments([:component_module_id!],method_argument_names)
|
796
|
+
module_name = context_params.retrieve_arguments([:component_module_name],method_argument_names)
|
797
|
+
version = options["version"]
|
798
|
+
|
799
|
+
# if this is not name it will not work, we need module name
|
800
|
+
if module_name.to_s =~ /^[0-9]+$/
|
801
|
+
component_module_id = module_name
|
802
|
+
module_name = get_module_name(component_module_id)
|
803
|
+
end
|
804
|
+
|
805
|
+
modules_path = OsUtil.module_clone_location()
|
806
|
+
module_location = "#{modules_path}/#{module_name}#{version && "-#{version}"}"
|
807
|
+
|
808
|
+
# check if there is repository cloned
|
809
|
+
if File.directory?(module_location)
|
810
|
+
list_diffs_aux(:component_module, component_module_id, options.remote?, version)
|
811
|
+
else
|
812
|
+
if Console.confirmation_prompt("Component module '#{module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone component module now"+'?')
|
813
|
+
response = clone_aux(:component_module,component_module_id,version,true)
|
814
|
+
# if error return
|
815
|
+
unless response.ok?
|
816
|
+
return response
|
817
|
+
end
|
818
|
+
else
|
819
|
+
# user choose not to clone needed module
|
820
|
+
return
|
821
|
+
end
|
822
|
+
end
|
823
|
+
|
824
|
+
end
|
825
|
+
|
826
|
+
#### end: commands related to cloning to and pushing from local clone
|
827
|
+
end
|
828
|
+
end
|
829
|
+
|