Skip to content

Commit

Permalink
Use ERB template
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Feb 22, 2019
1 parent c146867 commit 3ab643a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 37 deletions.
42 changes: 38 additions & 4 deletions src/data/registration/certificate_error.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,49 @@
textdomain "registration"
%>
<%# dialog heading %>
<%# TRANSLATORS: dialog heading %>
<h2><%= _("Secure Connection Error") %></h2>

<p>
<%# label followed by error details %>
<%= _("Details:") %> <%= _(OPENSSL_ERROR_MESSAGES[Storage::SSLErrors.instance.ssl_error_code]) %>
<%# TRANSLATORS: label followed by error details %>
<%= _("Details:") %> <%= @url %>: <%= @msg %>
</p>

<%# dialog sub-heading %>
<%# display a special help with description how to install the certificate manually %>
<% if error_code == SslErrorCodes::NO_LOCAL_ISSUER_CERTIFICATE %>

<p>
<%# TRANSLATORS: error description %>
<%= _("The issuer certificate cannot be found, "\
"it needs to be installed manually.") %>
</p>

<p>
<ul>
<li>
<%# TRANSLATORS: %{dir} is replaced by the certificate directory %>
<%= _("Copy the certificate in PEM format to %{dir} directory") %
{ dir: "<tt>/etc/pki/trust/anchors</tt>" } %>
</li>

<% import_commands.each do |cmd| %>
<li>
<%# TRANSLATORS: label followed by a command to run %>
<%= _("Run command:") %> <tt><%= h(cmd) %></tt>
</li>
<% end %>

<li>
<%= _("Run registration again") %>
</li>
</ul>
</p>

<hr>

<% end %>
<%# TRANSLATORS: dialog sub-heading %>
<h3><%= _("Failed Certificate Details") %></h3>

<%= SslCertificateDetails.new(certificate).richtext_summary %>
40 changes: 7 additions & 33 deletions src/lib/registration/ui/failed_certificate_popup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
# ------------------------------------------------------------------------------
#

require "erb"
require "yast"

require "registration/erb_renderer.rb"
require "registration/ssl_certificate_details"
require "registration/ssl_error_codes"
require "registration/url_helpers"
Expand All @@ -22,8 +24,8 @@ module Registration
module UI
# this class displays and runs the dialog for importing a SSL certificate
class FailedCertificatePopup
include Yast::Logger
include Yast::I18n
include ERB::Util

attr_accessor :certificate, :error_code, :message

Expand Down Expand Up @@ -60,50 +62,22 @@ def show
def ssl_error_message
# try to use a translatable message first, if not found then use
# the original error message from openSSL
msg = _(SslErrorCodes::OPENSSL_ERROR_MESSAGES[error_code]) || message
url = UrlHelpers.registration_url || SUSE::Connect::YaST::DEFAULT_URL
@url = UrlHelpers.registration_url || SUSE::Connect::YaST::DEFAULT_URL
@msg = _(SslErrorCodes::OPENSSL_ERROR_MESSAGES[error_code]) || message

msg = "<p>" + (_("Secure connection error: %s") % "#{url}: #{msg}") + "</p>\n"

if error_code == SslErrorCodes::NO_LOCAL_ISSUER_CERTIFICATE
msg << import_hint
end

msg << "<hr><h3>" << _("Failed Certificate Details") << "</h3>" <<
ssl_certificate_details
end

# render Richtext description with the certificate details
def ssl_certificate_details(richtext: true)
details = SslCertificateDetails.new(certificate)
richtext ? details.richtext_summary : details.summary
end

def import_hint
"<p>" + _("The issuer certificate cannot be found, " \
"it needs to be installed manually.") + "</p>\n<p><ul>\n" +
# TRANSLATORS: %{dir} is replaced by the certificate directory
_("<li>Copy the certificate in PEM format to <tt>%{dir}</tt> directory</li>") %
{ dir: "/etc/pki/trust/anchors" } + "\n" +
import_commands +
"<li>" + _("Run registration again") + "</li>" \
"\n</ul></p>"
Helpers.render_erb_template("certificate_error.erb", binding)
end

def import_commands
# in the inst-sys we need to import the certificate manually,
# the update-ca-certificates script is missing
commands = if Yast::Stage.initial
if Yast::Stage.initial
["trust extract --format=openssl-directory --filter=ca-anchors " \
"--overwrite #{SslCertificate::TMP_CA_CERTS_DIR}",
"cp #{SslCertificate::TMP_CA_CERTS_DIR}/* #{SslCertificate::CA_CERTS_DIR}/openssl"]
else
["update-ca-certificates"]
end

commands.map do |c|
"<li>" + (_("Run command: %s") % "<tt>#{c}</tt>") + "</li>\n"
end.join
end
end
end
Expand Down

0 comments on commit 3ab643a

Please sign in to comment.