class Puppet::FileServing::Mount::File
Public Class Methods
localmap()
click to toggle source
# File lib/puppet/file_serving/mount/file.rb 4 def self.localmap 5 @localmap ||= { 6 "h" => Facter.value("hostname"), 7 "H" => [ 8 Facter.value("hostname"), 9 Facter.value("domain") 10 ].join("."), 11 "d" => Facter.value("domain") 12 } 13 end
Public Instance Methods
complete_path(relative_path, node)
click to toggle source
# File lib/puppet/file_serving/mount/file.rb 15 def complete_path(relative_path, node) 16 full_path = path(node) 17 18 raise ArgumentError.new(_("Mounts without paths are not usable")) unless full_path 19 20 # If there's no relative path name, then we're serving the mount itself. 21 return full_path unless relative_path 22 23 file = ::File.join(full_path, relative_path) 24 25 if !(Puppet::FileSystem.exist?(file) or Puppet::FileSystem.symlink?(file)) 26 Puppet.info(_("File does not exist or is not accessible: %{file}") % { file: file }) 27 return nil 28 end 29 30 file 31 end
find(short_file, request)
click to toggle source
Return an instance of the appropriate class.
# File lib/puppet/file_serving/mount/file.rb 34 def find(short_file, request) 35 complete_path(short_file, request.node) 36 end
path(node = nil)
click to toggle source
Return the path as appropriate, expanding as necessary.
# File lib/puppet/file_serving/mount/file.rb 39 def path(node = nil) 40 if expandable? 41 return expand(@path, node) 42 else 43 return @path 44 end 45 end
path=(path)
click to toggle source
Set the path.
# File lib/puppet/file_serving/mount/file.rb 48 def path=(path) 49 # FIXME: For now, just don't validate paths with replacement 50 # patterns in them. 51 if path =~ /%./ 52 # Mark that we're expandable. 53 @expandable = true 54 else 55 raise ArgumentError, _("%{path} does not exist or is not a directory") % { path: path } unless FileTest.directory?(path) 56 raise ArgumentError, _("%{path} is not readable") % { path: path } unless FileTest.readable?(path) 57 @expandable = false 58 end 59 @path = path 60 end
search(path, request)
click to toggle source
# File lib/puppet/file_serving/mount/file.rb 62 def search(path, request) 63 path = complete_path(path, request.node) 64 return nil unless path 65 [path] 66 end
validate()
click to toggle source
Verify our configuration is valid. This should really check to make sure at least someone will be allowed, but, eh.
# File lib/puppet/file_serving/mount/file.rb 70 def validate 71 raise ArgumentError.new(_("Mounts without paths are not usable")) if @path.nil? 72 end
Private Instance Methods
clientmap(node)
click to toggle source
Create a map for a specific node.
# File lib/puppet/file_serving/mount/file.rb 77 def clientmap(node) 78 { 79 "h" => node.sub(/\..*$/, ""), 80 "H" => node, 81 "d" => node.sub(/[^.]+\./, "") # domain name 82 } 83 end
expand(path, node = nil)
click to toggle source
Replace % patterns as appropriate.
# File lib/puppet/file_serving/mount/file.rb 86 def expand(path, node = nil) 87 # This map should probably be moved into a method. 88 map = nil 89 90 if node 91 map = clientmap(node) 92 else 93 Puppet.notice _("No client; expanding '%{path}' with local host") % { path: path } 94 # Else, use the local information 95 map = localmap 96 end 97 98 path.gsub(/%(.)/) do |v| 99 key = $1 100 if key == "%" 101 "%" 102 else 103 map[key] || v 104 end 105 end 106 end
expandable?()
click to toggle source
Do we have any patterns in our path, yo?
# File lib/puppet/file_serving/mount/file.rb 109 def expandable? 110 if defined?(@expandable) 111 @expandable 112 else 113 false 114 end 115 end
localmap()
click to toggle source
Cache this manufactured map, since if it's used it's likely to get used a lot.
# File lib/puppet/file_serving/mount/file.rb 119 def localmap 120 self.class.localmap 121 end