Commit 8dfdaa1
Changed files (5)
exe/saml-kit
@@ -4,6 +4,7 @@ require "saml/kit/cli"
samlkitrc = ENV.fetch("SAMLKITRC", File.join(Dir.home, ".samlkitrc"))
Saml::Kit.configure do |configuration|
+ configuration.entity_id = ENV.fetch('ENTITY_ID', `hostname`.chomp)
configuration.registry = Saml::Kit::Cli::YamlRegistry.new(samlkitrc)
configuration.logger.level = Logger::FATAL
end
lib/saml/kit/cli/decode.rb
@@ -4,41 +4,32 @@ module Saml
class Decode < Thor
desc "redirect uri", "Decodes the uri using the HTTP Redirect binding"
def redirect(uri)
- binding = Saml::Kit::Bindings::HttpRedirect.new(location: '')
- uri = URI.parse(uri)
- query_params = Hash[uri.query.split('&').map { |x| x.split('=', 2) }]
- document = binding.deserialize(query_params)
-
- 2.times { say "" }
- say_status :success, "Decoded #{document.class}"
- print_table [
- ["ID", "Issuer", "Version", "Issue instant"],
- [document.id, document.issuer, document.version, document.issue_instant.iso8601 ]
- ]
- say ""
- say document.to_xml(pretty: true), :green
+ print_report_for(redirect_binding.deserialize(uri))
rescue StandardError => error
say error.message, :red
end
desc "post saml", "Decodes the SAMLRequest/SAMLResponse using the HTTP Post binding"
def post(saml_request)
- binding = Saml::Kit::Bindings::HttpPost.new(location: '')
- document = binding.deserialize('SAMLRequest' => saml_request)
- 2.times { say "" }
- say_status :success, "Decoded #{document.class}"
- print_table [
- ["ID", "Issuer", "Version", "Issue instant", "Type", "Valid", "Signed", "Trusted"],
- [document.id, document.issuer, document.version, document.issue_instant.iso8601, document.class, document.valid?, document.signed?, document.trusted? ]
- ]
- document.errors.full_messages.each do |error|
- say_status :error, error, :red
- end
- say ""
- say document.to_xml(pretty: true), :green
+ print_report_for(post_binding.deserialize('SAMLRequest' => saml_request))
rescue StandardError => error
say error.message, :red
end
+
+ private
+
+ def print_report_for(document)
+ 2.times { say "" }
+ Report.new(document).print(self)
+ end
+
+ def post_binding(location = '')
+ Saml::Kit::Bindings::HttpPost.new(location: location)
+ end
+
+ def redirect_binding(location = '')
+ Saml::Kit::Bindings::HttpRedirect.new(location: location)
+ end
end
end
end
lib/saml/kit/cli/report.rb
@@ -0,0 +1,42 @@
+module Saml
+ module Kit
+ module Cli
+ class Report
+ attr_reader :document
+
+ def initialize(document)
+ @document = document
+ end
+
+ def print(shell)
+ shell.say_status :success, "Decoded #{document.send(:name)}"
+ shell.print_table [
+ ['ID', document.id],
+ ['Issuer', document.issuer],
+ ['Version', document.version],
+ ['Issue Instant', document.issue_instant.iso8601],
+ ['Type', document.send(:name)],
+ ['Valid', document.valid?],
+ ['Signed?', document.signed?],
+ ['Trusted?', document.trusted?],
+ ]
+ document.errors.full_messages.each do |error|
+ shell.say_status :error, error, :red
+ end
+ shell.say ""
+ shell.say document.to_xml(pretty: true), :green
+ end
+
+ private
+
+ def truncate(text, max: 50)
+ if text.length >= max
+ "#{text[0..max]}..."
+ else
+ text
+ end
+ end
+ end
+ end
+ end
+end
lib/saml/kit/cli.rb
@@ -5,6 +5,7 @@ require "yaml/store"
require "saml/kit/cli/certificate"
require "saml/kit/cli/decode"
require "saml/kit/cli/metadata"
+require "saml/kit/cli/report"
require "saml/kit/cli/version"
require "saml/kit/cli/xml_digital_signature"
require "saml/kit/cli/yaml_registry"
saml-kit-cli.gemspec
@@ -1,4 +1,3 @@
-
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "saml/kit/cli/version"