diff --git a/inventory_provider/gap.py b/inventory_provider/gap.py index 31816ea5a67c36e6b7d947c6d1f4b0ab7692f59a..0a7b1de811f712cf2051029ea97fc59406ac472c 100644 --- a/inventory_provider/gap.py +++ b/inventory_provider/gap.py @@ -1,6 +1,7 @@ import concurrent.futures import logging import socket +from typing import Dict, Optional import requests from requests.adapters import HTTPAdapter @@ -52,7 +53,7 @@ def get_token(aai_config: dict) -> str: return response.json()['access_token'] -def make_request(body: dict, token: str, app_config: dict) -> dict: +def make_request(body: dict, token: str, app_config: dict) -> Dict: """Make a request to the orchestrator using the given body.""" api_url = f'{app_config["orchestrator"]["url"]}/api/graphql' headers = {'Authorization': f'Bearer {token}'} @@ -66,14 +67,15 @@ def make_request(body: dict, token: str, app_config: dict) -> dict: response = session.post(api_url, headers=headers, json=body) response.raise_for_status() # The graphql API returns a 200 status code even if there are errors in the response - if errors := response.json().get('errors'): + errors = response.json().get('errors') + if errors: err_msg = f'GraphQL query returned errors: {errors}' logger.error(err_msg) raise ValueError(err_msg) return response.json() -def extract_router_info(device: dict, token: str, app_config: dict) -> dict or None: +def extract_router_info(device: dict, token: str, app_config: dict) -> Optional[dict]: tag_to_key_map = { "RTR": "router", "OFFICE_ROUTER": "officeRouter", @@ -122,7 +124,7 @@ def extract_router_info(device: dict, token: str, app_config: dict) -> dict or N return None -def load_routers_from_orchestrator(app_config: dict) -> dict: +def load_routers_from_orchestrator(app_config: dict) -> Dict: """Gets devices from the orchestrator and returns a dictionary of FQDNs and vendors.""" token = get_token(app_config['aai']) routers = {} diff --git a/inventory_provider/routes/poller.py b/inventory_provider/routes/poller.py index bfa4844d1399c1ea73b9a07efef4a9f5f7f9d47d..f15d9727227f304ddcf33bdefd446309460e0a76 100644 --- a/inventory_provider/routes/poller.py +++ b/inventory_provider/routes/poller.py @@ -940,7 +940,7 @@ def load_error_report_interfaces( ) ) - def transform_interface(interface: dict) -> dict: + def transform_interface(interface: dict) -> Dict: return { "router": interface["router"], "name": interface["name"],