mirror of
https://github.com/projecthorus/sondehub-infra.git
synced 2025-04-09 12:01:15 +00:00
forgot to add the ham listner folder
This commit is contained in:
parent
915ae277de
commit
f2622844fc
59
lambda/ham_listener_put/__init__.py
Normal file
59
lambda/ham_listener_put/__init__.py
Normal file
@ -0,0 +1,59 @@
|
||||
import json
|
||||
import zlib
|
||||
import base64
|
||||
import datetime
|
||||
from email.utils import parsedate
|
||||
|
||||
CALLSIGN_BLOCK_LIST = ["CHANGEME_RDZTTGO"]
|
||||
|
||||
import es
|
||||
|
||||
def lambda_handler(event, context):
|
||||
if "isBase64Encoded" in event and event["isBase64Encoded"] == True:
|
||||
event["body"] = base64.b64decode(event["body"])
|
||||
if (
|
||||
"content-encoding" in event["headers"]
|
||||
and event["headers"]["content-encoding"] == "gzip"
|
||||
):
|
||||
event["body"] = zlib.decompress(event["body"], 16 + zlib.MAX_WBITS)
|
||||
time_delta = None
|
||||
if "date" in event["headers"]:
|
||||
try:
|
||||
time_delta_header = event["headers"]["date"]
|
||||
time_delta = (
|
||||
datetime.datetime(*parsedate(time_delta_header)[:7])
|
||||
- datetime.datetime.utcfromtimestamp(event["requestContext"]["timeEpoch"]/1000)
|
||||
).total_seconds()
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
payload = json.loads(event["body"])
|
||||
except:
|
||||
return {"statusCode": 400, "body": "JSON decode issue"}
|
||||
print(payload)
|
||||
if "user-agent" in event["headers"]:
|
||||
event["time_server"] = datetime.datetime.now().isoformat()
|
||||
payload["user-agent"] = event["headers"]["user-agent"]
|
||||
if time_delta:
|
||||
payload["upload_time_delta"] = time_delta
|
||||
|
||||
payload.pop("uploader_contact_email", None)
|
||||
|
||||
# clean up None reports
|
||||
|
||||
if "uploader_position" in payload and None == payload["uploader_position"] or None in payload["uploader_position"]:
|
||||
payload.pop("uploader_position", None)
|
||||
|
||||
if "uploader_position" in payload:
|
||||
(payload["uploader_alt"], payload["uploader_position_elk"]) = (
|
||||
payload["uploader_position"][2],
|
||||
f"{payload['uploader_position'][0]},{payload['uploader_position'][1]}",
|
||||
)
|
||||
if payload["uploader_callsign"] in CALLSIGN_BLOCK_LIST:
|
||||
return {"statusCode": 403, "body": "callsign blocked or invalid"}
|
||||
index = datetime.datetime.utcnow().strftime("ham-listeners-%Y-%m")
|
||||
payload["ts"] = datetime.datetime.utcnow().isoformat()
|
||||
|
||||
es.request(json.dumps(payload),f"{index}/_doc","POST")
|
||||
|
||||
return {"statusCode": 200, "body": "^v^ telm logged"}
|
43
lambda/ham_listener_put/__main__.py
Normal file
43
lambda/ham_listener_put/__main__.py
Normal file
@ -0,0 +1,43 @@
|
||||
from . import *
|
||||
payload = {
|
||||
"version": "2.0",
|
||||
"routeKey": "PUT /sondes/telemetry",
|
||||
"rawPath": "/sondes/telemetry",
|
||||
"rawQueryString": "",
|
||||
"headers": {
|
||||
"accept": "*/*",
|
||||
"accept-encoding": "gzip, deflate",
|
||||
"content-length": "2135",
|
||||
"content-type": "application/json",
|
||||
"host": "api.v2.sondehub.org",
|
||||
"user-agent": "autorx-1.4.1-beta4",
|
||||
"x-amzn-trace-id": "Root=1-6015f571-6aef2e73165042d53fcc317a",
|
||||
"x-forwarded-for": "103.107.130.22",
|
||||
"x-forwarded-port": "443",
|
||||
"x-forwarded-proto": "https",
|
||||
"date": "Sun, 31 Jan 2021 00:21:45 GMT",
|
||||
},
|
||||
"requestContext": {
|
||||
"accountId": "143841941773",
|
||||
"apiId": "r03szwwq41",
|
||||
"domainName": "api.v2.sondehub.org",
|
||||
"domainPrefix": "api",
|
||||
"http": {
|
||||
"method": "PUT",
|
||||
"path": "/sondes/telemetry",
|
||||
"protocol": "HTTP/1.1",
|
||||
"sourceIp": "103.107.130.22",
|
||||
"userAgent": "autorx-1.4.1-beta4",
|
||||
},
|
||||
"requestId": "Z_NJvh0RoAMEJaw=",
|
||||
"routeKey": "PUT /sondes/telemetry",
|
||||
"stage": "$default",
|
||||
"time": "31/Jan/2021:00:10:25 +0000",
|
||||
"timeEpoch": 1612051825409,
|
||||
},
|
||||
"body": """
|
||||
{"software_name": "radiosonde_auto_rx", "software_version": "1.5.8-beta2", "uploader_callsign": "CHANGEME_RDZTTGO", "uploader_position": [null,null,null], "uploader_antenna": "Dipole", "uploader_contact_email": "none@none.com", "mobile": false}
|
||||
""",
|
||||
"isBase64Encoded": False,
|
||||
}
|
||||
print(lambda_handler(payload, {}))
|
Loading…
x
Reference in New Issue
Block a user