diff --git a/.basedpyright/baseline.json b/.basedpyright/baseline.json index 7b7a0f1b51..79f556d844 100644 --- a/.basedpyright/baseline.json +++ b/.basedpyright/baseline.json @@ -1130,14 +1130,6 @@ "endColumn": 41, "lineCount": 1 } - }, - { - "code": "reportAttributeAccessIssue", - "range": { - "startColumn": 20, - "endColumn": 34, - "lineCount": 1 - } } ], "./monitoring/mock_uss/__init__.py": [ @@ -5930,1130 +5922,6 @@ } } ], - "./monitoring/monitorlib/idempotency.py": [ - { - "code": "reportArgumentType", - "range": { - "startColumn": 12, - "endColumn": 32, - "lineCount": 1 - } - } - ], - "./monitoring/monitorlib/infrastructure.py": [ - { - "code": "reportArgumentType", - "range": { - "startColumn": 56, - "endColumn": 60, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 37, - "endColumn": 54, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 37, - "endColumn": 54, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 37, - "endColumn": 48, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 38, - "endColumn": 49, - "lineCount": 1 - } - }, - { - "code": "reportIncompatibleMethodOverride", - "range": { - "startColumn": 8, - "endColumn": 15, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 45, - "endColumn": 50, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 32, - "endColumn": 35, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 32, - "endColumn": 35, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 32, - "endColumn": 36, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 32, - "endColumn": 38, - "lineCount": 1 - } - }, - { - "code": "reportAttributeAccessIssue", - "range": { - "startColumn": 24, - "endColumn": 38, - "lineCount": 1 - } - }, - { - "code": "reportAttributeAccessIssue", - "range": { - "startColumn": 24, - "endColumn": 38, - "lineCount": 1 - } - }, - { - "code": "reportAttributeAccessIssue", - "range": { - "startColumn": 22, - "endColumn": 36, - "lineCount": 1 - } - }, - { - "code": "reportAttributeAccessIssue", - "range": { - "startColumn": 22, - "endColumn": 36, - "lineCount": 1 - } - } - ], - "./monitoring/monitorlib/kml/f3548v21.py": [ - { - "code": "reportInvalidTypeForm", - "range": { - "startColumn": 52, - "endColumn": 55, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 37, - "endColumn": 52, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 37, - "endColumn": 52, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 37, - "endColumn": 64, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 37, - "endColumn": 64, - "lineCount": 1 - } - }, - { - "code": "reportInvalidTypeForm", - "range": { - "startColumn": 5, - "endColumn": 8, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 32, - "endColumn": 52, - "lineCount": 1 - } - }, - { - "code": "reportInvalidTypeForm", - "range": { - "startColumn": 30, - "endColumn": 33, - "lineCount": 1 - } - } - ], - "./monitoring/monitorlib/kml/flight_planning.py": [ - { - "code": "reportInvalidTypeForm", - "range": { - "startColumn": 5, - "endColumn": 8, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 43, - "endColumn": 58, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 43, - "endColumn": 58, - "lineCount": 1 - } - }, - { - "code": "reportInvalidTypeForm", - "range": { - "startColumn": 37, - "endColumn": 40, - "lineCount": 1 - } - } - ], - "./monitoring/monitorlib/kml/generation.py": [ - { - "code": "reportInvalidTypeForm", - "range": { - "startColumn": 5, - "endColumn": 8, - "lineCount": 1 - } - }, - { - "code": "reportOptionalIterable", - "range": { - "startColumn": 31, - "endColumn": 39, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 47, - "endColumn": 55, - "lineCount": 1 - } - }, - { - "code": "reportOptionalIterable", - "range": { - "startColumn": 31, - "endColumn": 39, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 47, - "endColumn": 55, - "lineCount": 1 - } - }, - { - "code": "reportOptionalIterable", - "range": { - "startColumn": 18, - "endColumn": 26, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 24, - "endColumn": 46, - "lineCount": 3 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 24, - "endColumn": 46, - "lineCount": 3 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 37, - "endColumn": 46, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 75, - "endColumn": 84, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 33, - "endColumn": 41, - "lineCount": 1 - } - }, - { - "code": "reportOptionalSubscript", - "range": { - "startColumn": 17, - "endColumn": 25, - "lineCount": 1 - } - }, - { - "code": "reportOptionalSubscript", - "range": { - "startColumn": 35, - "endColumn": 43, - "lineCount": 1 - } - }, - { - "code": "reportOptionalSubscript", - "range": { - "startColumn": 17, - "endColumn": 25, - "lineCount": 1 - } - }, - { - "code": "reportOptionalSubscript", - "range": { - "startColumn": 35, - "endColumn": 43, - "lineCount": 1 - } - }, - { - "code": "reportOptionalSubscript", - "range": { - "startColumn": 17, - "endColumn": 25, - "lineCount": 1 - } - }, - { - "code": "reportOptionalSubscript", - "range": { - "startColumn": 35, - "endColumn": 43, - "lineCount": 1 - } - }, - { - "code": "reportOptionalSubscript", - "range": { - "startColumn": 17, - "endColumn": 25, - "lineCount": 1 - } - }, - { - "code": "reportOptionalSubscript", - "range": { - "startColumn": 35, - "endColumn": 43, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 55, - "endColumn": 79, - "lineCount": 1 - } - }, - { - "code": "reportInvalidTypeForm", - "range": { - "startColumn": 27, - "endColumn": 30, - "lineCount": 1 - } - } - ], - "./monitoring/monitorlib/locality.py": [ - { - "code": "reportInvalidTypeVarUse", - "range": { - "startColumn": 52, - "endColumn": 64, - "lineCount": 1 - } - }, - { - "code": "reportReturnType", - "range": { - "startColumn": 27, - "endColumn": 32, - "lineCount": 1 - } - } - ], - "./monitoring/monitorlib/multiprocessing.py": [ - { - "code": "reportInvalidTypeForm", - "range": { - "startColumn": 11, - "endColumn": 32, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 30, - "endColumn": 34, - "lineCount": 1 - } - } - ], - "./monitoring/monitorlib/mutate/rid.py": [ - { - "code": "reportArgumentType", - "range": { - "startColumn": 12, - "endColumn": 40, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 27, - "endColumn": 35, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 12, - "endColumn": 41, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 28, - "endColumn": 36, - "lineCount": 1 - } - }, - { - "code": "reportOptionalIterable", - "range": { - "startColumn": 50, - "endColumn": 82, - "lineCount": 1 - } - }, - { - "code": "reportOptionalIterable", - "range": { - "startColumn": 51, - "endColumn": 84, - "lineCount": 1 - } - }, - { - "code": "reportReturnType", - "range": { - "startColumn": 19, - "endColumn": 33, - "lineCount": 1 - } - }, - { - "code": "reportReturnType", - "range": { - "startColumn": 19, - "endColumn": 34, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 48, - "endColumn": 61, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 16, - "endColumn": 36, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 33, - "endColumn": 36, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 49, - "endColumn": 62, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 16, - "endColumn": 36, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 34, - "endColumn": 37, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 12, - "endColumn": 40, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 27, - "endColumn": 35, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 12, - "endColumn": 41, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 28, - "endColumn": 36, - "lineCount": 1 - } - }, - { - "code": "reportOptionalIterable", - "range": { - "startColumn": 31, - "endColumn": 62, - "lineCount": 1 - } - }, - { - "code": "reportOptionalIterable", - "range": { - "startColumn": 38, - "endColumn": 69, - "lineCount": 1 - } - }, - { - "code": "reportGeneralTypeIssues", - "range": { - "startColumn": 15, - "endColumn": 18, - "lineCount": 1 - } - }, - { - "code": "reportInvalidTypeForm", - "range": { - "startColumn": 5, - "endColumn": 21, - "lineCount": 1 - } - }, - { - "code": "reportOptionalIterable", - "range": { - "startColumn": 23, - "endColumn": 47, - "lineCount": 1 - } - }, - { - "code": "reportOptionalIterable", - "range": { - "startColumn": 23, - "endColumn": 47, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 12, - "endColumn": 39, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 27, - "endColumn": 34, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 12, - "endColumn": 40, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 28, - "endColumn": 35, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 33, - "endColumn": 40, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 34, - "endColumn": 41, - "lineCount": 1 - } - } - ], - "./monitoring/monitorlib/mutate/scd.py": [ - { - "code": "reportReturnType", - "range": { - "startColumn": 24, - "endColumn": 33, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 16, - "endColumn": 58, - "lineCount": 1 - } - } - ], - "./monitoring/monitorlib/rid_automated_testing/injection_api.py": [ - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 42, - "endColumn": 45, - "lineCount": 1 - } - }, - { - "code": "reportAttributeAccessIssue", - "range": { - "startColumn": 40, - "endColumn": 47, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 37, - "endColumn": 50, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 73, - "endColumn": 86, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 60, - "endColumn": 73, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 171, - "endColumn": 184, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 38, - "endColumn": 51, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 37, - "endColumn": 52, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 46, - "endColumn": 61, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 66, - "endColumn": 81, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 184, - "endColumn": 199, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 38, - "endColumn": 53, - "lineCount": 1 - } - }, - { - "code": "reportCallIssue", - "range": { - "startColumn": 12, - "endColumn": 47, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 22, - "endColumn": 46, - "lineCount": 1 - } - }, - { - "code": "reportReturnType", - "range": { - "startColumn": 15, - "endColumn": 33, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 70, - "endColumn": 78, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 35, - "endColumn": 43, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 72, - "endColumn": 80, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 35, - "endColumn": 38, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 59, - "endColumn": 62, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 41, - "endColumn": 59, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 12, - "endColumn": 70, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 25, - "endColumn": 28, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 41, - "endColumn": 44, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 44, - "endColumn": 52, - "lineCount": 1 - } - }, - { - "code": "reportOptionalMemberAccess", - "range": { - "startColumn": 43, - "endColumn": 51, - "lineCount": 1 - } - }, - { - "code": "reportOptionalOperand", - "range": { - "startColumn": 35, - "endColumn": 37, - "lineCount": 1 - } - }, - { - "code": "reportOptionalOperand", - "range": { - "startColumn": 33, - "endColumn": 35, - "lineCount": 1 - } - } - ], - "./monitoring/monitorlib/rid_v1.py": [ - { - "code": "reportReturnType", - "range": { - "startColumn": 15, - "endColumn": 35, - "lineCount": 1 - } - } - ], - "./monitoring/monitorlib/schema_validation.py": [ - { - "code": "reportPrivateImportUsage", - "range": { - "startColumn": 36, - "endColumn": 41, - "lineCount": 1 - } - } - ], - "./monitoring/monitorlib/subscription_params.py": [ - { - "code": "reportReturnType", - "range": { - "startColumn": 15, - "endColumn": 49, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 22, - "endColumn": 36, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 22, - "endColumn": 36, - "lineCount": 1 - } - } - ], - "./monitoring/monitorlib/temporal.py": [ - { - "code": "reportOperatorIssue", - "range": { - "startColumn": 18, - "endColumn": 27, - "lineCount": 1 - } - }, - { - "code": "reportPossiblyUnboundVariable", - "range": { - "startColumn": 24, - "endColumn": 26, - "lineCount": 1 - } - }, - { - "code": "reportAttributeAccessIssue", - "range": { - "startColumn": 28, - "endColumn": 41, - "lineCount": 1 - } - }, - { - "code": "reportPossiblyUnboundVariable", - "range": { - "startColumn": 22, - "endColumn": 24, - "lineCount": 1 - } - }, - { - "code": "reportOperatorIssue", - "range": { - "startColumn": 27, - "endColumn": 42, - "lineCount": 1 - } - }, - { - "code": "reportOperatorIssue", - "range": { - "startColumn": 33, - "endColumn": 42, - "lineCount": 1 - } - }, - { - "code": "reportPossiblyUnboundVariable", - "range": { - "startColumn": 39, - "endColumn": 41, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 38, - "endColumn": 41, - "lineCount": 1 - } - }, - { - "code": "reportPossiblyUnboundVariable", - "range": { - "startColumn": 32, - "endColumn": 35, - "lineCount": 1 - } - }, - { - "code": "reportPossiblyUnboundVariable", - "range": { - "startColumn": 125, - "endColumn": 127, - "lineCount": 1 - } - }, - { - "code": "reportPossiblyUnboundVariable", - "range": { - "startColumn": 131, - "endColumn": 134, - "lineCount": 1 - } - }, - { - "code": "reportPossiblyUnboundVariable", - "range": { - "startColumn": 21, - "endColumn": 23, - "lineCount": 1 - } - }, - { - "code": "reportOperatorIssue", - "range": { - "startColumn": 26, - "endColumn": 41, - "lineCount": 1 - } - }, - { - "code": "reportOperatorIssue", - "range": { - "startColumn": 32, - "endColumn": 41, - "lineCount": 1 - } - }, - { - "code": "reportPossiblyUnboundVariable", - "range": { - "startColumn": 38, - "endColumn": 40, - "lineCount": 1 - } - }, - { - "code": "reportCallIssue", - "range": { - "startColumn": 21, - "endColumn": 38, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 31, - "endColumn": 37, - "lineCount": 1 - } - }, - { - "code": "reportArgumentType", - "range": { - "startColumn": 20, - "endColumn": 26, - "lineCount": 1 - } - }, - { - "code": "reportAttributeAccessIssue", - "range": { - "startColumn": 50, - "endColumn": 59, - "lineCount": 1 - } - } - ], "./monitoring/uss_qualifier/action_generators/action_generator.py": [ { "code": "reportInvalidTypeVarUse", diff --git a/monitoring/monitorlib/idempotency.py b/monitoring/monitorlib/idempotency.py index 1edfb152a9..60849bf122 100644 --- a/monitoring/monitorlib/idempotency.py +++ b/monitoring/monitorlib/idempotency.py @@ -46,7 +46,8 @@ def _set_responses(responses: dict[str, Response]) -> bytes: oldest_id = request_id oldest_timestamp = t - del responses[oldest_id] + if oldest_id: + del responses[oldest_id] return s.encode("utf-8") diff --git a/monitoring/monitorlib/infrastructure.py b/monitoring/monitorlib/infrastructure.py index 480ac42276..8c38434f13 100644 --- a/monitoring/monitorlib/infrastructure.py +++ b/monitoring/monitorlib/infrastructure.py @@ -37,11 +37,15 @@ def issue_token(self, intended_audience: str, scopes: list[str]) -> str: raise NotImplementedError() - def get_headers(self, url: str, scopes: list[str] = None) -> dict[str, str]: + def get_headers(self, url: str, scopes: list[str] | None = None) -> dict[str, str]: if scopes is None: scopes = ALL_SCOPES scopes = [s.value if isinstance(s, Enum) else s for s in scopes] intended_audience = urllib.parse.urlparse(url).hostname + + if not intended_audience: + return {} + scope_string = " ".join(scopes) if intended_audience not in self._tokens: self._tokens[intended_audience] = {} @@ -57,8 +61,9 @@ def get_headers(self, url: str, scopes: list[str] = None) -> dict[str, str]: return {"Authorization": "Bearer " + token} def add_headers(self, request: requests.PreparedRequest, scopes: list[str]): - for k, v in self.get_headers(request.url, scopes).items(): - request.headers[k] = v + if request.url: + for k, v in self.get_headers(request.url, scopes).items(): + request.headers[k] = v def get_sub(self) -> str | None: """Retrieve `sub` claim from one of the existing tokens""" @@ -91,7 +96,7 @@ def __init__( self._prefix_url = prefix_url[0:-1] if prefix_url[-1] == "/" else prefix_url self.auth_adapter = auth_adapter - self.default_scopes = None + self.default_scopes: list[str] | None = None self.timeout_seconds = timeout_seconds or CLIENT_TIMEOUT # Overrides method on requests.Session @@ -117,7 +122,7 @@ def adjust_request_kwargs(self, kwargs): def auth( prepared_request: requests.PreparedRequest, ) -> requests.PreparedRequest: - if scopes: + if scopes and self.auth_adapter: self.auth_adapter.add_headers(prepared_request, scopes) return prepared_request @@ -126,11 +131,11 @@ def auth( kwargs["timeout"] = self.timeout_seconds return kwargs - def request(self, method, url, **kwargs): + def request(self, method, url, *args, **kwargs): if "auth" not in kwargs: kwargs = self.adjust_request_kwargs(kwargs) - return super().request(method, url, **kwargs) + return super().request(method, url, *args, **kwargs) def get_prefix_url(self): return self._prefix_url @@ -161,15 +166,16 @@ def __init__( self._prefix_url = prefix_url[0:-1] if prefix_url[-1] == "/" else prefix_url self.auth_adapter = auth_adapter - self.default_scopes = None + self.default_scopes: list[str] | None = None self.timeout_seconds = timeout_seconds or CLIENT_TIMEOUT async def build_session(self): self._client = ClientSession() def close(self): - loop = asyncio.get_event_loop() - loop.run_until_complete(self._client.close()) + if self._client: + loop = asyncio.get_event_loop() + loop.run_until_complete(self._client.close()) def adjust_request_kwargs(self, url, method, kwargs): if self.auth_adapter: @@ -202,6 +208,10 @@ async def put(self, url, **kwargs): url = self._prefix_url + url if "auth" not in kwargs: kwargs = self.adjust_request_kwargs(url, "PUT", kwargs) + + if not self._client: + raise ValueError("Client is not ready") + async with self._client.put(url, **kwargs) as response: return ( response.status, @@ -214,6 +224,10 @@ async def get(self, url, **kwargs): url = self._prefix_url + url if "auth" not in kwargs: kwargs = self.adjust_request_kwargs(url, "GET", kwargs) + + if not self._client: + raise ValueError("Client is not ready") + async with self._client.get(url, **kwargs) as response: return ( response.status, @@ -226,6 +240,10 @@ async def post(self, url, **kwargs): url = self._prefix_url + url if "auth" not in kwargs: kwargs = self.adjust_request_kwargs(url, "POST", kwargs) + + if not self._client: + raise ValueError("Client is not ready") + async with self._client.post(url, **kwargs) as response: return ( response.status, @@ -238,6 +256,10 @@ async def delete(self, url, **kwargs): url = self._prefix_url + url if "auth" not in kwargs: kwargs = self.adjust_request_kwargs(url, "DELETE", kwargs) + + if not self._client: + raise ValueError("Client is not ready") + async with self._client.delete(url, **kwargs) as response: return ( response.status, diff --git a/monitoring/monitorlib/kml/f3548v21.py b/monitoring/monitorlib/kml/f3548v21.py index 7add7bb9d9..55cf0cef5f 100644 --- a/monitoring/monitorlib/kml/f3548v21.py +++ b/monitoring/monitorlib/kml/f3548v21.py @@ -21,14 +21,14 @@ from monitoring.monitorlib.scd import priority_of -def full_op_intent(op_intent: OperationalIntent) -> kml.Folder: +def full_op_intent(op_intent: OperationalIntent): """Render operational intent information into Placemarks in a KML folder.""" ref = op_intent.reference details = op_intent.details name = f"{ref.manager}'s P{priority_of(details)} {ref.state.value} {ref.id}[{ref.version}] @ {ref.ovn}" folder = kml.Folder(kml.name(name)) if "volumes" in details: - for i, v4_f3548 in enumerate(details.volumes): + for i, v4_f3548 in enumerate(details.volumes or []): v4 = Volume4D.from_f3548v21(v4_f3548) folder.append( make_placemark_from_volume( @@ -38,7 +38,7 @@ def full_op_intent(op_intent: OperationalIntent) -> kml.Folder: ) ) if "off_nominal_volumes" in details: - for i, v4_f3548 in enumerate(details.off_nominal_volumes): + for i, v4_f3548 in enumerate(details.off_nominal_volumes or []): v4 = Volume4D.from_f3548v21(v4_f3548) folder.append( make_placemark_from_volume( @@ -53,8 +53,12 @@ def full_op_intent(op_intent: OperationalIntent) -> kml.Folder: def op_intent_refs_query( req: QueryOperationalIntentReferenceParameters, resp: QueryOperationalIntentReferenceResponse, -) -> kml.Placemark: +): """Render the area of interest and response from an operational intent references query into a KML Placemark.""" + + if not req.area_of_interest: + raise ValueError("req.area_of_interest is not defined") + v4 = Volume4D.from_f3548v21(req.area_of_interest) items = "".join( f"