From 89a3738d2b0678ae8fb1e7191e01caf6c5ece1f9 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sun, 24 Aug 2008 12:18:42 -0500 Subject: Adding suitability as a requirement for a format being supported. Signed-off-by: Luke Kanies --- lib/puppet/network/format.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/puppet/network') diff --git a/lib/puppet/network/format.rb b/lib/puppet/network/format.rb index 5f259fa49..3e0a7d8aa 100644 --- a/lib/puppet/network/format.rb +++ b/lib/puppet/network/format.rb @@ -55,7 +55,8 @@ class Puppet::Network::Format end def supported?(klass) - klass.respond_to?(intern_method) and + suitable? and + klass.respond_to?(intern_method) and klass.respond_to?(intern_multiple_method) and klass.respond_to?(render_multiple_method) and klass.instance_methods.include?(render_method) -- cgit From 3101ea23e556081fe38502218034f02aafe0c5bf Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sun, 24 Aug 2008 13:02:16 -0500 Subject: Adding a hackish raw format. As the comment in the file says, we don't really have enough data to know what a good design would look like, and I think this format will be a bit of a one-off, so I'm just throwing up some barriers to keep people from doing silly things with it. Signed-off-by: Luke Kanies --- lib/puppet/network/formats.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'lib/puppet/network') diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb index 8e4c59fb3..c2a8b7ab6 100644 --- a/lib/puppet/network/formats.rb +++ b/lib/puppet/network/formats.rb @@ -42,7 +42,7 @@ Puppet::Network::FormatHandler.create(:marshal, :mime => "text/marshal") do Marshal.dump(instance) end - # Yaml monkey-patches Array, so this works. + # Marshal monkey-patches Array, so this works. def render_multiple(instances) Marshal.dump(instances) end @@ -54,3 +54,23 @@ Puppet::Network::FormatHandler.create(:marshal, :mime => "text/marshal") do end Puppet::Network::FormatHandler.create(:s, :mime => "text/plain") + +Puppet::Network::FormatHandler.create(:raw, :mime => "application/x-raw") do + def intern_multiple(klass, text) + raise NotImplementedError + end + + def render_multiple(instances) + raise NotImplementedError + end + + # LAK:NOTE The format system isn't currently flexible enough to handle + # what I need to support raw formats just for individual instances (rather + # than both individual and collections), but we don't yet have enough data + # to make a "correct" design. + # So, we hack it so it works for singular but fail if someone tries it + # on plurals. + def supported?(klass) + true + end +end -- cgit From 90e70227b0bb7cfd104ae34de8f7c2b7250edb09 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sun, 24 Aug 2008 14:10:39 -0500 Subject: Adding weights to network formats, and sorting them based on the weight. This way the new hackish RAW format will only ever be used if it's specifically chosen. Signed-off-by: Luke Kanies --- lib/puppet/network/format.rb | 9 ++++++++- lib/puppet/network/format_handler.rb | 5 ++++- lib/puppet/network/formats.rb | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) (limited to 'lib/puppet/network') diff --git a/lib/puppet/network/format.rb b/lib/puppet/network/format.rb index 3e0a7d8aa..21aead7cc 100644 --- a/lib/puppet/network/format.rb +++ b/lib/puppet/network/format.rb @@ -5,7 +5,7 @@ require 'puppet/provider/confiner' class Puppet::Network::Format include Puppet::Provider::Confiner - attr_reader :name, :mime + attr_reader :name, :mime, :weight def initialize(name, options = {}, &block) @name = name.to_s.downcase.intern @@ -17,6 +17,13 @@ class Puppet::Network::Format self.mime = "text/%s" % name end + if weight = options[:weight] + @weight = weight + options.delete(:weight) + else + @weight = 5 + end + unless options.empty? raise ArgumentError, "Unsupported option(s) %s" % options.keys end diff --git a/lib/puppet/network/format_handler.rb b/lib/puppet/network/format_handler.rb index 4c9f4e59e..f3c3380e1 100644 --- a/lib/puppet/network/format_handler.rb +++ b/lib/puppet/network/format_handler.rb @@ -61,7 +61,10 @@ module Puppet::Network::FormatHandler end def supported_formats - format_handler.formats.collect { |f| format_handler.format(f) }.find_all { |f| f.supported?(self) }.collect { |f| f.name } + format_handler.formats.collect { |f| format_handler.format(f) }.find_all { |f| f.supported?(self) }.collect { |f| f.name }.sort do |a, b| + # It's an inverse sort -- higher weight formats go first. + format_handler.format(b).weight <=> format_handler.format(a).weight + end end end diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb index c2a8b7ab6..85e8ce6f8 100644 --- a/lib/puppet/network/formats.rb +++ b/lib/puppet/network/formats.rb @@ -55,7 +55,8 @@ end Puppet::Network::FormatHandler.create(:s, :mime => "text/plain") -Puppet::Network::FormatHandler.create(:raw, :mime => "application/x-raw") do +# A very low-weight format so it'll never get chosen automatically. +Puppet::Network::FormatHandler.create(:raw, :mime => "application/x-raw", :weight => 1) do def intern_multiple(klass, text) raise NotImplementedError end -- cgit From 40e76fb83ef466425fec736abbf1913a6426bf01 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sun, 24 Aug 2008 20:53:25 -0500 Subject: Fixing the rest backends for webrick and mongrel so the get the whole request key. Also adding the Content work necessary to demonstrate that this is actually required. Signed-off-by: Luke Kanies --- lib/puppet/network/http/mongrel/rest.rb | 2 +- lib/puppet/network/http/webrick/rest.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet/network') diff --git a/lib/puppet/network/http/mongrel/rest.rb b/lib/puppet/network/http/mongrel/rest.rb index d265dde86..45d21ea62 100644 --- a/lib/puppet/network/http/mongrel/rest.rb +++ b/lib/puppet/network/http/mongrel/rest.rb @@ -35,7 +35,7 @@ class Puppet::Network::HTTP::MongrelREST < Mongrel::HttpHandler # return the key included in the request path def request_key(request) # LAK:NOTE See http://snurl.com/21zf8 [groups_google_com] - x = request.params[Mongrel::Const::REQUEST_PATH].split('/')[2] + x = request.params[Mongrel::Const::REQUEST_PATH].split('/', 3)[2] end # return the request body diff --git a/lib/puppet/network/http/webrick/rest.rb b/lib/puppet/network/http/webrick/rest.rb index 13f795fb2..f06914365 100644 --- a/lib/puppet/network/http/webrick/rest.rb +++ b/lib/puppet/network/http/webrick/rest.rb @@ -36,7 +36,7 @@ class Puppet::Network::HTTP::WEBrickREST < WEBrick::HTTPServlet::AbstractServlet def request_key(request) # LAK:NOTE See http://snurl.com/21zf8 [groups_google_com] - x = request.path.split('/')[2] + x = request.path.split('/', 3)[2] end def body(request) -- cgit From 151a54ff7ac69aa2fa1708188ad75e444158e8a2 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sun, 24 Aug 2008 21:17:15 -0500 Subject: Causing format selection to fail intelligently if no suitable format can be picked. Signed-off-by: Luke Kanies --- lib/puppet/network/http/handler.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/puppet/network') diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb index 6f5117b16..7c7abccf5 100644 --- a/lib/puppet/network/http/handler.rb +++ b/lib/puppet/network/http/handler.rb @@ -12,7 +12,18 @@ module Puppet::Network::HTTP::Handler # Which format to use when serializing our response. Just picks # the first value in the accept header, at this point. def format_to_use(request) - accept_header(request).split(/,\s*/)[0] + unless header = accept_header(request) + raise ArgumentError, "An Accept header must be provided to pick the right format" + end + + format = nil + header.split(/,\s*/).each do |name| + next unless format = Puppet::Network::FormatHandler.format(name) + next unless format.suitable? + return name + end + + raise "No specified acceptable formats (%s) are functional on this machine" % header end def initialize_for_puppet(args = {}) -- cgit From 8b45d13ab28837caf3bb09cc1c90ab61974bf4db Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 25 Aug 2008 18:00:42 -0700 Subject: Adding automatic attribute collection to the new fileserving code. Basically, this just includes a consistent method for collecting info (either content or metadata) and then calls that method when returning instances via the indirector. It's such a large commit mostly because of small changes in the normal code and large changes in the testing to accomodate those small changes. Signed-off-by: Luke Kanies --- lib/puppet/network/handler/fileserver.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/network') diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb index 183979429..14319ef96 100755 --- a/lib/puppet/network/handler/fileserver.rb +++ b/lib/puppet/network/handler/fileserver.rb @@ -75,7 +75,7 @@ class Puppet::Network::Handler return "" unless metadata.exist? begin - metadata.collect_attributes + metadata.collect rescue => detail puts detail.backtrace if Puppet[:trace] Puppet.err detail -- cgit