[why] everytime invoking the script, it will generate a new my_token for an existing user
[how] for old user, only if it has added a new token for the class, the patch will update the my_token, else it will use the old one in the ES.
Signed-off-by: Luan Shengde shdluan@163.com --- lib/build_my_info_client.rb | 41 ++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 12 deletions(-) mode change 100644 => 100755 lib/build_my_info_client.rb
diff --git a/lib/build_my_info_client.rb b/lib/build_my_info_client.rb old mode 100644 new mode 100755 index c946bec..9d2aaea --- a/lib/build_my_info_client.rb +++ b/lib/build_my_info_client.rb @@ -21,17 +21,16 @@ require_relative '../lib/es_client' # build_my_info = BuildMyInfo.new(email, name, lab) # build_my_info.config_my_info class BuildMyInfo - def initialize(my_email, my_name, lab, my_token = nil) + def initialize(my_email, my_name, lab, my_token) @lab = lab || 'nolab' - @my_token = my_token || %x(uuidgen).chomp @my_info = { 'my_email' => my_email, - 'my_name' => my_name, - 'my_token' => @my_token, - 'my_login_name' => nil, - 'my_commit_url' => nil, - 'my_ssh_pubkey' => [] + 'my_name' => my_name } + unless my_token.nil? + @my_info['my_token'] = my_token + end + @es = ESClient.new(index: 'accounts') end
def config_default_yaml @@ -50,6 +49,26 @@ class BuildMyInfo end end
+ def search_my_info + @es.query_by_id(@my_info['my_email']) || {} + end + + def update_from_es(my_info_es) + my_info_es.update @my_info + @my_info.update my_info_es + end + + def complete_my_info + my_info_es = search_my_info + update_from_es(my_info_es) unless my_info_es.empty? + + @my_info['my_token'] = %x(uuidgen).chomp if @my_info['my_token'].nil? + end + + def store_account_info + @es.put_source_by_id(@my_info['my_email'], @my_info) + end + def config_lab_yaml lab_yaml_dir = "#{ENV['HOME']}/.config/compass-ci/include/lab" FileUtils.mkdir_p lab_yaml_dir unless File.directory? lab_yaml_dir @@ -64,14 +83,12 @@ class BuildMyInfo end end
- def store_account_info - es = ESClient.new(index: 'accounts') - es.put_source_by_id(@my_info['my_email'], @my_info) - end - def config_my_info + complete_my_info + config_default_yaml config_lab_yaml + store_account_info end end