dtk-client 0.11.7 → 0.11.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/dtk-client.gemspec +2 -2
  4. data/lib/cli/command/account/add_to_group.rb +33 -0
  5. data/lib/cli/command/account/chmod.rb +33 -0
  6. data/lib/cli/command/account/create_namespace.rb +32 -0
  7. data/lib/cli/command/account/delete_namespace.rb +32 -0
  8. data/lib/cli/command/account/list_namespaces.rb +30 -0
  9. data/lib/cli/command/account/remove_from_group.rb +33 -0
  10. data/lib/cli/command/account.rb +14 -1
  11. data/lib/cli/command/module/delete_from_remote.rb +5 -3
  12. data/lib/cli/command/module/install.rb +242 -102
  13. data/lib/cli/command/module/list_remotes.rb +1 -1
  14. data/lib/cli/command/module/publish.rb +3 -2
  15. data/lib/cli/command/module/pull_dtkn.rb +2 -2
  16. data/lib/cli/command/module/push.rb +2 -1
  17. data/lib/cli/command/module/push_dtkn.rb +3 -2
  18. data/lib/cli/command/module/unpublish.rb +42 -0
  19. data/lib/cli/command/module/update.rb +33 -0
  20. data/lib/cli/command/module.rb +3 -1
  21. data/lib/cli/command/token.rb +9 -3
  22. data/lib/cli/context.rb +7 -5
  23. data/lib/cli/directory_parser/file_system.rb +76 -36
  24. data/lib/cli/processor/plugin/gli.rb +2 -0
  25. data/lib/cli/version.rb +1 -1
  26. data/lib/client/error/subclasses.rb +12 -0
  27. data/lib/client/git_repo/adapter/git_gem.rb +3 -1
  28. data/lib/client/operation/account/add_to_group.rb +29 -0
  29. data/lib/client/operation/account/chmod.rb +29 -0
  30. data/lib/client/operation/account/create_namespace.rb +29 -0
  31. data/lib/client/operation/account/delete_namespace.rb +29 -0
  32. data/lib/client/operation/account/list_namespaces.rb +29 -0
  33. data/lib/client/operation/account/remove_from_group.rb +29 -0
  34. data/lib/client/operation/account.rb +14 -1
  35. data/lib/client/operation/client_module_dir/git_repo/internal.rb +4 -22
  36. data/lib/client/operation/client_module_dir/git_repo.rb +5 -6
  37. data/lib/client/operation/client_module_dir/service_instance/internal/module_info.rb +67 -0
  38. data/lib/client/operation/client_module_dir/service_instance/internal.rb +106 -0
  39. data/lib/client/operation/client_module_dir/service_instance.rb +30 -0
  40. data/lib/client/operation/client_module_dir.rb +5 -0
  41. data/lib/client/operation/module/clone_module.rb +2 -2
  42. data/lib/client/operation/module/delete_from_remote.rb +7 -31
  43. data/lib/client/operation/module/install/dependent_modules/component_module.rb +1 -2
  44. data/lib/client/operation/module/install/dependent_modules/local_dependencies.rb +1 -1
  45. data/lib/client/operation/module/install/print_helper.rb +1 -1
  46. data/lib/client/operation/module/install.rb +25 -19
  47. data/lib/client/operation/module/install_from_catalog.rb +15 -29
  48. data/lib/client/operation/module/list_remotes.rb +4 -11
  49. data/lib/client/operation/module/publish.rb +17 -31
  50. data/lib/client/operation/module/pull_dtkn.rb +37 -28
  51. data/lib/client/operation/module/push.rb +69 -5
  52. data/lib/client/operation/module/push_dtkn.rb +25 -13
  53. data/lib/client/operation/module/stage.rb +3 -3
  54. data/lib/client/operation/module/unpublish.rb +60 -0
  55. data/lib/client/operation/module/update.rb +59 -0
  56. data/lib/client/operation/module.rb +23 -9
  57. data/lib/client/operation/service/clone_service.rb +3 -0
  58. data/lib/client/operation.rb +7 -0
  59. metadata +38 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41bddc4ef8eb1c096ffee27ace98b4c5e1d17f4e
4
- data.tar.gz: ac98dfb1857f1b916ed182072bff7278d7669901
3
+ metadata.gz: ce23832ed682975a0727ee818e047fd5cfd5d381
4
+ data.tar.gz: b9c6efe83f37a372cd2528f2adc3b7eecc2b5617
5
5
  SHA512:
