A utility that allows a certain routine to run under a given user. To achieve this, a
process will run under the uid
and gid
of the intended user. For that
reason, it is a requirement that the running process has SETUID
and
SETGID
capabilities.
- decorator for instance methods
- decorator for
classmethod
andstaticmethod
- decorator for classes
Install the package directly from PyPI
(recommended):
$ pip install -U impersonation
A simple example on how to work with a Flask
application:
from impersonation import impersonate
# it works on functions
@impersonate("username")
def printer(string):
print(string)
# ... and classes
@impersonate("username")
class Printer:
def __init__(self, prefix=""):
self.prefix = prefix
def printer1(self, string):
print(f"{self.prefix}{string}")
@staticmethod
def printer2(string):
print(string)
Run tests with tox
:
# ensure tox is installed
$ tox
Run linter only:
$ tox -e lint
Optionally, run coverage as well with:
$ tox -e coverage
MIT licensed. See LICENSE.