Skip to content
Snippets Groups Projects
Commit 2443fa66 authored by Erik Reid's avatar Erik Reid
Browse files

fixed some types, etc

parent 879ee4fb
Branches
No related tags found
No related merge requests found
...@@ -12,7 +12,7 @@ from fastapi import FastAPI ...@@ -12,7 +12,7 @@ from fastapi import FastAPI
from mapping_provider import config, environment from mapping_provider import config, environment
from mapping_provider.api import common, map from mapping_provider.api import common, map
from mapping_provider.backends import correlator, services, cache from mapping_provider.backends import correlator, inventory, cache
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -23,8 +23,6 @@ async def lifespan(app: FastAPI, app_config: config.Configuration) -> AsyncItera ...@@ -23,8 +23,6 @@ async def lifespan(app: FastAPI, app_config: config.Configuration) -> AsyncItera
if not app_config.rmq: if not app_config.rmq:
return # don't start any background tasks return # don't start any background tasks
assert cache.cache_dir is None # sanity
with tempfile.TemporaryDirectory() as _tmp_working_dir: with tempfile.TemporaryDirectory() as _tmp_working_dir:
cache.init(_tmp_working_dir) cache.init(_tmp_working_dir)
...@@ -41,7 +39,7 @@ async def lifespan(app: FastAPI, app_config: config.Configuration) -> AsyncItera ...@@ -41,7 +39,7 @@ async def lifespan(app: FastAPI, app_config: config.Configuration) -> AsyncItera
_correlator_thread.start() _correlator_thread.start()
_inventory_thread = threading.Thread( _inventory_thread = threading.Thread(
target=services.worker_proc, target=inventory.worker_proc,
daemon=True, daemon=True,
kwargs={ kwargs={
'inventory_base_uri': app_config.inventory, 'inventory_base_uri': app_config.inventory,
......
...@@ -32,11 +32,11 @@ def set(filename: str, data: dict[str, Any]) -> None: ...@@ -32,11 +32,11 @@ def set(filename: str, data: dict[str, Any]) -> None:
logger.debug(f"wrote cached data: {filename}") logger.debug(f"wrote cached data: {filename}")
def get(filename: str) -> dict[str, Any]: def get(filename: str) -> Any:
""" """
Loads the cached data, parses it as json & returns the object. Loads the cached data, parses it as json & returns the object.
""" """
assert _cache_dir is not None, f"cache_dir hasn't been initialized" assert _cache_dir is not None, f"cache_dir hasn't been initialized"
with open(os.path.join(_cache_dir, filename), 'r') as f: with open(os.path.join(_cache_dir, filename), 'r') as f:
logger.debug(f"reading cached data: {filename}") logger.debug(f"reading cached data: {filename}")
return json.load(f) return json.load(f)
\ No newline at end of file
...@@ -20,7 +20,7 @@ INPROV_MAP_SERVICES_CACHE_FILENAME = 'inprov-map-services.json' ...@@ -20,7 +20,7 @@ INPROV_MAP_SERVICES_CACHE_FILENAME = 'inprov-map-services.json'
def _load_and_cache_json( def _load_and_cache_json(
key: str, key: str,
url: str, url: str,
cache_filename: str) -> None: cache_filename: str) -> dict[str, Any]:
""" """
Load the JSON from the URL, return and cache it. Load the JSON from the URL, return and cache it.
......
...@@ -18,6 +18,7 @@ class Overlays(BaseModel): ...@@ -18,6 +18,7 @@ class Overlays(BaseModel):
class Service(BaseModel): class Service(BaseModel):
sid: str sid: str
scid: str
name: str name: str
type: str type: str
endpoints: list[Endpoint] endpoints: list[Endpoint]
...@@ -44,7 +45,7 @@ def _services(service_type: str | None = None) -> Generator[Service, None, None] ...@@ -44,7 +45,7 @@ def _services(service_type: str | None = None) -> Generator[Service, None, None]
logger.exception('not enough data available to build the service list') logger.exception('not enough data available to build the service list')
return return
def _get_down_correlator_services(): def _get_down_correlator_services() -> Generator[str, None, None]:
for _e in correlator_state['endpoints']: for _e in correlator_state['endpoints']:
if _e['up']: if _e['up']:
continue continue
...@@ -88,4 +89,4 @@ def build_service_info_list(service_type: str | None = None) -> ServiceList: ...@@ -88,4 +89,4 @@ def build_service_info_list(service_type: str | None = None) -> ServiceList:
""" """
return a list of mappable info about all operational services return a list of mappable info about all operational services
""" """
return ServiceList(services=_services(service_type)) return ServiceList(services=list(_services(service_type)))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment