summaryrefslogtreecommitdiffstats
path: root/lib/puppet/server/pelement.rb
blob: 79157666670446fd4400a12f2af1ab95045c56ad (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
require 'puppet'
require 'puppet/server'

module Puppet

class Server::PElementServer
    attr_accessor :local

    @interface = XMLRPC::Service::Interface.new("fileserver") { |iface|
        iface.add_method("string describe(string, string, array, array)")
        iface.add_method("string list(string, string, boolean, array)")
    }

    # Describe a given object.  This returns the 'is' values for every state
    # available on the object type.
    def describe(type, name, retrieve = nil, ignore = [], format = "yaml", client = nil, clientip = nil)
        @local = true unless client
        typeklass = nil
        unless typeklass = Puppet.type(type)
            raise Puppet::Error, "Puppet type %s is unsupported" % type
        end

        obj = nil

        retrieve ||= :all

        if obj = typeklass[name]
            obj[:check] = retrieve
        else
            begin
                obj = typeklass.create(:name => name, :check => retrieve)
            rescue Puppet::Error => detail
                raise Puppet::Error, "%s[%s] could not be created: %s" %
                    [type, name, detail]
            end
        end

        trans = obj.to_trans

        # Now get rid of any attributes they specifically don't want
        ignore.each do |st|
            if trans.include? st
                trans.delete(st)
            end
        end

        if @local
            return trans
        else
            str = nil
            case format
            when "yaml":
                str = YAML.dump(trans)
            else
                raise XMLRPC::FaultException.new(
                    1, "Unavailable config format %s" % format
                )
            end
            return CGI.escape(str)
        end
    end

    # Create a new fileserving module.
    def initialize(hash = {})
        if hash[:Local]
            @local = hash[:Local]
        else
            @local = false
        end
    end

    def list(type, name, client = nil, clientip = nil)
    end

    private

    def authcheck(file, mount, client, clientip)
        unless mount.allowed?(client, clientip)
            mount.warning "%s cannot access %s" %
                [client, file]
            raise Puppet::Server::AuthorizationError, "Cannot access %s" % mount
        end
    end

    # Deal with ignore parameters.
    def handleignore(children, path, ignore)            
        ignore.each { |ignore|                
            Dir.glob(File.join(path,ignore), File::FNM_DOTMATCH) { |match|
                children.delete(File.basename(match))
            }                
        }
        return children
    end  

    def to_s
        "pelementserver"
    end
end
end

# $Id$