On Thu, Oct 15, 2020 at 10:27:58AM +0800, Luan Shengde wrote:
fix bugs: unexpected errors if there is no pub_key /usr/share/ruby/json/common.rb:156:in `parse': 765: unexpected token at 'NoMethodError: undefined method `[]' for nil:NilClass (JSON::ParserError) /usr/local/bin/get_account_info.rb:96:in `setup_jumper_account_info' /usr/local/bin/assign-account.rb:24:in `block in <main>'
Signed-off-by: Luan Shengde luanshengde2@huawei.com
container/assign-account/get_account_info.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/container/assign-account/get_account_info.rb b/container/assign-account/get_account_info.rb index 6c211a4..2f93d5b 100755 --- a/container/assign-account/get_account_info.rb +++ b/container/assign-account/get_account_info.rb @@ -33,7 +33,7 @@ setup_jumper_account_info build_account_name read_jumper_info setup_authorized_key
the returned data for setup_jumper_account_info like: { "account" => "guest", @@ -93,15 +93,15 @@ class AccountStorage def setup_jumper_account_info account_info = read_account_info jumper_info = read_jumper_info
- pub_key = @data['pub_key']
- pub_key = @data['pub_key'] unless @data.nil?
It looks unnecessary, for below check pub_key.nil? first is enough.
Thanks, Xijian
jumper_ip = jumper_info[0].chomp jumper_port = jumper_info[1].chomp account = account_info[0]
- passwd = if pub_key
'Use pub_key to login'
else
- passwd = if pub_key.nil? account_info[1]
else
jumper_account_info = { 'account' => account,'Use pub_key to login' end
-- 2.23.0