before: users build info by input my_name, my_email, my_uuid, then write into ES and yaml file. after: no need users to input, get defaults administrator account info from configuration files /etc/compass-ci/account/*.yaml, then write into ES.
Signed-off-by: Liu Yinsi liuyinsi@163.com --- sbin/build-my-info.rb | 54 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 28 deletions(-)
diff --git a/sbin/build-my-info.rb b/sbin/build-my-info.rb index 73f7390..bb6e8d3 100755 --- a/sbin/build-my-info.rb +++ b/sbin/build-my-info.rb @@ -3,48 +3,46 @@ # Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. # frozen_string_literal: true
+require 'set' require 'json' require 'fileutils' require 'io/console' require_relative '../lib/es_client' - -print 'email: ' -my_email = $stdin.echo = gets.chomp -print 'name: ' -my_name = $stdin.echo = gets.chomp -my_uuid = %x(uuidgen).chomp - +require_relative '../container/defconfig' + +names = Set.new %w[ + my_email + my_name + my_uuid +] + +defaults = relevant_defaults(names) +my_email = defaults['my_email'] +my_name = defaults['my_name'] +my_uuid = defaults['my_uuid'] my_info = { 'my_email' => my_email, 'my_name' => my_name, - 'my_uuid' => my_uuid + 'my_uuid' => my_uuid, + 'my_login_name' => '', + 'my_commit_url' => '', + 'my_ssh_pubkey' => [] }
-def store_account_info(my_info) - es = ESClient.new(index: 'accounts') - es.put_source_by_id(my_info['my_email'], my_info) +def es + ESClient.new(index: 'accounts') end
-def config_default_yaml(my_info) - yaml_dir = "#{ENV['HOME']}/.config/compass-ci/defaults" - FileUtils.mkdir_p yaml_dir unless File.directory? yaml_dir - yaml_file = "#{yaml_dir}/account.yaml" - FileUtils.touch(yaml_file) unless File.exist? yaml_file - - yaml_info = YAML.load_file(yaml_file) || {} - yaml_info.update my_info +def store_account_info(my_info) + return if check_account_exist(my_info['my_email'])
- File.open(yaml_file, 'w') do |f| - f.puts yaml_info.to_yaml - end + es.put_source_by_id(my_info['my_email'], my_info) end
-def complete_my_info(my_info) - my_info['my_login_name'] = '' - my_info['my_commit_url'] = '' - my_info['my_ssh_pubkey'] = [] +def check_account_exist(email) + return true if es.query_by_id(email) + + return false end
-config_default_yaml(my_info) -complete_my_info(my_info) store_account_info(my_info)
On Mon, Dec 14, 2020 at 05:18:28PM +0800, Liu Yinsi wrote:
before: users build info by input my_name, my_email, my_uuid, then write into ES and yaml file. after: no need users to input, get defaults administrator account info from configuration files /etc/compass-ci/account/*.yaml, then write into ES.
Signed-off-by: Liu Yinsi liuyinsi@163.com
sbin/build-my-info.rb | 54 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 28 deletions(-)
diff --git a/sbin/build-my-info.rb b/sbin/build-my-info.rb index 73f7390..bb6e8d3 100755 --- a/sbin/build-my-info.rb +++ b/sbin/build-my-info.rb @@ -3,48 +3,46 @@ # Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. # frozen_string_literal: true
+require 'set' require 'json' require 'fileutils' require 'io/console' require_relative '../lib/es_client'
-print 'email: ' -my_email = $stdin.echo = gets.chomp -print 'name: ' -my_name = $stdin.echo = gets.chomp -my_uuid = %x(uuidgen).chomp
+require_relative '../container/defconfig'
+names = Set.new %w[
- my_email
- my_name
- my_uuid
+]
+defaults = relevant_defaults(names) +my_email = defaults['my_email'] +my_name = defaults['my_name'] +my_uuid = defaults['my_uuid'] my_info = { 'my_email' => my_email, 'my_name' => my_name,
- 'my_uuid' => my_uuid
- 'my_uuid' => my_uuid,
- 'my_login_name' => '',
- 'my_commit_url' => '',
- 'my_ssh_pubkey' => []
}
-def store_account_info(my_info)
- es = ESClient.new(index: 'accounts')
- es.put_source_by_id(my_info['my_email'], my_info)
+def es
- ESClient.new(index: 'accounts')
end
I think es function is unnecessary.
-def config_default_yaml(my_info)
- yaml_dir = "#{ENV['HOME']}/.config/compass-ci/defaults"
- FileUtils.mkdir_p yaml_dir unless File.directory? yaml_dir
- yaml_file = "#{yaml_dir}/account.yaml"
- FileUtils.touch(yaml_file) unless File.exist? yaml_file
- yaml_info = YAML.load_file(yaml_file) || {}
- yaml_info.update my_info
+def store_account_info(my_info)
- return if check_account_exist(my_info['my_email'])
- File.open(yaml_file, 'w') do |f|
- f.puts yaml_info.to_yaml
- end
- es.put_source_by_id(my_info['my_email'], my_info)
please use directly here.
Thanks, Liushaofei
end
-def complete_my_info(my_info)
- my_info['my_login_name'] = ''
- my_info['my_commit_url'] = ''
- my_info['my_ssh_pubkey'] = []
+def check_account_exist(email)
- return true if es.query_by_id(email)
- return false
end
-config_default_yaml(my_info) -complete_my_info(my_info) store_account_info(my_info) -- 2.23.0
+def es
- ESClient.new(index: 'accounts')
end
I think es function is unnecessary.
+def store_account_info(my_info)
return if check_account_exist(my_info['my_email'])
es.put_source_by_id(my_info['my_email'], my_info)
please use directly here.
because 2 functions -> store_account_info and check_account_exist all use es "ESClient.new(index: 'accounts')", so separate es function.
Thanks, Yinsi
Thanks, Liushaofei
end
+def check_account_exist(email)
- return true if es.query_by_id(email)
- return false
end
store_account_info(my_info)