Sha256: f3093405ef33561628938419e8a10e1e90e58d0bca92bcc7c789fc1ed90f0fc8

Contents?: true

Size: 1.82 KB

Versions: 4

Compression:

Stored size: 1.82 KB

Contents

require 'ipaddr'
require 'puppet/network/authstore'

# Define a set of rights and who has access to them.
class Puppet::Network::Rights < Hash
    # We basically just proxy directly to our rights.  Each Right stores
    # its own auth abilities.
    [:allow, :allowed?, :deny].each do |method|
        define_method(method) do |name, *args|
            name = name.intern if name.is_a? String

            if obj = right(name)
                obj.send(method, *args)
            else
                raise ArgumentError, "Unknown right '%s'" % name
            end
        end
    end

    def [](name)
        name = name.intern if name.is_a? String
        super(name)
    end

    # Define a new right to which access can be provided.
    def newright(name)
        name = name.intern if name.is_a? String
        shortname = Right.shortname(name)
        if self.include? name
            raise ArgumentError, "Right '%s' is already defined" % name
        else
            self[name] = Right.new(name, shortname)
        end
    end

    private

    # Retrieve a right by name.
    def right(name)
        name = name.intern if name.is_a? String
        self[name]
    end

    # A right.
    class Right < Puppet::Network::AuthStore
        attr_accessor :name, :shortname

        Puppet::Util.logmethods(self, true)

        def self.shortname(name)
            name.to_s[0..0]
        end

        def initialize(name, shortname = nil)
            @name = name
            @shortname = shortname
            unless @shortname
                @shortname = Right.shortname(name)
            end
            super()
        end

        def to_s
            "access[%s]" % @name
        end

        # There's no real check to do at this point
        def valid?
            true
        end
    end
end

# $Id: rights.rb 2180 2007-02-08 02:22:57Z luke $

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
puppet-0.23.0 lib/puppet/network/rights.rb
puppet-0.22.4 lib/puppet/network/rights.rb
puppet-0.23.1 lib/puppet/network/rights.rb
puppet-0.23.2 lib/puppet/network/rights.rb