lib/r509/certificateauthority/http/server.rb in r509-ca-http-0.3.1 vs lib/r509/certificateauthority/http/server.rb in r509-ca-http-0.3.2

- old
+ new

@@ -1,15 +1,24 @@ require 'sinatra/base' require 'r509' +require "#{File.dirname(__FILE__)}/config" require "#{File.dirname(__FILE__)}/subjectparser" require "#{File.dirname(__FILE__)}/validityperiodconverter" require "#{File.dirname(__FILE__)}/factory" require 'base64' require 'yaml' require 'logger' require 'dependo' +# Capture USR2 calls so we can reload and print the config +# I'd rather use HUP, but daemons like thin already capture that +# so we can't use it. +Signal.trap("USR2") do + R509::CertificateAuthority::HTTP::Config.load_config + R509::CertificateAuthority::HTTP::Config.print_config +end + module R509 module CertificateAuthority module HTTP class Server < Sinatra::Base extend Dependo::Mixin @@ -18,22 +27,10 @@ configure do disable :protection #disable Rack::Protection (for speed) disable :logging set :environment, :production - crls = {} - certificate_authorities = {} - options_builders = {} - config_pool.names.each do |name| - crls[name] = R509::CRL::Administrator.new(config_pool[name]) - options_builders[name] = R509::CertificateAuthority::OptionsBuilder.new(config_pool[name]) - certificate_authorities[name] = R509::CertificateAuthority::Signer.new(config_pool[name]) - end - - set :crls, crls - set :certificate_authorities, certificate_authorities - set :options_builders, options_builders set :subject_parser, R509::CertificateAuthority::HTTP::SubjectParser.new set :validity_period_converter, R509::CertificateAuthority::HTTP::ValidityPeriodConverter.new set :csr_factory, R509::CertificateAuthority::HTTP::Factory::CSRFactory.new set :spki_factory, R509::CertificateAuthority::HTTP::Factory::SPKIFactory.new end @@ -42,16 +39,16 @@ content_type :text end helpers do def crl(name) - settings.crls[name] + Dependo::Registry[:crls][name] end def ca(name) - settings.certificate_authorities[name] + Dependo::Registry[:certificate_authorities][name] end def builder(name) - settings.options_builders[name] + Dependo::Registry[:options_builders][name] end def subject_parser settings.subject_parser end def validity_period_converter