Commit ed08dc1

mo <mo.khan@gmail.com>
2018-03-04 19:36:26
move commands to commands namespace.
1 parent 6073c81
lib/saml/kit/cli/commands/certificate.rb
@@ -0,0 +1,27 @@
+module Saml
+  module Kit
+    module Cli
+      module Commands
+        class Certificate < Thor
+          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
+            command = GenerateKeyPair.new(passphrase: passphrase, format: format)
+            command.run(self)
+          end
+
+          desc 'dump', 'Dump the details of a X509 Certificate.'
+          def dump(raw)
+            CertificateReport.new(raw).print(self)
+          end
+        end
+      end
+    end
+  end
+end
lib/saml/kit/cli/commands/decode.rb
@@ -0,0 +1,52 @@
+module Saml
+  module Kit
+    module Cli
+      module Commands
+        class Decode < Thor
+          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))
+          rescue StandardError => error
+            say error.message, :red
+          end
+
+          desc(
+            'post saml',
+            'Decodes the SAMLRequest/SAMLResponse using the HTTP Post binding'
+          )
+          method_option :export, default: nil, required: false
+          def post(saml)
+            print_report_for(post_binding.deserialize('SAMLRequest' => saml))
+          rescue StandardError => error
+            say error.message, :red
+          end
+
+          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))
+          rescue StandardError => error
+            say error.message, :red
+          end
+
+          private
+
+          def print_report_for(document, export = options[:export])
+            IO.write(export, document.to_xml) if export
+            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
+  end
+end
lib/saml/kit/cli/commands/metadata.rb
@@ -0,0 +1,37 @@
+module Saml
+  module Kit
+    module Cli
+      module Commands
+        class Metadata < Thor
+          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"
+          def list
+            registry.each do |x|
+              say x.entity_id, :green
+            end
+          end
+
+          desc 'show entity_id', 'show the metadata associated with an entityId'
+          def show(entity_id)
+            metadata = registry.metadata_for(entity_id)
+            if metadata
+              Report.new(metadata).print(self)
+            else
+              say "`#{entity_id}` is not registered", :red
+            end
+          end
+
+          private
+
+          def registry
+            Saml::Kit.registry
+          end
+        end
+      end
+    end
+  end
+end
lib/saml/kit/cli/commands/xml_digital_signature.rb
@@ -0,0 +1,24 @@
+module Saml
+  module Kit
+    module Cli
+      module Commands
+        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: %w[short full]
+          )
+          def verify(file)
+            report = SignatureReport.new(file, format: options[:format])
+            report.print(self)
+          end
+        end
+      end
+    end
+  end
+end
lib/saml/kit/cli/certificate.rb
@@ -1,25 +0,0 @@
-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: %w[pem env]
-        )
-        method_option :passphrase, default: nil, required: false
-        def keypair
-          command = GenerateKeyPair.new(passphrase: passphrase, format: format)
-          command.run(self)
-        end
-
-        desc 'dump', 'Dump the details of a X509 Certificate.'
-        def dump(raw)
-          CertificateReport.new(raw).print(self)
-        end
-      end
-    end
-  end
-end
lib/saml/kit/cli/decode.rb
@@ -1,50 +0,0 @@
-module Saml
-  module Kit
-    module Cli
-      class Decode < Thor
-        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))
-        rescue StandardError => error
-          say error.message, :red
-        end
-
-        desc(
-          'post saml',
-          'Decodes the SAMLRequest/SAMLResponse using the HTTP Post binding'
-        )
-        method_option :export, default: nil, required: false
-        def post(saml)
-          print_report_for(post_binding.deserialize('SAMLRequest' => saml))
-        rescue StandardError => error
-          say error.message, :red
-        end
-
-        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))
-        rescue StandardError => error
-          say error.message, :red
-        end
-
-        private
-
-        def print_report_for(document, export = options[:export])
-          IO.write(export, document.to_xml) if export
-          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
-end
lib/saml/kit/cli/metadata.rb
@@ -1,35 +0,0 @@
-module Saml
-  module Kit
-    module Cli
-      class Metadata < Thor
-        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"
-        def list
-          registry.each do |x|
-            say x.entity_id, :green
-          end
-        end
-
-        desc 'show entity_id', 'show the metadata associated with an entityId'
-        def show(entity_id)
-          metadata = registry.metadata_for(entity_id)
-          if metadata
-            Report.new(metadata).print(self)
-          else
-            say "`#{entity_id}` is not registered", :red
-          end
-        end
-
-        private
-
-        def registry
-          Saml::Kit.registry
-        end
-      end
-    end
-  end
-end
lib/saml/kit/cli/xml_digital_signature.rb
@@ -1,24 +0,0 @@
-require 'uri'
-
-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: %w[short full]
-        )
-        def verify(file)
-          report = SignatureReport.new(file, format: options[:format])
-          report.print(self)
-        end
-      end
-    end
-  end
-end
lib/saml/kit/cli.rb
@@ -1,6 +1,7 @@
 require 'saml/kit'
 require 'thor'
 require 'yaml/store'
+require 'uri'
 
 require 'saml/kit/cli/certificate'
 require 'saml/kit/cli/certificate_report'