diff options
author | Jesse Wolfe <jes5199@gmail.com> | 2010-03-29 17:10:40 -0700 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | 23ccefe0e8b51af19a0283c0d8eb3de09b6e4c31 (patch) | |
tree | f5a13141985b8956987b0aad3f84269be7902243 /lib | |
parent | d8e1b272ec321d5f86558672252de60983751a15 (diff) | |
download | puppet-23ccefe0e8b51af19a0283c0d8eb3de09b6e4c31.tar.gz puppet-23ccefe0e8b51af19a0283c0d8eb3de09b6e4c31.tar.xz puppet-23ccefe0e8b51af19a0283c0d8eb3de09b6e4c31.zip |
REST: hide Request object
This change to the REST branch restores some sanity by explicitly
allowing a destination URL for indirector save() calls,
removing a hack that I was using to accomplish this.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/application/resource.rb | 3 | ||||
-rw-r--r-- | lib/puppet/application/run.rb | 3 | ||||
-rw-r--r-- | lib/puppet/file_bucket/dipper.rb | 4 | ||||
-rw-r--r-- | lib/puppet/indirector.rb | 4 | ||||
-rw-r--r-- | lib/puppet/indirector/indirection.rb | 14 | ||||
-rw-r--r-- | lib/puppet/indirector/request.rb | 24 | ||||
-rw-r--r-- | lib/puppet/network/http/handler.rb | 2 | ||||
-rwxr-xr-x | lib/puppet/node/facts.rb | 2 |
8 files changed, 28 insertions, 28 deletions
diff --git a/lib/puppet/application/resource.rb b/lib/puppet/application/resource.rb index 0046fc1d8..ae4349850 100644 --- a/lib/puppet/application/resource.rb +++ b/lib/puppet/application/resource.rb @@ -83,8 +83,7 @@ Puppet::Application.new(:resource) do if params.empty? [ Puppet::Resource.find( key ) ] else - request = Puppet::Indirector::Request.new(:resource, :save, key) # Yuck. - [ Puppet::Resource.new( type, name, params ).save( request ) ] + [ Puppet::Resource.new( type, name, params ).save( key ) ] end else Puppet::Resource.search( key, {} ) diff --git a/lib/puppet/application/run.rb b/lib/puppet/application/run.rb index 26ca362ff..46d1b191f 100644 --- a/lib/puppet/application/run.rb +++ b/lib/puppet/application/run.rb @@ -120,13 +120,12 @@ Puppet::Application.new(:run) do print "Triggering %s\n" % host begin - request = Puppet::Indirector::Request.new(:run, :save, url) # Yuck. run_options = { :tags => @tags, :background => ! options[:foreground], :ignoreschedules => options[:ignoreschedules] } - run = Puppet::Run.new( run_options ).save( request ) + run = Puppet::Run.new( run_options ).save( url ) result = run.status rescue => detail puts detail.backtrace if Puppet[:trace] diff --git a/lib/puppet/file_bucket/dipper.rb b/lib/puppet/file_bucket/dipper.rb index c73d76345..b13e590a9 100644 --- a/lib/puppet/file_bucket/dipper.rb +++ b/lib/puppet/file_bucket/dipper.rb @@ -38,9 +38,7 @@ class Puppet::FileBucket::Dipper file_bucket_file = Puppet::FileBucket::File.new(contents, :bucket_path => @local_path, :path => file) dest_path = "#{@rest_path}#{file_bucket_file.name}" - request = Puppet::Indirector::Request.new(:file_bucket_file, :save, dest_path) - - file_bucket_file.save(request) + file_bucket_file.save(dest_path) return file_bucket_file.checksum_data rescue => detail puts detail.backtrace if Puppet[:trace] diff --git a/lib/puppet/indirector.rb b/lib/puppet/indirector.rb index 61ef2db29..91c759331 100644 --- a/lib/puppet/indirector.rb +++ b/lib/puppet/indirector.rb @@ -61,8 +61,8 @@ module Puppet::Indirector end module InstanceMethods - def save(*args) - self.class.indirection.save self, *args + def save(key = nil) + self.class.indirection.save key, self end end end diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 3c6414624..266758b84 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -116,14 +116,8 @@ class Puppet::Indirector::Indirection end # Set up our request object. - def request(method, instance_or_key, request_or_options = {}) - if request_or_options.is_a? Puppet::Indirector::Request - request = request_or_options - request.instance = instance_or_key - request.method = method - return request - end - Puppet::Indirector::Request.new(self.name, method, instance_or_key, request_or_options) + def request(*args) + Puppet::Indirector::Request.new(self.name, *args) end # Return the singleton terminus for this indirection. @@ -254,8 +248,8 @@ class Puppet::Indirector::Indirection # Save the instance in the appropriate terminus. This method is # normally an instance method on the indirected class. - def save(instance, request_or_options = nil) - request = request(:save, instance, request_or_options) + def save(key, instance = nil) + request = request(:save, key, instance) terminus = prepare(request) result = terminus.save(request) diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb index 14608d0dc..cd354ac16 100644 --- a/lib/puppet/indirector/request.rb +++ b/lib/puppet/indirector/request.rb @@ -52,9 +52,14 @@ class Puppet::Indirector::Request ignore_terminus end - def initialize(indirection_name, method, key, options = {}) - options ||= {} - raise ArgumentError, "Request options must be a hash, not %s" % options.class unless options.is_a?(Hash) + def initialize(indirection_name, method, key_or_instance, options_or_instance = {}) + if options_or_instance.is_a? Hash + options = options_or_instance + @instance = nil + else + options = {} + @instance = options_or_instance + end self.indirection_name = indirection_name self.method = method @@ -63,7 +68,13 @@ class Puppet::Indirector::Request @options = options.inject({}) { |hash, ary| hash[ary[0].to_sym] = ary[1]; hash } - if key.is_a?(String) or key.is_a?(Symbol) + if key_or_instance.is_a?(String) || key_or_instance.is_a?(Symbol) + key = key_or_instance + else + @instance = key_or_instance if ! @instance + end + + if 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 @@ -73,10 +84,9 @@ class Puppet::Indirector::Request else @key = key end - else - @instance = key - @key = @instance.name end + + @key = @instance.name if ! @key and @instance end # Look up the indirection based on the name provided. diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb index 01ca65023..ab853665c 100644 --- a/lib/puppet/network/http/handler.rb +++ b/lib/puppet/network/http/handler.rb @@ -165,7 +165,7 @@ module Puppet::Network::HTTP::Handler # LAK:NOTE This has to be here for testing; it's a stub-point so # we keep infinite recursion from happening. def save_object(ind_request, object) - object.save(ind_request) + object.save(ind_request.key) end def get?(request) diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb index dca435c7d..ed7fe1253 100755 --- a/lib/puppet/node/facts.rb +++ b/lib/puppet/node/facts.rb @@ -10,7 +10,7 @@ class Puppet::Node::Facts # We want to expire any cached nodes if the facts are saved. module NodeExpirer - def save(instance, *args) + def save(key, instance) Puppet::Node.expire(instance.name) super end |