This basically consists of the node name (i.e., the certificate name),
the IP, and whether the request is authenticated (which is determined
by whether it provided a valid certificate).

Now the two REST classes (mongrel and webrick) need to correctly
pass this information to the indirection calls they make.

Signed-off-by: Luke Kanies <[EMAIL PROTECTED]>
---
 lib/puppet/indirector/request.rb |   24 ++++++++++++++++++++----
 spec/unit/indirector/request.rb  |   24 ++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb
index 68b7ee1..45c0667 100644
--- a/lib/puppet/indirector/request.rb
+++ b/lib/puppet/indirector/request.rb
@@ -3,10 +3,28 @@ require 'puppet/indirector'
 # Provide any attributes or functionality needed for indirected
 # instances.
 class Puppet::Indirector::Request
-    attr_accessor :indirection_name, :key, :method, :options, :instance
+    attr_accessor :indirection_name, :key, :method, :options, :instance, 
:node, :ip, :authenticated
+
+    # Is this an authenticated request?
+    def authenticated?
+        # Double negative, so we just get true or false
+        ! ! authenticated
+    end
 
     def initialize(indirection_name, method, key, options = {})
-        @indirection_name, @method, @options = indirection_name, method, 
(options || {})
+        options ||= {}
+        raise ArgumentError, "Request options must be a hash, not %s" % 
options.class unless options.is_a?(Hash)
+
+        @indirection_name, @method = indirection_name, 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
+        end
 
         if key.is_a?(String) or key.is_a?(Symbol)
             @key = key
@@ -14,8 +32,6 @@ class Puppet::Indirector::Request
             @instance = key
             @key = @instance.name
         end
-
-        raise ArgumentError, "Request options must be a hash, not %s" % 
@options.class unless @options.is_a?(Hash)
     end
 
     # Look up the indirection based on the name provided.
diff --git a/spec/unit/indirector/request.rb b/spec/unit/indirector/request.rb
index cdb40b1..4f0ad8b 100755
--- a/spec/unit/indirector/request.rb
+++ b/spec/unit/indirector/request.rb
@@ -43,6 +43,30 @@ describe Puppet::Indirector::Request do
         it "should use an empty options hash if nil was provided" do
             Puppet::Indirector::Request.new(:ind, :method, :key, 
nil).options.should == {}
         end
+
+        it "should default to a nil node" do
+            Puppet::Indirector::Request.new(:ind, :method, :key, 
nil).node.should be_nil
+        end
+
+        it "should set its node attribute if provided in the options" do
+            Puppet::Indirector::Request.new(:ind, :method, :key, :node => 
"foo.com").node.should == "foo.com"
+        end
+
+        it "should default to a nil ip" do
+            Puppet::Indirector::Request.new(:ind, :method, :key, 
nil).ip.should be_nil
+        end
+
+        it "should set its ip attribute if provided in the options" do
+            Puppet::Indirector::Request.new(:ind, :method, :key, :ip => 
"192.168.0.1").ip.should == "192.168.0.1"
+        end
+
+        it "should default to being unauthenticated" do
+            Puppet::Indirector::Request.new(:ind, :method, :key, 
nil).should_not be_authenticated
+        end
+
+        it "should set be marked authenticated if configured in the options" do
+            Puppet::Indirector::Request.new(:ind, :method, :key, 
:authenticated => "eh").should be_authenticated
+        end
     end
 
     it "should look use the Indirection class to return the appropriate 
indirection" do
-- 
1.5.3.7


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to