dtk-client 0.10.2 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.license_header +15 -0
  4. data/LICENSE +202 -0
  5. data/README.md +25 -2
  6. data/Rakefile +17 -1
  7. data/bin/dtk +18 -1
  8. data/lib/cli/command/account/add_ssh_key.rb +40 -0
  9. data/lib/cli/command/account/delete_ssh_key.rb +43 -0
  10. data/lib/cli/command/account/list_ssh_keys.rb +31 -0
  11. data/lib/cli/command/account/register_catalog_user.rb +31 -0
  12. data/lib/cli/command/account/set_catalog_credentials.rb +31 -0
  13. data/lib/cli/command/account/set_password.rb +31 -0
  14. data/lib/cli/command/account.rb +31 -0
  15. data/lib/cli/command/mixin.rb +1 -1
  16. data/lib/cli/command/module/delete_from_remote.rb +36 -0
  17. data/lib/cli/command/module/install.rb +15 -5
  18. data/lib/cli/command/module/publish.rb +34 -0
  19. data/lib/cli/command/module/pull_dtkn.rb +35 -0
  20. data/lib/cli/command/module/push_dtkn.rb +34 -0
  21. data/lib/cli/command/module/stage.rb +1 -1
  22. data/lib/cli/command/module/uninstall.rb +13 -7
  23. data/lib/cli/command/module.rb +14 -1
  24. data/lib/cli/command/options.rb +2 -0
  25. data/lib/cli/command/service/converge.rb +1 -1
  26. data/lib/cli/command/service/delete.rb +1 -1
  27. data/lib/cli/command/service/exec.rb +5 -2
  28. data/lib/cli/command/service/exec_sync.rb +4 -1
  29. data/lib/cli/command/service/{list_dependent_modules.rb → list_dependencies.rb} +3 -3
  30. data/lib/cli/command/service/uninstall.rb +11 -4
  31. data/lib/cli/command/service.rb +1 -1
  32. data/lib/cli/command/token.rb +3 -0
  33. data/lib/cli/command.rb +1 -1
  34. data/lib/cli/context/attributes.rb +1 -1
  35. data/lib/cli/context/type/account.rb +42 -0
  36. data/lib/cli/context/type/module.rb +2 -1
  37. data/lib/cli/context/type/service.rb +2 -1
  38. data/lib/cli/context.rb +82 -12
  39. data/lib/cli/version.rb +18 -2
  40. data/lib/client/git_repo/adapter/git_gem.rb +62 -4
  41. data/lib/client/git_repo.rb +33 -2
  42. data/lib/client/load_source/component_info.rb +44 -0
  43. data/lib/client/load_source/service_info.rb +47 -0
  44. data/lib/client/load_source.rb +148 -0
  45. data/lib/client/{util/module_ref.rb → module_ref.rb} +19 -0
  46. data/lib/client/operation/account/add_ssh_key.rb +47 -0
  47. data/lib/client/operation/account/delete_ssh_key.rb +41 -0
  48. data/lib/client/operation/account/list_ssh_keys.rb +28 -0
  49. data/lib/client/operation/account/register_catalog_user.rb +49 -0
  50. data/lib/client/operation/account/set_catalog_credentials.rb +32 -0
  51. data/lib/client/operation/account/set_password.rb +59 -0
  52. data/lib/client/operation/account.rb +7 -4
  53. data/lib/client/operation/client_module_dir/git_repo/internal/dtkn.rb +83 -0
  54. data/lib/client/operation/client_module_dir/git_repo/internal.rb +328 -0
  55. data/lib/client/operation/client_module_dir/git_repo.rb +73 -249
  56. data/lib/client/operation/client_module_dir.rb +2 -2
  57. data/lib/client/operation/module/clone_module.rb +41 -25
  58. data/lib/client/operation/module/delete_from_remote.rb +79 -0
  59. data/lib/client/operation/module/install/common_module.rb +10 -21
  60. data/lib/client/operation/module/install/dependent_modules/component_dependency_tree/cache.rb +47 -0
  61. data/lib/client/operation/module/install/dependent_modules/component_dependency_tree/resolve_modules.rb +69 -0
  62. data/lib/client/operation/module/install/dependent_modules/component_dependency_tree.rb +143 -0
  63. data/lib/client/operation/module/install/dependent_modules/component_module.rb +103 -0
  64. data/lib/client/operation/module/install/dependent_modules/prompt_helper.rb +54 -0
  65. data/lib/client/operation/module/install/dependent_modules.rb +65 -0
  66. data/lib/client/operation/module/install/mixin.rb +42 -0
  67. data/lib/client/operation/module/install/module_ref.rb +48 -0
  68. data/lib/client/operation/module/install/print_helper.rb +129 -0
  69. data/lib/client/operation/module/install.rb +68 -25
  70. data/lib/client/operation/module/install_from_catalog.rb +23 -32
  71. data/lib/client/operation/module/list.rb +4 -1
  72. data/lib/client/operation/module/publish.rb +78 -0
  73. data/lib/client/operation/module/pull_dtkn.rb +76 -0
  74. data/lib/client/operation/module/push.rb +16 -2
  75. data/lib/client/operation/module/push_dtkn/convert_source/component_info.rb +42 -0
  76. data/lib/client/operation/module/push_dtkn/convert_source/service_info.rb +47 -0
  77. data/lib/client/operation/module/push_dtkn/convert_source.rb +155 -0
  78. data/lib/client/operation/module/push_dtkn.rb +79 -0
  79. data/lib/client/operation/module/stage.rb +3 -2
  80. data/lib/client/operation/module/uninstall.rb +36 -0
  81. data/lib/client/operation/module.rb +23 -4
  82. data/lib/client/operation/service/converge.rb +3 -2
  83. data/lib/client/operation/service/delete.rb +2 -1
  84. data/lib/client/operation/service/destroy.rb +1 -1
  85. data/lib/client/operation/service/exec.rb +4 -0
  86. data/lib/client/operation/service/{list_dependent_modules.rb → list_dependencies.rb} +1 -1
  87. data/lib/client/operation/service/stage.rb +1 -1
  88. data/lib/client/operation/service/uninstall.rb +3 -3
  89. data/lib/client/operation/service.rb +1 -1
  90. data/lib/client/service_and_component_info/transform_from/info/component.rb +57 -0
  91. data/lib/client/service_and_component_info/transform_from/info/service.rb +53 -0
  92. data/lib/client/service_and_component_info/transform_from/info.rb +84 -0
  93. data/lib/client/service_and_component_info/transform_from.rb +47 -0
  94. data/lib/client/service_and_component_info/transform_to/info/component.rb +53 -0
  95. data/lib/client/service_and_component_info/transform_to/info/service.rb +49 -0
  96. data/lib/client/service_and_component_info/transform_to/info.rb +111 -0
  97. data/lib/client/service_and_component_info/transform_to.rb +49 -0
  98. data/lib/client/service_and_component_info.rb +26 -0
  99. data/lib/client/util/console.rb +22 -0
  100. data/lib/client/util/interactive_wizard.rb +90 -0
  101. data/lib/client/util.rb +18 -2
  102. data/lib/dtk_client.rb +5 -2
  103. metadata +63 -15
  104. data/lib/client/content_generator.rb +0 -189
  105. data/lib/client/operation/module/install/external_module.rb +0 -205
