-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
30 changed files
with
1,252 additions
and
0 deletions.
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 |
---|---|---|
@@ -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 |
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 @@ | ||
[metadata] | ||
name = bkr.api | ||
|
||
[options] | ||
package_dir= | ||
=src | ||
packages = find: | ||
zip_safe = False | ||
python_requires = >= 3 | ||
[options.packages.find] | ||
where = src | ||
exclude = | ||
tests* | ||
.gitignore |
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 @@ | ||
from setuptools import setup | ||
setup() |
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,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] |
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 @@ | ||
def search(): | ||
return {'msg': 'ok'}, 200 | ||
|
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,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 |
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,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 |
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 @@ | ||
def search(): | ||
pass | ||
|
||
def post(): | ||
pass | ||
|
||
def get(): | ||
pass | ||
|
||
def delete(): | ||
pass |
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 @@ | ||
def search(): | ||
pass | ||
|
||
def post(): | ||
pass | ||
|
||
def get(): | ||
pass | ||
|
||
def delete(): | ||
pass |
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,8 @@ | ||
def search(): | ||
pass | ||
|
||
def post(): | ||
pass | ||
|
||
def delete(): | ||
pass |
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 @@ | ||
def search(): | ||
pass | ||
|
||
def post(): | ||
pass | ||
|
||
def get(): | ||
pass | ||
|
||
def delete(): | ||
pass |
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 @@ | ||
def search(): | ||
pass | ||
|
||
def post(): | ||
pass | ||
|
||
def get(): | ||
pass | ||
|
||
def delete(): | ||
pass |
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 @@ | ||
def search(): | ||
pass | ||
|
||
def post(): | ||
pass | ||
|
||
def get(): | ||
pass | ||
|
||
def delete(): | ||
pass |
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 @@ | ||
def search(): | ||
pass | ||
|
||
def post(): | ||
pass | ||
|
||
def get(): | ||
pass | ||
|
||
def delete(): | ||
pass |
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 @@ | ||
def search(): | ||
pass | ||
|
||
def post(): | ||
pass | ||
|
||
def put(): | ||
pass | ||
|
||
def get(): | ||
pass | ||
|
||
def delete(): | ||
pass |
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 @@ | ||
def search(): | ||
pass | ||
|
||
def post(): | ||
pass | ||
|
||
def get(): | ||
pass | ||
|
||
def delete(): | ||
pass |
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 @@ | ||
def search(): | ||
pass | ||
|
||
def post(): | ||
pass | ||
|
||
def get(): | ||
pass | ||
|
||
def delete(): | ||
pass |
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 @@ | ||
def search(): | ||
pass | ||
|
||
def post(): | ||
pass | ||
|
||
def put(): | ||
pass | ||
|
||
def get(): | ||
pass | ||
|
||
def delete(): | ||
pass |
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 @@ | ||
def search(): | ||
pass | ||
|
||
def post(): | ||
pass | ||
|
||
def get(): | ||
pass | ||
|
||
def delete(): | ||
pass |
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 @@ | ||
def search(): | ||
pass | ||
|
||
def post(): | ||
pass | ||
|
||
def get(): | ||
pass | ||
|
||
def delete(): | ||
pass |
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 @@ | ||
<!-- 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> |
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,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) |
Oops, something went wrong.