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
@@ -74,6 +74,11 @@ module DTK::Client
74
74
  @git_repo.push(remote, branch_for_push, opts)
75
75
  end
76
76
 
77
+ def push_from_cached_branch(remote, branch, opts = {})
78
+ branch_for_push = "HEAD:#{branch}"
79
+ @git_repo.push(remote, branch_for_push, opts)
80
+ end
81
+
77
82
  def merge(branch_to_merge_from)
78
83
  @git_repo.merge(branch_to_merge_from)
79
84
  end
@@ -99,14 +104,24 @@ module DTK::Client
99
104
  end
100
105
 
101
106
  def stage_and_commit(commit_msg = nil)
107
+ commit_msg ||= default_commit_message
102
108
  add_all
103
109
  begin
104
- commit(commit_msg || "DTK Commit from client")
110
+ commit(commit_msg)
105
111
  rescue
106
112
  # do not raise if nothing to commit
107
113
  end
108
114
  end
109
115
 
116
+ def empty_commit(commit_msg = nil)
117
+ commit_msg ||= default_commit_message
118
+ commit(commit_msg, :allow_empty => true)
119
+ end
120
+
121
+ def reset_soft(sha)
122
+ @git_repo.reset(sha)
123
+ end
124
+
110
125
  def stage_changes()
111
126
  handle_git_error do
112
127
  @git_repo.add(untracked())
@@ -124,8 +139,10 @@ module DTK::Client
124
139
  end
125
140
  end
126
141
 
127
- def commit(commit_msg = "")
128
- @git_repo.commit(commit_msg)
142
+ # opts can have keys
143
+ # :allow_empty
144
+ def commit(commit_msg = "", opts = {})
145
+ @git_repo.commit(commit_msg, :allow_empty => opts[:allow_empty])
129
146
  end
130
147
 
131
148
  def add(*files)
@@ -164,7 +181,23 @@ module DTK::Client
164
181
  (!(changed().empty? && untracked().empty? && deleted().empty?))
165
182
  end
166
183
 
167
- def print_status
184
+ # opts can have keys:
185
+ # :with_diffs (Boolean)
186
+ def print_status(opts = {})
187
+ if opts[:with_diffs]
188
+ print_status_with_diffs
189
+ else
190
+ print_status_simple
191
+ end
192
+ end
193
+
194
+ def all_branches
195
+ @git_repo.branches
196
+ end
197
+
198
+ private
199
+
200
+ def print_status_simple
168
201
  changes = [changed(), untracked(), deleted()]
169
202
  puts "\nModified files:\n".colorize(:green) unless changes[0].empty?
170
203
  changes[0].each { |item| puts "\t#{item}" }
@@ -174,6 +207,31 @@ module DTK::Client
174
207
  changes[2].each { |item| puts "\t#{item}" }
175
208
  puts ""
176
209
  end
210
+
211
+ def print_status_with_diffs
212
+ changes = [changed(), untracked(), deleted()]
213
+ puts "\nThere are changes that are not pushed to the server that will not be staged:\n".colorize(:green) unless changes[0].empty?
214
+ diff = @git_repo.diff.stats[:files]
215
+ file_changed = changes[0].size
216
+ deletions = 0
217
+ insertions = 0
218
+ changes[0].each do |item|
219
+ deletions += diff[item][:deletions]
220
+ insertions += diff[item][:insertions]
221
+ puts "\t#{item} | #{insertions + deletions} " + "+".colorize(:green) * insertions + "-".colorize(:red) * deletions
222
+ end
223
+ puts "\t#{file_changed} file changed, #{deletions} deletions(-), #{insertions} insertions(+)"
224
+ puts "\nAdded files:\n".colorize(:yellow) unless changes[1].empty?
225
+ changes[1].each { |item| puts "\t#{item}" }
226
+ puts "\nDeleted files:\n".colorize(:red) unless changes[2].empty?
227
+ changes[2].each { |item| puts "\t#{item}" }
228
+ puts ""
229
+ end
230
+
231
+ def default_commit_message
232
+ "DTK Commit from client"
233
+ end
234
+
177
235
  end
178
236
  end
179
237
  end
@@ -57,6 +57,19 @@ module DTK::Client
57
57
  end
58
58
  end
59
59
 
60
+ def self.modified_with_diff?(dir, opts = {})
61
+ repo_dir = {
62
+ :path => dir,
63
+ :branch => Git.open(dir).branches.local
64
+ }
65
+
66
+ message = DTK::Client::Operation::ClientModuleDir::GitRepo.modified_with_diff(repo_dir)
67
+ if message.data(:modified)
68
+ error_msg = opts[:error_msg] || "To allow push to go through, use option '-f' or invoke 'dtk push' to push the changes before invoking stage again"
69
+ raise Error::Usage, error_msg
70
+ end
71
+ end
72
+
60
73
  def add_remote(name, url)
