From 66acd51b6d8db8f122b2677b853bb1fd1256530e Mon Sep 17 00:00:00 2001 From: Ivan Golikov Date: Tue, 20 Dec 2022 08:05:21 +0100 Subject: [PATCH 1/2] Allowing to retrieve data only once --- src/rectes/main.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/rectes/main.py b/src/rectes/main.py index 6f8d0fb..26d66b8 100644 --- a/src/rectes/main.py +++ b/src/rectes/main.py @@ -1,4 +1,5 @@ from fastapi import FastAPI +from fastapi.exceptions import HTTPException from rectes.models import Secret, SecretSaveResult from rectes.redis_db import redis @@ -18,8 +19,18 @@ async def set_secret(data: Secret): } -@app.get("/secret/{secret_key}", response_model=Secret) +@app.get( + "/secret/{secret_key}", + response_model=Secret, + responses={404: {"description": "The item was not found"}}, +) async def get_secret(secret_key): + data = await redis.get(secret_key) + + if data is None: + raise HTTPException(404) + + await redis.delete(secret_key) return { - "data": await redis.get(secret_key), + "data": data, } -- 2.43.0 From 647d25a8a1f6b8a9e26c5d012b6fd7733f0913c6 Mon Sep 17 00:00:00 2001 From: Ivan Golikov Date: Tue, 24 Dec 2024 22:03:53 +0100 Subject: [PATCH 2/2] Ignoring __pycache__ --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f6c4a2c..b2c4cd9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ dist/ rectes.egg-info/ build/ conf/rectes.toml +__pycache__/ -- 2.43.0