-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
35 lines (27 loc) · 828 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from lib.extra import *
from fastapi import FastAPI, Query
from pydantic import BaseModel, AnyHttpUrl
app = FastAPI()
r = redisCon()
class Item(BaseModel):
value: str
password: str = "abcd1234"
ttl: int = 604800
@app.put("/set/")
async def read_items(item: Item):
_id = getUID()
r.execute_command("rd_themis.cset {} {} {}".format(
_id, item.password, item.value))
r.expire(_id, item.ttl)
query_items = {"_id": _id}
return query_items
@app.get("/get/")
async def read_itemss(_id: str, password: str):
if _id == None:
value = "Does not exists, or the value has been expired"
try:
value = r.execute_command("rd_themis.cget {} {}".format(_id, password))
except:
value = "decryption failed"
query_items = {"value": value}
return query_items