summaryrefslogtreecommitdiffstats
path: root/lib/puppet/indirector
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2008-03-31 11:59:16 -0500
committerLuke Kanies <luke@madstop.com>2008-04-11 13:10:35 -0500
commit7a7343458402e493f690633f3cfa78abef316d28 (patch)
tree9ed3ef94f2816c34a95b6c16193ab8bfafe71fc5 /lib/puppet/indirector
parenta1c45790f6cac265a7bac7d63bfb8a3204ed228f (diff)
downloadpuppet-7a7343458402e493f690633f3cfa78abef316d28.tar.gz
puppet-7a7343458402e493f690633f3cfa78abef316d28.tar.xz
puppet-7a7343458402e493f690633f3cfa78abef316d28.zip
Much larger commit than I would like to land at once. This is all REST-related code. Two specs are failing related to how Mongrel is initialized for REST; will fix those shortly.
REST indirector now supports find, with deserialization. Network code in indirector now. Will still need to un-hardwire address/port for outbound connections. Will still need to urlencode path parameters. Code for search, destroy, update is coming, should be similar to find. Reworked how the Handler module is used. Needed to be included, rather than inherited. Needed to sidestep initializers for actual web servers (webrick, mongrel), needed to be possible to have handler-including class be used as a class (aka servlet) instead of as an instance. Webrick handler registration is now abstracted to "above" the servlet. Provided a #model method to use instead of @model in handler module. This allows neutering during testing. Brought class_for_protocol up into http/webrick class as a (tested) class method. Integration tests for rest indirection. Split server integration tests into mongrel and webrick tests. Got Node/REST working properly wrt the crazy-ass autoloader thing. We're now actually passing traffic w/ webrick, fwiw.
Diffstat (limited to 'lib/puppet/indirector')
-rw-r--r--lib/puppet/indirector/rest.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/puppet/indirector/rest.rb b/lib/puppet/indirector/rest.rb
index 7b7c932c4..4c54183c6 100644
--- a/lib/puppet/indirector/rest.rb
+++ b/lib/puppet/indirector/rest.rb
@@ -1,8 +1,16 @@
-require 'puppet/indirector/rest'
+require 'net/http'
+require 'uri'
# Access objects via REST
class Puppet::Indirector::REST < Puppet::Indirector::Terminus
+ def network_fetch(path)
+ # TODO: url_encode path, set proper server + port
+ Net::HTTP.get(URI.parse("http://127.0.0.1:34343/#{path}"))
+ end
+
def find(name, options = {})
- indirection.model.new(name)
+ network_result = network_fetch("#{indirection.name}/#{name}")
+ raise YAML.load(network_result) if network_result =~ %r{--- !ruby/exception}
+ decoded_result = indirection.model.from_yaml(network_result)
end
end