diff options
| author | Luke Kanies <luke@madstop.com> | 2009-03-18 01:00:56 -0500 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2009-03-20 18:27:08 +1100 |
| commit | a497263d97229489dcc4341cc98ca3c75f116374 (patch) | |
| tree | 8fdeb5589e4ba48aadb624c75448b4a23cd246e3 /lib | |
| parent | 3e954997f7688f0193010de776879d23545a8ca5 (diff) | |
| download | puppet-a497263d97229489dcc4341cc98ca3c75f116374.tar.gz puppet-a497263d97229489dcc4341cc98ca3c75f116374.tar.xz puppet-a497263d97229489dcc4341cc98ca3c75f116374.zip | |
Adding explicit optional attribute to indirection requests
Previously, any option that had a setter was treated
as an attribute, but now we're specifying the list of
attributes settable via options.
We also have a to_hash method that will take all of the
options and all of those attributes and join them
back into a hash. This method is used by the REST Handler
module, since it uses the indirection request internally.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/indirector/request.rb | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb index 5c577a05d..2ffed60e2 100644 --- a/lib/puppet/indirector/request.rb +++ b/lib/puppet/indirector/request.rb @@ -11,6 +11,8 @@ class Puppet::Indirector::Request attr_reader :indirection_name + OPTION_ATTRIBUTES = [:ip, :node, :authenticated, :ignore_terminus, :ignore_cache, :instance, :environment] + # Is this an authenticated request? def authenticated? # Double negative, so we just get true or false @@ -56,15 +58,9 @@ class Puppet::Indirector::Request self.indirection_name = indirection_name self.method = method - @options = options.inject({}) do |result, ary| - param, value = ary - if respond_to?(param.to_s + "=") - send(param.to_s + "=", value) - else - result[param] = value - end - result - end + set_attributes(options) + + @options = options.inject({}) { |hash, ary| hash[ary[0].to_sym] = ary[1]; hash } if key.is_a?(String) or key.is_a?(Symbol) # If the request key is a URI, then we need to treat it specially, @@ -130,6 +126,17 @@ class Puppet::Indirector::Request end.join("&") end + def to_hash + result = options.dup + + OPTION_ATTRIBUTES.each do |attribute| + if value = send(attribute) + result[attribute] = value + end + end + result + end + def to_s return uri if uri return "/%s/%s" % [indirection_name, key] @@ -137,6 +144,15 @@ class Puppet::Indirector::Request private + def set_attributes(options) + OPTION_ATTRIBUTES.each do |attribute| + if options.include?(attribute) + send(attribute.to_s + "=", options[attribute]) + options.delete(attribute) + end + end + end + # Parse the key as a URI, setting attributes appropriately. def set_uri_key(key) @uri = key |