6
- metadata.gz: 3b379952dd59a5bb7d87ed06e5be921b23d7e0ae2e706eb5c559d4ea440ab425739524d025a49f55b83279886d2ac695829afe57aae2db169cb34cf7074d6caa
7
- data.tar.gz: a0ce708ca651d169175fabf00be1d4de5a1d31b81aeed5b45f4309797fff3852b47f09420eebe94f9b1749ae40a62d188b07446d0162ffe6c149dbace15cb03b
6
+ metadata.gz: 82e0ddd1c3f426bb9f6220754eb82ea4923b6c71be157117b3f7b5c8aa4932dfa70130f8a73cfba955d67e61e2c7dd1a979947980edf383593b8cdccb48f88b2
7
+ data.tar.gz: c222153161e27520a0da7e28926c83c6ba3a37d51774944efcbcd734b3aedada908954b8940db8e5018c43b0abd12e9b23032b6d115ae4f830c98c3b9a359454
data/.gitignore CHANGED
@@ -4,9 +4,9 @@ sftp-config*.json
4
4
  .remote-sync.json.bak
5
5
  .tags
6
6
  .tags1
7
- Gemfile.lock
8
7
  .vscode
9
8
  doc
10
9
  .yardoc
11
10
  .solargraph.yml
12
- dtk-dsl
11
+ Gemfile.lock
12
+ sftp.json
data/dtk-client.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
 
20
- spec.add_dependency 'dtk-common-core','0.11.0'
20
+ spec.add_dependency 'dtk-common-core','0.11.1'
21
21
  spec.add_dependency 'gli', '2.13.4'
22
22
  spec.add_dependency 'highline', '1.7.8'
23
23
  spec.add_dependency 'colorize', '0.7.7'
@@ -25,5 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency 'hirb', '0.7.3'
26
26
  spec.add_dependency 'mime-types', '~> 2.99.3'
27
27
  spec.add_dependency 'dtk-dsl', '~> 1.1.0'
28
-
28
+ spec.add_dependency 'dtk-network-client', '~> 1.0.0'
29
29
  end
@@ -0,0 +1,33 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ module CLI::Command
20
+ module Account
21
+ subcommand_def 'add-to-group' do |c|
22
+ c.arg Token::Arg.group
23
+ c.arg Token::Arg.user
24
+ command_body c, 'add-to-group', 'Add user to specific group' do |sc|
25
+ sc.action do |_global_options, options, args|
26
+ Operation::Account.add_to_group(:group => args[0], :user => args[1])
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ module CLI::Command
20
+ module Account
21
+ subcommand_def 'chmod' do |c|
22
+ c.arg Token::Arg.namespace
23
+ c.arg Token::Arg.permissions
24
+ command_body c, 'chmod', 'Change permissions for specific namespace e.g. ug+rw , user and group get RW permissions' do |sc|
25
+ sc.action do |_global_options, options, args|
26
+ Operation::Account.chmod(:namespace => args[0], :permissions => args[1])
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ module CLI::Command
20
+ module Account
21
+ subcommand_def 'create-namespace' do |c|
22
+ c.arg Token::Arg.namespace
23
+ command_body c, 'create-namespace', 'Create new namespace on dtk network' do |sc|
24
+ sc.action do |_global_options, options, args|
25
+ Operation::Account.create_namespace(:namespace => args[0])
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ module CLI::Command
20
+ module Account
21
+ subcommand_def 'delete-namespace' do |c|
22
+ c.arg Token::Arg.namespace
23
+ command_body c, 'delete-namespace', 'Delete namespace from dtk network' do |sc|
24
+ sc.action do |_global_options, options, args|
25
+ Operation::Account.delete_namespace(:namespace => args[0])
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ module CLI::Command
20
+ module Account
21
+ subcommand_def 'list-namespaces' do |c|
22
+ command_body c, 'list-namespaces', 'List namespaces' do |sc|
23
+ sc.action do |_global_options, options, args|
24
+ Operation::Account.list_namespaces
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ module CLI::Command
20
+ module Account
21
+ subcommand_def 'remove-from-group' do |c|
22
+ c.arg Token::Arg.group
23
+ c.arg Token::Arg.user
24
+ command_body c, 'remove-from-group', 'Remove user from specific group' do |sc|
25
+ sc.action do |_global_options, options, args|
26
+ Operation::Account.remove_from_group(:group => args[0], :user => args[1])
27
+ end
28
+ end
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -21,7 +21,20 @@ module DTK::Client
21
21
  module Account
