Permalink
Browse files

Restructured the gems completely, made it so that there's a baseline …

…gem that includes the base libraries (cloudbridge) and one that does merb rack handler stuff.
  • Loading branch information...
graham@graham-battys-macbook.local authored and stormbrew committed Feb 21, 2009
1 parent ed63b97 commit 51438b0dd8e56e251683c2acbd885b713fe94a1c
View
@@ -1,2 +1 @@
build
-cloudbridge
@@ -1,6 +1,4 @@
#!/usr/bin/env ruby
-require 'cloud_mongrel'
-
if ENV['CLOUD_HOSTS']
cloud_hosts = ENV['CLOUD_HOSTS'].split(',')
else
@@ -28,8 +26,15 @@ ARGV.each_with_index {|arg, idx|
}
remove.reverse_each {|idx| ARGV.delete_at(idx) }
-ENV['CLOUD_HOSTS'] = (cloud_hosts.length() > 0 && cloud_hosts.join(',')) || nil
-ENV['CLOUD_KEYS'] = (cloud_keys.length() > 0 && cloud_keys.join(',')) || nil
+ENV['BRIDGE_HOSTS'] = (cloud_hosts.length() > 0 && cloud_hosts.join(',')) || nil
+ENV['BRIDGE_KEYS'] = (cloud_keys.length() > 0 && cloud_keys.join(',')) || nil
+
+# Replace the 'real' mongrel with the overloaded one
+require 'bridge_mongrel'
+module Mongrel
+ RealHttpServer = HttpServer
+ HttpServer = BridgeHttpServer
+end
# just load the native mongrel version and let it do its thing with our overloaded mongrel class.
load 'mongrel_rails'
Binary file not shown.
@@ -2,16 +2,22 @@
Gem::Specification.new do |s|
s.name = %q{cloudbridge}
- s.version = "0.9.3"
+ s.version = "0.9.5"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Graham Batty"]
s.date = %q{2009-02-08}
s.description = %q{CloudBridge is a self-healing minimal-configuration bridge between front-end and backend web servers. This library provides the tools needed to take advantage of it in ruby.}
- s.email = %q{graham@rubyoncloud.com}
- s.files = ["bin/cloud_mongrel_rails", "lib/cloudbridge.rb", "lib/cloud_mongrel.rb", "lib/cloudserver.rb", "test/test_cloud_mongrel.rb", "test/test_cloudserver.rb"]
+ s.email = %q{info@stormbrew.ca}
+ s.files = [
+ "bin/cloud_mongrel_rails",
+ "lib/cloudbridge.rb",
+ "lib/bridge_mongrel.rb",
+ "lib/cloudserver.rb",
+ "test/test_cloud_mongrel.rb",
+ "test/test_cloudserver.rb"]
s.has_rdoc = true
- s.homepage = %q{http://rubyoncloud.com/cloudmachine}
+ s.homepage = %q{http://stormbrew.ca/projects/cloudbridge}
s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
s.require_paths = ["lib"]
s.bindir = "bin"
@@ -15,9 +15,7 @@
end
module Mongrel
- class HttpServer
- alias_method(:native_initialize, :initialize)
-
+ class BridgeHttpServer < HttpServer
# Modified to take 2 arguments at the end which are a list of hosts to listen for and a list of host-keys
# to send to the server to authenticate authority over those domains.
def initialize(*args)
@@ -29,16 +27,16 @@ def initialize(*args)
listen_hosts, listen_host_keys = listen_host_keys, listen_hosts
end
# last but not least, get them from the environment or provide sensible defaults.
- listen_hosts ||= (ENV['CLOUD_HOSTS'] && ENV['CLOUD_HOSTS'].split(',')) || ["*"]
- listen_keys ||= (ENV['CLOUD_KEYS'] && ENV['CLOUD_KEYS'].split(',')) || []
-
+ listen_hosts ||= (ENV['BRIDGE_HOSTS'] && ENV['BRIDGE_HOSTS'].split(',')) || ["*"]
+ listen_host_keys ||= (ENV['BRIDGE_KEYS'] && ENV['BRIDGE_KEYS'].split(',')) || []
+
host, port = args[0], args[1]
args[0], args[1] = '0.0.0.0', 0 # make mongrel listen on a random port, we're going to close it after.
- native_initialize(*args)
+ super(*args)
@host = host
@port = port
@socket.close
- @socket = CloudBridge::Server.new(@host, @port, listen_hosts, listen_keys)
+ @socket = CloudBridge::Server.new(@host, @port, listen_hosts, listen_host_keys)
end
end
end
@@ -0,0 +1,33 @@
+require 'sha1'
+
+# CloudBridge Server Implementation
+module CloudBridge
+ # Generate a server key for a cloudbridge instance based on the secret key and hostname specified.
+ # The key grants you access to serving the host in hostname and all subdomains.
+ def self.generate_key(secret_key, hostname, timestamp = Time.now())
+ timestamp = timestamp.to_i
+ SHA1.hexdigest("#{secret_key}:#{timestamp}:#{hostname}") + ":#{timestamp}:#{hostname}"
+ end
+
+ def self.secret_for_timestamp(secrets_file, for_time)
+ last_secret = nil
+ for_time = for_time.to_i
+ File.open(secrets_file, "r") {|f|
+ f.each {|line|
+ timestamp, last_secret = line.strip.split(':', 2)
+ # go through until we find a timestamp that is lower than the current time. Ignore any further timestamps.
+ break if (timestamp.to_i < for_time)
+ }
+ }
+ if (!last_secret)
+ raise "Failed to find any secrets in the secrets file."
+ end
+ return last_secret
+ end
+
+ def self.add_secret(secrets_file, secret)
+ File.open(secrets_file, "a") {|f|
+ f.puts("#{Time.now.to_i}:#{secret}")
+ }
+ end
+end
File renamed without changes.
@@ -0,0 +1,6 @@
+module Merb
+ module Rack
+ autoload :CloudBridgeMongrel, "merb/rack/adapter/cloudbridge_mongrel"
+ Adapter.register %w{cmongrel cloudbridge}, :CloudBridgeMongrel
+ end
+end
@@ -0,0 +1,12 @@
+require 'bridge_mongrel'
+
+module Merb
+ module Rack
+ class CloudBridgeMongrel < Mongrel
+ # :api: plugin
+ def self.new_server(port)
+ @server = ::Mongrel::HttpServer.new(@opts[:host], port, 950, 0, 60, Merb::Config[:bridge_hosts] || [], Merb::Config[:bridge_keys] || [])
+ end
+ end
+ end
+end
Binary file not shown.
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{merb-cloudbridge}
+ s.version = "0.9.5"
+ s.add_dependency('cloudbridge', '>= 0.9.5')
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Graham Batty"]
+ s.date = %q{2009-02-08}
+ s.description = %q{CloudBridge is a self-healing minimal-configuration bridge between front-end and backend web servers. This library provides the tools needed to take advantage of it in ruby.}
+ s.email = %q{info@stormbrew.ca}
+ s.files = [
+ "lib/merb-cloudbridge.rb",
+ "lib/merb/rack/adapter/cloudbridge_mongrel.rb"
+ ]
+ s.has_rdoc = true
+ s.homepage = %q{http://stormbrew.ca/projects/cloudbridge}
+ s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.0}
+ s.summary = %q{CloudBridge is a self-healing minimal-configuration bridge between front-end and backend web servers. This library provides the tools needed to take advantage of it in ruby.}
+ s.rubyforge_project = "cloudbridge"
+end
@@ -0,0 +1,32 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{cloudbridge}
+ s.version = "0.9.5"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Graham Batty"]
+ s.date = %q{2009-02-08}
+ s.description = %q{CloudBridge is a self-healing minimal-configuration bridge between front-end and backend web servers. This library provides the tools needed to take advantage of it in ruby.}
+ s.email = %q{graham@rubyoncloud.com}
+ s.files = [
+ "bin/cloud_mongrel_rails",
+ "lib/cloudbridge.rb",
+ "lib/cloud_mongrel.rb",
+ "lib/cloudserver.rb",
+ "lib/rack/cloudbridge.rb",
+ "lib/rack/handler/cloudbridge_mongrel.rb",
+ "lib/merb/rack/cloudbridge.rb",
+ "lib/merb/rack/adapter/cloudbridge_mongrel.rb",
+ "test/test_cloud_mongrel.rb",
+ "test/test_cloudserver.rb"]
+ s.has_rdoc = true
+ s.homepage = %q{http://stormbrew.ca/projects/cloudbridge}
+ s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.bindir = "bin"
+ s.executables = ["cloud_mongrel_rails", "cloud_generate_key"]
+ s.rubygems_version = %q{1.3.0}
+ s.summary = %q{CloudBridge is a self-healing minimal-configuration bridge between front-end and backend web servers. This library provides the tools needed to take advantage of it in ruby.}
+ s.rubyforge_project = "cloudbridge"
+end

0 comments on commit 51438b0

Please sign in to comment.