diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f88399f..aec8f6e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,14 +7,17 @@ build job: script: - cd src - apt-get update -qy - - apt-get install -y python3-dev python3-pip python3.12-venv + - apt-get install -y python3-dev python3-pip python3.12-venv curl - python3 -V - - pip3 install --break-system-packages -r requirements.txt +# - pip3 install --break-system-packages -r requirements.txt + - curl -sSL https://pdm-project.org/install-pdm.py | python3 - + - export PATH=/root/.local/bin:$PATH + - pdm install # launch tests - export PYTHONPATH=. - export FLASK_APP=app - - pytest tests --cov --cov-report term --cov-report html + - pdm run pytest tests --cov --cov-report term --cov-report html artifacts: diff --git a/misc/index.html b/misc/index.html new file mode 100644 index 0000000..e965047 --- /dev/null +++ b/misc/index.html @@ -0,0 +1 @@ +Hello diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..7b3c3b1 --- /dev/null +++ b/src/README.md @@ -0,0 +1,36 @@ + +# CI/CD and SSDLC labs (TSM CyberSec) + +This is a simple calculator application using Flask. The application is a simple calculator that can perform addition, subtraction, multiplication, and division. + +## Environment setup and usage + +For the environment setup, the following steps are necessary: + +1. Install Python and [PDM (package manager)](https://pdm-project.org/latest/) +1. Install the required packages with `pdm install` --> The pyproject.toml file contains the required packages +1. Start the development server with `pdm run flask` + +The started server can be reached on the localhost (127.0.0.1) on port 5000. This can be configured if desired. + +## Usage and routes of the demo app + +The following table shows the different routes of the REST API: +| route | GET parameters | function | +| --- | --- | --- | +| / | n/a | Welcome page | +| /login | n/a | Login page (only the username is used for the moment) | +| /help | n/a | Help page | +| /inc | x | increments the value x by 1 | +| /add | x, y | executes x+y | +| /mul | x, y | executes x*y | +| /div | x, y | executes x/y | + +### Examples + +Here some usage examples + +- will take the value of x=5 and increments it +- will take the value of x=3 and y=7 and executes x\*y (3\*7=21) +- brings you to the landing page +- brings you to the login page diff --git a/src/pyproject.toml b/src/pyproject.toml new file mode 100644 index 0000000..3887694 --- /dev/null +++ b/src/pyproject.toml @@ -0,0 +1,25 @@ +[project] +name = "flask-api-calculator-demo" +version = "0.1.0" +description = "Default template for PDM package" +authors = [ + {name = "Michael Mäder", email = "michael.maeder@hefr.ch"}, +] +dependencies = [ + "pytest>=8.0.2", + "pytest-cov>=4.1.0", + "Flask>=3.0.2", + "flask-wtf>=1.2.1", +] +requires-python = ">3.10" +readme = "README.md" +license = {text = "MIT"} + + +[tool.pdm] +distribution = false + +[tool.pdm.scripts] +flask.cmd = "flask run -p 5000 --debug" +flask.env = {FLASK_ENV = "development"} +shell.cmd = "zsh" \ No newline at end of file diff --git a/src/templates/base.html b/src/templates/base.html new file mode 100644 index 0000000..cc42d88 --- /dev/null +++ b/src/templates/base.html @@ -0,0 +1,18 @@ + + + + {% if title %} + {{ title }} - Calculator + {% else %} + Welcome to Calculator + {% endif %} + + +
Calculator: + Home + Login +
+
+ {% block content %}{% endblock %} + + diff --git a/src/templates/index.html b/src/templates/index.html new file mode 100644 index 0000000..6b57bc7 --- /dev/null +++ b/src/templates/index.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} + +{% block content %} + {% autoescape false %} +

Calculator app

+ Hi {{ app_data.username }} + {% endautoescape %} +{% endblock %} diff --git a/src/templates/login.html b/src/templates/login.html new file mode 100644 index 0000000..239dd0c --- /dev/null +++ b/src/templates/login.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} + +{% block content %} +

Sign In

+ +
+
+
+ +
+{% endblock %}