22
22
  include Command::Mixin
23
23
 
24
- ALL_SUBCOMMANDS = ['list-ssh-keys', 'delete-ssh-key', 'add-ssh-key', 'set-password', 'set-catalog-credentials', 'register-catalog-user']
24
+ ALL_SUBCOMMANDS = [
25
+ 'list-ssh-keys',
26
+ 'delete-ssh-key',
27
+ 'add-ssh-key',
28
+ 'set-password',
29
+ 'set-catalog-credentials',
30
+ 'register-catalog-user',
31
+ 'add-to-group',
32
+ 'remove-from-group',
33
+ 'create-namespace',
34
+ 'chmod',
35
+ 'delete-namespace',
36
+ 'list-namespaces'
37
+ ]
25
38
  command_def :desc => 'Subcommands for interacting with current Account'
26
39
  ALL_SUBCOMMANDS.each { |subcommand| require_relative("account/#{subcommand.gsub(/-/,'_')}") }
27
40
  end
@@ -21,12 +21,14 @@ module DTK::Client
21
21
  subcommand_def 'delete-from-remote' do |c|
22
22
  c.arg Token::Arg.module_name
23
23
  command_body c, 'delete-from-dtkn', 'Delete module from the DTK remote catalog (DTKN)' do |sc|
24
- sc.flag Token.version
24
+ # sc.flag Token.version
25
+ raise Error::Usage, "Version option is not supported for this command" if ARGV.include?('delete-from-dtkn') && ARGV.include?('-v')
26
+
25
27
  sc.switch Token.skip_prompt
26
28
  sc.switch Token.force, :desc => 'Force delete'
27
-
29
+
28
30
  sc.action do |_global_options, options, args|
