This library provides a simple interface for auditing of user actions in Flask-based web applications.
Example
To setup auditing, simply import the package and run the setup method with the appropriate arguments. As an example, let's consider a postgres database. First, spin up the database via docker
docker run --name my-postgres -p 5432:5432 -d postgres
Next, setup the connection to the database,
import auditing
args_to_postgres = dict(database="mydb", user="postgres", host="127.0.0.1")
auditing.setup("postgres_auto", args=args_to_postgres)
The special "postgres_auto" driver creates databases and tables dynamically. Furthermore, it extends tables when new data entries are added to the audit call. If this behaviour is not desired, simply use the "postgres" driver instead. Subsequently, auditing can be performed as
from auditing import audit
audit("mytag", a="some data", c="some other data", b=0, username="me")
where "mytag" identifies the audit collection (in postgres sql it will map to the table name) while the following keyword arguments denotes the data. The current datetime is always appended unless overwritten via the "dt" argument. Querying the database
docker exec -it my-postgres bash
psql -U postgres
\c mydb
select * from mytag;
now yields
username | datetime | a | c | b
----------+----------------------------+-----------+-----------------+---
me | 2019-12-05 13:55:55.636742 | some data | some other data | 0
If the username is not provided, an attempt is made to extract it from the session context. If the user cannot be identified, the audit is cancelled. If the audit is made within a request context, the following data is appended
- path, host, ip (from "X-Forwarded-For" header)
[*] In addition to postgres, elastic search is supported. Other databases can also be used, simply inject a driver via the "inject_driver" method.
Deployment
Bump the version number in setup.py and run
python3 setup.py sdist
pip3 install twine
twine upload dist/*
Metadata
Release files for auditing 0.0.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| auditing-0.0.12.tar.gz | 5.7 kB | Without provenance | Details for auditing-0.0.12.tar.gz |
Release files / auditing-0.0.12.tar.gz
| Download URL | auditing-0.0.12.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd50faa32bb1cb60e740bf0aeea19b8b81fcb24e6376e0c36bb84767199add1c
|
|
BLAKE2b-256 checksum How to use checksums |
b8439fd63d80f3a48b561f254f8f7bd49a404dd9f6fa11e9130ea68f7117b31d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9
|
Security for auditing 0.0.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.