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