$72 GRAYBYTE WORDPRESS FILE MANAGER $61

SERVER : in-mum-web1330.main-hosting.eu #1 SMP Mon Feb 10 22:45:17 UTC 2025
SERVER IP : 88.222.243.241 | ADMIN IP 216.73.216.63
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/python311/lib/python3.11/site-packages/pyroute2/ndb/

HOME
Current File : /opt/alt/python311/lib/python3.11/site-packages/pyroute2/ndb//auth_manager.py
'''

AAA concept
-----------

AAA refers to Authentication, Authorization and Accounting. NDB provides
a minimalistic API to integrate Authorization routines, leaving the
rest -- Authentication and Accounting -- to the user.

Some of NDB routines and RTNL object methods are guarded with a
parametrized decorator. The decorator takes the only parameter `tag`::

    @check_auth('obj:read')
    def __getitem__(self, key):
        ...

    @check_auth('obj:modify')
    def __setitem__(self, key, value):
        ...

AuthManager
-----------

The tag is checked by `AuthManager.check(...)` routine. The routine is
the only method that must be provided by AuthManager-compatible objects,
and must be defined as::

    def check(self, obj, tag):
        # -> True: grant access to the tag
        # -> False: reject access
        # -> raise Exception(): reject access with a specific exception
        ...

NDB module provides an example AuthManager::

    from pyroute2 import NDB
    from pyroute2.ndb.auth_manager import AuthManager

    ndb = NDB(log='debug')

    am = AuthManager({'obj:list': False,    # deny dump(), summary()
                      'obj:read': True,     # permit reading RTNL attributes
                      'obj:modify': True},  # permit add_ip(), commit() etc.
                     ndb.log.channel('auth'))

    ap = ndb.auth_proxy(am)
    ap.interfaces.summary()  # <-- fails with PermissionError

You can implement custom AuthManager classes, the only requirement -- they
must provide `.check(self, obj, tag)` routine, which returns `True` or
`False` or raises an exception.

'''


class check_auth(object):
    def __init__(self, tag):
        self.tag = tag

    def __call__(self, f):
        def guard(obj, *argv, **kwarg):
            if not getattr(obj, '_init_complete', True):
                return f(obj, *argv, **kwarg)
            if not obj.auth_managers:
                raise PermissionError('access rejected')
            if all([x.check(obj, self.tag) for x in obj.auth_managers]):
                return f(obj, *argv, **kwarg)
            raise PermissionError('access rejected')

        guard.__doc__ = f.__doc__
        return guard


class AuthManager(object):
    def __init__(self, auth, log, policy=False):
        self.auth = auth
        self.log = log
        self.policy = policy
        self.exception = PermissionError

    def check(self, obj, tag):
        ret = self.policy
        if isinstance(self.auth, dict):
            ret = self.auth.get(tag, self.policy)
        if not ret and self.exception:
            raise self.exception('%s access rejected' % (tag,))
        return ret

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
8 May 2024 6.33 PM
root / root
0755
__pycache__
--
8 May 2024 6.33 PM
root / root
0755
objects
--
8 May 2024 6.33 PM
root / root
0755
__init__.py
0 KB
8 May 2024 6.33 PM
root / root
0644
auth_manager.py
2.585 KB
8 May 2024 6.33 PM
root / root
0644
cli.py
2.251 KB
8 May 2024 6.33 PM
root / root
0644
cluster.py
0.979 KB
8 May 2024 6.33 PM
root / root
0644
compat.py
2.201 KB
8 May 2024 6.33 PM
root / root
0644
events.py
2.019 KB
8 May 2024 6.33 PM
root / root
0644
main.py
20.957 KB
8 May 2024 6.33 PM
root / root
0644
messages.py
0.24 KB
8 May 2024 6.33 PM
root / root
0644
noipdb.py
5.026 KB
8 May 2024 6.33 PM
root / root
0644
query.py
4.753 KB
8 May 2024 6.33 PM
root / root
0644
report.py
11.863 KB
8 May 2024 6.33 PM
root / root
0644
schema.py
32.043 KB
8 May 2024 6.33 PM
root / root
0644
source.py
16.562 KB
8 May 2024 6.33 PM
root / root
0644
task_manager.py
9.578 KB
8 May 2024 6.33 PM
root / root
0644
transaction.py
11.049 KB
8 May 2024 6.33 PM
root / root
0644
transport.py
6.201 KB
8 May 2024 6.33 PM
root / root
0644
view.py
16.504 KB
8 May 2024 6.33 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF