class H2OConfigurator::Host

Attributes

dir[RW]
name[RW]

Public Class Methods

new(dir) click to toggle source
# File lib/h2o-configurator/host.rb, line 8
def initialize(dir)
  @dir = dir
  @name = dir.basename.to_s
end

Public Instance Methods

access_log_file() click to toggle source
# File lib/h2o-configurator/host.rb, line 123
def access_log_file
  H2OConfigurator::H2OLogDir / "#{@name}.access.log"
end
cert_dir() click to toggle source
# File lib/h2o-configurator/host.rb, line 103
def cert_dir
  H2OConfigurator::CertBaseDir / @name
end
htpasswd_file() click to toggle source
# File lib/h2o-configurator/host.rb, line 115
def htpasswd_file
  @dir / '.htpasswd'
end
make_config() click to toggle source
# File lib/h2o-configurator/host.rb, line 13
def make_config
  if cert_dir.exist?
    config_http = make_https_redirect_host_config(80)
    config_https = make_host_config(443)
    {
      "#{@name}:80" => config_http,
      "*.#{@name}:80" => config_http,
      "#{@name}:443" => config_https,
      "*.#{@name}:443" => config_https,
    }
  else
    config_http = make_host_config(80)
    {
      "#{@name}:80" => config_http,
      "*.#{@name}:80" => config_http,
    }
  end
end
make_file_dir_handler(dir) click to toggle source
# File lib/h2o-configurator/host.rb, line 97
def make_file_dir_handler(dir)
  {
    'file.dir' => dir.to_s,
  }
end
make_handlers() click to toggle source
# File lib/h2o-configurator/host.rb, line 67
def make_handlers
  handlers = []
  if htpasswd_file.exist?
    handlers << make_ruby_handler(
      %Q{
        require 'htpasswd'
        Htpasswd.new('#{htpasswd_file}', '#{@name}')
      }
    )
  end
  handlers << make_ruby_external_handler('RedirectHandler')
  handlers << make_ruby_external_handler('AutoExtensionHandler')
  handlers << make_file_dir_handler(@dir)
  handlers
end
make_host_config(port) click to toggle source
# File lib/h2o-configurator/host.rb, line 32
def make_host_config(port)
  config = {
    'listen' => { 'port' => port },
    'access-log' => access_log_file.to_s,
    'setenv' => { 'HOST_DIR' => @dir.to_s },
  }
  if proxy_reverse_url_file.exist?
    config['paths'] = {
      '/' => { 'proxy.reverse.url' => proxy_reverse_url_file.read.chomp }
    }
  else
    config['paths'] = {
      '/' => make_handlers
    }
  end
  if server_certificate_file.exist? && private_key_file.exist?
    config['listen']['ssl'] = {
      'certificate-file' => server_certificate_file.to_s,
      'key-file' => private_key_file.to_s,
    }
  end
  config
end
make_https_redirect_host_config(port) click to toggle source
# File lib/h2o-configurator/host.rb, line 56
def make_https_redirect_host_config(port)
  {
    'listen' => port,
    'paths' => {
      '/' => {
        'redirect' => "https://#{@name}",
      }
    }
  }
end
make_ruby_external_handler(klass) click to toggle source
# File lib/h2o-configurator/host.rb, line 89
def make_ruby_external_handler(klass)
  file = InstalledHandlersDir / H2OConfigurator::Handlers[klass]
  make_ruby_handler %Q{
    require '#{file}'
    H2OConfigurator::#{klass}.new
  }
end
make_ruby_handler(code) click to toggle source
# File lib/h2o-configurator/host.rb, line 83
def make_ruby_handler(code)
  {
    'mruby.handler' => code.gsub(/\n\s+/, "\n").strip,
  }
end
private_key_file() click to toggle source
# File lib/h2o-configurator/host.rb, line 111
def private_key_file
  cert_dir / H2OConfigurator::PrivateKeyFilename
end
proxy_reverse_url_file() click to toggle source
# File lib/h2o-configurator/host.rb, line 119
def proxy_reverse_url_file
  @dir / '.proxy-reverse-url'
end
server_certificate_file() click to toggle source
# File lib/h2o-configurator/host.rb, line 107
def server_certificate_file
  cert_dir / H2OConfigurator::ServerCertificateFilename
end