1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Fix errors and support token authentication

This commit is contained in:
Steffo 2020-03-09 15:44:40 +01:00
parent 668df043f4
commit 4049619c25
7 changed files with 15 additions and 24 deletions

View file

@ -4,7 +4,6 @@ from .api_login_royalnet import ApiLoginRoyalnetStar
from .api_token_info import ApiTokenInfoStar from .api_token_info import ApiTokenInfoStar
from .api_token_passwd import ApiTokenPasswdStar from .api_token_passwd import ApiTokenPasswdStar
from .api_token_create import ApiTokenCreateStar from .api_token_create import ApiTokenCreateStar
from .api_docs import ApiDocsStar
from .docs import DocsStar from .docs import DocsStar
# Enter the PageStars of your Pack here! # Enter the PageStars of your Pack here!
@ -14,7 +13,6 @@ available_page_stars = [
ApiTokenInfoStar, ApiTokenInfoStar,
ApiTokenPasswdStar, ApiTokenPasswdStar,
ApiTokenCreateStar, ApiTokenCreateStar,
ApiDocsStar,
DocsStar, DocsStar,
] ]

View file

@ -1,12 +0,0 @@
import royalnet.utils as ru
from royalnet.constellation.api import *
from royalnet.version import semantic
class ApiDocsStar(ApiStar):
path = "/api/docs"
summary = "Get the swagger.json file used to generate this documentation."
async def api(self, data: ApiData) -> ru.JSON:
return

View file

@ -13,7 +13,6 @@ class ApiTokenCreateStar(ApiStar):
summary = "Create a new login token of any duration." summary = "Create a new login token of any duration."
parameters = { parameters = {
"token": "Your current login token.",
"duration": "The duration in seconds of the new token." "duration": "The duration in seconds of the new token."
} }

View file

@ -5,11 +5,7 @@ from royalnet.constellation.api import *
class ApiTokenInfoStar(ApiStar): class ApiTokenInfoStar(ApiStar):
path = "/api/token/info/v1" path = "/api/token/info/v1"
summary = "Get info about a login token." summary = "Get info the current login token."
parameters = {
"token": "The login token to get info about.",
}
async def api(self, data: ApiData) -> ru.JSON: async def api(self, data: ApiData) -> ru.JSON:
token = await data.token() token = await data.token()

View file

@ -14,7 +14,6 @@ class ApiTokenPasswdStar(ApiStar):
summary = "Change Royalnet password for an user." summary = "Change Royalnet password for an user."
parameters = { parameters = {
"token": "Your current login token.",
"new_password": "The password you want to set." "new_password": "The password you want to set."
} }

View file

@ -19,13 +19,25 @@ class DocsStar(PageStar):
paths[star.path] = star.swagger() paths[star.path] = star.swagger()
spec = json.dumps({ spec = json.dumps({
"swagger": "2.0", "openapi": "3.0.0",
"info": { "info": {
"description": "Autogenerated Royalnet API documentation", "description": "Autogenerated Royalnet API documentation",
"title": "Royalnet", "title": "Royalnet",
"version": f"{semantic}", "version": f"{semantic}",
}, },
"paths": paths "paths": paths,
"components": {
"securitySchemes": {
"LoginTokenAuth": {
"type": "apiKey",
"in": "query",
"name": "token",
}
}
},
"security": [
{"LoginTokenAuth": []}
]
}) })
return HTMLResponse( return HTMLResponse(

View file

@ -56,7 +56,6 @@ class ApiStar(PageStar, ABC):
"operationId": cls.__name__, "operationId": cls.__name__,
"summary": cls.summary, "summary": cls.summary,
"description": cls.description, "description": cls.description,
"produces": ["application/json"],
"responses": { "responses": {
"200": {"description": "Success"}, "200": {"description": "Success"},
"400": {"description": "Bad request"}, "400": {"description": "Bad request"},