check to assign account invoke ParseApplyAccountEmail to parse commit url and pubkey generate uuid and invoke ApplyAccount to apply account store account info to es send uuid
Signed-off-by: Luan Shengde luanshengde2@huawei.com --- container/mail-robot/apply-account.rb | 71 +++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 container/mail-robot/apply-account.rb
diff --git a/container/mail-robot/apply-account.rb b/container/mail-robot/apply-account.rb new file mode 100755 index 0000000..55245ac --- /dev/null +++ b/container/mail-robot/apply-account.rb @@ -0,0 +1,71 @@ +#!/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 'mail' +require_relative "../../lib/es_client.rb" + +# assign uuid/account +class AssignAccount + def initialize(mail_content) + @mail_content = mail_content + @my_email = mail_content.from[0] + @my_name = mail_content.From.unparsed_value.gsub(/ <[^<>]*>/, '') + @send_mail_host = %x(/sbin/ip route |awk '/default/ {print $3}').chomp + end + + def check_to_send_account + my_commit_url, pub_key = check_out_commit_url_pub_key + my_uuid, acct_infos = check_to_apply_account(pub_key) + + my_info = { + 'my_email' => @my_email, + 'my_name' => @my_name, + 'my_commit_url' => my_commit_url, + 'my_login_name' => acct_infos['account'], + 'my_uuid' => my_uuid + } + store_account_info(my_info) + my_info['acct_infos'] = acct_infos + send_my_uuid(my_info) + end + + def check_out_commit_url_pub_key + parse_apply_account_email = ParseApplyAccountEmail.new(@mail_content) + my_commit_url, pub_key = parse_apply_account_email.parse_commit_url_pub_key + + return my_commit_url, pub_key + end + + def check_to_apply_account(pub_key) + my_uuid = %x(uuidgen).chomp + apply_account_info = { + 'my_email' => @my_email, + 'my_name' => @my_name, + 'my_uuid' => my_uuid, + 'my_ssh_pubkey' => pub_key + } + apply_account = ApplyAccount.new(apply_account_info) + acct_infos = apply_account.apply_jumper_account + + return my_uuid, acct_infos + end + + def store_account_info(my_info) + es = ESClient.new(index: 'accounts') + es.put_source_by_id(my_info['my_email'], my_info) + end + + def send_my_uuid(my_info) + send_uuid_email_info = { + 'my_email' => @my_email, + 'my_name' => @my_name, + 'my_info' => my_info, + 'error_message' => '' + } + send_uuid = SendMail.new(send_uuid_email_info) + send_uuid.send_uuid_email + end +end
- my_info['acct_infos'] = acct_infos
- send_my_uuid(my_info)
- def send_my_uuid(my_info)
- send_uuid_email_info = {
'my_email' => @my_email,
'my_name' => @my_name,
'my_info' => my_info,
好多hash嵌套, why?
'error_message' => ''
- }
- send_uuid = SendMail.new(send_uuid_email_info)
- send_uuid.send_uuid_email
- end
+end
2.23.0
On Tue, Nov 03, 2020 at 09:22:56AM +0800, Wu Fengguang wrote:
- my_info['acct_infos'] = acct_infos
- send_my_uuid(my_info)
- def send_my_uuid(my_info)
- send_uuid_email_info = {
'my_email' => @my_email,
'my_name' => @my_name,
'my_info' => my_info,
好多hash嵌套, why?
the apply_account_info is initialize data the my_info is used to store to es
send_uuid_email_info can be fix I will do it now
Thanks Luan Shengde
'error_message' => ''
- }
- send_uuid = SendMail.new(send_uuid_email_info)
- send_uuid.send_uuid_email
- end
+end
2.23.0