Skip to main content

Utility for user impersonation by running instructions under given user

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

impersonation-1.1.0.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

impersonation-1.1.0-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page