Sha256: 3bbbf257db320e752370fbb714942df084c13326142cac81809446e67742f56a

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Saml
  module Kit
    module Cli
      class SignatureReport
        attr_reader :content, :format, :path

        def initialize(path, format:)
          @format = format
          @path = path
          if File.exist?(File.expand_path(path))
            @content = IO.read(File.expand_path(path))
          else
            uri = URI.parse(path)
            @content = Net::HTTP.get_response(uri).body.chomp
          end
        end

        def print(shell)
          shell.say to_xml
          return shell.say_status :success, "#{path} is valid", :green if valid?
          errors.each { |error| shell.say_status(:error, error, :red) }
          return unless full?
          invalid_signatures.each { |x| shell.say(x.to_xml(indent: 2), :red) }
        end

        private

        def document
          @document ||= ::Xml::Kit::Document.new(content)
        end

        def to_xml
          document.to_xml(pretty: true)
        end

        def valid?
          document.valid?
        end

        def full?
          format == 'full'
        end

        def errors
          document.errors.full_messages
        end

        def invalid_signatures
          document.send(:invalid_signatures).map(&:signature)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
saml-kit-cli-0.3.8 lib/saml/kit/cli/signature_report.rb
saml-kit-cli-0.3.7 lib/saml/kit/cli/signature_report.rb