summaryrefslogtreecommitdiffstats
path: root/lib/puppet/indirector/request.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-09-23 23:50:43 -0500
committerLuke Kanies <luke@madstop.com>2008-09-23 23:50:43 -0500
commitbb23861e334e617b544c11bc75a35c40b36185a2 (patch)
tree18da91858e4fded78a56d673fc69014fdf266676 /lib/puppet/indirector/request.rb
parente31df2f7f5e98c524b68cd724cfaa3e308e7b9a1 (diff)
parentac5db5ec115455e54090542870847820357739a2 (diff)
downloadpuppet-bb23861e334e617b544c11bc75a35c40b36185a2.tar.gz
puppet-bb23861e334e617b544c11bc75a35c40b36185a2.tar.xz
puppet-bb23861e334e617b544c11bc75a35c40b36185a2.zip
Merge branch 'feature/master/1481'
This merges in the new fileserving code -- we're now using REST to do fileserving, rather than xmlrpc. Conflicts: lib/puppet/parameter.rb lib/puppet/type/file.rb spec/unit/type/file.rb
Diffstat (limited to 'lib/puppet/indirector/request.rb')
-rw-r--r--lib/puppet/indirector/request.rb53
1 files changed, 50 insertions, 3 deletions
diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb
index 98fa38885..49cc01aab 100644
--- a/lib/puppet/indirector/request.rb
+++ b/lib/puppet/indirector/request.rb
@@ -1,10 +1,13 @@
require 'puppet/indirector'
-# Provide any attributes or functionality needed for indirected
-# instances.
+# This class encapsulates all of the information you need to make an
+# Indirection call, and as a a result also handles REST calls. It's somewhat
+# analogous to an HTTP Request object, except tuned for our Indirector.
class Puppet::Indirector::Request
attr_accessor :indirection_name, :key, :method, :options, :instance, :node, :ip, :authenticated
+ attr_accessor :server, :port, :uri, :protocol
+
# Is this an authenticated request?
def authenticated?
# Double negative, so we just get true or false
@@ -28,7 +31,15 @@ class Puppet::Indirector::Request
end
if key.is_a?(String) or key.is_a?(Symbol)
- @key = key
+ # If the request key is a URI, then we need to treat it specially,
+ # because it rewrites the key. We could otherwise strip server/port/etc
+ # info out in the REST class, but it seemed bad design for the REST
+ # class to rewrite the key.
+ if key.to_s =~ /^\w+:\/\// # it's a URI
+ set_uri_key(key)
+ else
+ @key = key
+ end
else
@instance = key
@key = @instance.name
@@ -39,4 +50,40 @@ class Puppet::Indirector::Request
def indirection
Puppet::Indirector::Indirection.instance(@indirection_name)
end
+
+ # Are we trying to interact with multiple resources, or just one?
+ def plural?
+ method == :search
+ end
+
+ private
+
+ # Parse the key as a URI, setting attributes appropriately.
+ def set_uri_key(key)
+ @uri = key
+ begin
+ uri = URI.parse(URI.escape(key))
+ rescue => detail
+ raise ArgumentError, "Could not understand URL %s: %s" % [source, detail.to_s]
+ end
+
+ # Just short-circuit these to full paths
+ if uri.scheme == "file"
+ @key = uri.path
+ return
+ end
+
+ @server = uri.host if uri.host
+
+ # If the URI class can look up the scheme, it will provide a port,
+ # otherwise it will default to '0'.
+ if uri.port.to_i == 0 and uri.scheme == "puppet"
+ @port = Puppet.settings[:masterport].to_i
+ else
+ @port = uri.port.to_i
+ end
+
+ @protocol = uri.scheme
+ @key = uri.path.sub(/^\//, '')
+ end
end