Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 0 additions & 126 deletions .basedpyright/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -1070,24 +1070,6 @@
}
}
],
"./monitoring/mock_uss/dynamic_configuration/routes.py": [
{
"code": "reportReturnType",
"range": {
"startColumn": 11,
"endColumn": 5,
"lineCount": 3
}
},
{
"code": "reportReturnType",
"range": {
"startColumn": 11,
"endColumn": 5,
"lineCount": 3
}
}
],
"./monitoring/mock_uss/f3548v21/flight_planning.py": [
{
"code": "reportOperatorIssue",
Expand Down Expand Up @@ -1552,24 +1534,6 @@
}
}
],
"./monitoring/mock_uss/riddp/routes_behavior.py": [
{
"code": "reportReturnType",
"range": {
"startColumn": 11,
"endColumn": 37,
"lineCount": 1
}
},
{
"code": "reportReturnType",
"range": {
"startColumn": 11,
"endColumn": 43,
"lineCount": 1
}
}
],
"./monitoring/mock_uss/riddp/routes_observation.py": [
{
"code": "reportOptionalMemberAccess",
Expand Down Expand Up @@ -1802,14 +1766,6 @@
"endColumn": 87,
"lineCount": 1
}
},
{
"code": "reportReturnType",
"range": {
"startColumn": 11,
"endColumn": 32,
"lineCount": 1
}
}
],
"./monitoring/mock_uss/ridsp/behavior.py": [
Expand Down Expand Up @@ -1846,24 +1802,6 @@
}
}
],
"./monitoring/mock_uss/ridsp/routes_behavior.py": [
{
"code": "reportReturnType",
"range": {
"startColumn": 11,
"endColumn": 37,
"lineCount": 1
}
},
{
"code": "reportReturnType",
"range": {
"startColumn": 11,
"endColumn": 43,
"lineCount": 1
}
}
],
"./monitoring/mock_uss/ridsp/routes_injection.py": [
{
"code": "reportOperatorIssue",
Expand All @@ -1889,14 +1827,6 @@
"lineCount": 1
}
},
{
"code": "reportReturnType",
"range": {
"startColumn": 15,
"endColumn": 38,
"lineCount": 1
}
},
{
"code": "reportOptionalMemberAccess",
"range": {
Expand Down Expand Up @@ -1928,62 +1858,6 @@
"endColumn": 120,
"lineCount": 1
}
},
{
"code": "reportReturnType",
"range": {
"startColumn": 19,
"endColumn": 42,
"lineCount": 1
}
},
{
"code": "reportReturnType",
"range": {
"startColumn": 11,
"endColumn": 5,
"lineCount": 3
}
},
{
"code": "reportReturnType",
"range": {
"startColumn": 12,
"endColumn": 86,
"lineCount": 1
}
},
{
"code": "reportReturnType",
"range": {
"startColumn": 12,
"endColumn": 77,
"lineCount": 1
}
},
{
"code": "reportReturnType",
"range": {
"startColumn": 16,
"endColumn": 82,
"lineCount": 1
}
},
{
"code": "reportReturnType",
"range": {
"startColumn": 12,
"endColumn": 13,
"lineCount": 3
}
},
{
"code": "reportReturnType",
"range": {
"startColumn": 11,
"endColumn": 27,
"lineCount": 1
}
}
],
"./monitoring/mock_uss/ridsp/routes_ridsp_v19.py": [
Expand Down
2 changes: 1 addition & 1 deletion monitoring/mock_uss/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Database(ImplicitDict):
"""Timestamp of most recent time periodic task loop iterated"""


db = SynchronizedValue(
db = SynchronizedValue[Database](
Database(
one_time_tasks=[],
task_errors=[],
Expand Down
6 changes: 3 additions & 3 deletions monitoring/mock_uss/dynamic_configuration/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DynamicConfiguration(ImplicitDict):
locale: LocalityCode


db = SynchronizedValue(
db = SynchronizedValue[DynamicConfiguration](
DynamicConfiguration(locale=LocalityCode(webapp.config[KEY_BEHAVIOR_LOCALITY])),
decoder=lambda b: ImplicitDict.parse(
json.loads(b.decode("utf-8")), DynamicConfiguration
Expand All @@ -24,6 +24,6 @@ class DynamicConfiguration(ImplicitDict):


def get_locality() -> Locality:
with db as tx:
code = tx.locale
with db.transact() as tx:
code = tx.value.locale
return Locality.from_locale(code)
8 changes: 4 additions & 4 deletions monitoring/mock_uss/dynamic_configuration/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@


@webapp.route("/configuration/locality", methods=["GET"])
def locality_get() -> tuple[str, int]:
def locality_get() -> flask.Response:
return flask.jsonify(
GetLocalityResponse(locality_code=get_locality().locality_code())
)


@webapp.route("/configuration/locality", methods=["PUT"])
@requires_scope(MOCK_USS_CONFIG_SCOPE) # TODO: use separate public key for this
def locality_set() -> tuple[str, int]:
def locality_set() -> tuple[str, int] | flask.Response:
"""Set the locality of the mock_uss."""
try:
json = flask.request.json
Expand All @@ -38,8 +38,8 @@ def locality_set() -> tuple[str, int]:
msg = f"Invalid locality_code: {str(e)}"
return msg, 400

with db as tx:
tx.locale = req.locality_code
with db.transact() as tx:
tx.value.locale = req.locality_code

return flask.jsonify(
GetLocalityResponse(locality_code=get_locality().locality_code())
Expand Down
11 changes: 8 additions & 3 deletions monitoring/mock_uss/geoawareness/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
GeozoneSourceResponseResult,
)

from monitoring.mock_uss.geoawareness.database import Database, SourceRecord, db
from monitoring.mock_uss.geoawareness import database
from monitoring.mock_uss.geoawareness.database import SourceRecord, db
from monitoring.mock_uss.geoawareness.ed269 import evaluate_source

logger = logging.getLogger(__name__)
Expand All @@ -27,7 +28,7 @@ def combine_results(


def check_geozones(req: GeozonesCheckRequest) -> list[GeozonesCheckResultGeozone]:
sources: dict[str, SourceRecord] = Database.get_sources(db)
sources: dict[str, SourceRecord] = database.get_sources(db)

results: list[GeozonesCheckResultGeozone] = [
GeozonesCheckResultGeozone.Absent
Expand All @@ -44,7 +45,11 @@ def check_geozones(req: GeozonesCheckRequest) -> list[GeozonesCheckResultGeozone
)
continue

fmt = source.definition.https_source.format
fmt = (
source.definition.https_source.format
if source.definition.https_source
else None
)
if fmt == GeozoneHttpsSourceFormat.ED_269:
logger.debug(f" {j + 1}. ED269 source {source_id} ready.")
result = combine_results(
Expand Down
111 changes: 57 additions & 54 deletions monitoring/mock_uss/geoawareness/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,60 +26,63 @@ class Database(ImplicitDict):

sources: dict[str, SourceRecord] = {}

@staticmethod
def get_source(db: SynchronizedValue, id: str) -> SourceRecord:
return db.value.sources.get(id, None)

@staticmethod
def get_sources(db: SynchronizedValue) -> SourceRecord:
return db.value.sources

@staticmethod
def insert_source(
db: SynchronizedValue,
id: str,
definition: CreateGeozoneSourceRequest,
state: GeozoneSourceResponseResult,
message: str | None = None,
) -> SourceRecord:
with db as tx:
if id in tx.sources.keys():
raise ExistingRecordException()
tx.sources[id] = SourceRecord(
definition=definition, state=state, message=message
)
result = tx.sources[id]
return result

@staticmethod
def update_source_state(
db: SynchronizedValue,
id: str,
state: GeozoneSourceResponseResult,
message: str | None = None,
):
with db as tx:
tx.sources[id]["state"] = state
tx.sources[id]["message"] = message
result = tx.sources[id]
return result

@staticmethod
def update_source_geozone_ed269(
db: SynchronizedValue, id: str, geozone: ED269Schema
):
with db as tx:
tx.sources[id]["geozone_ed269"] = geozone
result = tx.sources[id]
return result

@staticmethod
def delete_source(db: SynchronizedValue, id: str):
with db as tx:
return tx.sources.pop(id, None)


db = SynchronizedValue(

def get_source(geo_db: SynchronizedValue[Database], source_id: str) -> SourceRecord:
result = geo_db.value.sources.get(source_id, None)
if result is None:
raise KeyError(f"No source exists with id '{source_id}'")
return result


def get_sources(geo_db: SynchronizedValue[Database]) -> dict[str, SourceRecord]:
return geo_db.value.sources


def insert_source(
geo_db: SynchronizedValue[Database],
source_id: str,
definition: CreateGeozoneSourceRequest,
state: GeozoneSourceResponseResult,
message: str | None = None,
) -> SourceRecord:
with geo_db.transact() as tx:
if source_id in tx.value.sources.keys():
raise ExistingRecordException()
tx.value.sources[source_id] = SourceRecord(
definition=definition, state=state, message=message
)
result = tx.value.sources[source_id]
return result


def update_source_state(
geo_db: SynchronizedValue[Database],
source_id: str,
state: GeozoneSourceResponseResult,
message: str | None = None,
):
with geo_db.transact() as tx:
tx.value.sources[source_id]["state"] = state
tx.value.sources[source_id]["message"] = message
result = tx.value.sources[source_id]
return result


def update_source_geozone_ed269(
geo_db: SynchronizedValue[Database], source_id: str, geozone: ED269Schema
):
with geo_db.transact() as tx:
tx.value.sources[source_id]["geozone_ed269"] = geozone
result = tx.value.sources[source_id]
return result


def delete_source(geo_db: SynchronizedValue[Database], source_id: str):
with geo_db.transact() as tx:
return tx.value.sources.pop(source_id, None)


db = SynchronizedValue[Database](
Database(),
decoder=lambda b: ImplicitDict.parse(json.loads(b.decode("utf-8")), Database),
)
Loading
Loading