limit the scope of executing answerback-email to 'z9'
[why]
when call es_client to store the account data, the data will be stored
in the es installed at the localhost.
It will cause validation to fail when submit a job if the data is not at
the server 'z9'.
Signed-off-by: Luan Shengde <shdluan(a)163.com>
---
container/assign-account/answerback-email.rb | 33 +++++++++++++++++---
1 file changed, 29 insertions(+), 4 deletions(-)
diff --git a/container/assign-account/answerback-email.rb b/container/assign-account/answerback-email.rb
index 825d815..77a2c1f 100755
--- a/container/assign-account/answerback-email.rb
+++ b/container/assign-account/answerback-email.rb
@@ -187,11 +187,14 @@ def apply_account(my_info, conf_info)
end
def check_my_email(my_info)
+ return true if my_info['my_email']
+
message = "No email address specified\n"
message += "use -e to add an email address for applying account\n"
message += 'or use -f to add an email file'
+ puts message
- raise message if my_info['my_email'].nil?
+ return false
end
def build_my_info_from_input(my_info, email_info, my_info_es, stdin_info)
@@ -219,13 +222,34 @@ def build_my_info_from_account_info(my_info, account_info, conf_info)
my_info['my_login_name'] = account_info['my_login_name'] unless conf_info['is_update_account']
end
+def check_server
+ return true if ENV['HOSTNAME'] == 'crystal.ci'
+
+ message = 'please run the tool on z9 server'
+
+ puts message
+ return false
+end
+
+def check_my_name_exist(my_info)
+ return true if my_info['my_name']
+
+ message = 'No my_name found, please use -n to add one'
+ puts message
+
+ return false
+end
+
def send_account(my_info, conf_info, email_info, my_info_es, stdin_info)
- check_my_email(my_info)
+ puts 'check_erver'
+ return unless check_server
+ return unless check_my_email(my_info)
+
my_info['my_uuid'] = %x(uuidgen).chomp unless conf_info['is_update_account']
build_my_info_from_input(my_info, email_info, my_info_es, stdin_info)
- message = 'No my_name found, please use -n to add one'
- raise message if my_info['my_name'].nil?
+ puts 'check_my_name'
+ return unless check_my_name_exist(my_info)
account_info = apply_account(my_info, conf_info)
build_my_info_from_account_info(my_info, account_info, conf_info)
@@ -241,6 +265,7 @@ def send_mail(my_info, account_info, conf_info)
else
build_message(my_info['my_email'], account_info)
end
+
%x(curl -XPOST '#{SEND_MAIL_HOST}:#{SEND_MAIL_PORT}/send_mail_text' -d "#{message}")
end
--
2.23.0