Skip to content

Commit ea3e6ea

Browse files
committed
initial auth token WIP
1 parent d887bab commit ea3e6ea

File tree

7 files changed

+371
-21
lines changed

7 files changed

+371
-21
lines changed

maverick_api/modules/api/authentication/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
from maverick_api.modules import schemaBase
1111
from maverick_api.modules.base.tornadoql.session_control import GraphQLSession
1212

13-
user1 = dict(id="1", userName="sam", password="password1")
13+
user1 = dict(id="1", userName="bob", password="password1")
1414
user2 = dict(id="2", userName="ben", password="password2")
1515
auth_data = {user1["id"]: user1, user2["id"]: user2}
1616

1717

1818
class AuthenticationSchema(schemaBase):
1919
def __init__(self):
2020
super().__init__(self)
21+
2122
self.auth_request_type = GraphQLObjectType(
2223
"AuthenticationRequest",
2324
lambda: {
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// These are local config settings. Because they can include sensitive information like usernames and passwords, this file
2+
// is excluded from ever being committed back to git.
3+
//
4+
// Any manifest parameter can be added here, what follows is a sampling of common useful settings.
5+
// More info and settings can be found here:
6+
// https://goodrobots.github.io/maverick/#/modules/intro
7+
{
8+
// Set passwords
9+
// "base::users::mav_password": "", // Set mav user encrypted password here (obtain using: mkpasswd -m sha-512 -s)
10+
// "base::users::root_password": "", // Set root user encrypted password here (obtain as above)
11+
"base::users::mav_password": "$6$xq6EVGnLPDit/0n$wPzRss9HjhhPPRQz4xezAnQ8C7Tymx8Aa7jl2CtjTd9KxA1fyqfd5pYacX/7bWll9kQ.Ytj/9rp8YW5cYa/iL.", // boseheadphonesaresilver
12+
// Set defaults for wifi. If set, any wifi interface detected will be automatically activated with these settings.
13+
// These setting can be overridden in the per-interface settings.
14+
// "wifi_ssid": "MySSID",
15+
// "wifi_passtype": "wpa2",
16+
// "wifi_passphrase": false, // unencrypted wifi passphrase, strongly recommended to use psk below instead
17+
// "wifi_psk": "averylonggeneratedkey", // must be encrypted psk created using 'wpa_passphrase MySSID MyPassphrase'
18+
// See https://goodrobots.github.io/maverick/#/modules-network for more info
19+
// Note a fallback generic eth0 and wlan0 config is always created in addition to these settings
20+
"maverick_analysis::grafana::admin_hash": "93e2aaac76487b067f0ac5ecedbb49814634a2381588dc9f8f2eef1f2cadc3db129f380eefa318079de31916887d8817d7ab",
21+
"maverick_analysis::grafana::admin_password": "boseheadphonesaresilver",
22+
// "maverick_dev::ardupilot::ardupilot_vehicle": "copter",
23+
// "maverick_dev::ardupilot::ardupilot_source": "https://github.com/ardupilot/ardupilot",
24+
"maverick_dev::px4": false,
25+
// "maverick_dev::vscode_watchers": 524288,
26+
27+
// "maverick_dev::px4::cross_compile": false,
28+
// "maverick_dev::px4::sitl_active": false,
29+
// "maverick_dev::px4::mavlink_active": false,
30+
// "maverick_dev::px4::rosmaster_active": false,
31+
// "maverick_dev::px4::mavros_active": false,
32+
// "maverick_dev::px4::api_active": false,
33+
// "maverick_dev::apsitl_dev::sitl_active": true,
34+
// "maverick_dev::apsitl_dev::mavlink_active": true,
35+
// "maverick_dev::apsitl_dev::mavros_active": true,
36+
// "maverick_dev::apsitl_dev::rosmaster_active": true,
37+
// "maverick_dev::apsitl_dev::api_active": true,
38+
// "maverick_ros::ros2": true,
39+
// "maverick_desktop::enable": true, // Desktop is disabled by default
40+
// "maverick_network::zerotier::libzt": true,
41+
// Flight Controller (fc) mavlink setup
42+
// "maverick_fc::mavlink_proxy": "mavproxy", // Default mavlink proxy type to use
43+
"maverick_fc::mavlink_active": false, // Whether the mavlink proxy is active or not
44+
// "maverick_fc::mavlink_input": "/dev/ttyS1", // Input source for mavlink proxy, how the Companion Computer connects to the Flight Controller
45+
// "maverick_fc::mavlink_baud": "115200", // Input baud rate for UART connections
46+
"maverick_fc::rosmaster_active": false, // Whether ROS master for fc is active or not
47+
"maverick_fc::mavros_active": false, // Whether Mavros for fc is active or not - requires fc rosmaster to be active
48+
// Dev SITL mavlink setup - note this requires dev environment to be active
49+
// "maverick_dev::sitl::mavlink_proxy": "mavlink-router", // Default mavlink proxy type to use
50+
// "maverick_dev::sitl::sitl_active": true, // Whether SITL is active or not
51+
// "maverick_dev::sitl::mavlink_active": true, // Whether mavlink proxy is active or not
52+
// "maverick_dev::sitl::rosmaster_active": false, // Whether ROS master for sitl is active or not
53+
// "maverick_dev::sitl::mavros_active": false, // Whether Mavros for sitl is active or not - requires sitl rosmaster to be active
54+
// "maverick_mavlink::mavcesium_active": false,
55+
// "maverick_dev::ardupilot::armeabi_packages": false, // Set to true to install packages that allow px4 firmware to be compiled and uploaded to fc
56+
57+
"maverick_ros::module_realsense": true,
58+
// "maverick_ros::ros2::installtype": "source",
59+
// "maverick_ros::ros2::distribution": "dashing",
60+
61+
"maverick_vision::visiond::active": false, // Whether visiond is active or not
62+
"maverick_vision::visiond::webvision_active": false,
63+
// "maverick_vision::vision_landing::active": false, // Whether vision_landing is active or not
64+
65+
"maverick_web::cloud9::cloud9_password": "boseheadphonesaresilver",
66+
"maverick_web::cloud9::cloud9_active": true,
67+
"maverick_web::server_fqdn": "dev.maverick.one",
68+
// "maverick_web::maverick_api": true,
69+
// "maverick_web::maverick_api::rosdistro": "kinetic",
70+
"maverick_web::maverick_web": true,
71+
"maverick_web::maverick_web::active": true,
72+
// "maverick_web::maverick_web::auth_message": "Restricted Access",
73+
// "maverick_web::maverick_web::auth_file": "/srv/maverick/data/web/.htpasswd",
74+
"maverick_web::nginx::www_root": "/var/www/html",
75+
"maverick_web::nginx::downloads": true,
76+
"maverick_web::nginx::downloads_dir": "/var/www/html/maverick/downloads",
77+
"maverick_web::codeserver": false,
78+
"maverick_web::codeserver::active": false,
79+
"maverick_web::codeserver::password": "boseheadphonesaresilver",
80+
81+
"maverick_web::janus::active": false,
82+
83+
"maverick_dev::apsitl_dev::api_devmode": true,
84+
"maverick_dev::apsitl_dev::api_debug": true,
85+
"maverick_dev::apsitl_dev::override": true,
86+
87+
// "maverick_ros::ros1::installtype": "source",
88+
// "maverick_ros::ros1::distribution": "melodic",
89+
// "maverick_ros::ros2::installtype": "source",
90+
// "maverick_ros::ros2::distribution": "dashing",
91+
92+
// Add classes here
93+
"classes": [
94+
// "sample_sitl_swarm",
95+
"api_py3"
96+
// "jenkins"
97+
// "maverick_network" // CAUTION: Read what this does before enabling: https://goodrobots.github.io/maverick/#/modules-network
98+
]
99+
}

maverick_api/modules/base/apiserver/__init__.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919

2020
from maverick_api.modules.base.tornadoql.tornadoql import TornadoQL
21+
from maverick_api.modules.base.database import MavDatabase
2122

2223
from maverick_api.modules import (
2324
generate_schema,
@@ -35,11 +36,10 @@ class ApiServer(object):
3536
def __init__(self):
3637
self.exit = False
3738
self.server = None
38-
self.mavros_connection = None
39-
self.mavlink_connection = None
39+
self.database = None
4040

41-
signal.signal(signal.SIGINT, self.exit_gracefully)
42-
signal.signal(signal.SIGTERM, self.exit_gracefully)
41+
signal.signal(signal.SIGINT, self.handle_signal)
42+
signal.signal(signal.SIGTERM, self.handle_signal)
4343

4444
def initialize(self):
4545
loop = tornado.ioloop.IOLoop.current()
@@ -61,6 +61,7 @@ def initialize(self):
6161
sys.exit(0)
6262

6363
start_all_modules()
64+
self.database = MavDatabase()
6465
ssl_options = self.get_ssl_options()
6566

6667
application = TornadoQL()
@@ -128,17 +129,25 @@ def serve(self):
128129
tornado.ioloop.IOLoop.current().start()
129130
# this function blocks at this point until the server
130131
# is asked to exit via request_stop()
131-
application_log.info("Maverick API server has stopped")
132+
self.exit_gracefully()
132133

133134
def request_stop(self):
134135
# TODO: close all websocket connections (required?)
136+
self.exit = True
135137
ioloop = tornado.ioloop.IOLoop.current()
136138
ioloop.add_callback(ioloop.stop)
137139
application_log.info("Stopping Maverick API server")
138140

139-
def exit_gracefully(self, signum, frame):
140-
"""called on sigterm"""
141-
self.exit = True
141+
def exit_gracefully(self):
142+
ioloop = tornado.ioloop.IOLoop.current()
142143
stop_all_modules()
143144
stop_all_schema()
144-
self.request_stop()
145+
if self.database:
146+
ioloop.run_sync(self.database.shutdown)
147+
ioloop.close()
148+
application_log.info("Maverick API server has stopped")
149+
150+
def handle_signal(self, signum, frame):
151+
"""called on sigterm"""
152+
ioloop = tornado.ioloop.IOLoop.current()
153+
ioloop.add_callback_from_signal(self.request_stop)
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import logging
2+
3+
# from pathlib import Path
24
from tornado.options import options
5+
import tornado.ioloop
6+
from tortoise import Tortoise
7+
8+
# from maverick_api.modules.base.util import functions
39

410
application_log = logging.getLogger("tornado.application")
511

@@ -10,12 +16,16 @@ class MavDatabase(object):
1016
def __init__(self):
1117
self.backend = options.database_backend
1218
application_log.info(f"Database backend seleceted: {self.backend}")
19+
ioloop = tornado.ioloop.IOLoop.current()
20+
ioloop.run_sync(self.init)
21+
22+
async def init(self):
23+
# Here we create a SQLite DB using file "db.sqlite3"
24+
# also specify the app name of "models"
25+
# which contain models from "app.models"
26+
await Tortoise.init(db_url="sqlite://db.sqlite3", modules={"models": []})
27+
# Generate the schema
28+
await Tortoise.generate_schemas()
1329

14-
if self.backend == "tinydb": # lightweight non-async json storage
15-
import tinydb # noqa: F401
16-
elif self.backend == "mongo": # async access to mongo database
17-
import motor # noqa: F401
18-
elif self.backend == "sqlite": # async access to sqlite3 database
19-
import aiosqlite # noqa: F401
20-
else:
21-
pass
30+
async def shutdown(self):
31+
await Tortoise.close_connections()

0 commit comments

Comments
 (0)