Skip to content

Commit

Permalink
WIP: swagger yaml defination
Browse files Browse the repository at this point in the history
Using openapi 3.0 specification to define the restAPI for beaker
backend.

skeleton api with some dummy methods to allow for testing the test
framework.

Once this is fleshed out we can start migrating the model code over and
then create the actual rest methods.
  • Loading branch information
p3ck committed Jan 31, 2024
1 parent ef0bc9c commit 4c077c3
Show file tree
Hide file tree
Showing 30 changed files with 1,252 additions and 0 deletions.
31 changes: 31 additions & 0 deletions API/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
attrs==23.1.0
blinker==1.6.3
certifi==2023.7.22
charset-normalizer==3.3.0
click==8.1.7
clickclick==20.10.2
connexion==3.0.5
Flask==2.2.2
flask-marshmallow==0.14.0
Flask-SQLAlchemy==3.0.3
greenlet==3.0.0
idna==3.4
inflection==0.5.1
itsdangerous==2.1.2
Jinja2==3.1.2
jsonschema==4.19.1
jsonschema-specifications==2023.7.1
MarkupSafe==2.1.3
marshmallow==3.20.1
marshmallow-sqlalchemy==0.29.0
packaging==23.2
PyYAML==6.0.1
referencing==0.30.2
requests==2.31.0
rpds-py==0.10.3
six==1.16.0
SQLAlchemy==2.0.22
swagger-ui-bundle==0.0.9
typing_extensions==4.8.0
urllib3==2.0.6
Werkzeug==2.2.2
14 changes: 14 additions & 0 deletions API/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[metadata]
name = bkr.api

[options]
package_dir=
=src
packages = find:
zip_safe = False
python_requires = >= 3
[options.packages.find]
where = src
exclude =
tests*
.gitignore
2 changes: 2 additions & 0 deletions API/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from setuptools import setup
setup()
Empty file added API/src/bkr/api/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions API/src/bkr/api/arches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from flask import abort

ARCHES = {}

def post(arch):
if arch and arch not in ARCHES:
ARCHES[arch] = {
"arch": arch,
}
return ARCHES[arch], 201
else:
abort(
406,
f"{arch} already exists",
)

def search(offset=0, limit=None):
start = 0
end = len(ARCHES.values())
if offset and limit:
start = offset * limit
end = start + limit
return list(ARCHES.values())[start:end]
3 changes: 3 additions & 0 deletions API/src/bkr/api/health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def search():
return {'msg': 'ok'}, 200

34 changes: 34 additions & 0 deletions API/src/bkr/api/lab_controllers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from flask import abort

LABCONTROLLERS = {}

def post(lab_controller):
fqdn = lab_controller.get("fqdn")
user_name = lab_controller.get("user_name", "")
email_address = lab_controller.get("email_address", "")
password = lab_controller.get("password", "")

if fqdn and fqdn not in LABCONTROLLERS:
LABCONTROLLERS[fqdn] = {
"fqdn": fqdn,
"user_name": user_name,
"email_address": email_address,
"password": password,
}
return LABCONTROLLERS[fqdn], 201
else:
abort(
406,
f"Lab Controller with fqdn {fqdn} already exists",
)

def search(offset=0, limit=None):
start = 0
end = len(LABCONTROLLERS.values())
if offset and limit:
start = offset * limit
end = start + limit
return list(LABCONTROLLERS.values())[start:end]

def get(lab_controller):
pass
78 changes: 78 additions & 0 deletions API/src/bkr/api/systems/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from flask import abort
from bkr.api.lab_controllers import LABCONTROLLERS
from bkr.api.arches import ARCHES
#from bkr.model import System

SYSTEMS = {}

def post(system):
fqdn = system.get("fqdn")
owner = system.get("owner")
status = system.get("status", "unavailable")
status_reason = system.get("status_reason", "")
arches = system.get("arches", [])
power = system.get("power", {})
location = system.get("location", "")
lender = system.get("lender", "")
vender = system.get("vender", "")
model = system.get("model", "")
serial = system.get("serial", "")
lab_controller = system.get("lab_controller", "")

