summaryrefslogtreecommitdiff
path: root/lib/saml/kit/cli/report.rb
blob: 9e29862028694ca2e8716f9485d16b4b4c36259b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

module Saml
  module Kit
    module Cli
      class Report
        attr_reader :document

        def initialize(document)
          @document = document
        end

        def print(shell)
          shell.say_status status, "Decoded #{document.send(:name)}"
          shell.print_table document.build_table
          print_signature(document.signature, shell)
          print_xml(shell)
          print_errors(document.errors.full_messages, shell)
        end

        private

        def status
          document.is_a?(Saml::Kit::InvalidDocument) ? :error : :sucess
        end

        def print_errors(errors, shell)
          errors.each { |x| shell.say_status :error, x, :red }
        end

        def print_signature(signature, shell)
          return if !signature.present? || !signature.certificate.present?
          shell.say(signature.certificate.x509.to_text)
        end

        def print_xml(shell)
          shell.say document.to_xml(pretty: true), :green
        end
      end
    end
  end
end