fmartingr
/
jeeves
Archived
1
0
Fork 0

API server and examples

This commit is contained in:
Felipe M 2021-02-14 12:36:37 +01:00
parent 8fe9babfca
commit 7a4bc92969
Signed by: fmartingr
GPG Key ID: 716BC147715E716F
7 changed files with 67 additions and 3 deletions

View File

@ -6,7 +6,7 @@ packages:
- libffi-dev
- openssl-dev
sources:
- https://git.sr.ht/~fmartingr/jeeves
- https://code.fmartingr.com/fmartingr/jeeves
tasks:
- setup: |
pip install poetry

View File

@ -9,7 +9,7 @@ source code and be able to run it in your local machine.
.. code-block:: bash
git clone git@git.sr.ht:~fmartingr/jeeves
git clone git@code.fmartingr.com:fmartingr/jeeves
In this project we use Poetry_ to manage

View File

@ -9,7 +9,7 @@ need to clone the repository or download a release manually.
.. code-block::
git clone git@git.sr.ht:~fmartingr/jeeves
git clone git@code.fmartingr.com:fmartingr/jeeves
cd jeeves
poetry install
poetry run jeeves --help

View File

@ -0,0 +1,5 @@
from jeeves.server.app import app
if __name__ == "__main__":
app.run(debug=True)

41
jeeves/server/app.py Normal file
View File

@ -0,0 +1,41 @@
import os
from quart import Quart, redirect, request, jsonify
import jinja2
from jeeves.core.parsers import FlowParser
app = Quart(__name__)
jinja2_env = jinja2.Environment(loader=jinja2.FileSystemLoader("/home/fmartingr/Code/jeeves/jeeves/server/frontend/templates"))
FLOWS = []
DATA_FOLDER = "~/Code/jeeves/_data"
for rootname, dirnames, filenames in os.walk(DATA_FOLDER):
for filename in filenames:
_zz, extension = os.path.splitext(os.path.join(rootname, filename))
if extension == '.yaml':
FLOWS.append(FlowParser.from_yaml(open(os.path.join(rootname, filename), "rb").read()))
@app.route("/healthz")
async def healthz_view():
return "ok"
@app.route("/")
async def home():
return redirect("/flows")
@app.route("/flows")
async def list_flows():
template = jinja2_env.get_template("flows/list.j2")
return template.render(flows=FLOWS)
@app.route("/flows/<int:flow_id>")
async def flow_detail(flow_id):
flow = list(filter(lambda flow: flow.id == flow_id, FLOWS))[0]
template = jinja2_env.get_template("flows/task-list.j2")
return template.render(flow=flow)

17
jeevesfiles/example.yaml Normal file
View File

@ -0,0 +1,17 @@
name: Build Synology-Drive AUR package
id: 123
tasks:
- name: Perform a curl command
type: contrib/script
parameters:
script: curl fmartingr.com
- name: Generate an output file (use `-a` flag with execute command)
type: contrib/template
parameters:
src: template.j2
dest: output.txt
arguments:
- name: variable
required: true

1
jeevesfiles/template.j2 Normal file
View File

@ -0,0 +1 @@
Hello {{ variable }}