Skip to main content

An extension for Flask application to extract audit logs.

Project description

Flask-Auditor

Flask-Auditor is an extension for Flask that extract request and response to audit log.

Installing

Install and upgrade using pip:

$ pip install flask_auditor

A simple example

from flask import Flask
from flask import jsonify

from flask_auditor import FlaskAuditor

app = Flask(__name__)
app.config['AUDIT_LOGGER_SOURCE_NAME'] = 'auditLogger'
auditor = FlaskAuditor(app)


@app.route('/api/v1/users', methods=['GET'])
@auditor.log(action_id='LIST_USERS', description='Fetch a list of users')
def list_users():
    resp = jsonify({
        'users': [
            {
                'id': 1,
                'name': 'Makai'
            },
            {
                'id': 2,
                'name': 'TNiaH'
            }
        ]
    })
    resp.status_code = 200
    return resp


if __name__ == '__main__':
    app.run(debug=True)

Audit Log Example

{
  "source": "auditLogger",
  "startTime": "2024-05-22 11:45:42",
  "actionId": "LIST_USERS",
  "description": "Fetch a list of users",
  "request": {
    "serverHost": "127.0.0.1",
    "serverPort": 5000,
    "requestID": "N/A",
    "remoteIP": "127.0.0.1",
    "remotePort": 34038,
    "protocol": "HTTP/1.1",
    "host": "127.0.0.1:5000",
    "method": "GET",
    "uri": "/api/v1/users?page=1&limit=10",
    "uriPath": "/api/v1/users",
    "routePath": "/api/v1/users",
    "referer": "N/A",
    "userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
    "contentLength": "N/A",
    "headers": {
      "Accept-Encoding": "gzip, deflate, br"
    },
    "queryParams": {
      "page": [
        "1"
      ],
      "limit": [
        "10"
      ]
    },
    "requestBody": {}
  },
  "response": {
    "statusCode": 200,
    "status": "OK",
    "responseSize": 120
  },
  "latency": 0.00011
}

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

flask_auditor-0.2.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

flask_auditor-0.2.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file flask_auditor-0.2.0.tar.gz.

File metadata

  • Download URL: flask_auditor-0.2.0.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.12

File hashes

Hashes for flask_auditor-0.2.0.tar.gz
Algorithm Hash digest
SHA256 295b63bcbfd18ceda87a6e9856777b01dcab192bb09f86a54303a2f21bb1174f
MD5 0ea2f69f06d0e6af5b0db79f964dfa38
BLAKE2b-256 d99edd2366872d941f376cc14d87e191be902c03f4db8a17431baa8b8dbb55a2

See more details on using hashes here.

File details

Details for the file flask_auditor-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_auditor-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 646ae5d8055357fdca4be5d7f6204c66ca158a11f5e2bf3fa04723b528bdd290
MD5 8fc89216fbaeeeb2f409486723e8035f
BLAKE2b-256 5b3c5c04e315713d0bc10199d4d9de5977206fc5e72429b5dd5737e6189a3c22

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