diff --git a/src/reliqua/auth.py b/src/reliqua/auth.py index 412cfa6..8ee552f 100644 --- a/src/reliqua/auth.py +++ b/src/reliqua/auth.py @@ -677,6 +677,11 @@ def process_resource(self, req, resp, resource, _params): user = None authorized = False + # if resource has explicit no_auth, always skip + # authentication. + if getattr(resource, "no_auth", False): + return + # check if request requires authentication if not self.control.authentication_required(req.uri_template, req.method, resource): return diff --git a/src/reliqua/docs.py b/src/reliqua/docs.py index 08f2ae4..38a29be 100644 --- a/src/reliqua/docs.py +++ b/src/reliqua/docs.py @@ -4,6 +4,8 @@ Copyright 2016-2024. """ +from reliqua.resources.base import Resource + def default_responses(): """Return default response schema.""" @@ -17,7 +19,7 @@ def default_responses(): } -class Docs: +class Docs(Resource): """ Documents endpoint class. @@ -59,6 +61,8 @@ class Docs: The return type of the method. """ + no_auth = True + def __init__(self, schema): """ Create Docs instance. diff --git a/src/reliqua/swagger.py b/src/reliqua/swagger.py index 106b58b..534754d 100644 --- a/src/reliqua/swagger.py +++ b/src/reliqua/swagger.py @@ -4,6 +4,8 @@ Copyright 2016-2024. """ +from reliqua.resources.base import Resource + from .status_codes import HTTP @@ -57,15 +59,20 @@ def index(spec, server, sort="alpha", highlight="true"): """ -class Swagger: +class Swagger(Resource): """Class to server the static swagger files.""" - def __init__(self, url, openapi_url, sort="alpha", highlight=True): + no_auth = True + + def __init__(self, url, openapi_url, sort="alpha", highlight=True, authenticate=False): """ Create a Swagger instance. :param str url: URL to Swagger instance - :param str swagger_file: URL to Swagger file + :param str openapi_url: URL to OpenAPI spec + :param srt sort: Tag/Endpoint sort order + :param bool highlight: Syntax highlighting + :param bool authenticate: Docs need authentication :return: None """ self.url = url