@@ -1,189 +0,0 @@
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
- require 'yaml'
19
-
20
- module DTK::Client
21
- # Abstract class that holds classes and methods for xecuting commands by
22
- # make calls to server and performing client side operations
23
- class ContentGenerator
24
- def initialize(content_dir, module_ref, version)
25
- @content_dir = content_dir
26
- @module_ref = module_ref
27
- @version = version
28
- @directory_content = nil
29
- end
30
-
31
- def generate_module_content
32
- module_hash = {
33
- 'dsl_version' => '1.0.0',
34
- 'module' => "#{@module_ref.namespace}/#{@module_ref.module_name}",
35
- 'version' => @version || 'master'
36
- }
37
-
38
- if dependencies = ret_dependencies_hash
39
- module_hash.merge!('dependencies' => dependencies)
40
- end
41
-
42
- if assemblies = ret_assemblies_hash
43
- module_hash.merge!('assemblies' => assemblies)
44
- end
45
-
46
- module_hash
47
- end
48
-
49
- private
50
-
51
- def get_raw_content?(file_path)
52
- File.open(file_path).read if file_path and File.exists?(file_path)
53
- end
54
-
55
- def convert_file_content_to_hash(file_path)
56
- begin
57
- YAML.load(get_raw_content?(file_path))
58
- rescue Exception => e
59
- yaml_err_msg = e.message.gsub(/\(<unknown>\): /,'').capitalize
60
- raise Error::Usage, "YAML parsing error in '#{file_path}':\n#{yaml_err_msg}"
61
- end
62
- end
63
-
64
- def get_directory_content
65
- @directory_content ||= Dir.glob("#{@content_dir}/**/*")
66
- end
67
-
68
- def invalidate_directory_content
69
- @directory_content = Dir.glob("#{@content_dir}/**/*")
70
- end
71
-
72
- def get_assembly_files
73
- get_directory_content.select { |f| f =~ AssemblyRegexp[:regexp] || f =~ AssemblyRegexp[:legacy_regexp] }
74
- end
75
- AssemblyRegexp = {
76
- :regexp => Regexp.new("assemblies/(.*)\.dtk\.assembly\.(yml|yaml)$"),
77
- :legacy_regexp => Regexp.new("assemblies/([^/]+)/assembly\.(yml|yaml)$")
78
- }
79
-
80
- def get_module_refs_file
81
- get_directory_content.find { |f| f =~ ModuleRefsRegexp[:regexp] }
82
- end
83
- ModuleRefsRegexp = {
84
- :regexp => Regexp.new("module_refs\.(yml|yaml)$")
85
- }
86
-
87
- def ret_assemblies_hash
88
- assemblies = {}
89
-
90
- get_assembly_files.each do |assembly|
91
- content_hash = convert_file_content_to_hash(assembly)
92
- name = content_hash['name']
93
- assembly_content = content_hash['assembly']
94
-
95
- workflows = ret_workflows_hash(content_hash)
96
- assembly_content.merge!('workflows' => workflows) if workflows
97
-
98
- # convert node_bindings to node attributes
99
- node_bindings = content_hash['node_bindings']
100
- create_node_properties_from_node_bindings?(node_bindings, assembly_content)
101
-
102
- assemblies.merge!(name => assembly_content)
103
- end
104
-
105
- assemblies.empty? ? nil : assemblies
106
- end
107
-
108
- def ret_workflows_hash(content_hash)
109
- if workflows = content_hash['workflow'] || content_hash['workflows']
110
- # this is legacy workflow
111
- if workflow_name = workflows.delete('assembly_action')
112
- { workflow_name => workflows }
113
- else
114
- workflows
115
- end
116
- end
117
- end
118
-
119
- def ret_dependencies_hash
120
- if file_path = get_module_refs_file
121
- module_refs_content = convert_file_content_to_hash(file_path)
122
- dependencies = {}
123
-
124
- if cmp_dependencies = module_refs_content['component_modules']
125
- cmp_dependencies.each_pair do |name, namespace_h|
126
- dependencies.merge!({ "#{namespace_h['namespace']}/#{name}" => namespace_h['version']||'master' })
127
- end
128
- end
129
-
130
- dependencies
131
- end
132
- end
133
-
134
- def create_node_properties_from_node_bindings?(node_bindings, assembly_content = {})
135
- return unless node_bindings
136
-
137
- nodes = assembly_content['nodes']
138
- return if nodes.empty?
139
-
140
- node_bindings.each do |node, node_binding|
141
- image, size = get_ec2_properties_from_node_binding(node_binding)
142
- new_attrs = { 'image' => image, 'size' => size }
143
-
144
- if node_content = nodes[node]
145
- components = node_content['components']
146
- components = components.is_a?(Array) ? components : [components]
147
-
148
- if index = include_node_property_component?(components)
149
- ec2_properties = components[index]
150
- if ec2_properties.is_a?(Hash)
151
- if attributes = ec2_properties.values.first['attributes']
152
- attributes['image'] = image unless attributes['image']
153
- attributes['size'] = size unless attributes['size']
154
- else
155
- ec2_properties.merge!('attributes' => new_attrs)
156
- end
157
- else
158
- components[index] = { ec2_properties => { 'attributes' => new_attrs } }
159
- end
160
- elsif node_attributes = node_content['attributes']
161
- node_attributes['image'] = image unless node_attributes['image']
162
- node_attributes['size'] = size unless node_attributes['size']
163
- else
164
- node_content['attributes'] = new_attrs
165
- end
166
- end
167
- end
168
- end
169
-
170
- def get_ec2_properties_from_node_binding(node_binding)
171
- image, size = node_binding.split('-')
172
- [image, size]
173
- end
174
-
175
- def include_node_property_component?(components)
176
- property_component = 'ec2::properties'
177
- components.each do |component|
178
- if component.is_a?(Hash)
179
- return components.index(component) if component.keys.first.eql?(property_component)
180
- else
181
- return components.index(component) if component.eql?(property_component)
182
- end
183
- end
184
-
185
- false
186
- end
187
- end
188
- end
189
-
@@ -1,205 +0,0 @@
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
- class Operation::Module::Install
20
- class ExternalModule < self
21
- BaseRoute = "modules"
22
- @update_all = false
23
- @update_none = false
24
-
25
- def self.install_dependent_modules(module_refs, opts = {})
26
- @update_all = opts[:skip_prompt] if opts[:skip_prompt]
27
- @print_dependency_newline = false
28
-
29
- module_refs.each do |module_ref|
30
- if module_exists?(module_ref, { :type => :component_module })
31
- print_using_message(module_ref, opts)
32
- pull_module?(module_ref, opts)
33
- find_and_install_component_module_dependency(module_ref, opts.merge(:skip_if_no_remote => true, indent: " "))
34
- else
35
- install_module(module_ref, opts)
36
- end
37
- end
38
- end
39
-
40
- def self.pull_dependent_modules?(module_refs, opts = {})
41
- module_refs.each do |module_ref|
42
- print_using_message(module_ref, opts)
43
- pull_module?(module_ref, opts)
44
- end
45
- end
46
-
47
- private
48
-
49
- def self.pull_module?(component_module, opts = {})
50
- namespace = component_module.namespace
51
- module_name = component_module.module_name
52
- version = component_module.version
53
- full_module_name = "#{namespace}:#{module_name}"
54
-
55
- return if @update_none
56
- options = %w(all none)
57
- unless @update_all
58
- update = Console.confirmation_prompt_additional_options("#{opts[:indent]}Do you want to update dependent module '#{full_module_name}' from the catalog?", options)
59
-
60
- return unless update
61
-
62
- if update.eql?('all')
63
- @update_all = true
64
- elsif update.eql?('none')
65
- @update_none = true
66
- return
67
- end
68
- end
69
-
70
- print "#{opts[:indent]}Pulling component module content for '#{full_module_name}' ... "
71
-
72
- post_body = {
73
- :module_name => module_name,
74
- :namespace => namespace,
75
- :rsa_pub_key => SSHUtil.rsa_pub_key_content,
76
- :version? => version,
77
- :full_module_name => full_module_name,
78
- :json_diffs => ""
79
- }
80
- response = rest_post "#{BaseRoute}/update_dependency_from_remote", PostBody.new(post_body)
81
-
82
- if custom_message = response.data[:custom_message]
83
- OsUtil.print(custom_message)
84
- elsif (response.data[:diffs].nil? || response.data[:diffs].empty?)
85
- OsUtil.print("No changes to pull from remote.", :yellow) unless response['errors']
86
- else
87
- OsUtil.print("Changes pulled from remote", :green)
88
- end
89
- end
90
-
91
- def self.install_module(component_module, opts = {})
92
- namespace = component_module.namespace
93
- module_name = component_module.module_name
94
- version = component_module.version
95
-
96
- print_opts = {
97
- :module_name => module_name,
98
- :namespace => namespace,
99
- :version => version
100
- }
101
-
102
- import_msg = "#{opts[:indent]}Importing module '#{DTK::Common::PrettyPrintForm.module_ref(module_name, print_opts)}' ..."
103
-
104
- # Using print to avoid adding cr at the end.
105
- print "\n" if opts[:add_newline]
106
- print import_msg
107
-
108
- post_body = {
109
- :module_name => module_name,
110
- :namespace => namespace,
111
- :rsa_pub_key => SSHUtil.rsa_pub_key_content,
112
- :version? => version
113
- }
114
-
115
- unless opts[:skip_dependencies]
116
- find_and_install_component_module_dependency(component_module, opts.merge(:add_newline => true, indent: " "))
117
- end
118
-
119
- response = rest_post "#{BaseRoute}/install_component_module", PostBody.new(post_body)
120
-
121
- clone_args = {
122
- :module_type => :component_module,
123
- :repo_url => response.required(:repo_url),
124
- :branch => response.required(:workspace_branch),
125
- :module_name => response.required(:full_module_name)
126
- }
127
-
128
- if opts[:add_newline]
129
- print OsUtil.colorize("Done.", :yellow)
130
- @print_dependency_newline = true
131
- else
132
- print "\n" if @print_dependency_newline
133
- OsUtil.print('Done.', :yellow)
134
- @print_dependency_newline = false
135
- end
136
-
137
- response
138
- end
139
-
140
- def self.get_module_dependencies(component_module)
141
- query_string_hash = QueryStringHash.new(
142
- :module_name => component_module.module_name,
143
- :namespace => component_module.namespace,
144
- :rsa_pub_key => SSHUtil.rsa_pub_key_content,
145
- :version? => component_module.version
146
- )
147
- rest_get "#{BaseRoute}/module_dependencies", query_string_hash
148
- end
149
-
150
- def self.find_and_install_component_module_dependency(component_module, opts = {})
151
- begin
152
- dependencies = get_module_dependencies(component_module)
153
- rescue Error::ServerNotOkResponse => e
154
- # temp fix for issue when dependent module is imported from puppet forge
155
- if errors = e.response && e.response['errors']
156
- dependencies = nil if errors.first.include?('not found')
157
- else
158
- raise e
159
- end
160
- end
161
-
162
- return unless dependencies
163
-
164
- are_there_warnings = RemoteDependency.check_permission_warnings(dependencies)
165
- are_there_warnings ||= RemoteDependency.print_dependency_warnings(dependencies, nil, :ignore_permission_warnings => true)
166
-
167
- if are_there_warnings
168
- return false unless Console.prompt_yes_no("Do you still want to proceed with import?", :add_options => true)
169
- end
170
-
171
- if (missing_modules = dependencies.data(:missing_module_components)) && !missing_modules.empty?
172
- dep_module_refs = (missing_modules || []).map do |ref_hash|
173
- ModuleRef.new(:namespace => ref_hash['namespace'], :module_name => ref_hash['name'], :version => ref_hash['version'])
174
- end
175
- install_dependent_modules(dep_module_refs, opts.merge(:skip_dependencies => true))
176
- end
177
-
178
- if (required_modules = dependencies.data(:required_modules)) && !required_modules.empty?
179
- dep_module_refs = (required_modules || []).map do |ref_hash|
180
- required_modules.uniq!
181
- ModuleRef.new(:namespace => ref_hash['namespace'], :module_name => ref_hash['name'], :version => ref_hash['version'])
182
- end
183
- pull_dependent_modules?(dep_module_refs, opts.merge(:skip_dependencies => true))
184
- end
185
- end
186
-
187
- def self.print_using_message(module_ref, opts = {})
188
- # special case where, after importing dependencies of dependency, comes a using message
189
- if opts[:add_newline]
190
- print "\n"
191
- @print_dependency_newline = false
192
- end
193
-
194
- opts = {
195
- :namespace => module_ref.namespace,
196
- :version => module_ref.version
197
- }
198
- OsUtil.print("#{opts[:indent]}Using module '#{DTK::Common::PrettyPrintForm.module_ref(module_ref.module_name, opts)}'")
199
- end
200
-
201
- end
202
- end
203
- end
204
-
205
-