From 60c6698495c1e8206ad210c7b4618331f20fe384 Mon Sep 17 00:00:00 2001 From: Fabian Date: Sat, 4 Apr 2020 13:53:26 +0200 Subject: [PATCH 1/6] comments added --- consumer_api/views/consumers_view.py | 4 +++- consumer_api/views/log_view.py | 3 +++ consumer_api/views/sync_view.py | 12 +++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/consumer_api/views/consumers_view.py b/consumer_api/views/consumers_view.py index 0582bc4..8c03a07 100644 --- a/consumer_api/views/consumers_view.py +++ b/consumer_api/views/consumers_view.py @@ -8,6 +8,8 @@ from flask_classful import FlaskView class ConsumersView(FlaskView): def get(self): + # load the currently available consumer list from the redis database consumer_list = json.loads((redis_client.get("consumer_list") or b"{}").decode('utf-8')) - current_app.logger.warning(jsonify([v['ip'] for k, v in consumer_list.items()])) + + # jsonify and return the list of active consumers return jsonify([v['ip'] for k, v in consumer_list.items()]) diff --git a/consumer_api/views/log_view.py b/consumer_api/views/log_view.py index abfff93..470b16b 100644 --- a/consumer_api/views/log_view.py +++ b/consumer_api/views/log_view.py @@ -5,5 +5,8 @@ from flask_classful import FlaskView class LogView(FlaskView): def post(self): + # display received message current_app.logger.info(f"New message: {request.json['message']}") + + # return HTTP 204 - No content message return Response(status = 204) diff --git a/consumer_api/views/sync_view.py b/consumer_api/views/sync_view.py index a6f8eb5..3c2f771 100644 --- a/consumer_api/views/sync_view.py +++ b/consumer_api/views/sync_view.py @@ -1,7 +1,7 @@ import json from flask import request, current_app, jsonify from flask_classful import FlaskView -from db import redis_client # ez nagyon otvar +from db import redis_client class SyncView(FlaskView): @@ -10,23 +10,25 @@ class SyncView(FlaskView): remote_uuid = request.json['uuid'] remote_ip = request.remote_addr + # load the currently available consumer list from the redis database consumer_list = json.loads((redis_client.get("consumer_list") or b"{}").decode('utf-8')) - # Log something about it if remote_uuid not in consumer_list.keys(): + # display newly registered consumer current_app.logger.info(f"New consumer registered (unknown UUID): {remote_uuid} at {remote_ip}") - else: # known + else: if consumer_list[remote_uuid]['ip'] != remote_ip: + # log address changes current_app.logger.info(f"Address of consumer {remote_uuid} changed to {remote_ip}") + # update consumer list redis databasse consumer_list.update( {remote_uuid: {"ip": remote_ip}} ) - redis_client.set("consumer_list", json.dumps(consumer_list).encode('utf-8')) + # return with the current UUID response = { "uuid": current_app.config['LOCAL_UUID'] } - return jsonify(response) From 36d297f22738566151d53844363dde31a6ec981e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sat, 4 Apr 2020 19:05:27 +0200 Subject: [PATCH 2/6] sphinx drone --- .drone.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.drone.yml b/.drone.yml index 5cbb14a..3f2eaa9 100644 --- a/.drone.yml +++ b/.drone.yml @@ -30,6 +30,13 @@ steps: - docker push "$DOCKER_USERNAME/consumer_api" - docker push "$DOCKER_USERNAME/consumer_api:$DRONE_BUILD_NUMBER" +- name: static_analysis + image: python:3 + commands: + - pip3 install Sphinx + - pip3 install -r requirements.txt + - sphinx-quickstart + - name: slack image: plugins/slack settings: From 54aa6ef71245e52a1f1907fa2801c16947a88a1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Sat, 4 Apr 2020 19:07:57 +0200 Subject: [PATCH 3/6] fix drone config --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 3f2eaa9..0692293 100644 --- a/.drone.yml +++ b/.drone.yml @@ -30,7 +30,7 @@ steps: - docker push "$DOCKER_USERNAME/consumer_api" - docker push "$DOCKER_USERNAME/consumer_api:$DRONE_BUILD_NUMBER" -- name: static_analysis +- name: build_docs image: python:3 commands: - pip3 install Sphinx From d3aee82cbe3d577acc443b3487a1dbb15155e30b Mon Sep 17 00:00:00 2001 From: Fabian Date: Tue, 7 Apr 2020 21:34:32 +0200 Subject: [PATCH 4/6] readme added --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c2e6ffd --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +Repository for the consumer's API + +implemented interfaces / functionalities: +- consumer +- log +- sync + From fa1309b87f58a507ce5f955dae5f7cc70d646d2b Mon Sep 17 00:00:00 2001 From: marcsello Date: Wed, 8 Apr 2020 21:40:32 +0200 Subject: [PATCH 5/6] added docs --- README.md => README.rst | 11 ++++++--- docs/Makefile | 20 +++++++++++++++ docs/conf.py | 55 +++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 23 +++++++++++++++++ docs/make.bat | 35 ++++++++++++++++++++++++++ docs/readme.rst | 1 + docs/source/app.rst | 7 ++++++ docs/source/db.rst | 7 ++++++ docs/source/modules.rst | 9 +++++++ docs/source/views.rst | 38 ++++++++++++++++++++++++++++ 10 files changed, 203 insertions(+), 3 deletions(-) rename README.md => README.rst (50%) create mode 100644 docs/Makefile create mode 100644 docs/conf.py create mode 100644 docs/index.rst create mode 100644 docs/make.bat create mode 100644 docs/readme.rst create mode 100644 docs/source/app.rst create mode 100644 docs/source/db.rst create mode 100644 docs/source/modules.rst create mode 100644 docs/source/views.rst diff --git a/README.md b/README.rst similarity index 50% rename from README.md rename to README.rst index c2e6ffd..dc233b7 100644 --- a/README.md +++ b/README.rst @@ -1,7 +1,12 @@ +================ +P2P Consumer API +================ + Repository for the consumer's API implemented interfaces / functionalities: -- consumer -- log -- sync + +* consumer +* log +* sync diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..d4bb2cb --- /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 0000000..15cc577 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,55 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- Project information ----------------------------------------------------- + +project = 'Consumer API' +copyright = '2020, GoldenPogacsa Inc.' +author = 'GoldenPogacsa Inc.' + +# The full version, including alpha/beta/rc tags +release = '0.1.0' + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..0769b9b --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,23 @@ +.. Consumer API documentation master file, created by + sphinx-quickstart on Wed Apr 8 21:31:18 2020. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to Consumer API's documentation! +======================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + readme + source/modules + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` +* `Git repository `_ diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..2119f51 --- /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 + +if "%1" == "" goto help + +%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.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/readme.rst b/docs/readme.rst new file mode 100644 index 0000000..6b2b3ec --- /dev/null +++ b/docs/readme.rst @@ -0,0 +1 @@ +.. include:: ../README.rst \ No newline at end of file diff --git a/docs/source/app.rst b/docs/source/app.rst new file mode 100644 index 0000000..ceb7f40 --- /dev/null +++ b/docs/source/app.rst @@ -0,0 +1,7 @@ +app module +========== + +.. automodule:: app + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/db.rst b/docs/source/db.rst new file mode 100644 index 0000000..8d4f164 --- /dev/null +++ b/docs/source/db.rst @@ -0,0 +1,7 @@ +db module +========= + +.. automodule:: db + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/modules.rst b/docs/source/modules.rst new file mode 100644 index 0000000..026c014 --- /dev/null +++ b/docs/source/modules.rst @@ -0,0 +1,9 @@ +consumer_api +============ + +.. toctree:: + :maxdepth: 4 + + app + db + views diff --git a/docs/source/views.rst b/docs/source/views.rst new file mode 100644 index 0000000..2b282cb --- /dev/null +++ b/docs/source/views.rst @@ -0,0 +1,38 @@ +views package +============= + +Submodules +---------- + +views.consumers\_view module +---------------------------- + +.. automodule:: views.consumers_view + :members: + :undoc-members: + :show-inheritance: + +views.log\_view module +---------------------- + +.. automodule:: views.log_view + :members: + :undoc-members: + :show-inheritance: + +views.sync\_view module +----------------------- + +.. automodule:: views.sync_view + :members: + :undoc-members: + :show-inheritance: + + +Module contents +--------------- + +.. automodule:: views + :members: + :undoc-members: + :show-inheritance: From d3a75b5f95aa1dfbb84972dd695b85933cd6eefc Mon Sep 17 00:00:00 2001 From: marcsello Date: Wed, 8 Apr 2020 21:54:04 +0200 Subject: [PATCH 6/6] added docs to CI pipeline --- .drone.yml | 27 +++++++++++++++++++++++---- docs/Dockerfile | 3 +++ docs/conf.py | 6 +++--- 3 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 docs/Dockerfile diff --git a/.drone.yml b/.drone.yml index 0692293..9f8f59e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -30,12 +30,31 @@ steps: - docker push "$DOCKER_USERNAME/consumer_api" - docker push "$DOCKER_USERNAME/consumer_api:$DRONE_BUILD_NUMBER" -- name: build_docs - image: python:3 +- name: make_docs + image: python:3.8 commands: - - pip3 install Sphinx + - pip3 install Sphinx sphinx_rtd_theme - pip3 install -r requirements.txt - - sphinx-quickstart + - cd docs + - make html + +- name: build_docs + image: docker:stable-dind + volumes: + - name: dockersock + path: /var/run + environment: + DOCKER_USERNAME: + from_secret: DOCKER_USERNAME + DOCKER_PASSWORD: + from_secret: DOCKER_PASSWORD + commands: + - cd docs + - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin + - docker build -t="$DOCKER_USERNAME/consumer-api-docs" . + - docker build -t="$DOCKER_USERNAME/consumer-api-docs:$DRONE_BUILD_NUMBER" . + - docker push "$DOCKER_USERNAME/consumer-api-docs" + - docker push "$DOCKER_USERNAME/consumer-api-docs:$DRONE_BUILD_NUMBER" - name: slack image: plugins/slack diff --git a/docs/Dockerfile b/docs/Dockerfile new file mode 100644 index 0000000..691c92e --- /dev/null +++ b/docs/Dockerfile @@ -0,0 +1,3 @@ +FROM nginx:latest + +COPY _build/html/ /usr/share/nginx/html \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py index 15cc577..5f67273 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -34,7 +34,7 @@ extensions = [ ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = [] # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -47,9 +47,9 @@ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'alabaster' +html_theme = 'sphinx_rtd_theme' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] \ No newline at end of file +html_static_path = [] \ No newline at end of file