diff --git a/.gitignore b/.gitignore index 36f4d3f4..dafff4d7 100644 --- a/.gitignore +++ b/.gitignore @@ -168,3 +168,5 @@ env */__MACOSX .DS_Store + +docs/source \ No newline at end of file diff --git a/README.md b/README.md index 41a31fcf..36e69b5c 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ Install using github: `pip install git+https://github.com/italia/eudi-wallet-it-python` +Optionally for generate the documentation you need to install the following packages: +`pip install sphinx sphinx_rtd_theme` ## Usage @@ -91,6 +93,13 @@ backend to enable the OpenID4VP protocol. Please read this [README](README.SATOSA.md) any details about how to configure SaToSa with the OpenID4VP Relying Party backend. +## Setup Documentation +For generate the documentaation enter in the terminal the following commands: +```` +cd docs +sphinx-apidoc -o ./source ../pyeudiw +make html +```` ## Contribute diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 00000000..d4bb2cbb --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 00000000..4a4102dc --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,32 @@ +import os +import sys + +sys.path.insert(0, os.path.abspath('../pyeudiw/')) + +# Configuration file for the Sphinx documentation builder. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Project information ----------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information + +project = 'Pyeudiw' +copyright = '2023, Giuseppe De Marco' +author = 'Giuseppe De Marco' + +# -- General configuration --------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration + +extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] + +templates_path = ['_templates'] +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +#path = pathlib.Path(__file__).resolve() / '..' / '..' / 'pyeudiw' + +# -- Options for HTML output ------------------------------------------------- +# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output + +html_theme = 'alabaster' +html_static_path = ['_static'] diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 00000000..ff6677b6 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,20 @@ +.. Pyeudiw documentation master file, created by + sphinx-quickstart on Fri Dec 22 11:05:33 2023. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to Pyeudiw's documentation! +=================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 00000000..32bb2452 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/pyeudiw/satosa/backend.py b/pyeudiw/satosa/backend.py index 30a081ec..3c00a6dd 100644 --- a/pyeudiw/satosa/backend.py +++ b/pyeudiw/satosa/backend.py @@ -128,7 +128,7 @@ def register_endpoints(self) -> list[tuple[str, Callable[[Context], Response]]]: ) if k == 'get_response': self.registered_get_response_endpoint = _endpoint - elif k == 'redirect': + elif k == 'response': self.absolute_redirect_url = _endpoint elif k == 'request': self.absolute_request_url = _endpoint @@ -391,7 +391,7 @@ def request_endpoint(self, context: Context, *args: tuple) -> Redirect | JsonRes status="200" ) - def redirect_endpoint(self, context: Context, *args) -> JsonResponse: + def response_endpoint(self, context: Context, *args) -> JsonResponse: """ This endpoint is called by the User-Agent/Wallet Instance after the user has been authenticated. @@ -404,7 +404,7 @@ def redirect_endpoint(self, context: Context, *args) -> JsonResponse: :rtype: JsonResponse """ - self._log_function_debug("redirect_endpoint", context, "args", args) + self._log_function_debug("response_endpoint", context, "args", args) # check DPOP for WIA if any try: diff --git a/pyeudiw/tests/satosa/test_backend.py b/pyeudiw/tests/satosa/test_backend.py index fcf65f69..2caa4887 100644 --- a/pyeudiw/tests/satosa/test_backend.py +++ b/pyeudiw/tests/satosa/test_backend.py @@ -509,12 +509,12 @@ def test_request_endpoint(self, context): request_uri = CONFIG['metadata']['request_uris'][0] context.request_uri = request_uri - redirect_endpoint = self.backend.redirect_endpoint(context) + response_endpoint = self.backend.response_endpoint(context) - assert redirect_endpoint - assert redirect_endpoint.status == "200" - assert redirect_endpoint.message - msg = json.loads(redirect_endpoint.message) + assert response_endpoint + assert response_endpoint.status == "200" + assert response_endpoint.message + msg = json.loads(response_endpoint.message) assert msg["response"] header = decode_jwt_header(msg["response"]) diff --git a/pyeudiw/tests/settings.py b/pyeudiw/tests/settings.py index 6a940ea5..4b45172f 100644 --- a/pyeudiw/tests/settings.py +++ b/pyeudiw/tests/settings.py @@ -28,7 +28,7 @@ "endpoints": { "entity_configuration": "/.well-known/openid-federation", "pre_request": "/pre-request", - "redirect": "/redirect-uri", + "response": "/redirect-uri", "request": "/request-uri", "status": "/status-uri", "get_response": "/get-response", diff --git a/requirements-dev.txt b/requirements-dev.txt index 365794f0..16bd9ae3 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -12,3 +12,5 @@ beautifulsoup4 lxml freezegun html-linter +sphinx +sphinx_rtd_theme \ No newline at end of file