summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2008-04-02 00:48:54 -0500
committerLuke Kanies <luke@madstop.com>2008-04-11 13:10:39 -0500
commitf28f20b675737741a98b1b87b4791f736a996d40 (patch)
treeb67032811412f78980fe0fd0d3efa96964e3df58 /lib/puppet
parent07974401178a8b46314971bc7a9858cff1d9797b (diff)
downloadpuppet-f28f20b675737741a98b1b87b4791f736a996d40.tar.gz
puppet-f28f20b675737741a98b1b87b4791f736a996d40.tar.xz
puppet-f28f20b675737741a98b1b87b4791f736a996d40.zip
Added support for destroy/DELETE over REST (including units & integrations on both webrick & mongrel).
Added pending specs for the trivialities in the REST network_fetch and network_delete methods. Refactored YAML exception detection out into a private helper method.
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/indirector/rest.rb35
1 files changed, 27 insertions, 8 deletions
diff --git a/lib/puppet/indirector/rest.rb b/lib/puppet/indirector/rest.rb
index 0c86b2706..076e96356 100644
--- a/lib/puppet/indirector/rest.rb
+++ b/lib/puppet/indirector/rest.rb
@@ -4,19 +4,38 @@ 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 network_delete(path)
+ Net::HTTP.start("127.0.0.1", 34343) {|x| x.delete("/#{path}").body } # weird-ass net/http library
+ end
+
def find(name, options = {})
- 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)
+ network_result = network_fetch("#{indirection.name}/#{name}")
+ raise YAML.load(network_result) if exception?(network_result)
+ decoded_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) }
+ 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)
+ end
+
+ def save
+
end
- def search(key, options = {})
- network_results = network_fetch("#{indirection.name}s/#{key}")
- raise YAML.load(network_results) if network_results =~ %r{--- !ruby/exception}
- decoded_results = YAML.load(network_results.to_s).collect {|result| indirection.model.from_yaml(result) }
+ private
+
+ def exception?(yaml_string)
+ yaml_string =~ %r{--- !ruby/exception}
end
end