Skip to content

Commit 909ca5a

Browse files
authored
Защита ручки GET /file/{pin} (#86)
## Изменения добавил авторизацию ручки GET /file/{pin}
1 parent a818a52 commit 909ca5a

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

print_service/routes/file.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import aiofiles
66
import aiofiles.os
7+
from auth_lib.fastapi import UnionAuth
78
from fastapi import APIRouter, File, UploadFile
89
from fastapi.exceptions import HTTPException
910
from fastapi.params import Depends
@@ -159,7 +160,10 @@ async def send(inp: SendInput, settings: Settings = Depends(get_settings)):
159160
response_model=SendOutput,
160161
)
161162
async def upload_file(
162-
pin: str, file: UploadFile = File(...), settings: Settings = Depends(get_settings)
163+
pin: str,
164+
file: UploadFile = File(...),
165+
settings: Settings = Depends(get_settings),
166+
_=Depends(UnionAuth(scopes=["print.file.create"], allow_none=False, auto_error=True)),
163167
):
164168
"""Загрузить файл на сервер.
165169
@@ -229,7 +233,10 @@ async def upload_file(
229233
response_model=SendOutput,
230234
)
231235
async def update_file_options(
232-
pin: str, inp: SendInputUpdate, settings: Settings = Depends(get_settings)
236+
pin: str,
237+
inp: SendInputUpdate,
238+
settings: Settings = Depends(get_settings),
239+
_=Depends(UnionAuth(scopes=["print.file.update"], allow_none=False, auto_error=True)),
233240
):
234241
"""Обновляет настройки печати.
235242
@@ -275,7 +282,11 @@ async def update_file_options(
275282
},
276283
response_model=ReceiveOutput,
277284
)
278-
async def print_file(pin: str, settings: Settings = Depends(get_settings)):
285+
async def print_file(
286+
pin: str,
287+
settings: Settings = Depends(get_settings),
288+
_=Depends(UnionAuth(scopes=["print.file.get"], allow_none=False, auto_error=True)),
289+
):
279290
"""Получить файл для печати.
280291
281292
Требует пин-код, полученный в методе POST `/file`. Файл можно скачать

0 commit comments

Comments
 (0)