lib/dokku_installer/ssl.rb in dokku-installer-cli-0.0.9.3 vs lib/dokku_installer/ssl.rb in dokku-installer-cli-0.1.0
- old
+ new
@@ -1,25 +1,67 @@
module DokkuInstaller
class Cli < Thor
- desc "ssl:certificate <file path>", "Add a signed certificate for SSL (server.crt)"
- def ssl_certificate(*args)
- file_path = args.first
- file_contents = File.read(file_path)
- command = "echo \"#{file_contents}\" | ssh dokku@#{domain} ssl:certificate #{app_name}"
+ # certs:add CRT KEY # Add an ssl endpoint to an app.
+ # certs:chain CRT [CRT ...] # Print the ordered and complete chain for the given certificate.
+ # certs:info # Show certificate information for an ssl endpoint.
+ # certs:key CRT KEY [KEY ...] # Print the correct key for the given certificate.
+ # certs:remove # Remove an SSL Endpoint from an app.
+ # certs:rollback # Rollback an SSL Endpoint for an app.
+ # certs:update CRT KEY # Update an SSL Endpoint on an app.
- puts "Running #{command}..."
+ desc "ssl:add CRT KEY", "Add an SSL endpoint."
+ def ssl_add(*args)
+ key = nil
+ certificate = nil
+ intermediate_certificates = []
+
+ args.each do |arg|
+ file_contents = File.read(arg)
+ if file_contents.include?("KEY")
+ key = file_contents
+ elsif file_contents.include?("BEGIN CERTIFICATE")
+ certificate = file_contents
+ elsif file_contents.include?("NEW CERTIFICATE REQUEST")
+ intermediate_certificates << file_contents
+ end
+ end
+
+ if key.nil?
+ puts "Missing SSL private key.\nSpecify the key, certificate, and any intermediate certificates."
+ exit
+ elsif certificate.nil?
+ puts "Missing SSL certificate.\nSpecify the key, certificate, and any intermediate certificates."
+ exit
+ end
+
+ puts "Adding SSL private key..."
+ command = "echo \"#{key}\" | ssh dokku@#{domain} ssl:key #{app_name}"
+ result = `#{command}`
+
+ puts "Adding SSL certificate..."
+ combined_certificate = certificate
+ if intermediate_certificates.length > 0
+ combined_certificate += "#{intermediate_certificates.join("\n")}\n"
+ end
+ command = "echo \"#{combined_certificate}\" | ssh dokku@#{domain} ssl:certificate #{app_name}"
exec(command)
end
- desc "ssl:key <file path>", "Add a private key for SSL (server.key)"
- def ssl_key(*args)
- file_path = args.first
- file_contents = File.read(file_path)
- command = "echo \"#{file_contents}\" | ssh dokku@#{domain} ssl:key #{app_name}"
+ desc "ssl:force DOMAIN", "Force SSL on the given domain."
+ def ssl_force(*args)
+ domain = args.first
+ if domain.nil?
+ puts "Specify a domain to force SSL."
+ exit
+ end
- puts "Running #{command}..."
- exec(command)
+ run_command "ssl:force #{app_name} #{domain}"
+ end
+
+ desc "ssl:remove", "Remove an SSL endpoint."
+ def ssl_remove
+ run_command "ssl:delete #{domain} #{app_name}"
end
end
end