77from enum import Enum
88from http import HTTPStatus
99from pprint import pformat
10- from typing import Any , Final
10+ from typing import Any , Final , cast
1111
1212import aiodocker
1313import aiodocker .networks
@@ -136,9 +136,9 @@ def _parse_env_settings(settings: list[str]) -> dict:
136136
137137async def _read_service_settings (
138138 app : FastAPI , key : str , tag : str , settings_name : str
139- ) -> dict :
139+ ) -> dict [ str , Any ] | list [ Any ] :
140140 image_labels , _ = await registry_proxy .get_image_labels (app , key , tag )
141- settings = (
141+ settings : dict [ str , Any ] | list [ Any ] = (
142142 json .loads (image_labels [settings_name ]) if settings_name in image_labels else {}
143143 )
144144
@@ -317,6 +317,7 @@ async def _create_docker_service_params(
317317 ]
318318
319319 # some services define strip_path:true if they need the path to be stripped away
320+ assert isinstance (reverse_proxy_settings , dict ) # nosec
320321 if reverse_proxy_settings and reverse_proxy_settings .get ("strip_path" ):
321322 docker_params ["labels" ][
322323 f"traefik.http.middlewares.{ service_name } _stripprefixregex.stripprefixregex.regex"
@@ -329,7 +330,7 @@ async def _create_docker_service_params(
329330 placement_substitutions : dict [
330331 str , str
331332 ] = app_settings .DIRECTOR_GENERIC_RESOURCE_PLACEMENT_CONSTRAINTS_SUBSTITUTIONS
332-
333+ assert isinstance ( service_parameters_labels , list ) # nosec
333334 for param in service_parameters_labels :
334335 _check_setting_correctness (param )
335336 # replace %service_uuid% by the given uuid
@@ -488,12 +489,15 @@ async def _create_docker_service_params(
488489 return docker_params
489490
490491
491- def _get_service_entrypoint (service_boot_parameters_labels : dict ) -> str :
492+ def _get_service_entrypoint (
493+ service_boot_parameters_labels : list [dict [str , Any ]]
494+ ) -> str :
492495 log .debug ("Getting service entrypoint" )
493496 for param in service_boot_parameters_labels :
494497 _check_setting_correctness (param )
495498 if param ["name" ] == "entry_point" :
496499 log .debug ("Service entrypoint is %s" , param ["value" ])
500+ assert isinstance (param ["value" ], str ) # nosec
497501 return param ["value" ]
498502 return ""
499503
@@ -558,7 +562,7 @@ async def _get_docker_image_port_mapping(
558562async def _pass_port_to_service (
559563 service_name : str ,
560564 port : str ,
561- service_boot_parameters_labels : dict ,
565+ service_boot_parameters_labels : list [ Any ] ,
562566 session : ClientSession ,
563567 app_settings : ApplicationSettings ,
564568) -> None :
@@ -608,7 +612,7 @@ async def _create_overlay_network_in_swarm(
608612 service_name ,
609613 node_uuid ,
610614 )
611- return docker_network .id
615+ return cast ( str , docker_network .id )
612616 except aiodocker .exceptions .DockerError as err :
613617 log .exception ("Error while creating network for service %s" , service_name )
614618 msg = "Error while creating network"
@@ -872,6 +876,7 @@ async def _start_docker_service(
872876 service_boot_parameters_labels = await _read_service_settings (
873877 app , service_key , service_tag , SERVICE_RUNTIME_BOOTSETTINGS
874878 )
879+ assert isinstance (service_boot_parameters_labels , list ) # nosec
875880 service_entrypoint = _get_service_entrypoint (service_boot_parameters_labels )
876881 if published_port :
877882 session = get_client_session (app )
@@ -983,8 +988,8 @@ async def _get_service_key_version_from_docker_service(
983988 return service_key , service_tag
984989
985990
986- async def _get_service_basepath_from_docker_service (service : dict ) -> str :
987- envs_list = service ["Spec" ]["TaskTemplate" ]["ContainerSpec" ]["Env" ]
991+ async def _get_service_basepath_from_docker_service (service : dict [ str , Any ] ) -> str :
992+ envs_list : list [ str ] = service ["Spec" ]["TaskTemplate" ]["ContainerSpec" ]["Env" ]
988993 envs_dict = dict (x .split ("=" ) for x in envs_list )
989994 return envs_dict ["SIMCORE_NODE_BASEPATH" ]
990995
0 commit comments