Skip to content

Utility for user impersonation by running instructions under given user account

License

Notifications You must be signed in to change notification settings

codectl/impersonation

Repository files navigation

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.

About

Utility for user impersonation by running instructions under given user account

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages