Skip to content

Latest commit

 

History

History
94 lines (69 loc) · 2.33 KB

README.rst

File metadata and controls

94 lines (69 loc) · 2.33 KB

impersonation

PyPI version CI codecov Python compatibility code style: black license: MIT

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.

Features

  • decorator for instance methods
  • decorator for classmethod and staticmethod
  • decorator for classes

Installation

Install the package directly from PyPI (recommended):

$ pip install -U impersonation

Example usage

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)

Tests & linting 🚥

Run tests with tox:

# ensure tox is installed
$ tox

Run linter only:

$ tox -e lint

Optionally, run coverage as well with:

$ tox -e coverage

License

MIT licensed. See LICENSE.