Tag update over mongo ID

PEP8 changes and Updating tags over Mongo ID
This commit is contained in:
Marvin Martinson 2021-06-01 19:29:56 +00:00
parent ae1c5611e5
commit 00355354f1

View File

@ -21,6 +21,7 @@ app = Sanic("events")
monitor(app).expose_endpoint() monitor(app).expose_endpoint()
app.config.RESPONSE_TIMEOUT = 999 app.config.RESPONSE_TIMEOUT = 999
def cookie_login(func): def cookie_login(func):
@wraps(func) @wraps(func)
async def wrapped(request, *args, **kwargs): async def wrapped(request, *args, **kwargs):
@ -38,8 +39,8 @@ def cookie_login(func):
}, },
}, { }, {
"$set": { "$set": {
"last_seen": now, "last_seen": now
} }
}) })
return await func(request, *args, **kwargs) return await func(request, *args, **kwargs)
return wrapped return wrapped
@ -86,19 +87,18 @@ async def view_event(request):
events_emitted.inc() events_emitted.inc()
if event.get("operationType") == "update" and "tags" in event.get("updateDescription").get("updatedFields"): if event.get("operationType") == "update" and "tags" in event.get("updateDescription").get("updatedFields"):
await resp.write("event: tag-update\ndata: %s\n\n" % event["fullDocument"].get("common_name")) await resp.write("event: tag-update\ndata: %s\n\n" % str(event["documentKey"].get("_id")))
events_emitted.inc() events_emitted.inc()
if event.get("operationType") == "update" and "attributes" in event.get("updateDescription").get("updatedFields"): if event.get("operationType") == "update" and "attributes" in event.get("updateDescription").get("updatedFields"):
await resp.write("event: attribute-update\ndata: %s\n\n" % str(event["documentKey"].get("_id"))) await resp.write("event: attribute-update\ndata: %s\n\n" % str(event["documentKey"].get("_id")))
events_emitted.inc() events_emitted.inc()
if event.get("ns").get("coll") == "certidude_logs": if event.get("ns").get("coll") == "certidude_logs":
from pinecrypt.server.decorators import MyEncoder from pinecrypt.server.decorators import MyEncoder
obj=dict( obj = dict(
created=event["fullDocument"].get("created"), created=event["fullDocument"].get("created"),
message=event["fullDocument"].get("message"), message=event["fullDocument"].get("message"),
severity=event["fullDocument"].get("severity") severity=event["fullDocument"].get("severity")
@ -111,7 +111,7 @@ async def view_event(request):
@app.route("/api/event/request-signed/<id>") @app.route("/api/event/request-signed/<id>")
async def publish(request, id): async def publish(request, id):
pipeline = [{"$match": { "operationType": "update", "fullDocument.status": "signed", "documentKey._id": ObjectId(id)}}] pipeline = [{"$match": {"operationType": "update", "fullDocument.status": "signed", "documentKey._id": ObjectId(id)}}]
resp = await request.respond(content_type="application/x-x509-user-cert") resp = await request.respond(content_type="application/x-x509-user-cert")
async with app.db["certidude_certificates"].watch(pipeline, full_document="updateLookup") as stream: async with app.db["certidude_certificates"].watch(pipeline, full_document="updateLookup") as stream:
async for event in stream: async for event in stream: