Skip to content

Commit

Permalink
[uss_qualifier] warn upon unattributed or untyped queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Shastick committed Dec 21, 2023
1 parent d9c8ea8 commit 6167a65
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 32 deletions.
137 changes: 131 additions & 6 deletions monitoring/monitorlib/fetch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,81 @@ def describe_flask_response(resp: flask.Response, elapsed_s: float):


class QueryType(str, Enum):
F3411v22aFlights = "astm.f3411.v22a.sp.flights"
F3411v19Flights = "astm.f3411.v19.sp.flights"
F3411v22aFlightDetails = "astm.f3411.v22a.sp.flight_details"
F3411v19aFlightDetails = "astm.f3411.v19.sp.flight_details"

# ASTM F3411-19 and F3411-22a (RID)
F3411v19DSSSearchIdentificationServiceAreas = (
"astm.f3411.v19.dss.searchIdentificationServiceAreas"
)
F3411v22aDSSSearchIdentificationServiceAreas = (
"astm.f3411.v22a.dss.searchIdentificationServiceAreas"
)

F3411v19DSSGetIdentificationServiceArea = (
"astm.f3411.v19.dss.getIdentificationServiceArea"
)
F3411v22aDSSGetIdentificationServiceArea = (
"astm.f3411.v22a.dss.getIdentificationServiceArea"
)

F3411v19DSSCreateIdentificationServiceArea = (
"astm.f3411.v19.dss.createIdentificationServiceArea"
)
F3411v22aDSSCreateIdentificationServiceArea = (
"astm.f3411.v22a.dss.createIdentificationServiceArea"
)

F3411v19DSSUpdateIdentificationServiceArea = (
"astm.f3411.v19.dss.updateIdentificationServiceArea"
)
F3411v22aDSSUpdateIdentificationServiceArea = (
"astm.f3411.v22a.dss.updateIdentificationServiceArea"
)

F3411v19DSSDeleteIdentificationServiceArea = (
"astm.f3411.v19.dss.deleteIdentificationServiceArea"
)
F3411v22aDSSDeleteIdentificationServiceArea = (
"astm.f3411.v22a.dss.deleteIdentificationServiceArea"
)

F3411v19DSSSearchFlights = "astm.f3411.v19.dss.searchFlights"
F3411v22aDSSSearchFlights = "astm.f3411.v22a.dss.searchFlights"

F3411v19DSSSearchSubscriptions = "astm.f3411.v19.dss.searchSubscriptions"
F3411v22aDSSSearchSubscriptions = "astm.f3411.v22a.dss.searchSubscriptions"

F3411v19DSSGetSubscription = "astm.f3411.v19.dss.getSubscription"
F3411v22aDSSGetSubscription = "astm.f3411.v22a.dss.getSubscription"

F3411v19DSSCreateSubscription = "astm.f3411.v19.dss.createSubscription"
F3411v22aDSSCreateSubscription = "astm.f3411.v22a.dss.createSubscription"

F3411v19DSSUpdateSubscription = "astm.f3411.v19.dss.updateSubscription"
F3411v22aDSSUpdateSubscription = "astm.f3411.v22a.dss.updateSubscription"

F3411v19DSSDeleteSubscription = "astm.f3411.v19.dss.deleteSubscription"
F3411v22aDSSDeleteSubscription = "astm.f3411.v22a.dss.deleteSubscription"

F3411v19USSPostIdentificationServiceArea = (
"astm.f3411.v19.uss.postIdentificationServiceArea"
)
F3411v22aUSSPostIdentificationServiceArea = (
"astm.f3411.v22a.uss.postIdentificationServiceArea"
)

# Flight injection (test harness)

F3411v19USSCreateTest = "rid.f3411.v19.sp.createTest"
F3411v22aUSSCreateTest = "rid.f3411.v22a.sp.createTest"

