2
2
# Created by Luke Kanies on 2007-10-19.
3
3
# Copyright (c) 2007. All rights reserved.
5
require 'puppet/util/uri_helper'
6
5
require 'puppet/file_serving/configuration'
7
6
require 'puppet/file_serving/fileset'
8
7
require 'puppet/file_serving/terminus_helper'
11
10
# Look files up using the file server.
12
11
class Puppet::Indirector::FileServer < Puppet::Indirector::Terminus
13
include Puppet::Util::URIHelper
14
12
include Puppet::FileServing::TerminusHelper
16
14
# Is the client authorized to perform this action?
17
15
def authorized?(request)
18
16
return false unless [:find, :search].include?(request.method)
20
uri = key2uri(request.key)
18
mount, file_path = configuration.split_path(request)
22
configuration.authorized?(uri.path, :node => request.node, :ipaddress => request.ip)
20
# If we're not serving this mount, then access is denied.
21
return false unless mount
22
return mount.allowed?(request.node, request.ip)
25
25
# Find our key using the fileserver.
27
return nil unless path = find_path(request)
28
result = model.new(request.key, :path => path)
27
mount, relative_path = configuration.split_path(request)
29
return nil unless mount
31
# The mount checks to see if the file exists, and returns nil
33
return nil unless path = mount.find(relative_path, request)
34
result = model.new(path)
29
35
result.links = request.options[:links] if request.options[:links]
33
40
# Search for files. This returns an array rather than a single
35
42
def search(request)
36
return nil unless path = find_path(request)
38
path2instances(request, path)
43
mount, relative_path = configuration.split_path(request)
45
unless mount and paths = mount.search(relative_path, request)
46
Puppet.info "Could not find filesystem info for file '%s' in environment %s" % [request.key, request.environment]
50
filesets = paths.collect do |path|
51
# Filesets support indirector requests as an options collection
52
Puppet::FileServing::Fileset.new(path, request)
55
Puppet::FileServing::Fileset.merge(*filesets).collect do |file, base_path|
56
inst = model.new(base_path, :relative_path => file)
57
inst.links = request.options[:links] if request.options[:links]