A
8672b0de6b
Full working closed-loop eSIM provisioning stack (spec in claude.md / plan/): Flask API, SQLite subscriber store, credential/profile generator, Open5GS and free5gc core adapters, captive portal, operational scripts, systemd units, network configs, and a 44-test suite. Profile generation currently returns a mock JSON profile; real SGP.22 generation via pySim is the planned Phase-2 upgrade. Fixes two bugs found while getting the suite green: - generate_imsi hardcoded a 10-digit MSIN, producing 16-digit IMSIs for a 3-digit MNC; MSIN length is now 15 - len(mcc) - len(mnc). - check_rate_limit compared timestamps as strings across mismatched formats (SQLite CURRENT_TIMESTAMP vs Python isoformat); both sides now normalized via SQLite datetime() so the window check is chronologically correct. Add .gitignore for venv, caches, runtime config.yaml, and databases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
import logging
|
|
|
|
from pymongo import MongoClient
|
|
|
|
from .base import CoreAdapter
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class Open5GSAdapter(CoreAdapter):
|
|
def __init__(self, mongodb_uri: str, database_name: str = "open5gs"):
|
|
self.client = MongoClient(mongodb_uri)
|
|
self.db = self.client[database_name]
|
|
|
|
def add_subscriber(self, imsi: str, ki: str, opc: str) -> None:
|
|
"""Upsert a subscriber into the Open5GS MongoDB collection."""
|
|
doc = {
|
|
"imsi": imsi,
|
|
"security": {
|
|
"k": ki,
|
|
"opc": opc,
|
|
"amf": "8000",
|
|
"sqn": 0,
|
|
},
|
|
"ambr": {
|
|
"downlink": {"value": 1, "unit": 3},
|
|
"uplink": {"value": 1, "unit": 3},
|
|
},
|
|
"slice": [
|
|
{
|
|
"sst": 1,
|
|
"default_indicator": True,
|
|
"session": [
|
|
{
|
|
"name": "internet",
|
|
"type": 3,
|
|
"ambr": {
|
|
"downlink": {"value": 1, "unit": 3},
|
|
"uplink": {"value": 1, "unit": 3},
|
|
},
|
|
}
|
|
],
|
|
}
|
|
],
|
|
}
|
|
self.db.subscribers.replace_one({"imsi": imsi}, doc, upsert=True)
|
|
logger.info(f"Added subscriber {imsi} to Open5GS")
|
|
|
|
def remove_subscriber(self, imsi: str) -> None:
|
|
self.db.subscribers.delete_one({"imsi": imsi})
|
|
logger.info(f"Removed subscriber {imsi} from Open5GS")
|
|
|
|
def list_subscribers(self) -> list:
|
|
return list(self.db.subscribers.find({}, {"_id": 0}))
|