forked from k-space/doorboy-proxy
Rolled out in prod
This commit is contained in:
9
main.py
9
main.py
@@ -9,9 +9,8 @@ import const
|
||||
|
||||
app = Sanic(__name__)
|
||||
|
||||
#mongodb = MongoClient('mongodb://172.21.27.1,172.21.27.2,172.21.27.3:27017/', replicaSet="kspace-mongo-set").kspace_accounting
|
||||
mongodb = AsyncIOMotorClient(const.MONGO_URI)
|
||||
mongodb = mongodb.get_default_database()
|
||||
db = mongodb.get_default_database()
|
||||
|
||||
DOORBOY_SECRET = os.environ["DOORBOY_SECRET"]
|
||||
|
||||
@@ -22,10 +21,10 @@ async def view_doorboy_uids(request):
|
||||
if request.headers.get('KEY') != DOORBOY_SECRET:
|
||||
return text("how about no")
|
||||
allowed_names = []
|
||||
async for obj in mongodb.member.find({"enabled": True}):
|
||||
async for obj in db.member.find({"enabled": True}):
|
||||
allowed_names.append(obj["_id"])
|
||||
allowed_uids = []
|
||||
async for obj in mongodb.inventory.find({"token.uid_hash": {"$exists":True}, "inventory.owner_id": {"$exists":True}, "token.enabled": True}, {"inventory.owner_id": True, "token.uid_hash": True }):
|
||||
async for obj in db.inventory.find({"token.uid_hash": {"$exists":True}, "inventory.owner_id": {"$exists":True}, "token.enabled": True}, {"inventory.owner_id": True, "token.uid_hash": True }):
|
||||
if obj["inventory"].pop("owner_id") in allowed_names:
|
||||
del obj["_id"]
|
||||
del obj["inventory"]
|
||||
@@ -50,7 +49,7 @@ async def view_longpoll(request):
|
||||
}
|
||||
]
|
||||
try:
|
||||
async with mongodb.eventlog.watch(pipeline) as stream:
|
||||
async with db.eventlog.watch(pipeline) as stream:
|
||||
await response.write("data: watch-stream-opened\n\n")
|
||||
async for event in stream:
|
||||
if event["fullDocument"].get("type") == "open-door":
|
||||
|
||||
Reference in New Issue
Block a user