2
2
import json as json
3
3
from collections import namedtuple
4
4
from logging import warning
5
- from typing import Optional
5
+ from typing import Any , Optional
6
6
7
7
DockerAuthInfo = namedtuple ("DockerAuthInfo" , ["registry" , "username" , "password" ])
8
8
12
12
}
13
13
14
14
15
- def process_docker_auth_config_encoded (auth_config_dict : dict ) -> list [DockerAuthInfo ]:
15
+ def process_docker_auth_config_encoded (auth_config_dict : dict [ str , dict [ str , dict [ str , Any ]]] ) -> list [DockerAuthInfo ]:
16
16
"""
17
17
Process the auths config.
18
18
@@ -30,16 +30,19 @@ def process_docker_auth_config_encoded(auth_config_dict: dict) -> list[DockerAut
30
30
auth_info : list [DockerAuthInfo ] = []
31
31
32
32
auths = auth_config_dict .get ("auths" )
33
+ if not auths :
34
+ raise KeyError ("No auths found in the docker auth config" )
35
+
33
36
for registry , auth in auths .items ():
34
- auth_str = auth .get ("auth" )
37
+ auth_str = str ( auth .get ("auth" ) )
35
38
auth_str = base64 .b64decode (auth_str ).decode ("utf-8" )
36
39
username , password = auth_str .split (":" )
37
40
auth_info .append (DockerAuthInfo (registry , username , password ))
38
41
39
42
return auth_info
40
43
41
44
42
- def process_docker_auth_config_cred_helpers (auth_config_dict : dict ) -> None :
45
+ def process_docker_auth_config_cred_helpers (auth_config_dict : dict [ str , Any ] ) -> None :
43
46
"""
44
47
Process the credHelpers config.
45
48
@@ -56,7 +59,7 @@ def process_docker_auth_config_cred_helpers(auth_config_dict: dict) -> None:
56
59
warning (_AUTH_WARNINGS .pop ("credHelpers" ))
57
60
58
61
59
- def process_docker_auth_config_store (auth_config_dict : dict ) -> None :
62
+ def process_docker_auth_config_store (auth_config_dict : dict [ str , Any ] ) -> None :
60
63
"""
61
64
Process the credsStore config.
62
65
@@ -74,7 +77,7 @@ def process_docker_auth_config_store(auth_config_dict: dict) -> None:
74
77
def parse_docker_auth_config (auth_config : str ) -> Optional [list [DockerAuthInfo ]]:
75
78
"""Parse the docker auth config from a string and handle the different formats."""
76
79
try :
77
- auth_config_dict : dict = json .loads (auth_config )
80
+ auth_config_dict : dict [ str , Any ] = json .loads (auth_config )
78
81
if "credHelpers" in auth_config :
79
82
process_docker_auth_config_cred_helpers (auth_config_dict )
80
83
if "credsStore" in auth_config :
0 commit comments