Class: Puma::Acme::Plugin
- Inherits:
-
Plugin
- Object
- Plugin
- Puma::Acme::Plugin
- Defined in:
- lib/puma/acme/plugin.rb
Overview
Puma plugin for SSL certificate provisioning via an ACME server.
Instance Method Summary collapse
Instance Method Details
#start(launcher) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/puma/acme/plugin.rb', line 9 def start(launcher) identifiers = launcher.[:acme_server_names] || raise(Error, 'missing ACME server name(s)') algorithm = launcher..fetch(:acme_algorithm, :ecdsa) contact = launcher..fetch(:acme_contact, nil) directory = launcher..fetch(:acme_directory, DEFAULT_DIRECTORY) tos_agreed = launcher..fetch(:acme_tos_agreed, false) if (eab_kid = launcher.[:acme_eab_kid]) eab = Eab.new(kid: eab_kid, hmac_key: launcher..fetch(:acme_eab_hmac_key)) end store = launcher.[:acme_cache] || disk_store(launcher.) mode = launcher..fetch(:acme_mode, :background) poll_interval = launcher..fetch(:acme_poll_interval, 1) renew_at = launcher..fetch(:acme_renew_at, nil) renew_interval = launcher..fetch(:acme_renew_interval, DEFAULT_RENEW_INTERVAL) @manager = Manager.new( store: store, contact: contact, directory: directory, tos_agreed: tos_agreed, eab: eab ) @acme_binds, binds = launcher.[:binds].partition { |bind| bind.start_with?('acme://') } launcher.[:binds] = binds launcher.[:app] = Middleware.new( launcher.[:app], manager: @manager ) @logger = launcher.respond_to?(:log_writer) ? launcher.log_writer : launcher.events cert = @manager.cert!(identifiers: identifiers, algorithm: algorithm) if cert.usable? @logger.debug 'Acme: cert already provisioned' bind_to(launcher, cert) if renew_at in_background do renew(cert, renew_at: renew_at, renew_interval: renew_interval, poll_interval: poll_interval) launcher.restart end end elsif mode == :background @logger.log 'Puma background provisioning cert via puma-acme plugin...' in_background do provision(cert, poll_interval: poll_interval) @logger.log 'Puma restarting after provisioning cert via puma-acme plugin...' launcher.restart end elsif mode == :foreground @logger.log 'Puma foreground provisioning cert via puma-acme plugin...' provision(cert, poll_interval: poll_interval) @logger.log "Cert provisioned for [#{cert.names.join(', ')}] via puma-acme plugin." bind_to(launcher, cert) if renew_at in_background do renew(cert, renew_at: renew_at, renew_interval: renew_interval, poll_interval: poll_interval) launcher.restart end end else raise UnknownMode, mode end end |