Skip to content

Commit 6121a0b

Browse files
committed
bump connexion
1 parent dc5ea12 commit 6121a0b

File tree

7 files changed

+136
-24
lines changed

7 files changed

+136
-24
lines changed

coderbot/main.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import picamera
99
import connexion
1010

11-
from flask_cors import CORS
11+
from connexion.options import SwaggerUIOptions
12+
from connexion.middleware import MiddlewarePosition
13+
from starlette.middleware.cors import CORSMiddleware
1214

1315
from camera import Camera
1416
from motion import Motion
@@ -22,29 +24,27 @@
2224
# Logging configuration
2325
logger = logging.getLogger()
2426
logger.setLevel(os.environ.get("LOGLEVEL", "INFO"))
25-
# sh = logging.StreamHandler()
26-
# formatter = logging.Formatter('%(message)s')
27-
# sh.setFormatter(formatter)
28-
# logger.addHandler(sh)
2927

3028
## (Connexion) Flask app configuration
3129

3230
# Serve a custom version of the swagger ui (Jinja2 templates) based on the default one
3331
# from the folder 'swagger-ui'. Clone the 'swagger-ui' repository inside the backend folder
34-
options = {"swagger_ui": False}
35-
connexionApp = connexion.App(__name__, options=options)
36-
37-
# Connexion wraps FlaskApp, so app becomes connexionApp.app
38-
app = connexionApp.app
39-
# Access-Control-Allow-Origin
40-
CORS(app)
41-
app.debug = False
32+
wagger_ui_options = SwaggerUIOptions(swagger_ui=True)
33+
app = connexion.App(__name__, swagger_ui_options=swagger_ui_options)
34+
app.add_middleware(
35+
CORSMiddleware,
36+
position=MiddlewarePosition.BEFORE_EXCEPTION,
37+
allow_origins=["*"],
38+
allow_credentials=True,
39+
allow_methods=["*"],
40+
allow_headers=["*"],
41+
)
4242
app.prog_engine = ProgramEngine.get_instance()
4343

4444
## New API and web application
4545

4646
# API v1 is defined in v1.yml and its methods are in api.py
47-
connexionApp.add_api('v1.yml')
47+
app.add_api('v1.yml')
4848

4949
def button_pushed():
5050
if app.bot_config.get('button_func') == "startstop":
@@ -97,7 +97,7 @@ def run_server():
9797

9898
remove_doreset_file()
9999

100-
app.run(host="0.0.0.0", port=5000, debug=False, use_reloader=False, threaded=True)
100+
app.run(host="0.0.0.0", port=5000)
101101
finally:
102102
if cam:
103103
cam.exit()

docker/stub/requirements.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# API framework
2-
connexion==2.14.2
3-
Flask==2.2.5
4-
Flask-Cors==3.0.10
2+
connexion[uvicorn,flask,swagger-ui]==3.0.5
53
tinydb==4.8.0
6-
Werkzeug==2.2.3
74

85
# Misc utils
96
setuptools==69.2.0

docker/stub/start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
export PYTHONPATH=./stub:./test:./coderbot
44
cd /coderbot
5-
python3 coderbot/main.py
5+
python3 coderbot/main.py & python3 wifi/main.py

requirements.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# API framework
2-
connexion==2.14.2
3-
Flask==2.2.5
4-
Flask-Cors==3.0.10
2+
connexion[uvicorn,flask,swagger-ui]==3.0.5
53
tinydb==4.8.0
6-
Werkzeug==2.2.3
74

85
# Misc utils
96
setuptools==69.2.0

stub/wifi/api.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import logging
2+
3+
def list_access_points():
4+
return {"ssids": [{"ssid": "my_wifi"}]}
5+
6+
def connection_status():
7+
return {"wifi": "true", "internet": "true"}
8+
9+
def connect():
10+
return "ok"
11+
12+
def forget():
13+
return "ok"
14+
15+
def sset_hotspot_ssid():
16+
return "ok"
17+
18+
def set_hotspot_password():
19+
return "ok"

stub/wifi/main.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/python
2+
3+
import os
4+
import logging
5+
import logging.handlers
6+
import connexion
7+
from connexion.middleware import MiddlewarePosition
8+
from starlette.middleware.cors import CORSMiddleware
9+
10+
# Logging configuration
11+
logger = logging.getLogger()
12+
logger.setLevel(os.environ.get("LOGLEVEL", "INFO"))
13+
14+
## (Connexion) Flask app configuration
15+
16+
# Serve a custom version of the swagger ui (Jinja2 templates) based on the default one
17+
# from the folder 'swagger-ui'. Clone the 'swagger-ui' repository inside the backend folder
18+
19+
app = connexion.App(__name__)
20+
app.add_middleware(
21+
CORSMiddleware,
22+
position=MiddlewarePosition.BEFORE_EXCEPTION,
23+
allow_origins=["*"],
24+
allow_credentials=True,
25+
allow_methods=["*"],
26+
allow_headers=["*"],
27+
)
28+
29+
## New API and web application
30+
31+
# API v1 is defined in v1.yml and its methods are in api.py
32+
app.add_api('v1.yml')
33+
34+
if __name__ == "__main__":
35+
app.run(host="0.0.0.0", port=9090)

stub/wifi/openapi.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: "1.0"
4+
title: OpenAPI 3.0 definition of WiFi API
5+
6+
servers:
7+
- url: http://coderbot.local/v1
8+
9+
# Paths supported by the server application
10+
paths:
11+
/list_access_points:
12+
get:
13+
operationId: "api.list_access_points"
14+
summary: "list Access Points"
15+
responses:
16+
200:
17+
description: "ok"
18+
tags:
19+
- Wifi
20+
/connection_status:
21+
get:
22+
operationId: "api.connection_status"
23+
summary: "connection Status"
24+
responses:
25+
200:
26+
description: "ok"
27+
tags:
28+
- Wifi
29+
/connect:
30+
post:
31+
operationId: "api.connect"
32+
summary: "connect"
33+
responses:
34+
200:
35+
description: "ok"
36+
tags:
37+
- Wifi
38+
/forget:
39+
post:
40+
operationId: "api.forget"
41+
summary: "forget"
42+
responses:
43+
200:
44+
description: "ok"
45+
tags:
46+
- Wifi
47+
/sset_hotspot_ssid:
48+
post:
49+
operationId: "api.sset_hotspot_ssid"
50+
summary: "sset_hotspot_ssid"
51+
responses:
52+
200:
53+
description: "ok"
54+
tags:
55+
- Wifi
56+
/set_hotspot_password:
57+
post:
58+
operationId: "api.set_hotspot_password"
59+
summary: "set_hotspot_password"
60+
responses:
61+
200:
62+
description: "ok"
63+
tags:
64+
- Wifi

0 commit comments

Comments
 (0)