summaryrefslogtreecommitdiffstats
path: root/lib/puppet/indirector/file_server.rb
blob: 2eb323d461ddb8609db2be386df5216921b21a2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#
#  Created by Luke Kanies on 2007-10-19.
#  Copyright (c) 2007. All rights reserved.

require 'puppet/util/uri_helper'
require 'puppet/file_serving/configuration'
require 'puppet/file_serving/fileset'
require 'puppet/file_serving/terminus_helper'
require 'puppet/indirector/terminus'

# Look files up using the file server.
class Puppet::Indirector::FileServer < Puppet::Indirector::Terminus
    include Puppet::Util::URIHelper
    include Puppet::FileServing::TerminusHelper

    # Is the client authorized to perform this action?
    def authorized?(method, key, options = {})
        return false unless [:find, :search].include?(method)

        uri = key2uri(key)

        configuration.authorized?(uri.path, :node => options[:node], :ipaddress => options[:ipaddress])
    end

    # Find our key using the fileserver.
    def find(key, options = {})
        return nil unless path = find_path(key, options)
        result =  model.new(key, :path => path)
        result.links = options[:links] if options[:links]
        return result
    end

    # Search for files.  This returns an array rather than a single
    # file.
    def search(key, options = {})
        return nil unless path = find_path(key, options)

        path2instances(key, path, options)
    end

    private

    # Our fileserver configuration, if needed.
    def configuration
        Puppet::FileServing::Configuration.create
    end

    # Find our path; used by :find and :search.
    def find_path(key, options)
        uri = key2uri(key)

        return nil unless path = configuration.file_path(uri.path, :node => options[:node])

        return path
    end
end