before: users build info by input my_name, my_email, then write into ES
and yaml file.
after: no need users to input, get defaults admin account info
from /etc/compass-ci/defaults/admin-account.yaml, then write into ES.
Signed-off-by: Liu Yinsi <liuyinsi(a)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..d0cc7ec 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_token
+]
+
+defaults = relevant_defaults(names)
+my_email = defaults['my_email']
+my_name = defaults['my_name']
+my_token = defaults['my_token']
my_info = {
'my_email' => my_email,
'my_name' => my_name,
- 'my_uuid' => my_uuid
+ 'my_token' => my_token,
+ '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)
--
2.23.0