Commit f9cfef9
Changed files (13)
bin
exe
lib
spec
saml
kit
bin/console
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
-require "bundler/setup"
-require "saml/kit/cli"
+require 'bundler/setup'
+require 'saml/kit/cli'
# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "saml/kit/cli"
# require "pry"
# Pry.start
-require "irb"
+require 'irb'
IRB.start(__FILE__)
exe/saml-kit
@@ -1,8 +1,8 @@
#!/usr/bin/env ruby
-require "saml/kit/cli"
+require 'saml/kit/cli'
-samlkitrc = ENV.fetch("SAMLKITRC", File.join(Dir.home, ".samlkitrc"))
+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)
lib/saml/kit/cli/certificate.rb
@@ -2,8 +2,8 @@ module Saml
module Kit
module Cli
class Certificate < Thor
- desc "keypair", "Create a key pair using a self signed certificate."
- method_option :format, default: "pem", required: false, enum: ["pem", "env"]
+ desc 'keypair', 'Create a key pair using a self signed certificate.'
+ method_option :format, default: 'pem', required: false, enum: %w[pem env]
method_option :passphrase, default: nil, required: false
def keypair
passphrase = options[:passphrase]
@@ -11,30 +11,30 @@ module Saml
generator = ::Xml::Kit::SelfSignedCertificate.new
certificate, private_key = generator.create(passphrase: passphrase)
- if "pem" == format
- say "** BEGIN PEM Format **", :green
+ if format == 'pem'
+ say '** BEGIN PEM Format **', :green
print certificate
say private_key
- say "***********************", :green
+ say '***********************', :green
else
- say "** BEGIN ENV Format **", :green
- say "X509_CERTIFICATE=" + certificate.inspect
+ say '** BEGIN ENV Format **', :green
+ say 'X509_CERTIFICATE=' + certificate.inspect
say
- say "PRIVATE_KEY=" + private_key.inspect
- say "***********************", :green
+ say 'PRIVATE_KEY=' + private_key.inspect
+ say '***********************', :green
end
say
- say "Private Key Passphrase:", :green
+ say 'Private Key Passphrase:', :green
say passphrase.inspect
end
- desc "dump", "Dump the details of a X509 Certificate."
+ desc 'dump', 'Dump the details of a X509 Certificate.'
def dump(raw)
certificate = ::Xml::Kit::Certificate.new(raw, use: :unknown)
x509 = certificate.x509
print_table [
- ["Subject", "Issuer", "Serial", "Not Before", "Not After", "Fingerprint"],
+ ['Subject', 'Issuer', 'Serial', 'Not Before', 'Not After', 'Fingerprint'],
[x509.subject, x509.issuer, x509.serial, x509.not_before, x509.not_after, certificate.fingerprint]
]
say x509.to_text, :green
lib/saml/kit/cli/decode.rb
@@ -2,7 +2,7 @@ module Saml
module Kit
module Cli
class Decode < Thor
- desc "redirect uri", "Decodes the uri using the HTTP Redirect binding"
+ desc 'redirect uri', 'Decodes the uri using the HTTP Redirect binding'
method_option :export, default: nil, required: false
def redirect(uri)
print_report_for(redirect_binding.deserialize(uri))
@@ -10,7 +10,7 @@ module Saml
say error.message, :red
end
- desc "post saml", "Decodes the SAMLRequest/SAMLResponse using the HTTP Post binding"
+ desc 'post saml', 'Decodes the SAMLRequest/SAMLResponse using the HTTP Post binding'
method_option :export, default: nil, required: false
def post(saml_request)
print_report_for(post_binding.deserialize('SAMLRequest' => saml_request))
@@ -18,7 +18,7 @@ module Saml
say error.message, :red
end
- desc "raw <file>", "Decode the contents of a decoded file"
+ desc 'raw <file>', 'Decode the contents of a decoded file'
def raw(file)
content = IO.read(File.expand_path(file))
print_report_for(Document.to_saml_document(content))
@@ -30,7 +30,7 @@ module Saml
def print_report_for(document, export = options[:export])
IO.write(export, document.to_xml) if export
- 2.times { say "" }
+ 2.times { say '' }
Report.new(document).print(self)
end
lib/saml/kit/cli/metadata.rb
@@ -2,19 +2,19 @@ module Saml
module Kit
module Cli
class Metadata < Thor
- desc "register url", "Registers the Metadata from the remote url."
+ desc 'register url', 'Registers the Metadata from the remote url.'
def register(url)
say registry.register_url(url).to_xml(pretty: true), :green
end
- desc "list", "List each of the registered entityId's"
+ desc 'list', "List each of the registered entityId's"
def list
registry.each do |x|
say x.entity_id, :green
end
end
- desc "show entity_id", "show the metadata associated with an entityId"
+ desc 'show entity_id', 'show the metadata associated with an entityId'
def show(entity_id)
metadata = registry.metadata_for(entity_id)
if metadata
lib/saml/kit/cli/report.rb
@@ -11,13 +11,13 @@ module Saml
def print(shell)
shell.say_status :success, "Decoded #{document.send(:name)}"
shell.print_table build_table_for(document)
- shell.say ""
+ shell.say ''
if document.signature.present? && document.signature.certificate.present?
shell.say(document.signature.certificate.x509.to_text)
end
- shell.say ""
+ shell.say ''
shell.say document.to_xml(pretty: true), :green
- shell.say ""
+ shell.say ''
document.errors.full_messages.each do |error|
shell.say_status :error, error, :red
end
@@ -30,7 +30,7 @@ module Saml
end
def build_table_for(document)
- table = [ ]
+ table = []
case document
when Saml::Kit::Document
table.push(['ID', document.id])
@@ -49,10 +49,10 @@ module Saml
table.push(['Organization', document.organization_name])
table.push(['Url', document.organization_url])
table.push(['Contact', document.contact_person_company])
- [
- 'SingleSignOnService',
- 'SingleLogoutService',
- 'AssertionConsumerService'
+ %w[
+ SingleSignOnService
+ SingleLogoutService
+ AssertionConsumerService
].each do |type|
document.services(type).each do |service|
table.push([type, [service.location, service.binding]])
lib/saml/kit/cli/version.rb
@@ -1,7 +1,7 @@
module Saml
module Kit
module Cli
- VERSION = "0.3.6"
+ VERSION = '0.3.6'.freeze
end
end
end
lib/saml/kit/cli/xml_digital_signature.rb
@@ -4,8 +4,8 @@ module Saml
module Kit
module Cli
class XmlDigitalSignature < Thor
- desc "verify file", "Verify if the contents of a file has a valid signature."
- method_option :format, default: "short", required: false, enum: ["short", "full"]
+ desc 'verify file', 'Verify if the contents of a file has a valid signature.'
+ method_option :format, default: 'short', required: false, enum: %w[short full]
def verify(file)
format = options[:format]
path = File.expand_path(file)
@@ -15,7 +15,11 @@ module Saml
say_status :status, "Attempting to read #{path}...", :yellow
content = IO.read(path)
else
- uri = URI.parse(file) rescue nil
+ uri = begin
+ URI.parse(file)
+ rescue StandardError
+ nil
+ end
say_status :status, "Downloading from #{uri}...", :yellow
content = Net::HTTP.get_response(uri).body.chomp
end
@@ -28,7 +32,7 @@ module Saml
say_status :error, error, :red
end
- if "full" == format
+ if format == 'full'
document.send(:invalid_signatures).each_with_index do |invalid_signature, index|
say "Signature: #{index}"
say invalid_signature.signature.to_xml(indent: 2), :red
lib/saml/kit/cli.rb
@@ -1,30 +1,30 @@
-require "saml/kit"
-require "thor"
-require "yaml/store"
+require 'saml/kit'
+require 'thor'
+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"
+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'
module Saml
module Kit
module Cli
class Application < Thor
- desc "decode SUBCOMMAND ...ARGS", "decode SAMLRequest/SAMLResponse."
- subcommand "decode", Decode
+ desc 'decode SUBCOMMAND ...ARGS', 'decode SAMLRequest/SAMLResponse.'
+ subcommand 'decode', Decode
- desc "certificate SUBCOMMAND ...ARGS", "Work with SAML Certificates."
- subcommand "certificate", Certificate
+ desc 'certificate SUBCOMMAND ...ARGS', 'Work with SAML Certificates.'
+ subcommand 'certificate', Certificate
- desc "metadata SUBCOMMAND ...ARGS", "Work with SAML Metadata."
- subcommand "metadata", Metadata
+ desc 'metadata SUBCOMMAND ...ARGS', 'Work with SAML Metadata.'
+ subcommand 'metadata', Metadata
- desc "xmldsig SUBCOMMAND ...ARGS", "Check XML digital signatures."
- subcommand "xmldsig", XmlDigitalSignature
+ desc 'xmldsig SUBCOMMAND ...ARGS', 'Check XML digital signatures.'
+ subcommand 'xmldsig', XmlDigitalSignature
end
end
end
spec/saml/kit/cli_spec.rb
@@ -1,9 +1,9 @@
RSpec.describe Saml::Kit::Cli do
- it "has a version number" do
+ it 'has a version number' do
expect(Saml::Kit::Cli::VERSION).not_to be nil
end
- it "does something useful" do
+ it 'does something useful' do
expect(false).to eq(false)
end
end
spec/spec_helper.rb
@@ -1,9 +1,9 @@
-require "bundler/setup"
-require "saml/kit/cli"
+require 'bundler/setup'
+require 'saml/kit/cli'
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
- config.example_status_persistence_file_path = ".rspec_status"
+ config.example_status_persistence_file_path = '.rspec_status'
# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
Gemfile
@@ -1,6 +1,6 @@
-source "https://rubygems.org"
+source 'https://rubygems.org'
-git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
+git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
# Specify your gem's dependencies in saml-kit-cli.gemspec
gemspec
saml-kit-cli.gemspec
@@ -1,33 +1,33 @@
-lib = File.expand_path("../lib", __FILE__)
+lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
-require "saml/kit/cli/version"
+require 'saml/kit/cli/version'
Gem::Specification.new do |spec|
- spec.name = "saml-kit-cli"
+ spec.name = 'saml-kit-cli'
spec.version = Saml::Kit::Cli::VERSION
- spec.authors = ["mo khan"]
- spec.email = ["mo@mokhan.ca"]
+ spec.authors = ['mo khan']
+ spec.email = ['mo@mokhan.ca']
- spec.summary = %q{A command line interface for saml-kit.}
- spec.description = %q{A command line interface for saml-kit.}
- spec.homepage = "http://www.mokhan.ca/"
- spec.license = "MIT"
+ spec.summary = 'A command line interface for saml-kit.'
+ spec.description = 'A command line interface for saml-kit.'
+ spec.homepage = 'http://www.mokhan.ca/'
+ spec.license = 'MIT'
spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
- spec.bindir = "exe"
+ spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
- spec.require_paths = ["lib"]
- spec.required_ruby_version = "~> 2.0"
+ spec.require_paths = ['lib']
+ spec.required_ruby_version = '~> 2.0'
- spec.add_dependency "saml-kit", "1.0.12"
- spec.add_dependency "thor", "~> 0.20"
- spec.add_development_dependency "bundler", "~> 1.16"
+ spec.add_dependency 'saml-kit', '1.0.12'
+ spec.add_dependency 'thor', '~> 0.20'
+ spec.add_development_dependency 'bundler', '~> 1.16'
spec.add_development_dependency 'bundler-audit', '~> 0.6'
- spec.add_development_dependency "rake", "~> 10.0"
- spec.add_development_dependency "rspec", "~> 3.0"
+ spec.add_development_dependency 'rake', '~> 10.0'
+ spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop', '~> 0.52'
spec.add_development_dependency 'rubocop-rspec', '~> 1.22'
end