if lab_controller and lab_controller not in LABCONTROLLERS:
abort(
406,
f"Lab Controller {lab_controller} doesn't exist",
)

for arch in arches:
if arch not in ARCHES:
abort(
406,
f"{arch} doesn't exist, create it first.",
)

if fqdn and fqdn not in SYSTEMS:
SYSTEMS[fqdn] = {
"fqdn": fqdn,
"owner": owner,
"status": status,
"status_reason": status_reason,
"arches": arches,
"power": power,
"location": location,
"lender": lender,
"vender": vender,
"model": model,
"serial": serial,
"lab_controller": lab_controller,
}
return SYSTEMS[fqdn], 201
else:
abort(
406,
f"System with fqdn {fqdn} already exists",
)

def search(offset=0, limit=None):
start = 0
end = len(SYSTEMS.values())
if offset and limit:
start = offset * limit
end = start + limit
return list(SYSTEMS.values())[start:end]

def get(fqdn):
if fqdn in SYSTEMS:
return SYSTEMS[fqdn]
else:
abort(
404,
f"System with fqdn {fqdn} not found",
)

def put(fqdn):
pass

def delete(fqdn):
pass
11 changes: 11 additions & 0 deletions API/src/bkr/api/systems/access_policies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def search():
pass

def post():
pass

def get():
pass

def delete():
pass
11 changes: 11 additions & 0 deletions API/src/bkr/api/systems/activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def search():
pass

def post():
pass

def get():
pass

def delete():
pass
8 changes: 8 additions & 0 deletions API/src/bkr/api/systems/cc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def search():
pass

def post():
pass

def delete():
pass
11 changes: 11 additions & 0 deletions API/src/bkr/api/systems/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def search():
pass

def post():
pass

def get():
pass

def delete():
pass
11 changes: 11 additions & 0 deletions API/src/bkr/api/systems/excluded_families.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def search():
pass

def post():
pass

def get():
pass

def delete():
pass
11 changes: 11 additions & 0 deletions API/src/bkr/api/systems/executed_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def search():
pass

def post():
pass

def get():
pass

def delete():
pass
11 changes: 11 additions & 0 deletions API/src/bkr/api/systems/install_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def search():
pass

def post():
pass

def get():
pass

def delete():
pass
14 changes: 14 additions & 0 deletions API/src/bkr/api/systems/loan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def search():
pass

def post():
pass

def put():
pass

def get():
pass

def delete():
pass
11 changes: 11 additions & 0 deletions API/src/bkr/api/systems/notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def search():
pass

def post():
pass

def get():
pass

def delete():
pass
11 changes: 11 additions & 0 deletions API/src/bkr/api/systems/problem_reports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def search():
pass

def post():
pass

def get():
pass

def delete():
pass
14 changes: 14 additions & 0 deletions API/src/bkr/api/systems/reservation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def search():
pass

def post():
pass

def put():
pass

def get():
pass

def delete():
pass
11 changes: 11 additions & 0 deletions API/src/bkr/api/systems/status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def search():
pass

def post():
pass

def get():
pass

def delete():
pass
11 changes: 11 additions & 0 deletions API/src/bkr/api/systems/system_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def search():
pass

def post():
pass

def get():
pass

def delete():
pass
14 changes: 14 additions & 0 deletions API/src/bkr/api/templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- templates/home.html -->

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Flask REST API</title>
</head>
<body>
<h1>
Hello, World!
</h1>
</body>
</html>
18 changes: 18 additions & 0 deletions API/src/bkr/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import logging
import sys
import time
from connexion.resolver import RestyResolver
from bkr import config

logger = logging.getLogger(__name__)


def create_app():
app = config.connex_app
app.add_api("swagger.yml", resolver=RestyResolver('bkr.api'))
return app


if __name__ == "__main__":
app = create_app()
app.run(host="0.0.0.0", port=8000)
Loading

0 comments on commit 4c077c3

Please sign in to comment.