Skip to content

Commit 35a719f

Browse files
committed
Update handling of environment variables
1 parent 5c4642e commit 35a719f

File tree

7 files changed

+32
-15
lines changed

7 files changed

+32
-15
lines changed

.env.local

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
SO_API=/api
1+
SO_API=http://localhost:8000
22
SO_MQTT=localhost
3-
SO_MQTT_PORT=8080
3+
SO_MQTT_PORT=8083
44
SO_MQTT_PATH=/mqtt
55
SO_MCS_USERNAME=sim
66
SO_MCS_PASSWORD=ops
77
SO_MCS_ADMIN_PASSWORD=admin
88
SO_MCS_SIMPLE=0
9+
SO_CONTROL_TCP=tcp://localhost:5555

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ A Python (version 3.11 recommended) needs to be available, the list of required
4545

4646
Once an MQTT is running and reachable and all the requirements installed, run:
4747

48+
# setup environment variables (required for all scripts and npm)
49+
sim-ops$ . scripts/export.env.dev.sh .env.local
50+
4851
sim-ops$ cd sim-ops-lib
4952

5053
# run master script
@@ -57,6 +60,7 @@ Once an MQTT is running and reachable and all the requirements installed, run:
5760

5861
# run mcs
5962
sim-ops-mcs$ npm run dev
63+
# mcs is available from http://localhost:5173
6064

6165
Running Python lib tests:
6266

scripts/export-env.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
# export variables
4+
export $(grep -v '^#' $1 | xargs)
5+
6+
# export variables for vite env
7+
export $(grep -v '^#' $1 | sed -r 's/SO_/VITE_SO_/g' | xargs)

sim-ops-lib/so/api.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _admin_status(admin_pw: str):
4949
if _valid_auth(admin_pw):
5050
return _control({ 'system': 'admin', 'control': 'status', 'value': 'null' })
5151
else:
52-
raise HTTPException(status_code=405, detail='Requires admin auth:'+MCS_ADMIN_PW)
52+
raise HTTPException(status_code=405, detail='Requires admin auth:')
5353

5454
@app.post('/admin', status_code=200)
5555
async def _admin(admin_pw: str, request: Request):
@@ -59,13 +59,12 @@ async def _admin(admin_pw: str, request: Request):
5959
else:
6060
raise HTTPException(status_code=405, detail='Requires admin auth.')
6161

62-
@app.post('/control', status_code=200)
63-
async def _ground_stations_control(admin_pw: str, request: Request):
64-
if _valid_auth(admin_pw):
65-
body = await request.json()
66-
return _control(body)
67-
else:
68-
raise HTTPException(status_code=405, detail='Requires admin auth.')
62+
@app.post('/control')
63+
async def _ground_stations_control(request: Request):
64+
body = await request.json()
65+
result = _control(body)
66+
67+
return result
6968

7069
@app.get('/admin/hist')
7170
def _control_hist():

sim-ops-lib/so/mqtt.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11

2-
import json
2+
import os, json
33
import paho.mqtt.client as mqtt
44

5+
SO_MQTT = os.getenv('SO_MQTT', 'so-mqtt')
6+
if not SO_MQTT:
7+
SO_MQTT = 'so-mqtt'
8+
59
class MQTT:
6-
def __init__(self) -> None:
10+
def __init__(self, host=SO_MQTT, port=1883) -> None:
711
self.client = mqtt.Client()
8-
self.client.connect(host='so-mqtt', port=1883)
12+
self.client.connect(host=host, port=port)
913

1014
def publish(self, topic, data):
11-
print('publis', 'topic', topic)
1215
return self.client.publish(topic, json.dumps(data))

sim-ops-mcs/src/utils/env.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

22
export default function getEnv(name, default_) {
3+
const _name = `VITE_${name}`
4+
if (_name in import.meta.env)
5+
return import.meta.env?.[_name]
6+
37
return (window?.configs?.[name] || default_)
48
}
59

sim-ops-mcs/src/views/Admin.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ export default {
6262
methods: {
6363
handleAuth() {
6464
this.admin_pw = document.getElementById("password").value;
65-
console.log('handleAtuh:'+this.admin_pw)
6665
this.adminStatus();
6766
},
6867
resetAuth() {

0 commit comments

Comments
 (0)