diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-09-22 02:03:57 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-09-22 02:03:57 +0800 |
commit | 7e62ad05b5a5dae10e276b687968d90ba2876b7a (patch) | |
tree | f52dcd4f9f7f901c0751f66f4620d86d68b2401b /lib/system_check | |
parent | 905d24fbdf943ea5ff5ddb3163b8162fad7a4e78 (diff) | |
download | gitlab-ce-7e62ad05b5a5dae10e276b687968d90ba2876b7a.tar.gz |
Fix rake gitlab:incoming_email:check and make it38197-fix-ImapAuthenticationCheck
report error properly, so that we know what's really wrong.
Diffstat (limited to 'lib/system_check')
-rw-r--r-- | lib/system_check/incoming_email/imap_authentication_check.rb | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/lib/system_check/incoming_email/imap_authentication_check.rb b/lib/system_check/incoming_email/imap_authentication_check.rb index dee108d987b..e55bea86d3f 100644 --- a/lib/system_check/incoming_email/imap_authentication_check.rb +++ b/lib/system_check/incoming_email/imap_authentication_check.rb @@ -4,22 +4,17 @@ module SystemCheck set_name 'IMAP server credentials are correct?' def check? - if mailbox_config - begin - imap = Net::IMAP.new(config[:host], port: config[:port], ssl: config[:ssl]) - imap.starttls if config[:start_tls] - imap.login(config[:email], config[:password]) - connected = true - rescue - connected = false - end + if config + try_connect_imap + else + @error = "#{mail_room_config_path} does not have mailboxes setup" + false end - - connected end def show_error try_fixing_it( + "An error occurred: #{@error.class}: #{@error.message}", 'Check that the information in config/gitlab.yml is correct' ) for_more_information( @@ -30,15 +25,31 @@ module SystemCheck private - def mailbox_config - return @config if @config + def try_connect_imap + imap = Net::IMAP.new(config[:host], port: config[:port], ssl: config[:ssl]) + imap.starttls if config[:start_tls] + imap.login(config[:email], config[:password]) + true + rescue => error + @error = error + false + end + + def config + @config ||= load_config + end + + def mail_room_config_path + @mail_room_config_path ||= + Rails.root.join('config', 'mail_room.yml').to_s + end - config_path = Rails.root.join('config', 'mail_room.yml').to_s - erb = ERB.new(File.read(config_path)) - erb.filename = config_path + def load_config + erb = ERB.new(File.read(mail_room_config_path)) + erb.filename = mail_room_config_path config_file = YAML.load(erb.result) - @config = config_file[:mailboxes]&.first + config_file.dig(:mailboxes, 0) end end end |