1818import logging
1919from charon .config import get_config
2020from typing import List
21+ from urllib .parse import urlparse
2122
2223logger = logging .getLogger (__name__ )
2324
@@ -31,21 +32,24 @@ def __init__(self):
3132 self .conf = get_config ()
3233 self .client = oras .client .OrasClient ()
3334
34- def login_if_needed (self ) -> None :
35+ def login_if_needed (self , registry : str ) -> None :
3536 """
36- If quay_radas_auth_enabled is true , call login to authenticate.
37+ If quay_radas_registry_config is provided , call login to authenticate.
3738 """
39+ if not registry .startswith ("http://" ) and not registry .startswith ("https://" ):
40+ registry = "https://" + registry
41+ registry = urlparse (registry ).netloc
3842
39- if self .conf and self .conf .is_quay_radas_auth_enabled ():
40- logger .info ("Logging in to registry." )
43+ rconf = self .conf .get_radas_config () if self .conf else None
44+ if rconf and rconf .quay_radas_registry_config ():
45+ logger .info ("Logging in to registry: %s" , registry )
4146 res = self .client .login (
42- hostname = self .conf .get_quay_radas_registry (),
43- username = self .conf .get_quay_radas_username (),
44- password = self .conf .get_quay_radas_password (),
47+ hostname = registry ,
48+ config_path = rconf .quay_radas_registry_config (),
4549 )
4650 logger .info (res )
4751 else :
48- logger .info ("Registry auth not enabled , skip login." )
52+ logger .info ("Registry config is not provided , skip login." )
4953
5054 def pull (self , result_reference_url : str , sign_result_loc : str ) -> List [str ]:
5155 """
@@ -58,7 +62,7 @@ def pull(self, result_reference_url: str, sign_result_loc: str) -> List[str]:
5862 """
5963 files = []
6064 try :
61- self .login_if_needed ()
65+ self .login_if_needed (registry = result_reference_url )
6266 files = self .client .pull (target = result_reference_url , outdir = sign_result_loc )
6367 logger .info ("Pull file from %s to %s" , result_reference_url , sign_result_loc )
6468 except Exception as e :
0 commit comments