Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/pyroute2/ndb/__pycache__/auth_manager.cpython-39.pyc
Ðазад
a ]�hW � @ s( d Z G dd� de�ZG dd� de�ZdS )a@ 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. c @ s e Zd Zdd� Zdd� ZdS )� check_authc C s || _ d S �N)�tag)�selfr � r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/pyroute2/ndb/auth_manager.py�__init__9 s zcheck_auth.__init__c s � �fdd�}� j |_ |S )Nc sl t � dd�s"�� g|�R i |��S � js0td��t� �fdd�� jD ��r`�� g|�R i |��S td��d S )NZ_init_completeTzaccess rejectedc s g | ]}|� � �j��qS r )�checkr )�.0�x)�objr r r � <listcomp>B � z6check_auth.__call__.<locals>.guard.<locals>.<listcomp>)�getattrZ auth_managers�PermissionError�all)r �argv�kwarg��fr )r r �guard= s z"check_auth.__call__.<locals>.guard)�__doc__)r r r r r r �__call__<