61
74
  @git_adapter.add_remote(name, url)
62
75
  end
@@ -95,14 +108,20 @@ module DTK::Client
95
108
  @git_adapter.merge(branch_to_merge_from)
96
109
  end
97
110
 
98
- def print_status
99
- @git_adapter.print_status
111
+ # opts can have keys:
112
+ # :with_diffs (Boolean)
113
+ def print_status(opts = {})
114
+ @git_adapter.print_status(opts)
100
115
  end
101
116
 
102
117
  def push(remote, branch, opts = {})
103
118
  @git_adapter.push(remote, branch, opts)
104
119
  end
105
120
 
121
+ def push_from_cached_branch(remote, branch, opts = {})
122
+ @git_adapter.push_from_cached_branch(remote, branch, opts)
123
+ end
124
+
106
125
  def pull(remote, branch)
107
126
  @git_adapter.pull(remote, branch)
108
127
  end
@@ -119,6 +138,18 @@ module DTK::Client
119
138
  @git_adapter.stage_and_commit(commit_msg)
120
139
  end
121
140
 
141
+ def empty_commit(commit_msg = nil)
142
+ @git_adapter.empty_commit(commit_msg)
143
+ end
144
+
145
+ def reset_soft(sha)
146
+ @git_adapter.reset_soft(sha)
147
+ end
148
+
149
+ def all_branches
150
+ @git_adapter.all_branches
151
+ end
152
+
122
153
  private
123
154
 
124
155
  def git_adapter_class
@@ -0,0 +1,44 @@
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 LoadSource
20
+ class ComponentInfo < self
21
+ def fetch_and_cache_info
22
+ fetch_remote
23
+ merge_from_remote
24
+ transform_from_component_info
25
+ end
26
+
27
+ def fetch_info
28
+ fetch_remote
29
+ end
30
+
31
+ private
32
+
33
+ def self.info_type
34
+ :component_info
35
+ end
36
+
37
+ def transform_from_component_info
38
+ info_processor.read_inputs_and_compute_outputs!
39
+ info_processor.input_file_paths.map { |path| Operation::ClientModuleDir.rm_f(path) }
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,47 @@
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 LoadSource
20
+ class ServiceInfo < self
21
+ def fetch_and_cache_info
22
+ fetch_remote
23
+ merge_from_remote
24
+ transform_from_service_info
25
+ end
26
+
27
+ def fetch_info
28
+ fetch_remote
29
+ end
30
+
31
+ private
32
+
33
+ def self.info_type
34
+ :service_info
35
+ end
36
+
37
+ def transform_from_service_info
38
+ info_processor.read_inputs_and_compute_outputs!
39
+
40
+ # delete old files
41
+ # Assumed that this is done before ComponentInfo.transform_from_service_info
42
+ Operation::ClientModuleDir.delete_directory_content(target_repo_dir)
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,148 @@
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 LoadSource
20
+ require_relative('load_source/service_info')
21
+ require_relative('load_source/component_info')
22
+
23
+ def initialize(transform_helper, info_type, remote_repo_url, parent)
24
+ @info_processor = transform_helper.info_processor(info_type)
25
+ @info_type = info_type
26
+ @remote_repo_url = remote_repo_url
27
+ @target_repo_dir = parent.target_repo_dir
28
+ @version = parent.version
29
+ end
30
+ private :initialize
31
+
32
+ # opts can have keys
33
+ # :stage_and_commit_steps - used to stage and commit every step for pull-dtkn
34
+ def self.fetch_transform_and_merge(remote_module_info, parent, opts = {})
35
+ target_repo_dir = parent.target_repo_dir
36
+ transform_helper = ServiceAndComponentInfo::TransformFrom.new(target_repo_dir, parent.module_ref, parent.version)
37
+ info_types_processed = []
38
+
39
+ if service_info = remote_module_info.data(:service_info)
40
+ ServiceInfo.fetch_and_cache_info(transform_helper, service_info['remote_repo_url'], parent)
41
+ info_types_processed << ServiceInfo.info_type
42
+ stage_and_commit(target_repo_dir, commit_msg(info_types_processed)) if opts[:stage_and_commit_steps]
43
+ end
44
+
45
+ if component_info = remote_module_info.data(:component_info)
46
+ ComponentInfo.fetch_and_cache_info(transform_helper, component_info['remote_repo_url'], parent)
47
+ info_types_processed << ComponentInfo.info_type
48
+ end
49
+
50
+ unless info_types_processed.empty?
51
+ transform_helper.output_path_text_pairs.each_pair do |path, text_content|
52
+ Operation::ClientModuleDir.create_file_with_content("#{target_repo_dir}/#{path}", text_content)
53
+ end
54
+ stage_and_commit(target_repo_dir, commit_msg(info_types_processed))
55
+ end
56
+ end
57
+
58
+ def self.fetch_and_cache_info(transform_helper, remote_repo_url, parent)
59
+ new(transform_helper, info_type, remote_repo_url, parent).fetch_and_cache_info
60
+ end
61
+
62
+ def self.fetch_from_remote(remote_module_info, parent, opts = {})
63
+ target_repo_dir = parent.target_repo_dir
64
+
65
+ # if remotes added do not add them again
66
+ branches = Operation::ClientModuleDir::GitRepo.all_branches(:path => target_repo_dir).data(:branches)
67
+ remote_branches = branches.select { |branch| branch.full.include?('dtkn') || branch.full.include?('dtkn-component-info') }
68
+
69
+ return unless remote_branches.empty?
70
+
71
+ transform_helper = ServiceAndComponentInfo::TransformFrom.new(target_repo_dir, parent.module_ref, parent.version)
72
+
73
+ if service_info = remote_module_info.data(:service_info)
74
+ srv_info = ServiceInfo.new(transform_helper, ServiceInfo.info_type, service_info['remote_repo_url'], parent)
75
+ srv_info.fetch_info
76
+ end
77
+
78
+ if component_info = remote_module_info.data(:component_info)
79
+ cmp_info = ComponentInfo.new(transform_helper, ComponentInfo.info_type, component_info['remote_repo_url'], parent)
80
+ cmp_info.fetch_info
81
+ end
82
+
83
+ nil
84
+ end
85
+
86
+ private
87
+
88
+ attr_reader :info_processor, :target_repo_dir
89
+
90
+ def self.write_output_path_text_pairs(transform_helper, target_repo_dir, info_types_processed)
91
+ end
92
+
93
+ def common_git_repo_args
94
+ {
95
+ :info_type => @info_type,
96
+ :repo_dir => @target_repo_dir
97
+ }
98
+ end
99
+
100
+ def git_repo_remote_branch
101
+ (@version && !@version.eql?('master')) ? "v#{@version}" : 'master'
102
+ end
103
+
104
+ def fetch_remote
105
+ git_repo_args = common_git_repo_args.merge(:add_remote => @remote_repo_url)
106
+ git_repo_operation.fetch_dtkn_remote(git_repo_args)
107
+ end
108
+
109
+ def merge_from_remote
110
+ git_repo_args = common_git_repo_args.merge(:remote_branch => git_repo_remote_branch, :no_commit => true)
111
+ git_repo_operation.merge_from_dtkn_remote(git_repo_args)
112
+ end
113
+
114
+ def self.stage_and_commit(target_repo_dir, commit_msg = nil)
115
+ git_repo_args = {
116
+ :repo_dir => target_repo_dir,
117
+ :commit_msg => commit_msg,
118
+ :local_branch_type => :dtkn
119
+ }
120
+ git_repo_operation.stage_and_commit(git_repo_args)
121
+ end
122
+
123
+ def self.commit_msg(info_types_processed)
124
+ msg = "Added "
125
+ count = 0
126
+ types = info_types_processed #info
127
+ if types.include?(ServiceInfo.info_type)
128
+ msg << 'service '
129
+ count +=1
130
+ end
131
+ if types.include?(ComponentInfo.info_type)
132
+ msg << 'and ' if count > 0
133
+ msg << 'component'
134
+ count +=1
135
+ end
136
+ msg << 'info'
137
+ msg
138
+ end
139
+
140
+ def self.git_repo_operation
141
+ Operation::ClientModuleDir::GitRepo
142
+ end
143
+
144
+ def git_repo_operation
145
+ self.class.git_repo_operation
146
+ end
147
+ end
148
+ end
@@ -19,6 +19,7 @@ module DTK::Client
19
19
  class ModuleRef
20
20
 
21
21
  attr_reader :namespace, :module_name, :version, :client_dir_path
22
+ attr_accessor :version
22
23
 
23
24
  # opts can have keys
24
25
  # :namespace
@@ -41,10 +42,28 @@ module DTK::Client
41
42
  @client_dir_path = opts[:client_dir_path]
42
43
  end
43
44
 
45
+ def pretty_print
46
+ ::DTK::Common::PrettyPrintForm.module_ref(@module_name, :namespace => @namespace, :version => @version)
47
+ end
48
+ # TODO: look at deprecating print_form
44
49
  def print_form
45
50
  NamespaceModuleName.print_form(@namespace, @module_name, :version => @version)
