purpose: build my_info for users when they installing compass-ci as private environment if not, will face account verification problems when they submitting jobs - store my_info to ES - write my_info to default/lab yaml file
Signed-off-by: Luan Shengde shdluan@163.com --- lib/build_my_info_client.rb | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 lib/build_my_info_client.rb
diff --git a/lib/build_my_info_client.rb b/lib/build_my_info_client.rb new file mode 100755 index 0000000..2a664b4 --- /dev/null +++ b/lib/build_my_info_client.rb @@ -0,0 +1,79 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true + +require 'json' +require 'fileutils' +require 'io/console' +require_relative '../lib/es_client' + +# purpose: +# build my_info +# store my_info to ES +# write my_info to default/lab yaml file +# for user install compass-ci at their local server +# user meet verification problems when submit jobs +# add calling in installing script to meet the verification function +# usage: +# require_relative 'build_my_info_client' +# +# build_my_info = BuildMyInfo.new(email, name, lab) +# build_my_info.config_my_info +class BuildMyInfo + def initialize(my_email, my_name, lab) + @lab = lab || 'z9' + @my_info = { + 'my_email' => my_email, + 'my_name' => my_name, + 'my_token' => %x(uuidgen).chomp + } + end + + def config_default_yaml + 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'] + + File.open(default_yaml_file, 'w') do |f| + f.puts default_yaml_info.to_yaml + end + 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 + lab_yaml_file = "#{lab_yaml_dir}/#{@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'] + + File.open(lab_yaml_file, 'w') do |f| + f.puts lab_yaml_info.to_yaml + end + end + + def complete_my_info + @my_info['my_login_name'] = nil + @my_info['my_commit_url'] = nil + @my_info['my_ssh_pubkey'] = [] + end + + def store_account_info + complete_my_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 + end +end
On Sat, Dec 26, 2020 at 11:42:22AM +0800, Luan Shengde wrote:
purpose: build my_info for users when they installing compass-ci as private environment if not, will face account verification problems when they submitting jobs
- store my_info to ES
- write my_info to default/lab yaml file
Signed-off-by: Luan Shengde shdluan@163.com
lib/build_my_info_client.rb | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 lib/build_my_info_client.rb
diff --git a/lib/build_my_info_client.rb b/lib/build_my_info_client.rb new file mode 100755 index 0000000..2a664b4 --- /dev/null +++ b/lib/build_my_info_client.rb @@ -0,0 +1,79 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require 'json' +require 'fileutils' +require 'io/console' +require_relative '../lib/es_client'
+# purpose: +# build my_info +# store my_info to ES +# write my_info to default/lab yaml file +# for user install compass-ci at their local server +# user meet verification problems when submit jobs +# add calling in installing script to meet the verification function +# usage: +# require_relative 'build_my_info_client' +# +# build_my_info = BuildMyInfo.new(email, name, lab) +# build_my_info.config_my_info +class BuildMyInfo
- def initialize(my_email, my_name, lab)
- @lab = lab || 'z9'
- @my_info = {
'my_email' => my_email,
'my_name' => my_name,
'my_token' => %x(uuidgen).chomp
- }
why not build them as attr? class Myinfo @lab @email @name @token end
Thanks, Shenwei
- end
- def config_default_yaml
- 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']
- File.open(default_yaml_file, 'w') do |f|
f.puts default_yaml_info.to_yaml
- end
- 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
- lab_yaml_file = "#{lab_yaml_dir}/#{@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']
- File.open(lab_yaml_file, 'w') do |f|
f.puts lab_yaml_info.to_yaml
- end
- end
- def complete_my_info
- @my_info['my_login_name'] = nil
- @my_info['my_commit_url'] = nil
- @my_info['my_ssh_pubkey'] = []
- end
- def store_account_info
- complete_my_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
- end
+end
2.23.0
On Sat, Dec 26, 2020 at 02:14:28PM +0800, Xiao Shenwei wrote:
On Sat, Dec 26, 2020 at 11:42:22AM +0800, Luan Shengde wrote:
purpose: build my_info for users when they installing compass-ci as private environment if not, will face account verification problems when they submitting jobs
- store my_info to ES
- write my_info to default/lab yaml file
+class BuildMyInfo
- def initialize(my_email, my_name, lab)
- @lab = lab || 'z9'
- @my_info = {
'my_email' => my_email,
'my_name' => my_name,
'my_token' => %x(uuidgen).chomp
- }
why not build them as attr? class Myinfo @lab @email @name @token end
I need to store the my_info(hash) to es
Thanks, Luan Shengde
Thanks, Shenwei
- }
why not build them as attr? class Myinfo @lab @email @name @token end
I need to store the my_info(hash) to es
class Myinfo @lab @email @name @token
def to_hash return my_info = { xxx } end end
if use class to save message, it easy for use erb to transform template,
compass-ci/container/mail-robot/lib/assign-account-email.rb
To: <%= @my_email %> Subject: [compass-ci] Account Ready Dear <%= @my_name %>,
Thank you for joining us. ......
Thanks, Shenwei
Thanks, Luan Shengde
Thanks, Shenwei
On Sat, Dec 26, 2020 at 03:13:16PM +0800, Xiao Shenwei wrote:
- }
why not build them as attr? class Myinfo @lab @email @name @token end
I need to store the my_info(hash) to es
class Myinfo @lab @email @name @token
def to_hash return my_info = { xxx } end
end
if use class to save message, it easy for use erb to transform template,
compass-ci/container/mail-robot/lib/assign-account-email.rb
To: <%= @my_email %> Subject: [compass-ci] Account Ready Dear <%= @my_name %>,
Thank you for joining us. ......
Thanks, Shenwei
This patch is used for user who install compass-ci in their private environment, just build write my_info to .config and store it to eS there is no requirement to sending email or anything else, so there is no need for you to care it.
Thanks, Luan Shengde
Thanks, Luan Shengde
Thanks, Shenwei
On Sat, Dec 26, 2020 at 03:19:41PM +0800, Luan Shengde wrote:
On Sat, Dec 26, 2020 at 03:13:16PM +0800, Xiao Shenwei wrote:
- }
why not build them as attr? class Myinfo @lab @email @name @token end
I need to store the my_info(hash) to es
class Myinfo @lab @email @name @token
def to_hash return my_info = { xxx } end
end
if use class to save message, it easy for use erb to transform template,
compass-ci/container/mail-robot/lib/assign-account-email.rb
To: <%= @my_email %> Subject: [compass-ci] Account Ready Dear <%= @my_name %>,
Thank you for joining us. ......
Thanks, Shenwei
This patch is used for user who install compass-ci in their private environment, just build write my_info to .config and store it to eS there is no requirement to sending email or anything else, so there is no need for you to care it.
ok,
Thanks, Shenwei
Thanks, Luan Shengde
Thanks, Luan Shengde
Thanks, Shenwei