Skip to content

Commit

Permalink
[mock_uss] add isa notification endpoint to mock RID display provider (
Browse files Browse the repository at this point in the history
  • Loading branch information
Shastick authored Jan 15, 2025
1 parent 5d6d38c commit 6d7c256
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
13 changes: 13 additions & 0 deletions monitoring/mock_uss/riddp/routes.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
from monitoring.mock_uss import webapp
from monitoring.mock_uss.riddp.config import KEY_RID_VERSION
from ...monitorlib.rid import RIDVersion

rid_version: RIDVersion = webapp.config[KEY_RID_VERSION]


@webapp.route("/riddp/status")
def riddp_status():
return "Mock RID Display Provider ok"


if rid_version == RIDVersion.f3411_19:
from . import routes_riddp_v19
elif rid_version == RIDVersion.f3411_22a:
from . import routes_riddp_v22a
else:
raise NotImplementedError(
f"Mock USS does not yet support RID version {rid_version}"
)

from . import routes_observation
from . import routes_behavior
39 changes: 39 additions & 0 deletions monitoring/mock_uss/riddp/routes_riddp_v19.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import flask
from implicitdict import ImplicitDict
from uas_standards.astm.f3411.v19.api import (
OperationID,
OPERATIONS,
PutIdentificationServiceAreaNotificationParameters,
)
from uas_standards.astm.f3411.v19.constants import (
Scope,
)

from monitoring.mock_uss import webapp
from monitoring.mock_uss.auth import requires_scope


def rid_v19_operation(op_id: OperationID):
op = OPERATIONS[op_id]
path = op.path.replace("{", "<").replace("}", ">")
return webapp.route("/mock/riddp" + path, methods=[op.verb])


@rid_v19_operation(OperationID.PostIdentificationServiceArea)
@requires_scope(Scope.Write)
def ridsp_notify_isa_v19(id: str):
try:
json = flask.request.json
if json is None:
raise ValueError("Request did not contain a JSON payload")
ImplicitDict.parse(json, PutIdentificationServiceAreaNotificationParameters)
except ValueError as e:
msg = "Unable to parse PutIdentificationServiceAreaNotificationParameters JSON request: {}".format(
e
)
return msg, 400

return (
flask.jsonify(None),
204,
)
39 changes: 39 additions & 0 deletions monitoring/mock_uss/riddp/routes_riddp_v22a.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import flask
from implicitdict import ImplicitDict
from uas_standards.astm.f3411.v22a.api import (
OperationID,
OPERATIONS,
PutIdentificationServiceAreaNotificationParameters,
)
from uas_standards.astm.f3411.v22a.constants import (
Scope,
)

from monitoring.mock_uss import webapp
from monitoring.mock_uss.auth import requires_scope


def rid_v22a_operation(op_id: OperationID):
op = OPERATIONS[op_id]
path = op.path.replace("{", "<").replace("}", ">")
return webapp.route("/mock/riddp" + path, methods=[op.verb])


@rid_v22a_operation(OperationID.PostIdentificationServiceArea)
@requires_scope(Scope.ServiceProvider)
def ridsp_notify_isa_v22a(id: str):
try:
json = flask.request.json
if json is None:
raise ValueError("Request did not contain a JSON payload")
ImplicitDict.parse(json, PutIdentificationServiceAreaNotificationParameters)
except ValueError as e:
msg = "Unable to parse PutIdentificationServiceAreaNotificationParameters JSON request: {}".format(
e
)
return msg, 400

return (
flask.jsonify(None),
204,
)

0 comments on commit 6d7c256

Please sign in to comment.