main
 1# frozen_string_literal: true
 2
 3module Saml
 4  module Kit
 5    module Cli
 6      class Report
 7        attr_reader :document
 8
 9        def initialize(document)
10          @document = document
11        end
12
13        def print(shell)
14          shell.say_status status, "Decoded #{document.send(:name)}"
15          shell.print_table document.build_table
16          print_signature(document.signature, shell)
17          print_xml(shell)
18          print_errors(document.errors.full_messages, shell)
19        end
20
21        private
22
23        def status
24          document.is_a?(Saml::Kit::InvalidDocument) ? :error : :sucess
25        end
26
27        def print_errors(errors, shell)
28          errors.each { |x| shell.say_status :error, x, :red }
29        end
30
31        def print_signature(signature, shell)
32          return if !signature.present? || !signature.certificate.present?
33          shell.say(signature.certificate.x509.to_text)
34        end
35
36        def print_xml(shell)
37          shell.say document.to_xml(pretty: true), :green
38        end
39      end
40    end
41  end
42end