On Thu, Nov 05, 2020 at 09:52:42AM +0800, Wu Fengguang wrote:
Can name it lib/assign_account.rb Ditto for other files that define class code.
I got it
On Wed, Nov 04, 2020 at 06:17:59PM +0800, Luan Shengde wrote:
check to assign account invoke ParseApplyAccountEmail to parse commit url and pubkey generate uuid and invoke AssignJumperAccount to apply account store account info to es send uuid
Signed-off-by: Luan Shengde shdluan@163.com
container/mail-robot/apply-account.rb | 65 +++++++++++++++++++++++++++ 1 file changed, 65 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..9a8d706 --- /dev/null +++ b/container/mail-robot/apply-account.rb @@ -0,0 +1,65 @@ +#!/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'
+# 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
Please remove the check_to_ check_out etc. prefix.
I got it
- my_commit_url, my_ssh_pubkey = check_out_commit_url_pub_key
- my_uuid, acct_infos = check_to_apply_account(my_ssh_pubkey)
- my_info = {
'my_email' => @my_email,
'my_name' => @my_name,
'my_commit_url' => my_commit_url,
'my_login_name' => acct_infos['my_login_name'],
'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, my_ssh_pubkey = parse_apply_account_email.parse_commit_url_pub_key
Please do one thing per func. Please remove dumb wrapper parse_commit_url_pub_key() -- it only makes things more obscure by having to remember one more level of function.
I will fix it
- return my_commit_url, my_ssh_pubkey
- end
- def check_to_apply_account(my_ssh_pubkey)
- my_uuid = %x(uuidgen).chomp
- apply_account_info = {
That's mostly identical to my_info above. Can they be shared as class member?
I will optimize it
Thanks, Luan Shengde
'my_email' => @my_email,
'my_name' => @my_name,
'my_uuid' => my_uuid,
'my_ssh_pubkey' => my_ssh_pubkey
- }
- apply_account = AssignJumperAccount.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 = SendApplyAccountEmail.new(my_info)
- send_uuid.send_uuid_email
- end
+end
2.23.0