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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file impersonation-1.1.0.tar.gz.

File metadata

  • Download URL: impersonation-1.1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.9.16 Linux/5.15.0-1034-azure

File hashes

Hashes for impersonation-1.1.0.tar.gz
Algorithm Hash digest
SHA256 75f629e1ccff9c34592c1013346c830d70a6b5a7f79a49108e0eee274937b3df
MD5 7c14da2425b50726710c9f1006b06e69
BLAKE2b-256 40402e2064598d1d23015ce7b39952a0719b9c30a0a06538bbf6507788117cb4

See more details on using hashes here.

File details

Details for the file impersonation-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: impersonation-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.9.16 Linux/5.15.0-1034-azure

File hashes

Hashes for impersonation-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8050910e1c5b45bb9094a5033cc82ba828e5d2f88fded3d6c4526642ceb8eedb
MD5 ff817cad232ac1c8027accc8e76c5ce9
BLAKE2b-256 3d3f1278310e11e2773ee89e973de21cddc9a998af01b5acdd8bcddd4f0eaf8f

See more details on using hashes here.

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