AssignJumperAccount apply account with apply_account_info apply_account_info - my_email - my_name - my_uuid - my_ssh_pubkey check account exists
Signed-off-by: Luan Shengde shdluan@163.com --- container/mail-robot/assign-jumper-account.rb | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 container/mail-robot/assign-jumper-account.rb
diff --git a/container/mail-robot/assign-jumper-account.rb b/container/mail-robot/assign-jumper-account.rb new file mode 100755 index 0000000..0728b89 --- /dev/null +++ b/container/mail-robot/assign-jumper-account.rb @@ -0,0 +1,41 @@ +#!/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' + +# apply jumper account for user +# the enter point is apply_jumper_account +# the apply_account_info hash need include +# my_email, my_name, my_uuid, my_ssh_pubkey +class AssignJumperAccount + def initialize(apply_account_info) + @apply_account_info = apply_account_info + end + + def send_error_email(error_message) + @apply_account_info['error_message'] = error_message + send_err_mail = SendApplyAccountEmail.new(@apply_account_info) + send_err_mail.send_error_email + end + + def apply_jumper_account + account_info_str = %x(curl -XGET "#{ENV['JUMPER_HOST']}:#{ENV['JUMPER_PORT']}/assign_account" \ + -d '#{@apply_account_info.to_json}') + account_info = JSON.parse account_info_str + + check_account_info(account_info) + + return account_info + end + + def check_account_info(account_info) + return unless account_info['my_login_name'].nil? + + error_message = 'No more available jumper account.' + send_error_email(error_message) + + raise error_message + end +end