main
1# frozen_string_literal: true
2
3module Saml
4 module Kit
5 module Cli
6 class SignatureReport
7 attr_reader :content, :format, :path
8
9 def initialize(path, format:)
10 @format = format
11 @path = path
12 if File.exist?(File.expand_path(path))
13 @content = IO.read(File.expand_path(path))
14 else
15 uri = URI.parse(path)
16 @content = Net::HTTP.get_response(uri).body.chomp
17 end
18 end
19
20 def print(shell)
21 shell.say to_xml
22 return shell.say_status :success, "#{path} is valid", :green if valid?
23 errors.each { |error| shell.say_status(:error, error, :red) }
24 return unless full?
25 invalid_signatures.each { |x| shell.say(x.to_xml(indent: 2), :red) }
26 end
27
28 private
29
30 def document
31 @document ||= ::Xml::Kit::Document.new(content)
32 end
33
34 def to_xml
35 document.to_xml(pretty: true)
36 end
37
38 def valid?
39 document.valid?
40 end
41
42 def full?
43 format == 'full'
44 end
45
46 def errors
47 document.errors.full_messages
48 end
49
50 def invalid_signatures
51 document.send(:invalid_signatures).map(&:signature)
52 end
53 end
54 end
55 end
56end