cancel modify my_info enable user invoke each method alone. add search method: my_info
Signed-off-by: Luan Shengde shdluan@163.com --- lib/build_my_info_client.rb | 53 +++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 29 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..6d35e97 --- a/lib/build_my_info_client.rb +++ b/lib/build_my_info_client.rb @@ -18,60 +18,55 @@ require_relative '../lib/es_client' # usage: # require_relative 'build_my_info_client' # -# build_my_info = BuildMyInfo.new(email, name, lab) -# build_my_info.config_my_info +# build_my_info = BuildMyInfo.new(my_info['email']) +# build_my_info.config_my_info(my_info) class BuildMyInfo - def initialize(my_email, my_name, lab, my_token = nil) - @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' => [] - } + def initialize(my_email) + @my_email = my_email + @es = ESClient.new(index: 'accounts') end
- def config_default_yaml + def search_my_info + @es.query_by_id(@my_email) || {} + end + + def store_account_info(my_info) + @es.put_source_by_id(@my_email, my_info) + end + + def config_default_yaml(my_info) default_yaml_dir = "#{ENV['HOME']}/.config/compass-ci/defaults" FileUtils.mkdir_p default_yaml_dir unless File.directory? default_yaml_dir default_yaml_file = "#{default_yaml_dir}/account.yaml" FileUtils.touch(default_yaml_file) unless File.exist? default_yaml_file
default_yaml_info = YAML.load_file(default_yaml_file) || {} - default_yaml_info['my_email'] = @my_info['my_email'] - default_yaml_info['my_name'] = @my_info['my_name'] - default_yaml_info['lab'] = @lab + default_yaml_info['my_email'] = my_info['my_email'] + default_yaml_info['my_name'] = my_info['my_name'] + default_yaml_info['lab'] = my_info['lab']
File.open(default_yaml_file, 'w') do |f| f.puts default_yaml_info.to_yaml end end
- def config_lab_yaml + def config_lab_yaml(my_info) lab_yaml_dir = "#{ENV['HOME']}/.config/compass-ci/include/lab" FileUtils.mkdir_p lab_yaml_dir unless File.directory? lab_yaml_dir - lab_yaml_file = "#{lab_yaml_dir}/#{@lab}.yaml" + lab_yaml_file = "#{lab_yaml_dir}/#{my_info['lab']}.yaml" FileUtils.touch(lab_yaml_file) unless File.exist? lab_yaml_file
lab_yaml_info = YAML.load_file(lab_yaml_file) || {} - lab_yaml_info['my_token'] = @my_info['my_token'] + lab_yaml_info['my_token'] = my_info['my_token']
File.open(lab_yaml_file, 'w') do |f| f.puts lab_yaml_info.to_yaml 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 - config_default_yaml - config_lab_yaml - store_account_info + def config_my_info(my_info) + store_account_info(my_info) + config_default_yaml(my_info) + config_lab_yaml(my_info) end end