Permalink
Browse files

specs work, most things in place

  • Loading branch information...
1 parent e781f5a commit 17e934ad5b1988520a34c7c02b244fb10959f993 Philip (flip) Kromer committed Jul 25, 2011
View
@@ -1,5 +1,5 @@
-PassthruProxy
+ArmandoProxy
responds to requests by forwarding to a given responder
responds to requests
forwards to our API server
@@ -16,5 +16,5 @@ PassthruProxy
forwards POST requests
forwards POST requests
-Finished in 0.06414 seconds
+Finished in 0.03642 seconds
10 examples, 0 failures
View
@@ -1,6 +1,7 @@
+module Goliath ; ROOT_DIR = File.expand_path(File.dirname(__FILE__)) ; end
require File.join(File.dirname(__FILE__), 'lib/senor_armando/use_gemfile_jail')
+$LOAD_PATH.unshift(Goliath.root_path("lib")) unless $LOAD_PATH.include?(Goliath.root_path("lib"))
require 'rake'
-
require 'senor_armando/tasks'
require 'jeweler'
View
@@ -1,18 +1,16 @@
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), '../lib/boot')
-require 'goliath/endpoint/echo'
-
# Usage:
# ruby -r ./lib/boot.rb ./bin/goliath_echo.rb -sv -p 9002
#
# curl -vv 'http://127.0.0.1:9002/this/that?the=other#yup'
#
# Summarizes the request back into the response header fields
#
-class GoliathEcho < Goliath::Endpoint::Echo
+class ArmandoEcho < SenorArmando::Endpoint::Echo
use Goliath::Rack::Heartbeat # respond to /status with 200, OK (monitoring, etc)
use Goliath::Rack::Tracer # log trace statistics
use Goliath::Rack::Params # parse & merge query and body parameters
- use Goliath::Rack::ExceptionHandler # catch errors and present as non-200 responses
+ use SenorArmando::Rack::ExceptionHandler # catch errors and present as non-200 responses
end
View
@@ -1,8 +1,6 @@
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), '../lib/boot')
-require 'goliath/endpoint/proxy'
-
# Usage:
# ruby -r ./lib/boot.rb ./bin/goliath_repeater -sv -p 9001
#
@@ -11,9 +9,9 @@
# Takes all requests and forwards them to another server using EM-HTTP-Request.
# See http://everburning.com/news/stage-left-enter-goliath for more details --
#
-class GoliathRepeater < Goliath::Endpoint::Proxy
- use Goliath::Rack::Heartbeat # respond to /status with 200, OK (monitoring, etc)
- use Goliath::Rack::Tracer, Settings.tracer_name # log trace statistics
- use Goliath::Rack::Params # parse & merge query and body parameters
- use Goliath::Rack::ExceptionHandler # catch errors and present as non-200 responses
+class ArmandoProxy < SenorArmando::Endpoint::Proxy
+ use Goliath::Rack::Heartbeat # respond to /status with 200, OK (monitoring, etc)
+ # use Goliath::Rack::Tracer # log trace statistics
+ use Goliath::Rack::Params # parse & merge query and body parameters
+ use SenorArmando::Rack::ExceptionHandler # catch errors and present as non-200 responses
end
View
@@ -1,4 +1 @@
-Settings.define :app_name, :default => File.basename($0, '.rb'), :description => 'Name to key on for tracer stats, statsd metrics, etc.'
-Settings.read(Goliath.root_path('config/app.yaml'))
-Settings.resolve!
View
@@ -1,19 +1,13 @@
-module Goliath
- ::Goliath::ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), '../..')) unless defined?(::Goliath::ROOT_DIR)
- def self.root_path(*dirs)
- File.join(::Goliath::ROOT_DIR, *dirs)
- end
-end
+require File.expand_path(File.join(File.dirname(__FILE__), 'senor_armando/use_gemfile_jail'))
$LOAD_PATH.unshift(Goliath.root_path("lib")) unless $LOAD_PATH.include?(Goliath.root_path("lib"))
+require 'senor_armando'
+# #
+# require 'yajl/json_gem'
+# #
+# require 'goliath/rack/exception_handler'
+# require 'goliath/rack/errors'
-require File.expand_path(File.join(File.dirname(__FILE__), 'senor_armando/use_gemfile_jail'))
-require 'em-http'
-require 'em-synchrony/em-http'
-#
-require 'gorillib'
-require 'yajl/json_gem'
-require 'configliere'
-#
-require 'goliath/rack/exception_handler'
-require 'goliath/rack/errors'
+Settings.define :app_name, :default => File.basename($0, '.rb'), :description => 'Name to key on for tracer stats, statsd metrics, etc.'
+Settings.read(Goliath.root_path('config/app.yaml'))
+Settings.resolve!
View
@@ -1,16 +1,20 @@
require 'goliath'
-require 'senor_armando/errors'
+require 'gorillib'
+require 'configliere'
+require 'yajl/json_gem'
+
+require 'senor_armando/error'
+require 'senor_armando/rack/tracer'
module SenorArmando
module Endpoint
- autoload :SenorArmando::Endpoint::Proxy, 'senor_armando/endpoint/proxy'
- autoload :SenorArmando::Endpoint::Echo, 'senor_armando/endpoint/echo'
+ autoload :Proxy, 'senor_armando/endpoint/proxy'
+ autoload :Echo, 'senor_armando/endpoint/echo'
end
module Rack
# autoload :SenorArmando::Rack::EchoParams, 'senor_armando/rack/echo_params'
- autoload :SenorArmando::Rack::ExceptionHandler, 'senor_armando/rack/exception_handler'
- autoload :SenorArmando::Rack::EchoParams, 'senor_armando/rack/echo_params'
+ autoload :ExceptionHandler, 'senor_armando/rack/exception_handler'
end
end
@@ -1,3 +1,5 @@
+require 'em-http'
+require 'em-synchrony/em-http'
require 'postrank-uri'
Settings.define :forwarder, :required => true, :description => "Destination host to forward requests to"
@@ -21,7 +23,7 @@ def dest_url_and_params(env)
# Set the target host correctly
dest_url = PostRank::URI.normalize("#{Settings[:forwarder]}#{env[Goliath::Request::REQUEST_PATH]}")
- env.logger.info ['proxy', dest_url].join("\t")
+ env.logger.debug ['proxy', dest_url, dest_params].join("\t")
[dest_url, dest_params]
end
@@ -31,7 +33,6 @@ def response(env)
dest_url, dest_params = dest_url_and_params(env)
dest_params[:head]['Host'] = dest_url.host
- env.logger.debug( [dest_url, dest_params] )
req = EM::HttpRequest.new(dest_url.to_s)
resp =
@@ -1,5 +1,6 @@
require 'goliath/validation/standard_http_errors'
require 'goliath/validation/error'
+require 'gorillib/metaprogramming/class_attribute'
module Goliath
module Validation
@@ -8,7 +9,7 @@ module Validation
# Style guide:
#
# * be careful about interpolating messages into the error response.
- # Escape anything that might lead to an injection attack.
+ # Escape anything that might lead to an injection attack.
# * To quote text, use {}. For example,
# raise Apeyeye::ApiCallNotFoundError, "There is no api call at {#{request.path}}. Check the catalog at http://infochimps.com/api to ensure the path is correct. If there is a mismatch, please email help@infochimps.com."
# which leads eventually to
@@ -1,5 +1,5 @@
module SenorArmando
- module Plugin
+ module Plugins
# Sends metrics to a remote statsd-compatible server
class StatsdSender < EventMachine::Connection
DEFAULT_HOST = '127.0.0.1'
@@ -46,7 +46,7 @@ def self.open options={}
# Sends metrics to a remote statsd-compatible server
#
# @example
- # plugin SenorArmando::Plugin::StatsdPlugin
+ # plugin SenorArmando::Plugins::StatsdPlugin
#
# You might also enjoy using the SenorArmando::Rack::StatsdLogger middleware.
#
@@ -59,7 +59,7 @@ class StatsdPlugin
# @param config [Hash] The server configuration data
# @param status [Hash] A status hash
# @param logger [Log4R::Logger] The logger
- # @return [Goliath::Plugin::StatsdPlugin] An instance of the Goliath::Plugin::StatsdPlugin plugin
+ # @return [SenorArmando::Plugins::StatsdPlugin] An instance of the SenorArmando::Plugins::StatsdPlugin plugin
def initialize(port, config, status, logger)
@status = status
@config = config[:statsd_logger] || {}
@@ -1,4 +1,4 @@
-module Goliath
+module SenorArmando
module Rack
# Middleware to rescue validation errors and send them up the chain as normal non-200 responses
@@ -1,6 +1,6 @@
Settings.define :statsd_name, :description => 'Name for statsd metrics', :finally => lambda{ Settings.statsd_name ||= Settings.app_name }
-module Goliath
+module SenorArmando
module Rack
class StatsdLogger
include Goliath::Rack::AsyncMiddleware
File renamed without changes.
@@ -0,0 +1,35 @@
+module SenorArmando
+ module Spec
+ module HeHelpMeTest
+ include Goliath::TestHelper
+
+ DEFAULT_ERRBACK = Proc.new{|c| fail "HTTP Request failed #{c.response}" }
+
+ def config_file
+ Goliath.root_path('config', 'app.rb')
+ end
+
+ def get_api_request query={}, params={}, errback=DEFAULT_ERRBACK, &block
+ params[:query] = query
+ get_request(params, errback, &block)
+ end
+
+ def should_have_response(c,r)
+ [c.response, c.response_header.status].should == r
+ end
+
+ def should_have_ok_response(c)
+ [c.response, c.response_header.status].should == ["Hello from Responder\n", 200]
+ end
+
+ def with_echo_target api, options
+ with_api(api, options) do |api|
+ s = server(SenorArmando::Endpoint::Echo, 9009)
+ Settings[:forwarder] = 'http://localhost:9009'
+ yield
+ end
+ end
+
+ end
+ end
+end
@@ -1,33 +0,0 @@
-module GoliathSkeleton
- module TestHelper
- include Goliath::TestHelper
-
- DEFAULT_ERRBACK = Proc.new{|c| fail "HTTP Request failed #{c.response}" }
-
- def config_file
- Goliath.root_path('config', 'app.rb')
- end
-
- def get_api_request query={}, params={}, errback=DEFAULT_ERRBACK, &block
- params[:query] = query
- get_request(params, errback, &block)
- end
-
- def should_have_response(c,r)
- [c.response, c.response_header.status].should == r
- end
-
- def should_have_ok_response(c)
- [c.response, c.response_header.status].should == ["Hello from Responder\n", 200]
- end
-
- def with_echo_target api, options
- with_api(api, options) do |api|
- s = server(Goliath::Endpoint::Echo, 9009)
- Settings[:forwarder] = 'http://localhost:9009'
- yield
- end
- end
-
- end
-end
@@ -1,3 +1,3 @@
%w[yard rspec].each do |rake_file|
- require File.join('senor_armando/tasks', "#{rake_file}.rake")
+ load File.join('senor_armando/tasks', "#{rake_file}.rake")
end
@@ -1,3 +1,11 @@
+module Goliath
+ ::Goliath::ROOT_DIR = File.expand_path(File.join(File.dirname($0), '..')) unless defined?(::Goliath::ROOT_DIR)
+ def self.root_path(*dirs)
+ File.join(::Goliath::ROOT_DIR, *dirs)
+ end
+end
+# $LOAD_PATH.unshift(Goliath.root_path("lib")) unless $LOAD_PATH.include?(Goliath.root_path("lib"))
+
if defined? RACK_ENV
true #pass
elsif (idx = (ARGV.index('-e') || ARGV.index('--environment')))
View
@@ -35,7 +35,15 @@ Gem::Specification.new do |s|
"config/app.rb",
"config/app.yaml",
"lib/boot.rb",
- "lib/senor_armando/spec/senor_armando_he_helps_test.rb",
+ "lib/senor_armando.rb",
+ "lib/senor_armando/endpoint/echo.rb",
+ "lib/senor_armando/endpoint/proxy.rb",
+ "lib/senor_armando/error.rb",
+ "lib/senor_armando/plugins/statsd_plugin.rb",
+ "lib/senor_armando/rack/exception_handler.rb",
+ "lib/senor_armando/rack/statsd_logger.rb",
+ "lib/senor_armando/rack/tracer.rb",
+ "lib/senor_armando/spec/he_help_me_test.rb",
"lib/senor_armando/tasks.rb",
"lib/senor_armando/tasks/rspec.rake",
"lib/senor_armando/tasks/yard.rake",
Oops, something went wrong.

0 comments on commit 17e934a

Please sign in to comment.