ActivityFormatter for object changes (auditlog)
Project description
deed - Python
ActivityFormatter for object changes (auditlog)
Usage
Try it on your python console:
from deed import AuditLog, AuditMode
# stored resource
resource = {'_id': '123', 'user_id': '123',
'customer_id': '123',
'title': "My amazing post"}
refs = [ # stakeholders
'post:' + resource['_id'],
'owner:' + resource['user_id'],
'customer:' + resource['customer_id'],
]
# update example
audit_log = AuditLog(resource_type='shipment',
action='update', audit_mode=AuditMode.DIFF)
audit_log.session(actor='user:admin@example.com', where='10.0.0.2',
channel='edit-form', stakeholders=refs)
patch = {'title': 'My first post'}
new_resource = {**resource, **patch}
audit_log.audit(resource, payload=new_resource)
Bottle Integration
from bottle import run, request, Bottle
from deed import AuditMode
from deed.bottle_kit import audit, DeedPlugin
from business.models import Post
api = Bottle()
api.install(DeedPlugin())
@api.put('/post/<id:int>')
@audit(resource_type='post', action='update', audit_mode=AuditMode.DIFF)
def update_post(id: int):
stored_post = Post.find(id)
payload = request.json
updated_post = {**stored_post, **payload}
Post.update(updated_post)
request.audit.session['actor'] = 'admin' # authorized user
request.audit.resource = stored_post
request.audit.payload = updated_post
return post
if __name__ == '__main__':
run(api, port=8080)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
deed-0.1.6.tar.gz
(5.1 kB
view details)
Built Distribution
deed-0.1.6-py3-none-any.whl
(6.1 kB
view details)
File details
Details for the file deed-0.1.6.tar.gz
.
File metadata
- Download URL: deed-0.1.6.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b68341f971e1f5f215a84c855b56482f30c5fd2edd8d06be4a8971b8741e70e4 |
|
MD5 | d1f1d46dfd9fb1b60bf1a5980a5aad40 |
|
BLAKE2b-256 | e3f9c8ff1e1fafb8059137470923f875be03abef25676091e94feb4d561471cb |
File details
Details for the file deed-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: deed-0.1.6-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32fcc836f00c565268c3f970f12704b1df96392ab25dbf5520ee7b970c1dd59a |
|
MD5 | cd90e9a8c66a2acd65fea194c6c97407 |
|
BLAKE2b-256 | 3c5bb9638f7c89f88a394622a3bbbd0dbbe7b2c9275931ab288c76bd47d5fd89 |