On Thu, Oct 15, 2020 at 10:09:59AM +0800, Luan Shengde wrote:
user email_addr,pub_key as parameter for answerback-email tool
Usage: ./answerback-email.rb email_addr [pub_key] add pub_key if needed
Signed-off-by: Luan Shengde luanshengde2@huawei.com
container/assign-account/answerback-email.rb | 78 ++++++-------------- 1 file changed, 21 insertions(+), 57 deletions(-)
diff --git a/container/assign-account/answerback-email.rb b/container/assign-account/answerback-email.rb index b5283ba..ad24fcd 100755 --- a/container/assign-account/answerback-email.rb +++ b/container/assign-account/answerback-email.rb @@ -34,31 +34,37 @@ the returned data for account_info like: "jumper_ip" => "10.10.10.10", "jumper_port" => "10000" }
+Usage: ruby answerback-email.rb email_addr pub_key
=end
require 'json' require 'mail' require 'set' -require_relative '../defconfig.rb' +require_relative '../defconfig'
names = Set.new %w[
- JUMPER_IP
- JUMPER_HOST JUMPER_PORT CRYSTAL_INTRANET SEND_MAIL_PORT
]
+# xx --email xxx --login --ssh-pubkey xxx --raw-email email-file +# samba mount +# ssh logshn (huawei, ) (install pubkey / send password)
defaults = relevant_defaults(names)
-JUMPER_IP = defaults['JUMPER_IP'] +JUMPER_HOST = defaults['JUMPER_HOST'] JUMPER_PORT = defaults['JUMPER_PORT'] CRYSTAL_INTRANET = defaults['CRYSTAL_INTRANET'] SEND_MAIL_PORT = defaults['SEND_MAIL_PORT']
-def build_message(email, message_id, infos) +def build_message(email, infos) message = <<~EMAIL_MESSAGE To: #{email}
Message-ID: #{message_id} Subject: jumper account is ready
Dear #{email}
@@ -79,67 +85,25 @@ def build_message(email, message_id, infos) return message end
-def email_addr(mail_content)
- msg = 'not an applying account email'
- raise msg unless mail_content.subject =~ /apply ssh account/i
- email = mail_content.from.join(',')
- return email
-end
-# def check_email_available(mail_content, email) -# oos_list = File.read('/c/upstream-repos/repo_list').split(/\n/) -# url = mail_content.body.decoded.split(/\n/).find { |line| line =~ /https?:/// } -# base_url = url.split('/')[0,5].join('/') -# message = 'The url is not in upstream repo_list' -# -# raise message unless oos_list.include? base_url -# -# url_fdback = %x(curl #{url}) -# email_index = url_fdback.index email -# -# message = 'No commit info found from the url for the email' -# raise message unless email_index -# end
-def email_message_id(mail_content)
- message_id = mail_content.message_id
- return message_id
-end
-def pub_key_value(mail_content)
- pub_key = mail_content.body.decoded.split(/\n/).find { |line| line =~ /ssh-rsa/ }
- return pub_key
-end
def account_info(pub_key)
- account_info_str = %x(curl -XGET '#{JUMPER_IP}:#{JUMPER_PORT}/assign_account' -d "pub_key: #{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
"curl -XGET '#{JUMPER_HOST}:#{JUMPER_PORT}/assign_account'" is twice used, we can define le str for them.
Thanks, Xijian