29
- module_ref = module_ref_object_from_options_or_context?(:module_ref => args[0], :version => options[:version])
31
+ module_ref = module_ref_object_from_options_or_context?(:module_ref => args[0])
30
32
  operation_args = {
31
33
  :module_ref => module_ref,
32
34
  :skip_prompt => options[:skip_prompt],
@@ -26,134 +26,274 @@ module DTK::Client
26
26
  # Add '-d' flag if development mode is active
27
27
  if Config[:development_mode]
28
28
  sc.flag Token.directory_path, :desc => 'Absolute or relative path to directory containing content to install'
29
+ sc.switch Token.skip_server
29
30
  end
30
31
  sc.switch Token.update_deps
31
-
32
+ sc.switch Token.update_lock
33
+
32
34
  sc.action do |_global_options, options, args|
33
- directory_path = args[1] || options[:directory_path]
34
- version = options[:version]
35
- update_deps = options[:update_deps]
36
- has_remote_repo = false
37
- is_clone = false
38
-
39
- if module_name = args[0]
40
- # reached if installing from dtkn
41
- # installs content from dtkn (later probably from other remote catalogs) onto client machine
42
- # in so doing installes depedent modules onto teh dtk server; this step though does not install main module onto
43
- # server (the later step Operation::Module.install does this)
44
- has_remote_repo = true
45
- module_ref = module_ref_object_from_options_or_context?(:module_ref => module_name, :version => version)
46
- remote_module_info = nil
47
-
48
- unless version
49
- if remote_module_info = get_remote_module_info(module_ref)
50
- version = remote_module_info.required(:version)
51
- module_ref.version = version
52
- end
53
- end
35
+ module_name = args[0]
36
+ directory_path = args[1] || options[:directory_path]
37
+ has_directory_param = !options['d'].nil?
38
+
39
+ opts_hash = {
40
+ module_name: module_name,
41
+ directory_path: directory_path,
42
+ version: options[:version],
43
+ update_deps: options[:update_deps],
44
+ has_directory_param: has_directory_param,
45
+ update_lock_file: options['update-lock']
46
+ }
47
+ Install.execute(self, opts_hash)
48
+ nil
49
+ end
50
+ end
54
51
 
55
- if Operation::Module.module_version_exists?(module_ref, :type => :common_module)
56
- clone_module(module_ref, directory_path, version)
57
- is_clone = true
52
+ # TODO: 3070: in sprint 7 should move a lot of this logic into the install operation directoty and use commands/moduel/install just to get params
53
+ class Install
54
+ def initialize(context, opts = {})
55
+ @context = context
56
+ @module_name = opts[:module_name]
57
+ @explicit_version = opts[:version]
58
+ @update_deps = opts[:update_deps]
59
+ @directory_path = opts[:directory_path]
60
+ @has_directory_param = opts[:has_directory_param]
61
+ @update_lock_file = opts[:update_lock_file]
62
+ end
63
+
64
+ def self.execute(context, opts = {})
65
+ new(context, opts).execute
66
+ end
67
+
68
+ def execute
69
+ if @module_name
70
+ if Operation::Module.module_version_exists?(self.module_ref)
71
+ clone_module
58
72
  else
59
- target_repo_dir = Operation::Module.install_from_catalog(:module_ref => module_ref, :version => version, :directory_path => directory_path, :remote_module_info => remote_module_info)
73
+ install_from_catalog
60
74
  end
75
+ else
76
+ install_from_directory
77
+ end
78
+ end
79
+
80
+ protected
81
+
82
+ attr_reader :context
83
+
84
+ def module_ref
85
+ @module_ref ||= ret_module_ref
86
+ end
87
+
88
+ def version
89
+ @version ||= self.module_ref.version
90
+ end
91
+
92
+ def base_dsl_file_obj
93
+ @base_dsl_file_obj ||= self.context.base_dsl_file_obj
94
+ end
95
+
96
+ OPTIONAL_vars = [:module_name, :explicit_version, :update_deps, :directory_path, :has_directory_param]
97
+ OPTIONAL_vars.each { |var| class_eval("def #{var}?; @#{var}; end") }
98
+
99
+ private
100
+
101
+ def install_from_catalog
102
+ # installs content from dtkn (later probably from other remote catalogs) onto client machine
103
+ # in so doing installes dependent modules onto teh dtk server; this step though does not install main module onto
104
+ # server (the later step Operation::Module.install does this)
105
+
106
+ # TODO: 3070: handle sitution where response is not ok
107
+ install_response = Operation::Module.install_from_catalog(module_ref: self.module_ref, version: self.version, directory_path: self.directory_path?)
108
+
109
+ if client_installed_modules = (install_response && install_response.data[:installed_modules])
110
+ opts_server_install = {
111
+ has_directory_param: self.has_directory_param?,
112
+ has_remote_repo: true,
113
+ update_deps: self.update_deps?,
114
+ install_from: :remote
115
+ }
116
+ install_on_server(client_installed_modules, opts_server_install)
61
117
  end
118
+ end
119
+
120
+ def install_from_directory
121
+ operation_args = {
122
+ :module_ref => self.module_ref,
123
+ :base_dsl_file_obj => self.base_dsl_file_obj,
124
+ :has_directory_param => self.has_directory_param?,
125
+ :has_remote_repo => false,
126
+ :update_deps => self.update_deps?
127
+ }
128
+ get_and_install_dependencies
129
+ Operation::Module.install(operation_args)
130
+ end
62
131
 
63
- unless is_clone
64
- raise Error::Usage, "You can use version only with 'namespace/name' provided" if version && module_name.nil?
132
+ def get_and_install_dependencies
133
+ file_obj = nil
134
+ if self.has_directory_param?
135
+ file_obj = self.base_dsl_file_obj.raise_error_if_no_content_flag(:module_ref)
136
+ else
137
+ file_obj = self.base_dsl_file_obj.raise_error_if_no_content
138
+ end
65
139
 
66
- if target_repo_dir
67
- directory_path ||= target_repo_dir.data[:target_repo_dir]
140
+ module_info = {
141
+ name: self.module_ref.module_name,
142
+ namespace: self.module_ref.namespace,
143
+ version: self.module_ref.version,
144
+ repo_dir: file_obj.parent_dir
145
+ }
146
+ parsed_module = file_obj.parse_content(:common_module_summary)
147
+ dependency_tree = Operation::DtkNetworkDependencyTree.get_or_create(module_info, { format: :hash, parsed_module: parsed_module, save_to_file: true, update_lock_file: @update_lock_file })
148
+
149
+ dependency_tree.each do |dependency|
150
+ dep_module_ref = module_ref_object_from_options_or_context(module_ref: "#{dependency[:namespace]}/#{dependency[:name]}", version: dependency[:version])
151
+ if Operation::Module.module_version_exists?(dep_module_ref)
152
+ p_helper = Operation::Module::Install::PrintHelper.new(:module_ref => dep_module_ref, :source => :local)
153
+ p_helper.print_using_installed_dependent_module
154
+ else
155
+ client_installed_modules = nil
156
+
157
+ if dependency[:source]
158
+ client_installed_modules = [dependency]
159
+ else
160
+ install_response = Operation::Module.install_from_catalog(module_ref: dep_module_ref, version: dep_module_ref.version, type: :dependency)
161
+ client_installed_modules = (install_response && install_response.data[:installed_modules])
162
+ end
163
+
164
+ if client_installed_modules# = (install_response && install_response.data[:installed_modules])
165
+ install_from = dependency[:source] ? :local : :remote
166
+ opts_server_install = {
167
+ has_directory_param: false,
168
+ has_remote_repo: true,
169
+ update_deps: self.update_deps?,
170
+ install_from: install_from
171
+ }
172
+ install_on_server(client_installed_modules, opts_server_install)
173
+ end
68
174
  end
175
+ end
176
+ end
177
+
178
+ # opts can have keys:
179
+ # :has_directory_param,
180
+ # :has_remote_repo
181
+ # :update_dep
182
+ def install_on_server(client_installed_modules, opts = {})
183
+ client_installed_modules.each do |installed_module|
184
+ directory_path = installed_module[:location] || installed_module[:source]
185
+ module_ref = module_ref_object_from_options_or_context(directory_path: directory_path, version: installed_module[:version])
186
+ use_or_install_on_server(module_ref, directory_path, opts)
187
+ end
188
+ end
69
189
 
70
- install_opts = directory_path ? { :directory_path => directory_path, :version => (version || 'master') } : options
71
- module_ref = module_ref_object_from_options_or_context?(install_opts)
190
+ def use_or_install_on_server(module_ref, directory_path, opts = {})
191
+ if Operation::Module.module_version_exists?(module_ref)
192
+ p_helper = Operation::Module::Install::PrintHelper.new(:module_ref => module_ref, :source => :local)
193
+ p_helper.print_using_installed_dependent_module
194
+ else
195
+ base_dsl_file_obj = CLI::Context.base_dsl_file_obj(dir_path: directory_path)
72
196
  operation_args = {
73
197
  :module_ref => module_ref,
74
- :base_dsl_file_obj => @base_dsl_file_obj,
75
- :has_directory_param => !options["d"].nil?,
76
- :has_remote_repo => has_remote_repo,
77
- :update_deps => update_deps
198
+ :base_dsl_file_obj => base_dsl_file_obj,
199
+ :has_directory_param => opts[:has_directory_param],
200
+ :has_remote_repo => opts[:has_remote_repo],
201
+ :update_deps => opts[:update_dep],
202
+ :install_from => opts[:install_from]
78
203
  }
79
204
  Operation::Module.install(operation_args)
80
205
  end
81
206
  end
82
- end
83
- end
84
207
 
85
- def clone_module(module_ref, directory_path, version)
86
- arg = {
87
- :module_ref => module_ref,
88
- :target_directory => Operation::ClientModuleDir.create_module_dir_from_path(directory_path || OsUtil.current_dir)
89
- }
208
+ def clone_module
209
+ # clone module into current directory + module name; same as when installing base module from dtk-network
210
+ target_directory_path = self.directory_path? || "#{OsUtil.current_dir}/#{self.module_ref.module_name}"
211
+ arg = {
212
+ :module_ref => self.module_ref,
213
+ :target_directory => Operation::ClientModuleDir.create_module_dir_from_path(target_directory_path)
214
+ }
215
+ repo_dir_info = Operation::Module.clone_module(arg).data
216
+ OsUtil.print_info("DTK module '#{self.module_ref.pretty_print}' has been successfully cloned from server into '#{repo_dir_info[:target_repo_dir]}'")
217
+ end
218
+
219
+ def should_install_from_catalog?
220
+ !!@module_name
221
+ end
90
222
 
91
- unless version
92
- if server_version = get_last_version_from_server(module_ref)
93
- version = server_version
94
- module_ref.version = version
223
+ def ret_module_ref
224
+ if should_install_from_catalog?
225
+ module_ref_version_unset = module_ref_object_from_options_or_context(module_ref: self.module_name?, version: @explicit_version)
226
+ fill_in_version_from_server_or_remote!(module_ref_version_unset) unless @explicit_version
227
+ module_ref_version_unset
228
+ else
229
+ module_ref_object_from_options_or_context(directory_path: self.directory_path?)
230
+ end
95
231
  end
96
- end
97
232
 
98
- repo_dir_info = Operation::Module.clone_module(arg).data
99
- repo_dir = repo_dir_info[:target_repo_dir]
100
-
101
- # DTK-3088 - need this to pull service info for dependency module on clone
102
- if repo_dir_info[:pull_service_info]# && (version.nil? || version.eql?('master'))
103
- repo_dir = repo_dir_info[:target_repo_dir]
104
- module_ref = module_ref_object_from_options_or_context(:directory_path => repo_dir)
105
-
106
- operation_args = {
107
- :module_ref => module_ref,
108
- :base_dsl_file_obj => @base_dsl_file_obj,
109
- :has_directory_param => true,
110
- :directory_path => repo_dir,
111
- :update_deps => false,
112
- :do_not_print => true,
113
- :force => true,
114
- :allow_version => true
115
- }
116
-
117
- Operation::Module.pull_dtkn(operation_args)
118
- Operation::Module.push(operation_args.merge(:method => "pulled"))
119
- end
233
+ # opts can have keys
234
+ # :module_ref
235
+ # :version
236
+ # :directory_path
237
+ def module_ref_object_from_options_or_context(opts = {})
238
+ self.context.module_ref_object_from_options_or_context(opts)
239
+ end
120
240
 
121
- OsUtil.print_info("DTK module '#{module_ref.pretty_print}' has been successfully cloned from server into '#{repo_dir}'")
122
- end
241
+ def fill_in_version_from_server_or_remote!(module_ref_version_unset)
242
+ module_ref = module_ref_version_unset
123
243
 
124
- private
125
-
126
- def get_remote_module_info(module_ref)
127
- query_string_hash = QueryStringHash.new(
128
- :module_name => module_ref.module_name,
129
- :namespace => module_ref.namespace,
130
- :rsa_pub_key => SSHUtil.rsa_pub_key_content,
131
- :version? => nil
132
- )
133
- begin
134
- Operation::Module.rest_get("#{Operation::Module::BaseRoute}/remote_module_info", query_string_hash)
135
- rescue Error::ServerNotOkResponse => e
136
- # do not raise if version not specified and module does not exist on repoman but exist on server; clone module from server instead
137
- return
138
- end
139
- end
244
+ module_info = {
245
+ name: module_ref.module_name,
246
+ namespace: module_ref.namespace,
247
+ }
140
248
 
141
- def get_last_version_from_server(module_ref)
142
- query_string_hash = QueryStringHash.new(
143
- :module_name => module_ref.module_name,
144
- :namespace => module_ref.namespace
145
- )
146
- response = Operation::Module.rest_get("#{Operation::Module::BaseRoute}/versions", query_string_hash)
147
- versions = response.required(:versions)
148
-
149
- if versions.size > 1
150
- versions.delete('master')
151
- versions.sort.last.strip
152
- else
153
- versions.first.strip
249
+ begin
250
+ versions = Operation::Module::DtkNetworkClient::Info.run(module_info, about: :versions)
251
+ rescue Exception => e
252
+ # if does not exist on repoman try getting version from server
253
+ versions = get_versions_from_server(module_ref)
254
+ end
255
+
256
+ if versions.empty?
257
+ raise Error::Usage, "Module '#{module_term(module_ref)}' does not exist."
258
+ elsif version = self.explicit_version?
259
+ if versions.include?(version)
260
+ module_ref.version = version
261
+ else
262
+ legal_versions = versions.join(', ')
263
+ raise Error::Usage, "Module '#{module_term(module_ref)}' does not have specified version '#{version}'; legal versions are: #{legal_versions}"
264
+ end
265
+ else
266
+ # use latest version
267
+ module_ref.version = find_latest_version(versions)
268
+ end
269
+ module_ref
270
+ end
271
+
272
+ def module_term(module_ref)
273
+ "#{module_ref.namespace}:#{module_ref.module_name}"
274
+ end
275
+
276
+ def find_latest_version(versions)
277
+ if versions.size > 1
278
+ versions.delete('master')
279
+ versions.sort.last
280
+ else
281
+ versions.first
282
+ end
283
+ end
284
+
285
+ def get_versions_from_server(module_ref)
286
+ query_string_hash = QueryStringHash.new(
287
+ :module_name => module_ref.module_name,
288
+ :namespace => module_ref.namespace
289
+ )
290
+ response = Operation::Module.rest_get("#{Operation::Module::BaseRoute}/versions", query_string_hash)
291
+ versions = response.data(:versions) || []
292
+
293
+ versions
294
+ end
154
295
  end
155
296
  end
156
297
  end
157
298
  end
158
299
  end
159
-