summaryrefslogtreecommitdiffstats
path: root/lib/puppet/file_serving
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/file_serving')
-rw-r--r--lib/puppet/file_serving/configuration.rb43
-rw-r--r--lib/puppet/file_serving/configuration/parser.rb11
-rw-r--r--lib/puppet/file_serving/mount.rb28
-rw-r--r--lib/puppet/file_serving/terminus_helper.rb22
-rw-r--r--lib/puppet/file_serving/terminus_selector.rb4
5 files changed, 24 insertions, 84 deletions
diff --git a/lib/puppet/file_serving/configuration.rb b/lib/puppet/file_serving/configuration.rb
index 6cd99b267..03be1b9dd 100644
--- a/lib/puppet/file_serving/configuration.rb
+++ b/lib/puppet/file_serving/configuration.rb
@@ -28,21 +28,14 @@ class Puppet::FileServing::Configuration
private_class_method :new
- # Return a content instance.
- def content(path, options = {})
- mount, file_path = split_path(path, options[:node])
-
- return nil unless mount
-
- mount.file_instance :content, file_path, options
- end
-
# Search for a file.
def file_path(key, options = {})
mount, file_path = split_path(key, options[:node])
return nil unless mount
+ # The mount checks to see if the file exists, and returns nil
+ # if not.
return mount.file(file_path, options)
end
@@ -55,15 +48,6 @@ class Puppet::FileServing::Configuration
readconfig(false)
end
- # Return a metadata instance.
- def metadata(path, options = {})
- mount, file_path = split_path(path, options[:node])
-
- return nil unless mount
-
- mount.file_instance :metadata, file_path, options
- end
-
# Is a given mount available?
def mounted?(name)
@mounts.include?(name)
@@ -85,27 +69,6 @@ class Puppet::FileServing::Configuration
return children
end
- # Return the mount for the Puppet modules; allows file copying from
- # the modules.
- def modules_mount(module_name, client)
- unless hostname = (client || Facter.value("hostname"))
- raise ArgumentError, "Could not find hostname"
- end
- if node = Puppet::Node.find(hostname)
- env = node.environment
- else
- env = nil
- end
-
- # And use the environment to look up the module.
- mod = Puppet::Module::find(module_name, env)
- if mod
- return @mounts[Mount::MODULES].copy(mod.name, mod.files)
- else
- return nil
- end
- end
-
# Read the configuration file.
def readconfig(check = true)
config = Puppet[:fileserverconfig]
@@ -139,7 +102,7 @@ class Puppet::FileServing::Configuration
# Strip off the mount name.
mount_name, path = uri.sub(%r{^/}, '').split(File::Separator, 2)
- return nil unless mount = modules_mount(mount_name, node) || @mounts[mount_name]
+ return nil unless mount = @mounts[mount_name]
if path == ""
path = nil
diff --git a/lib/puppet/file_serving/configuration/parser.rb b/lib/puppet/file_serving/configuration/parser.rb
index 5b17d9801..707c3f9b1 100644
--- a/lib/puppet/file_serving/configuration/parser.rb
+++ b/lib/puppet/file_serving/configuration/parser.rb
@@ -3,6 +3,7 @@ require 'puppet/util/loadedfile'
class Puppet::FileServing::Configuration::Parser < Puppet::Util::LoadedFile
Mount = Puppet::FileServing::Mount
+ MODULES = 'modules'
# Parse our configuration file.
def parse
@@ -52,10 +53,10 @@ class Puppet::FileServing::Configuration::Parser < Puppet::Util::LoadedFile
# Add the mount for getting files from modules.
def add_module_mount
- unless @mounts[Mount::MODULES]
- mount = Mount.new(Mount::MODULES)
+ unless @mounts[MODULES]
+ mount = Mount.new(MODULES)
mount.allow("*")
- @mounts[Mount::MODULES] = mount
+ @mounts[MODULES] = mount
end
end
@@ -98,8 +99,8 @@ class Puppet::FileServing::Configuration::Parser < Puppet::Util::LoadedFile
# Set the path for a mount.
def path(mount, value)
- if mount.name == Mount::MODULES
- Puppet.warning "The '#{Mount::MODULES}' module can not have a path. Ignoring attempt to set it"
+ if mount.name == MODULES
+ Puppet.warning "The '#{MODULES}' module can not have a path. Ignoring attempt to set it"
else
begin
mount.path = value
diff --git a/lib/puppet/file_serving/mount.rb b/lib/puppet/file_serving/mount.rb
index be67e6d2b..8e5bd03e8 100644
--- a/lib/puppet/file_serving/mount.rb
+++ b/lib/puppet/file_serving/mount.rb
@@ -13,10 +13,12 @@ require 'puppet/file_serving/content'
class Puppet::FileServing::Mount < Puppet::Network::AuthStore
include Puppet::Util::Logging
- # A constant that defines how we refer to our modules mount.
- MODULES = "modules"
+ @@localmap = nil
- InstanceTypes = {:metadata => Puppet::FileServing::Metadata, :content => Puppet::FileServing::Content}
+ # Clear the cache. This is only ever used for testing.
+ def self.clear_cache
+ @@localmap = nil
+ end
attr_reader :name
@@ -30,14 +32,12 @@ class Puppet::FileServing::Mount < Puppet::Network::AuthStore
end
# Return an instance of the appropriate class.
- def file_instance(return_type, short_file, options = {})
- raise(ArgumentError, "Invalid file type %s" % return_type) unless InstanceTypes.include?(return_type)
-
+ def file(short_file, options = {})
file = file_path(short_file, options[:node])
return nil unless FileTest.exists?(file)
- return InstanceTypes[return_type].new(file)
+ return file
end
# Return a fully qualified path, given a short path and
@@ -85,11 +85,8 @@ class Puppet::FileServing::Mount < Puppet::Network::AuthStore
# Mark that we're expandable.
@expandable = true
else
- unless FileTest.exists?(path)
- raise ArgumentError, "%s does not exist" % path
- end
unless FileTest.directory?(path)
- raise ArgumentError, "%s is not a directory" % path
+ raise ArgumentError, "%s does not exist or is not a directory" % path
end
unless FileTest.readable?(path)
raise ArgumentError, "%s is not readable" % path
@@ -111,11 +108,7 @@ class Puppet::FileServing::Mount < Puppet::Network::AuthStore
# Verify our configuration is valid. This should really check to
# make sure at least someone will be allowed, but, eh.
def valid?
- if name == MODULES
- return @path.nil?
- else
- return ! @path.nil?
- end
+ return ! @path.nil?
end
private
@@ -157,6 +150,7 @@ class Puppet::FileServing::Mount < Puppet::Network::AuthStore
# Else, use the local information
map = localmap()
end
+
path.gsub(/%(.)/) do |v|
key = $1
if key == "%"
@@ -179,7 +173,7 @@ class Puppet::FileServing::Mount < Puppet::Network::AuthStore
# Cache this manufactured map, since if it's used it's likely
# to get used a lot.
def localmap
- unless defined? @@localmap
+ unless @@localmap
@@localmap = {
"h" => Facter.value("hostname"),
"H" => [Facter.value("hostname"),
diff --git a/lib/puppet/file_serving/terminus_helper.rb b/lib/puppet/file_serving/terminus_helper.rb
deleted file mode 100644
index b7f560c57..000000000
--- a/lib/puppet/file_serving/terminus_helper.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-#
-# Created by Luke Kanies on 2007-10-16.
-# Copyright (c) 2007. All rights reserved.
-
-require 'uri'
-require 'puppet/file_serving'
-require 'puppet/file_serving/configuration'
-
-module Puppet::FileServing::TerminusHelper
- def key2uri(key)
- # Return it directly if it's fully qualified.
- if key =~ /^#{::File::SEPARATOR}/
- key = "file://" + key
- end
-
- begin
- uri = URI.parse(URI.escape(key))
- rescue => detail
- raise ArgumentError, "Could not understand URI %s: %s" % [key, detail.to_s]
- end
- end
-end
diff --git a/lib/puppet/file_serving/terminus_selector.rb b/lib/puppet/file_serving/terminus_selector.rb
index 4525a8570..08009cd2b 100644
--- a/lib/puppet/file_serving/terminus_selector.rb
+++ b/lib/puppet/file_serving/terminus_selector.rb
@@ -29,6 +29,10 @@ module Puppet::FileServing::TerminusSelector
terminus = :mounts
end
+ if uri.path =~ /^\/modules\b/ and terminus == :mounts
+ terminus = :modules
+ end
+
return terminus
end
end