switch to pdm
This commit is contained in:
36
src/README.md
Normal file
36
src/README.md
Normal file
@@ -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
|
||||
|
||||
- <http://127.0.0.1:5000/inc?x=5> will take the value of x=5 and increments it
|
||||
- <http://127.0.0.1:5000/mul?x=3&y=7> will take the value of x=3 and y=7 and executes x\*y (3\*7=21)
|
||||
- <http://127.0.0.1:5000/> brings you to the landing page
|
||||
- <http://127.0.0.1:5000/login> brings you to the login page
|
25
src/pyproject.toml
Normal file
25
src/pyproject.toml
Normal file
@@ -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"
|
18
src/templates/base.html
Normal file
18
src/templates/base.html
Normal file
@@ -0,0 +1,18 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
{% if title %}
|
||||
<title>{{ title }} - Calculator</title>
|
||||
{% else %}
|
||||
<title>Welcome to Calculator</title>
|
||||
{% endif %}
|
||||
</head>
|
||||
<body>
|
||||
<div>Calculator:
|
||||
<a href="{{ url_for('index') }}">Home</a>
|
||||
<a href="{{ url_for('login') }}">Login</a>
|
||||
</div>
|
||||
<hr>
|
||||
{% block content %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
8
src/templates/index.html
Normal file
8
src/templates/index.html
Normal file
@@ -0,0 +1,8 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
{% autoescape false %}
|
||||
<h1>Calculator app</h1>
|
||||
Hi {{ app_data.username }}
|
||||
{% endautoescape %}
|
||||
{% endblock %}
|
11
src/templates/login.html
Normal file
11
src/templates/login.html
Normal file
@@ -0,0 +1,11 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Sign In</h1>
|
||||
|
||||
<form action="" method="POST" novalidate>
|
||||
<div><label>Username: <input type="text" name="username"></label></div>
|
||||
<div><label>Password: <input type="text" name="password"></label></div>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
{% endblock %}
|
Reference in New Issue
Block a user