F3411v19USSDeleteTest = "rid.f3411.v19.sp.deleteTest"
F3411v22aUSSDeleteTest = "rid.f3411.v22a.sp.deleteTest"

# RID flight details endpoint that a USS provides (!= DSS)
F3411v22aUSSGetDisplayData = "rid.f3411.v22a.sp.getDisplayData"
F3411v19USSGetDisplayData = "rid.f3411.v19.sp.getDisplayData"
F3411v22aUSSGetFlightDetails = "rid.f3411.v22a.sp.getDetails"
F3411v19USSGetFlightDetails = "rid.f3411.v19.sp.getDetails"

# ASTM F3548-21
F3548v21DSSQueryOperationalIntentReferences = (
Expand Down Expand Up @@ -257,9 +328,63 @@ class QueryType(str, Enum):
@staticmethod
def flight_details(rid_version: RIDVersion):
if rid_version == RIDVersion.f3411_19:
return QueryType.F3411v19aFlightDetails
return QueryType.F3411v19USSGetFlightDetails
elif rid_version == RIDVersion.f3411_22a:
return QueryType.F3411v22aUSSGetFlightDetails
else:
raise ValueError(f"Unsupported RID version: {rid_version}")

@staticmethod
def dss_get_isa(rid_version: RIDVersion):
if rid_version == RIDVersion.f3411_19:
return QueryType.F3411v19DSSGetIdentificationServiceArea
elif rid_version == RIDVersion.f3411_22a:
return QueryType.F3411v22aDSSGetIdentificationServiceArea
else:
raise ValueError(f"Unsupported RID version: {rid_version}")

@staticmethod
def dss_create_isa(rid_version: RIDVersion):
if rid_version == RIDVersion.f3411_19:
return QueryType.F3411v19DSSCreateIdentificationServiceArea
elif rid_version == RIDVersion.f3411_22a:
return QueryType.F3411v22aDSSCreateIdentificationServiceArea
else:
raise ValueError(f"Unsupported RID version: {rid_version}")

@staticmethod
def dss_update_isa(rid_version: RIDVersion):
if rid_version == RIDVersion.f3411_19:
return QueryType.F3411v19DSSUpdateIdentificationServiceArea
elif rid_version == RIDVersion.f3411_22a:
return QueryType.F3411v22aDSSUpdateIdentificationServiceArea
else:
raise ValueError(f"Unsupported RID version: {rid_version}")

@staticmethod
def dss_delete_isa(rid_version: RIDVersion):
if rid_version == RIDVersion.f3411_19:
return QueryType.F3411v19DSSDeleteIdentificationServiceArea
elif rid_version == RIDVersion.f3411_22a:
return QueryType.F3411v22aDSSDeleteIdentificationServiceArea
else:
raise ValueError(f"Unsupported RID version: {rid_version}")

@staticmethod
def sp_create_test(rid_version: RIDVersion):
if rid_version == RIDVersion.f3411_19:
return QueryType.F3411v19USSCreateTest
elif rid_version == RIDVersion.f3411_22a:
return QueryType.F3411v22aUSSCreateTest
else:
raise ValueError(f"Unsupported RID version: {rid_version}")

@staticmethod
def sp_delete_test(rid_version: RIDVersion):
if rid_version == RIDVersion.f3411_19:
return QueryType.F3411v19USSDeleteTest
elif rid_version == RIDVersion.f3411_22a:
return QueryType.F3411v22aFlightDetails
return QueryType.F3411v22aUSSDeleteTest
else:
raise ValueError(f"Unsupported RID version: {rid_version}")

Expand Down
29 changes: 26 additions & 3 deletions monitoring/monitorlib/fetch/rid.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,14 @@ def set_participant_id(self, participant_id: str) -> None:
else:
raise NotImplementedError(f"Cannot set participant_id")

def set_query_type(self, query_type: QueryType) -> None:
if self.v19_query is not None:
self.v19_query.query_type = query_type
elif self.v22a_query is not None:
self.v22a_query.query_type = query_type
else:
raise NotImplementedError(f"Cannot set query_type")


class FetchedISA(RIDQuery):
"""Version-independent representation of an ISA read from the DSS."""
Expand Down Expand Up @@ -773,6 +781,7 @@ def isa(
url,
scope=v19.constants.Scope.Read,
participant_id=participant_id,
query_type=QueryType.F3411v19DSSGetIdentificationServiceArea,
)
)
elif rid_version == RIDVersion.f3411_22a:
Expand All @@ -785,6 +794,7 @@ def isa(
url,
scope=v22a.constants.Scope.DisplayProvider,
participant_id=participant_id,
query_type=QueryType.F3411v22aDSSGetIdentificationServiceArea,
)
)
else:
Expand Down Expand Up @@ -915,6 +925,7 @@ def isas(
url,
scope=v19.constants.Scope.Read,
participant_id=participant_id,
query_type=QueryType.F3411v19DSSSearchIdentificationServiceAreas,
)
)
elif rid_version == RIDVersion.f3411_22a:
Expand All @@ -928,6 +939,7 @@ def isas(
url,
scope=v22a.constants.Scope.DisplayProvider,
participant_id=participant_id,
query_type=QueryType.F3411v22aDSSSearchIdentificationServiceAreas,
)
)
else:
Expand Down Expand Up @@ -1023,7 +1035,7 @@ def uss_flights(
else "false",
},
scope=v19.constants.Scope.Read,
query_type=QueryType.F3411v19Flights,
query_type=QueryType.F3411v19USSGetDisplayData,
participant_id=participant_id,
)
return FetchedUSSFlights(v19_query=query)
Expand All @@ -1044,7 +1056,7 @@ def uss_flights(
flights_url,
params=params,
scope=v22a.constants.Scope.DisplayProvider,
query_type=QueryType.F3411v22aFlights,
query_type=QueryType.F3411v22aUSSGetDisplayData,
participant_id=participant_id,
)
return FetchedUSSFlights(v22a_query=query)
Expand Down Expand Up @@ -1143,13 +1155,20 @@ def flight_details(
)
else:
kwargs["scope"] = v19.constants.Scope.Read
query = fetch.query_and_describe(session, "GET", url, **kwargs)
query = fetch.query_and_describe(
session,
"GET",
url,
query_type=QueryType.F3411v19USSGetFlightDetails,
**kwargs,
)
return FetchedUSSFlightDetails(v19_query=query)
elif rid_version == RIDVersion.f3411_22a:
query = fetch.query_and_describe(
session,
"GET",
url,
query_type=QueryType.F3411v22aUSSGetFlightDetails,
scope=v22a.constants.Scope.DisplayProvider,
participant_id=participant_id,
)
Expand Down Expand Up @@ -1329,6 +1348,7 @@ def subscription(
url,
scope=v19.constants.Scope.Read,
participant_id=participant_id,
query_type=QueryType.F3411v19DSSGetSubscription,
)
)
elif rid_version == RIDVersion.f3411_22a:
Expand All @@ -1341,6 +1361,7 @@ def subscription(
url,
scope=v22a.constants.Scope.DisplayProvider,
participant_id=participant_id,
query_type=QueryType.F3411v22aDSSGetSubscription,
)
)
else:
Expand Down Expand Up @@ -1436,6 +1457,7 @@ def subscriptions(
url,
scope=v19.constants.Scope.Read,
participant_id=participant_id,
query_type=QueryType.F3411v19DSSSearchSubscriptions,
)
)
elif rid_version == RIDVersion.f3411_22a:
Expand All @@ -1448,6 +1470,7 @@ def subscriptions(
url,
scope=v22a.constants.Scope.DisplayProvider,
participant_id=participant_id,
query_type=QueryType.F3411v22aDSSSearchSubscriptions,
)
)
else:
Expand Down
Loading

0 comments on commit 6167a65

Please sign in to comment.