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.1.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

flask_auditor-0.2.1-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for flask_auditor-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f85e47bdc174bde25beb037727203123cac33be5d615debf6b436dc949651ca5
MD5 e199228d5337e621358f51bcd0e659a6
BLAKE2b-256 831e385928f1dcc735787d1451c193dcc87cae627dcf9f6611d61d1490601902

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for flask_auditor-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 61e84bd6a068277a2102475f85371a815347f3735980651d55e8ba9af283fcb5
MD5 cb9a2f67812b9071129b5fe29e4e33d7
BLAKE2b-256 33486d93bef413da558b0e9086d7fb409e4bc05338aa834e03742834b0581792

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