Class: SSLocal::PumaRebinder

Inherits:
Object
  • Object
show all
Defined in:
lib/sslocal/puma_rebinder.rb

Overview

Takes a Puma configuration/dsl object, and - if there are any non-SSL TCP bindings and if the expected certificate files exist - then change those bindings to use SSL with the certificate files.

If there’s an unexpected binding string, then return to the originally supplied bindings.

Constant Summary collapse

UnexpectedBindFormat =
Class.new(StandardError)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dsl) ⇒ PumaRebinder

Returns a new instance of PumaRebinder.



19
20
21
22
# File 'lib/sslocal/puma_rebinder.rb', line 19

def initialize(dsl)
  @dsl = dsl
  @binds = dsl.get(:binds)
end

Class Method Details

.call(dsl) ⇒ Object



15
16
17
# File 'lib/sslocal/puma_rebinder.rb', line 15

def self.call(dsl)
  new(dsl).call
end

Instance Method Details

#callObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/sslocal/puma_rebinder.rb', line 24

def call
  return if binds.nil?
  return unless state.enabled?

  dsl.clear_binds!
  rebind
rescue UnexpectedBindFormat => error
  puts "SSLocal: ssl not enabled due to #{error.message}"
  reset
end