1. disable use golbal variable apply_info [why] Style/GlobalVars: Do not introduce global variables. [how] use local variables instead of global variables
2. enable transfer user info when execute apply account command [why] when applying account, the assign-account service will write the user info to user's default config file ~/.config/compass-ci/default/${USER}.yaml user info: - my_email - my_name - my_uuid - lab [how] transfer the user info along with the pub_key to assign-account service
Signed-off-by: Luan Shengde luanshengde2@huawei.com --- container/assign-account/answerback-email.rb | 60 ++++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-)
diff --git a/container/assign-account/answerback-email.rb b/container/assign-account/answerback-email.rb index bb8e809..4227081 100755 --- a/container/assign-account/answerback-email.rb +++ b/container/assign-account/answerback-email.rb @@ -18,29 +18,31 @@ names = Set.new %w[ JUMPER_PORT SEND_MAIL_HOST_INTERNET SEND_MAIL_PORT_INTERNET + LAB ]
defaults = relevant_defaults(names)
JUMPER_HOST = defaults['JUMPER_HOST'] || 'api.compass-ci.openeuler.org' JUMPER_PORT = defaults['JUMPER_PORT'] || 29999 -SEND_MAIL_HOST = defaults['SEND_MAIL_HOST_INTERNET'] || 'localhost' -SEND_MAIL_PORT = defaults['SEND_MAIL_PORT_INTERNET'] || 11312 +SEND_MAIL_HOST = defaults['SEND_MAIL_HOST'] || 'localhost' +SEND_MAIL_PORT = defaults['SEND_MAIL_PORT'] || 49000 +LAB = defaults['LAB'] || z9
-$apply_info = { +apply_info = { 'my_email' => nil, + 'my_name' => nil, 'my_ssh_pubkey' => nil }
-def init_info(email_file) - mail_content = Mail.read(email_file) +def init_info(mail_content, apply_info) + apply_info['my_email'] = mail_content.from[0] + apply_info['my_name'] = mail_content.From.unparsed_value.gsub(/ <[^<>]*>/, '') + apply_info['my_ssh_pubkey'] = if mail_content.part[1].filename == 'id_rsa.pub' + mail_content.part[1].body.decoded.gsub(/\r|\n/, '') + end
- $apply_info['my_email'] = mail_content.from[0] - $apply_info['my_ssh_pubkey'] = if mail_content.part[1].filename == 'id_rsa.pub' - mail_content.part[1].body.decoded.gsub(/\r|\n/, '') - end - - $apply_info + apply_info end
options = OptionParser.new do |opts| @@ -52,15 +54,18 @@ options = OptionParser.new do |opts| opts.separator 'options:'
opts.on('-e|--email email_address', 'appoint email address') do |email_address| - $apply_info['my_email'] = email_address + apply_info['my_email'] = email_address + # when apply account with email address, will not get the user name + apply_info['my_name'] = '' end
opts.on('-s|--ssh-pubkey pub_key_file', 'ssh pub_key file, enable password-less login') do |pub_key_file| - $apply_info['my_ssh_pubkey'] = File.read(pub_key_file) + apply_info['my_ssh_pubkey'] = File.read(pub_key_file) end
opts.on('-f|--raw-email email_file', 'email file') do |email_file| - init_info(email_file) + mail_content = Mail.read(email_file) + init_info(mail_content, apply_info) end
opts.on_tail('-h|--help', 'show this message') do @@ -94,26 +99,31 @@ def build_message(email, acct_infos) return message end
-def account_info(pub_key) - account_info_str = if pub_key.nil? - %x(curl -XGET '#{JUMPER_HOST}:#{JUMPER_PORT}/assign_account') - else - %x(curl -XGET '#{JUMPER_HOST}:#{JUMPER_PORT}/assign_account' -d "pub_key: #{pub_key}") - end +def account_info(user_info) + account_info_str = %x(curl -XGET '#{JUMPER_HOST}:#{JUMPER_PORT}/assign_account' -d '#{user_info.to_json}') JSON.parse account_info_str end
-def send_account +def send_account(apply_info) message = "No email address specified\n" message += "use -e email_address add a email address\n" message += 'or use -f to add a email file' - raise message if $apply_info['my_email'].nil? + raise message if apply_info['my_email'].nil? + + user_info = { + 'my_email': apply_info['my_email'], + 'my_name': apply_info['my_name'], + # for manually assign account, there will be no my_uuid specified + 'my_uuid': '', + 'lab': LAB, + 'pub_key': apply_info['my_ssh_pubkey'] + }
- acct_info = account_info($apply_info['my_ssh_pubkey']) + acct_info = account_info(user_info)
- message = build_message($apply_info['my_email'], acct_info) + message = build_message(apply_info['my_email'], acct_info)
%x(curl -XPOST '#{SEND_MAIL_HOST}:#{SEND_MAIL_PORT}/send_mail_text' -d "#{message}") end
-send_account +send_account(apply_info)
On Fri, Oct 30, 2020 at 03:13:37PM +0800, Wang Yong wrote:
On Fri, Oct 30, 2020 at 02:56:51PM +0800, Luan Shengde wrote:
- # when apply account with email address, will not get the user name
- # for manually assign account, there will be no my_uuid specified
the commention should be aligned to the commented line.
Thanks Luan Shengde
left-justified
Thanks, Wang Yong
On Fri, Oct 30, 2020 at 02:56:51PM +0800, Luan Shengde wrote:
- disable use golbal variable apply_info
[why] Style/GlobalVars: Do not introduce global variables. [how] use local variables instead of global variables
- enable transfer user info when execute apply account command
[why] when applying account, the assign-account service will write the user info to user's default config file ~/.config/compass-ci/default/${USER}.yaml user info: - my_email - my_name
What's this 'my_name' for? If it's used for logging, do you mean username, thus how about change into 'my_username'?
Thanks, Xijian
- my_uuid - lab
[how] transfer the user info along with the pub_key to assign-account service
On Fri, Oct 30, 2020 at 03:36:55PM +0800, Xu Xijian wrote:
On Fri, Oct 30, 2020 at 02:56:51PM +0800, Luan Shengde wrote:
- disable use golbal variable apply_info
[why] Style/GlobalVars: Do not introduce global variables. [how] use local variables instead of global variables
- enable transfer user info when execute apply account command
[why] when applying account, the assign-account service will write the user info to user's default config file ~/.config/compass-ci/default/${USER}.yaml user info: - my_email - my_name
What's this 'my_name' for? If it's used for logging, do you mean username, thus how about change into 'my_username'?
example: user email: Zhang San <zhangsan.163.com> "Zhang San" is my_name for the user email
Thanks Luan Shengde
Thanks, Xijian
- my_uuid - lab
[how] transfer the user info along with the pub_key to assign-account service
On Fri, Oct 30, 2020 at 02:56:51PM +0800, Luan Shengde wrote:
- disable use golbal variable apply_info
[why] Style/GlobalVars: Do not introduce global variables. [how] use local variables instead of global variables
- enable transfer user info when execute apply account command
[why] when applying account, the assign-account service will write the user info to user's default config file ~/.config/compass-ci/default/${USER}.yaml
default => defaults
$USER.yaml => account.yaml $USER looks unnecessary complexity. It's already personal config under $HOME, so just use "account.yaml" to express personal info.
user info: - my_email - my_name - my_uuid - lab
[how] transfer the user info along with the pub_key to assign-account service
Signed-off-by: Luan Shengde luanshengde2@huawei.com
container/assign-account/answerback-email.rb | 60 ++++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-)
diff --git a/container/assign-account/answerback-email.rb b/container/assign-account/answerback-email.rb index bb8e809..4227081 100755 --- a/container/assign-account/answerback-email.rb +++ b/container/assign-account/answerback-email.rb @@ -18,29 +18,31 @@ names = Set.new %w[ JUMPER_PORT SEND_MAIL_HOST_INTERNET SEND_MAIL_PORT_INTERNET
- LAB
]
defaults = relevant_defaults(names)
JUMPER_HOST = defaults['JUMPER_HOST'] || 'api.compass-ci.openeuler.org' JUMPER_PORT = defaults['JUMPER_PORT'] || 29999 -SEND_MAIL_HOST = defaults['SEND_MAIL_HOST_INTERNET'] || 'localhost' -SEND_MAIL_PORT = defaults['SEND_MAIL_PORT_INTERNET'] || 11312 +SEND_MAIL_HOST = defaults['SEND_MAIL_HOST'] || 'localhost' +SEND_MAIL_PORT = defaults['SEND_MAIL_PORT'] || 49000 +LAB = defaults['LAB'] || z9
z9 => 'z9'
- user_info = {
- 'my_email': apply_info['my_email'],
- 'my_name': apply_info['my_name'],
- # for manually assign account, there will be no my_uuid specified
Nope. my_uuid shall always be assigned.
Thanks, Fengguang
On Sun, Nov 01, 2020 at 12:02:52PM +0800, Wu Fengguang wrote:
On Fri, Oct 30, 2020 at 02:56:51PM +0800, Luan Shengde wrote:
- disable use golbal variable apply_info
[why] Style/GlobalVars: Do not introduce global variables. [how] use local variables instead of global variables
- enable transfer user info when execute apply account command
[why] when applying account, the assign-account service will write the user info to user's default config file ~/.config/compass-ci/default/${USER}.yaml
default => defaults
$USER.yaml => account.yaml $USER looks unnecessary complexity. It's already personal config under $HOME, so just use "account.yaml" to express personal info.
I got it.
user info: - my_email - my_name - my_uuid - lab
[how] transfer the user info along with the pub_key to assign-account service
Signed-off-by: Luan Shengde luanshengde2@huawei.com
container/assign-account/answerback-email.rb | 60 ++++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-)
diff --git a/container/assign-account/answerback-email.rb b/container/assign-account/answerback-email.rb index bb8e809..4227081 100755 --- a/container/assign-account/answerback-email.rb +++ b/container/assign-account/answerback-email.rb @@ -18,29 +18,31 @@ names = Set.new %w[ JUMPER_PORT SEND_MAIL_HOST_INTERNET SEND_MAIL_PORT_INTERNET
- LAB
]
defaults = relevant_defaults(names)
JUMPER_HOST = defaults['JUMPER_HOST'] || 'api.compass-ci.openeuler.org' JUMPER_PORT = defaults['JUMPER_PORT'] || 29999 -SEND_MAIL_HOST = defaults['SEND_MAIL_HOST_INTERNET'] || 'localhost' -SEND_MAIL_PORT = defaults['SEND_MAIL_PORT_INTERNET'] || 11312 +SEND_MAIL_HOST = defaults['SEND_MAIL_HOST'] || 'localhost' +SEND_MAIL_PORT = defaults['SEND_MAIL_PORT'] || 49000 +LAB = defaults['LAB'] || z9
z9 => 'z9'
- user_info = {
- 'my_email': apply_info['my_email'],
- 'my_name': apply_info['my_name'],
- # for manually assign account, there will be no my_uuid specified
Nope. my_uuid shall always be assigned.
whether need to write the my infos to es for manually assigned users
Thanks Luan Shengde
Thanks, Fengguang