generated from vanHeemstraSystems/template-default-repository
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c1c4ae
commit 53707bb
Showing
33 changed files
with
866 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
# 200 - Requirements | ||
|
||
We use [pipx](https://github.com/pypa/pipx?tab=readme-ov-file#install-pipx) instead of ```pip```, for isolation. | ||
1. Install pipx: | ||
see https://github.com/pypa/pipx?tab=readme-ov-file#install-pipx for platform (Linux, macOS, Windows) specifics. | ||
2. Install python with pipx: | ||
```bash | ||
$ pipx install python | ||
``` | ||
|
||
We use [hatch](https://hatch.pypa.io/) for project management. | ||
2. Install hatch: | ||
```bash | ||
$ pipx install hatch | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Threagile Builder | ||
|
||
[![PyPI - Version](https://img.shields.io/pypi/v/threagile-builder.svg)](https://pypi.org/project/threagile-builder) | ||
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/threagile-builder.svg)](https://pypi.org/project/threagile-builder) | ||
|
||
----- | ||
|
||
## Table of Contents | ||
|
||
- [Installation](#installation) | ||
- [License](#license) | ||
|
||
## Installation | ||
|
||
```console | ||
pip install threagile-builder | ||
``` | ||
|
||
## License | ||
|
||
`threagile-builder` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# threagile-builder/pyproject.toml | ||
[build-system] | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" | ||
|
||
[project] | ||
name = "threagile-builder" | ||
dynamic = ["version"] | ||
description = 'A Threagile Builder.' | ||
readme = "README.md" | ||
requires-python = ">=3.8" | ||
license = "MIT" | ||
keywords = [] | ||
authors = [ | ||
{ name = "Willem van Heemstra", email = "[email protected]" }, | ||
] | ||
classifiers = [ | ||
"Development Status :: 4 - Beta", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12", | ||
"Programming Language :: Python :: Implementation :: CPython", | ||
"Programming Language :: Python :: Implementation :: PyPy", | ||
] | ||
dependencies = [ | ||
"Flask", | ||
"Flask-SQLAlchemy", | ||
"Flask-WTF", | ||
"apiflask", | ||
"black", | ||
"opentelemetry-api", | ||
"opentelemetry-sdk", | ||
"opentelemetry-instrumentation-flask", | ||
"opentelemetry-instrumentation-sqlalchemy", | ||
"opentelemetry-exporter-prometheus", | ||
"prefect", | ||
"prometheus_client", | ||
"python-dotenv" | ||
] | ||
|
||
[project.urls] | ||
Documentation = "https://github.com/vanHeemstraSystems/threagile-builder#readme" | ||
Issues = "https://github.com/vanHeemstraSystems/threagile-builder/issues" | ||
Source = "https://github.com/vanHeemstraSystems/threagile-builder" | ||
|
||
[tool.hatch.version] | ||
path = "src/threagile_builder/__about__.py" | ||
|
||
[tool.hatch.envs.default] | ||
dependencies = [ | ||
"coverage[toml]>=6.5", | ||
"pytest", | ||
"flask" | ||
] | ||
[tool.hatch.envs.default.scripts] | ||
app = "python src/threagile_builder/app.py" | ||
|
||
[tool.hatch.envs.types] | ||
extra-dependencies = [ | ||
"mypy>=1.0.0", | ||
] | ||
|
||
[tool.hatch.envs.types.scripts] | ||
check = "mypy --install-types --non-interactive {args:src/threagile_builder tests}" | ||
|
||
[tool.hatch.envs.test] | ||
dependencies = [ | ||
"pytest", | ||
"pytest-cov", | ||
"pytest-watcher" | ||
] | ||
|
||
[tool.hatch.envs.test.scripts] | ||
test = "pytest {args:tests}" | ||
test-cov = "coverage run -m pytest {args:tests}" | ||
cov-report = [ | ||
"- coverage combine", | ||
"coverage report", | ||
] | ||
cov = [ | ||
"test-cov", | ||
"cov-report", | ||
] | ||
|
||
[[tool.hatch.envs.test.matrix]] | ||
python = ["3.10", "3.11"] | ||
|
||
[[tool.hatch.envs.all.matrix]] | ||
python = ["3.12"] | ||
|
||
[tool.coverage.run] | ||
source_pkgs = ["threagile_builder", "tests"] | ||
branch = true | ||
parallel = true | ||
omit = [ | ||
"src/threagile_builder/__about__.py", | ||
] | ||
|
||
[tool.coverage.paths] | ||
threagile_builder = ["src/threagile_builder", "*/threagile-builder/src/threagile_builder"] | ||
tests = ["tests", "*/threagile-builder/tests"] | ||
|
||
[tool.coverage.report] | ||
exclude_lines = [ | ||
"no cov", | ||
"if __name__ == .__main__.:", | ||
"if TYPE_CHECKING:", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# threagile-builder/requirements.txt | ||
Flask==3.0.3 | ||
Flask-SQLAlchemy==3.1.1 | ||
Flask-WTF==1.2.2 | ||
apiflask==2.2.1 | ||
black==24.10.0 | ||
opentelemetry-api==1.27.0 | ||
opentelemetry-sdk==1.27.0 | ||
opentelemetry-instrumentation-flask==0.48b0 | ||
opentelemetry-instrumentation-sqlalchemy==0.48b0 | ||
opentelemetry-exporter-prometheus==0.48b0 | ||
prefect==2.20.10 | ||
prometheus_client==0.15.0 | ||
python-dotenv==1.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# threagile-builder/scr/threagile_builder/__about__.py | ||
__version__ = "0.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# threagile-builder/scr/threagile_builder/__init__.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# threagile-builder/src/threagile_builder/app.py | ||
from utils import create_app | ||
|
||
app = create_app() | ||
|
||
if __name__ == "__main__": | ||
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# threagile-builder/scr/threagile_builder/config/__init__.py | ||
from .config import Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# threagile-builder/scr/threagile_builder/config/config.py | ||
import os | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
|
||
class Config: | ||
SECRET_KEY = os.getenv("SECRET_KEY") or "secret" | ||
SQLALCHEMY_DATABASE_URI = os.getenv("SQLALCHEMY_DATABASE_URI") or "sqlite:///app.db" | ||
SQLALCHEMY_TRACK_MODIFICATIONS = os.getenv("SQLALCHEMY_TRACK_MODIFICATIONS") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# threagile-builder/scr/threagile_builder/forms/__init__.py | ||
from .build_form import BuildForm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# threagile-builder/scr/threagile_builder/forms/build_form_.py | ||
from flask_wtf import FlaskForm | ||
from wtforms import StringField, SubmitField | ||
from wtforms.validators import DataRequired | ||
|
||
|
||
class BuildForm(FlaskForm): | ||
title = StringField("Build Title", validators=[DataRequired()]) | ||
submit = SubmitField("Create Build") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# threagile-builder/scr/threagile_builder/models/__init__.py | ||
from .build_model import Build |
7 changes: 7 additions & 0 deletions
7
threagile-builder/src/threagile_builder/models/build_model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# threagile-builder/scr/threagile_builder/models/build_model.py | ||
from utils.db_utils import db | ||
|
||
|
||
class Build(db.Model): | ||
id = db.Column(db.Integer, primary_key=True) | ||
title = db.Column(db.String(100), nullable=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# threagile-builder/scr/threagile_builder/routes/__init__.py | ||
from .build_routes import build_bp | ||
from .main_routes import main_bp |
68 changes: 68 additions & 0 deletions
68
threagile-builder/src/threagile_builder/routes/build_routes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# threagile-builder/scr/threagile_builder/routes/build_routes.py | ||
import json | ||
import logging | ||
from apiflask import APIBlueprint | ||
from flask import request, jsonify | ||
from models import Build | ||
from utils.db_utils import db | ||
from workflows import build_workflow | ||
|
||
|
||
build_bp = APIBlueprint("build", __name__) | ||
|
||
|
||
# Create a Build | ||
@build_bp.route("/builds", methods=["POST"]) | ||
def create_build(): | ||
data = request.json | ||
new_build = Build(title=data["title"]) | ||
db.session.add(new_build) | ||
db.session.commit() | ||
return jsonify({"id": new_build.id, "title": new_build.title}), 201 | ||
|
||
|
||
# Read all Builds | ||
@build_bp.route("/builds", methods=["GET"]) | ||
def get_builds(): | ||
builds = Build.query.all() | ||
return jsonify([{"id": build.id, "title": build.title} for build in builds]), 200 | ||
|
||
|
||
# Read a single Build by ID | ||
@build_bp.route("/builds/<int:id>", methods=["GET"]) | ||
def get_build(id): | ||
build = Build.query.get_or_404(id) | ||
return jsonify({"id": build.id, "title": build.title}), 200 | ||
|
||
|
||
# Update a Build by ID | ||
@build_bp.route("/builds/<int:id>", methods=["PUT"]) | ||
def update_build(id): | ||
build = Build.query.get_or_404(id) | ||
data = request.json | ||
build.title = data["title"] | ||
db.session.commit() | ||
return jsonify({"id": build.id, "title": build.title}), 200 | ||
|
||
|
||
# Delete a Build by ID | ||
@build_bp.route("/builds/<int:id>", methods=["DELETE"]) | ||
def delete_build(id): | ||
build = Build.query.get_or_404(id) | ||
db.session.delete(build) | ||
db.session.commit() | ||
return jsonify({"message": "Build deleted successfully."}), 204 | ||
|
||
|
||
@build_bp.route("/run-build", methods=["POST"]) | ||
def run_build(): | ||
logging.info("Received request to run the Build's workflow.") | ||
try: | ||
data = json.loads(request.data) | ||
logging.debug(f"Workflow data: {data}") | ||
result = build_workflow() | ||
logging.info("Build's workflow executed successfully.") | ||
return result, 200 | ||
except Exception as e: | ||
logging.error(f"Error occurred while running the workflow: {e}") | ||
return {"error": "An error occurred while processing your request."}, 500 |
Oops, something went wrong.