class FileServing::Configuration

Constants

Mount

Attributes

mounts[R]

Public Class Methods

configuration() click to toggle source
# File lib/puppet/file_serving/configuration.rb, line 14
def self.configuration
  synchronize do
    @configuration ||= new
  end
end
new() click to toggle source
# File lib/puppet/file_serving/configuration.rb, line 36
def initialize
  @mounts = {}
  @config_file = nil

  # We don't check to see if the file is modified the first time,
  # because we always want to parse at first.
  readconfig(false)
end

Public Instance Methods

find_mount(mount_name, environment) click to toggle source

Find the right mount. Does some shenanigans to support old-style module mounts.

# File lib/puppet/file_serving/configuration.rb, line 29
def find_mount(mount_name, environment)
  # Reparse the configuration if necessary.
  readconfig
  # This can be nil.
  mounts[mount_name]
end
mounted?(name) click to toggle source

Is a given mount available?

# File lib/puppet/file_serving/configuration.rb, line 46
def mounted?(name)
  @mounts.include?(name)
end
split_path(request) click to toggle source

Split the path into the separate mount point and path.

# File lib/puppet/file_serving/configuration.rb, line 51
def split_path(request)
  # Reparse the configuration if necessary.
  readconfig

  mount_name, path = request.key.split(File::Separator, 2)

  raise(ArgumentError, "Cannot find file: Invalid mount '#{mount_name}'") unless mount_name =~ %r{^[-\w]+$}
  raise(ArgumentError, "Cannot find file: Invalid relative path '#{path}'") if path and path.split('/').include?('..')

  return nil unless mount = find_mount(mount_name, request.environment)
  if mount.name == "modules" and mount_name != "modules"
    # yay backward-compatibility
    path = "#{mount_name}/#{path}"
  end

  if path == ""
    path = nil
  elsif path
    # Remove any double slashes that might have occurred
    path = path.gsub(/\/+/, "/")
  end

  return mount, path
end
umount(name) click to toggle source
# File lib/puppet/file_serving/configuration.rb, line 76
def umount(name)
  @mounts.delete(name) if @mounts.include? name
end