From eacbb963a586692558ee9d417c02daf1c8b91ca0 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 9 Mar 2020 19:13:32 +0100 Subject: [PATCH] Some more improvements, but i'm not satisfied yet --- royalnet/backpack/stars/api_token_create.py | 2 ++ royalnet/backpack/stars/api_token_info.py | 2 ++ royalnet/backpack/stars/api_token_passwd.py | 6 ++++-- royalnet/backpack/stars/api_user_find.py | 4 ++-- royalnet/backpack/stars/docs.py | 7 ++----- royalnet/constellation/api/apistar.py | 4 ++++ royalnet/version.py | 2 +- 7 files changed, 17 insertions(+), 10 deletions(-) diff --git a/royalnet/backpack/stars/api_token_create.py b/royalnet/backpack/stars/api_token_create.py index 831f3d7a..23a56f89 100644 --- a/royalnet/backpack/stars/api_token_create.py +++ b/royalnet/backpack/stars/api_token_create.py @@ -18,6 +18,8 @@ class ApiTokenCreateStar(ApiStar): tags = ["token"] + requires_auth = True + async def api(self, data: ApiData) -> ru.JSON: user = await data.user() try: diff --git a/royalnet/backpack/stars/api_token_info.py b/royalnet/backpack/stars/api_token_info.py index 3986e6dd..7626fc78 100644 --- a/royalnet/backpack/stars/api_token_info.py +++ b/royalnet/backpack/stars/api_token_info.py @@ -9,6 +9,8 @@ class ApiTokenInfoStar(ApiStar): tags = ["token"] + requires_auth = True + async def api(self, data: ApiData) -> ru.JSON: token = await data.token() return token.json() diff --git a/royalnet/backpack/stars/api_token_passwd.py b/royalnet/backpack/stars/api_token_passwd.py index 29a28d4b..6f04c496 100644 --- a/royalnet/backpack/stars/api_token_passwd.py +++ b/royalnet/backpack/stars/api_token_passwd.py @@ -9,15 +9,17 @@ from ..tables.tokens import Token class ApiTokenPasswdStar(ApiStar): path = "/api/token/passwd/v1" - methods = ["POST"] + methods = ["PUT"] summary = "Change Royalnet password for an user." + tags = ["token"] + parameters = { "new_password": "The password you want to set." } - tags = ["token"] + requires_auth = True async def api(self, data: ApiData) -> ru.JSON: TokenT = self.alchemy.get(Token) diff --git a/royalnet/backpack/stars/api_user_find.py b/royalnet/backpack/stars/api_user_find.py index c61b3fc3..009b8721 100644 --- a/royalnet/backpack/stars/api_user_find.py +++ b/royalnet/backpack/stars/api_user_find.py @@ -8,12 +8,12 @@ class ApiUserFindStar(ApiStar): summary = "Find a Royalnet user by one of their aliases." + tags = ["user"] + parameters = { "alias": "One of the aliases of the user to get." } - tags = ["user"] - async def api(self, data: ApiData) -> dict: user = await Alias.find_user(self.alchemy, data.session, data["alias"]) if user is None: diff --git a/royalnet/backpack/stars/docs.py b/royalnet/backpack/stars/docs.py index 4fb23645..fb395294 100644 --- a/royalnet/backpack/stars/docs.py +++ b/royalnet/backpack/stars/docs.py @@ -28,16 +28,13 @@ class DocsStar(PageStar): "paths": paths, "components": { "securitySchemes": { - "LoginTokenAuth": { + "RoyalnetLoginToken": { "type": "apiKey", "in": "query", "name": "token", } } - }, - "security": [ - {"LoginTokenAuth": []} - ] + } }) return HTMLResponse( diff --git a/royalnet/constellation/api/apistar.py b/royalnet/constellation/api/apistar.py index 62ccdd53..d7ba7549 100644 --- a/royalnet/constellation/api/apistar.py +++ b/royalnet/constellation/api/apistar.py @@ -19,6 +19,8 @@ class ApiStar(PageStar, ABC): tags: List[str] = [] + requires_auth: bool = False + async def page(self, request: Request) -> JSONResponse: if request.query_params: data = request.query_params @@ -74,4 +76,6 @@ class ApiStar(PageStar, ABC): "type": "string" } for parameter in cls.parameters] } + if cls.requires_auth: + result[method.lower()]["security"] = [{"RoyalnetLoginToken": ["logged_in"]}] return result diff --git a/royalnet/version.py b/royalnet/version.py index 214a6363..3e2df96c 100644 --- a/royalnet/version.py +++ b/royalnet/version.py @@ -1 +1 @@ -semantic = "5.6.1" +semantic = "5.6.2"