Class: Puppet::FileServing::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Util::Cacher
Defined in:
lib/puppet/file_serving/configuration.rb

Defined Under Namespace

Classes: Parser

Constant Summary collapse

Mount =
Puppet::FileServing::Mount

Instance Attribute Summary collapse

Attributes included from Util::Cacher::Expirer

#timestamp

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::Cacher

extended, included

Methods included from Util::Cacher::Expirer

#dependent_data_expired?, #expire

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



52
53
54
55
56
57
58
59
# File 'lib/puppet/file_serving/configuration.rb', line 52

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

Instance Attribute Details

#mountsObject (readonly)

Returns the value of attribute mounts.



30
31
32
# File 'lib/puppet/file_serving/configuration.rb', line 30

def mounts
  @mounts
end

Class Method Details

.createObject

Create our singleton configuration.



24
25
26
# File 'lib/puppet/file_serving/configuration.rb', line 24

def self.create
  configuration
end

Instance Method Details

#find_mount(mount_name, environment) ⇒ Object

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



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/puppet/file_serving/configuration.rb', line 35

def find_mount(mount_name, environment)
  # Reparse the configuration if necessary.
  readconfig

  if mount = mounts[mount_name]
    return mount
  end

  if environment.module(mount_name)
    Puppet::Util::Warnings.notice_once "DEPRECATION NOTICE: Files found in modules without specifying 'modules' in file path will be deprecated in the next major release.  Please fix module '#{mount_name}' when no 0.24.x clients are present"
    return mounts["modules"]
  end

  # This can be nil.
  mounts[mount_name]
end

#mounted?(name) ⇒ Boolean

Is a given mount available?

Returns:

  • (Boolean)


62
63
64
# File 'lib/puppet/file_serving/configuration.rb', line 62

def mounted?(name)
  @mounts.include?(name)
end

#split_path(request) ⇒ Object

Split the path into the separate mount point and path.

Raises:

  • (ArgumentError)


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/puppet/file_serving/configuration.rb', line 67

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 path '#{mount_name}'") unless mount_name =~ %r{^[-\w]+$}

  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) ⇒ Object



91
92
93
# File 'lib/puppet/file_serving/configuration.rb', line 91

def umount(name)
  @mounts.delete(name) if @mounts.include? name
end