Class: FakeS3::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/fakes3/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(address, port, store, hostname, ssl_cert_path, ssl_key_path, extra_options = {}) ⇒ Server

Returns a new instance of Server.



508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
# File 'lib/fakes3/server.rb', line 508

def initialize(address, port, store, hostname, ssl_cert_path, ssl_key_path, extra_options={})
  @address = address
  @port = port
  @store = store
  @hostname = hostname
  @ssl_cert_path = ssl_cert_path
  @ssl_key_path = ssl_key_path
  webrick_config = {
    :BindAddress => @address,
    :Port => @port
  }
  if !@ssl_cert_path.to_s.empty?
    webrick_config.merge!(
      {
        :SSLEnable => true,
        :SSLCertificate => OpenSSL::X509::Certificate.new(File.read(@ssl_cert_path)),
        :SSLPrivateKey => OpenSSL::PKey::RSA.new(File.read(@ssl_key_path))
      }
    )
  end

  if extra_options[:quiet]
    webrick_config.merge!(
      :Logger => WEBrick::Log.new("/dev/null"),
      :AccessLog => []
    )
  end

  @server = WEBrick::HTTPServer.new(webrick_config)
end

Instance Method Details

#serveObject



539
540
541
542
543
544
545
# File 'lib/fakes3/server.rb', line 539

def serve
  @server.mount "/", Servlet, @store, @hostname
  shutdown = proc { @server.shutdown }
  trap "INT", &shutdown
  trap "TERM", &shutdown
  @server.start
end

#shutdownObject



547
548
549
# File 'lib/fakes3/server.rb', line 547

def shutdown
  @server.shutdown
end