diff options
author | Rick Bradley <rick@rickbradley.com> | 2008-04-02 19:29:04 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-04-11 13:11:28 -0500 |
commit | 93bc1a946f2da6e7c78a38ff90dac8a20b1bcbc7 (patch) | |
tree | af2894a72c59138abdf5a53bcf5e9d7b33948b29 /lib/puppet | |
parent | 99b295b8301d7a89c97ecdc1d636c2d2b7f1ae8e (diff) | |
download | puppet-93bc1a946f2da6e7c78a38ff90dac8a20b1bcbc7.tar.gz puppet-93bc1a946f2da6e7c78a38ff90dac8a20b1bcbc7.tar.xz puppet-93bc1a946f2da6e7c78a38ff90dac8a20b1bcbc7.zip |
adding REST save support, with integration tests. A handful of unit tests in that area now need to be updated.
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/indirector/rest.rb | 27 | ||||
-rw-r--r-- | lib/puppet/network/http/handler.rb | 12 |
2 files changed, 21 insertions, 18 deletions
diff --git a/lib/puppet/indirector/rest.rb b/lib/puppet/indirector/rest.rb index 33ae34006..889f63648 100644 --- a/lib/puppet/indirector/rest.rb +++ b/lib/puppet/indirector/rest.rb @@ -4,47 +4,46 @@ require 'uri' # Access objects via REST class Puppet::Indirector::REST < Puppet::Indirector::Terminus def network_fetch(path) - network(path, 'get') + Net::HTTP.start("127.0.0.1", 34343) {|x| x.get("/#{path}").body } end def network_delete(path) - network(path, 'delete') + Net::HTTP.start("127.0.0.1", 34343) {|x| x.delete("/#{path}").body } end def network_put(path, data) - network(path, 'put', data) - end - - def network(path, meth, data = nil) - # TODO: include data here, for #save - Net::HTTP.start("127.0.0.1", 34343) {|x| x.send(meth.to_sym, "/#{path}").body } # weird-ass net/http library + Net::HTTP.start("127.0.0.1", 34343) {|x| x.put("/#{path}", data).body } end def find(name, options = {}) network_result = network_fetch("#{indirection.name}/#{name}") raise YAML.load(network_result) if exception?(network_result) - decoded_result = indirection.model.from_yaml(network_result) + indirection.model.from_yaml(network_result) end def search(name, options = {}) network_results = network_fetch("#{indirection.name}s/#{name}") raise YAML.load(network_results) if exception?(network_results) - decoded_results = YAML.load(network_results.to_s).collect {|result| indirection.model.from_yaml(result) } + YAML.load(network_results.to_s).collect {|result| indirection.model.from_yaml(result) } end def destroy(name, options = {}) network_result = network_delete("#{indirection.name}/#{name}") raise YAML.load(network_result) if exception?(network_result) - decoded_result = YAML.load(network_result.to_s) + YAML.load(network_result.to_s) end - def save - + def save(obj, options = {}) + network_result = network_put("#{indirection.name}/", obj.to_yaml) + # TODO: swap these two lines out: + raise network_result.inspect if exception?(network_result) + # raise YAML.load(network_result) if exception?(network_result) + indirection.model.from_yaml(network_result) end private def exception?(yaml_string) - yaml_string =~ %r{--- !ruby/exception} + yaml_string =~ %r{--- !ruby/exception} end end diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb index 9e6c28512..7113c92d3 100644 --- a/lib/puppet/network/http/handler.rb +++ b/lib/puppet/network/http/handler.rb @@ -44,13 +44,17 @@ module Puppet::Network::HTTP::Handler end def do_save(request, response) - data = body(request) + data = body(request).to_s raise ArgumentError, "No data to save" if !data or data.empty? - args = params(request) - obj = model.new - result = obj.save(args.merge(:data => data)).to_yaml + # args = params(request) + obj = model.from_yaml(data) + result = save_object(obj).to_yaml encode_result(request, response, result) end + + def save_object(obj) + obj.save + end def do_exception(request, response, exception, status=404) encode_result(request, response, exception.to_yaml, status) |