Commit 519a33e

mo <mo.khan@gmail.com>
2018-02-04 00:54:11
add format option.
1 parent 76f5b19
Changed files (1)
lib
saml
lib/saml/kit/cli.rb
@@ -25,20 +25,27 @@ module Saml
       end
 
       class Generate < Thor
-        desc "keypair passphrase", "Create a key pair using a self signed certificate."
-        def keypair(passphrase = nil)
+        desc "keypair", "Create a key pair using a self signed certificate."
+        method_option :format, default: "pem", required: false, enum: ["pem", "env"]
+        method_option :passphrase, default: nil, required: false
+        def keypair
+          passphrase = options[:passphrase]
+          format = options[:format]
           generator = ::Xml::Kit::SelfSignedCertificate.new
           certificate, private_key = generator.create(passphrase: passphrase)
 
-          say "** BEGIN File Format **", :green
-          print certificate
-          say private_key
-          say "***********************", :green
-          say
-
-          say "X509_CERTIFICATE=" + certificate.inspect
-          say
-          say "PRIVATE_KEY=" + private_key.inspect
+          if "pem" == format
+            say "** BEGIN PEM Format **", :green
+            print certificate
+            say private_key
+            say "***********************", :green
+          else
+            say "** BEGIN ENV Format **", :green
+            say "X509_CERTIFICATE=" + certificate.inspect
+            say
+            say "PRIVATE_KEY=" + private_key.inspect
+            say "***********************", :green
+          end
 
           say
           say "Private Key Passphrase:", :green