ssl.rb 1.02 KB
Newer Older
telyn's avatar
telyn committed
1
require 'symbiosis'
2
require 'open3'
telyn's avatar
telyn committed
3

4
module Symbiosis
telyn's avatar
telyn committed
5
  # SSL knows about which SSL providers exist and provides SSL helper functions
6
  class SSL
7
    PROVIDERS ||= []
telyn's avatar
telyn committed
8

9
    def self.call_hooks(domains_with_updates, event)
10
      hooks_path = Symbiosis.path_in_etc('/symbiosis/ssl-hooks.d/*')
11
      success = true
telyn's avatar
telyn committed
12
13

      Dir.glob(hooks_path).each do |script|
telyn's avatar
telyn committed
14
        next unless File.executable?(script)
15
        next unless File.basename(script) =~ /^[a-zA-Z0-9_-]+$/
16
17

        success &&= run_hook_script(event, script, domains_with_updates)
telyn's avatar
telyn committed
18
      end
19
20
21
22
23
24
25
26
27
28
29
30
31
32
      success
    end

    def self.run_hook_script(event, script, domains_with_updates)
      opts = { stdin_data: domains_with_updates.join("\n") }
      output, status = Open3.capture2e([script, event], opts)

      return true if status.success?

      puts "============================================\n"
      puts "Error executing SSL script for #{event} hook\n"
      puts "#{script} exited with status #{status.exitstatus}\n"
      puts output + "\n\n"
      false
telyn's avatar
telyn committed
33
    end
34
35
  end
end