Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tniah/flask-audit-log
Flask-Auditor is an extension for Flask that extract request and response to audit log.
https://github.com/tniah/flask-audit-log
audit-log flask flask-extension python3
Last synced: 29 days ago
JSON representation
Flask-Auditor is an extension for Flask that extract request and response to audit log.
- Host: GitHub
- URL: https://github.com/tniah/flask-audit-log
- Owner: tniah
- License: apache-2.0
- Created: 2024-04-24T07:20:28.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-05-22T07:02:44.000Z (8 months ago)
- Last Synced: 2024-05-22T11:01:53.242Z (8 months ago)
- Topics: audit-log, flask, flask-extension, python3
- Language: Python
- Homepage: https://github.com/tniah/flask-audit-log
- Size: 53.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Flask-Auditor
Flask-Auditor is an extension for Flask that extracts request and response to audit log.
## Installing
Install and upgrade using pip:
```shell
$ pip install flask-auditor
```## A simple example
```py
from flask import Flask
from flask import jsonifyfrom 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 respif __name__ == '__main__':
app.run(debug=True)```
## Audit Log Example
```json
{
"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
}
```