46
51
  end
47
52
 
53
+ MASTER_VERSION = 'master'
54
+ def is_master_version?
55
+ @version.nil? or @version == MASTER_VERSION
56
+ end
57
+
58
+ def same_module?(module_ref)
59
+ @module_name == module_ref.module_name
60
+ end
61
+
62
+ def exact_match?(module_ref)
63
+ same_module?(module_ref) and @namespace == module_ref.namespace and @version == module_ref.version
64
+ end
65
+
66
+
48
67
  private
49
68
 
50
69
  module NamespaceModuleName
@@ -0,0 +1,47 @@
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::Account
20
+ class AddSshKey < self
21
+ def self.execute(args = Args.new)
22
+ path_to_key = args[:directory_path] unless args[:directory_path].nil?
23
+ path_to_key ||= SSHUtil.default_rsa_pub_key_path()
24
+
25
+ opts = {
26
+ :name => args[:name]
27
+ }
28
+
29
+ response, matched, matched_username = Account.add_key(path_to_key, opts)
30
+
31
+ if matched
32
+ OsUtil.print("Provided SSH pub key has already been added.", :yellow)
33
+ elsif matched_username
34
+ OsUtil.print("User ('#{matched_username}') already exists.", :yellow)
35
+ else
36
+ Configurator.add_current_user_to_direct_access() if response.ok?
37
+ end
38
+
39
+ if response.ok? && response.data(:repoman_registration_error)
40
+ OsUtil.print("Warning: We were not able to register your key with remote catalog! #{response.data(:repoman_registration_error)}", :yellow)
41
+ end
42
+
43
+ response.ok? ? nil : response
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,41 @@
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::Account
20
+ class DeleteSshKey < self
21
+ def self.execute(args = Args.new)
22
+ name = args[:name]
23
+ unless args[:skip_prompt]
24
+ is_go = DTK::Client::Console.prompt_yes_no("Are you sure you want to delete SSH key '#{name}'"+"?")
25
+ return nil unless is_go
26
+ end
27
+ post_body = {
28
+ :username => name
29
+ }
30
+ response = rest_post("#{RoutePrefix}/delete_ssh_key", post_body)
31
+ return response unless response.ok?
32
+
33
+ if response.ok? && response.data(:repoman_registration_error)
34
+ OsUtil.print("Warning: We were not able to unregister your key with remote catalog! #{response.data(:repoman_registration_error)}", :yellow)
35
+ end
36
+
37
+ OsUtil.print("SSH key '#{name}' removed successfully!", :yellow)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,28 @@
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::Account
20
+ class ListSshKeys < self
21
+ def self.execute(args = Args.new)
22
+ post_body = { :username => Configurator.client_username }
23
+ response = rest_get("#{RoutePrefix}/list_ssh_keys", post_body)
24
+ response.set_render_as_table!
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,49 @@
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::Account
20
+ class RegisterCatalogUser < self
21
+ def self.execute(args = Args.new)
22
+ body_params = DTK::Client::InteractiveWizard.interactive_user_input([
23
+ {:username => { :required => true} },
24
+ {:password => { :type => :password }},
25
+ {:repeat_password => { :type => :repeat_password }},
26
+ {:email => { :type => :email, :required => true }},
27
+ {:first_name => {}},
28
+ {:last_name => {}}
29
+ ])
30
+ OsUtil.print("Creating account please wait ...", :white)
31
+
32
+ response = rest_post("#{RoutePrefix}/register_catalog_account", body_params)
33
+
34
+ if response.ok?
35
+ OsUtil.print("You have successfully created catalog account!", :green)
36
+ if DTK::Client::Console.prompt_yes_no("Do you want to make this account active?")
37
+ post_body = { :username => body_params[:username], :password => body_params[:password], :validate => true }
38
+ response = rest_post("#{RoutePrefix}/set_catalog_credentials", post_body)
39
+ OsUtil.print("Catalog user '#{body_params[:username]}' is currently active user!", :green)
40
+ end
41
+ else
42
+ return response
43
+ end
44
+
45
+ nil
46
+ end
47
+ end
48
+ end
49
+ 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
+ class Operation::Account
20
+ class SetCatalogCredentials < self
21
+ def self.execute(args = Args.new)
22
+ creds = DTK::Client::Configurator.enter_catalog_credentials()
23
+
24
+ post_body = { :username => creds[:username], :password => creds[:password], :validate => true }
25
+ response = rest_post("#{RoutePrefix}/set_catalog_credentials", post_body)
26
+ return response unless response.ok?
27
+
28
+ OsUtil.print("Your catalog credentials have been set!", :yellow)
29
+ end
30
+ end
31
+ end
32
+ end