Commit 7847301b authored by Patrick J Cherry's avatar Patrick J Cherry
Browse files

Various fixes to allow ssl-hooks tests to pass.

parent 732465ec
......@@ -157,6 +157,7 @@ require 'symbiosis'
require 'symbiosis/domains'
require 'symbiosis/domain/ssl'
require 'symbiosis/ssl'
require 'symbiosis/ssl/hooks'
require 'symbiosis/ssl/letsencrypt'
require 'symbiosis/ssl/selfsigned'
......@@ -254,7 +255,7 @@ domains.sort_by(&:name).each do |domain|
end
end
success = Symbiosis::SSL::Hooks.run! domains_altered, 'live-update'
success = Symbiosis::SSL::Hooks.run! 'live-update', domains_altered
exit_code = 2 unless success
exit exit_code
# Symbiosis module
module Symbiosis
# SSL submodule
module SSL
# SSL subclass
class SSL
# Runs the SSL hooks for symbiosis-ssl when
# domains' certificate sets are altered
class Hooks
HOOKS_GLOB = '/symbiosis/ssl-hooks.d/*'.freeze
def self.run!(event, domains)
Hooks.new.run_hooks(event, domains)
Hooks.new.run!(event, domains)
end
def initialize(hooks_glob = Symbiosis.path_in_etc(HOOKS_GLOB))
......@@ -19,9 +19,9 @@ module Symbiosis
@event = event
@domains = domains
Dir.glob(@hooks_dir)
.filter(valid_hook?)
.all?(runs_successfully?)
Dir.glob(@hooks_glob)
.select { |h| valid_hook?(h) }
.all? { |h| runs_successfully?(h) }
end
def valid_hook?(hook)
......@@ -31,18 +31,17 @@ module Symbiosis
private
def runs_successfully?(hook)
opts = { stdin_data: @domains.join("\n") }
output, status = Open3.capture2e([hook, event], opts)
def runs_successfully?(script)
opts = { stdin_data: @domains.join("\n") + "\n" }
output, status = Open3.capture2e(script, @event, opts)
return true if status.success?
puts hook_status(output, status)
puts script_status(script, output, status)
false
end
def hook_status(output, status)
def script_status(script, output, status)
"============================================\n" \
"Error executing SSL script for #{@event} hook\n" \
"Error executing SSL script for #{@event} event\n" \
"#{script} exited with status #{status.exitstatus}\n" \
"#{output}\n\n"
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment