@@ -2860,19 +2860,45 @@ def command_registry_login(ctx: CephadmContext) -> int:
28602860 if ctx .registry_json :
28612861 logger .info ('Pulling custom registry login info from %s.' % ctx .registry_json )
28622862 d = get_parm (ctx .registry_json )
2863- if d .get ('url' ) and d .get ('username' ) and d .get ('password' ):
2864- ctx .registry_url = d .get ('url' )
2865- ctx .registry_username = d .get ('username' )
2866- ctx .registry_password = d .get ('password' )
2867- registry_login (ctx , ctx .registry_url , ctx .registry_username , ctx .registry_password )
2868- else :
2869- raise Error ('json provided for custom registry login did not include all necessary fields. '
2870- 'Please setup json file as\n '
2871- '{\n '
2872- ' "url": "REGISTRY_URL",\n '
2873- ' "username": "REGISTRY_USERNAME",\n '
2874- ' "password": "REGISTRY_PASSWORD"\n '
2875- '}\n ' )
2863+ # to support multiple container registries, the command will now accept a list
2864+ # of dictionaries. For backward compatibility, it will first check for the presence
2865+ # of the registry_credentials key. If the key is not found, it will fall back to
2866+ # parsing the old JSON format.
2867+ example_multi_registry = {
2868+ 'registry_credentials' : [
2869+ {
2870+ 'url' : 'REGISTRY_URL1' ,
2871+ 'username' : 'REGISTRY_USERNAME1' ,
2872+ 'password' : 'REGISTRY_PASSWORD1'
2873+ },
2874+ {
2875+ 'url' : 'REGISTRY_URL2' ,
2876+ 'username' : 'REGISTRY_USERNAME2' ,
2877+ 'password' : 'REGISTRY_PASSWORD2'
2878+ }
2879+ ]
2880+ }
2881+ registry_creds = d .get ('registry_credentials' )
2882+ if not registry_creds :
2883+ registry_creds = [d ]
2884+ for d in registry_creds :
2885+ if d .get ('url' ) and d .get ('username' ) and d .get ('password' ):
2886+ ctx .registry_url = d .get ('url' )
2887+ ctx .registry_username = d .get ('username' )
2888+ ctx .registry_password = d .get ('password' )
2889+ registry_login (ctx , ctx .registry_url , ctx .registry_username , ctx .registry_password )
2890+ else :
2891+ raise Error (
2892+ 'json provided for custom registry login did not include all necessary fields. '
2893+ 'Please setup json file as\n '
2894+ '{\n '
2895+ ' "url": "REGISTRY_URL",\n '
2896+ ' "username": "REGISTRY_USERNAME",\n '
2897+ ' "password": "REGISTRY_PASSWORD"\n '
2898+ '}\n '
2899+ 'or as below for multiple registry login\n '
2900+ f'{ json .dumps (example_multi_registry , indent = 4 )} '
2901+ )
28762902 elif ctx .registry_url and ctx .registry_username and ctx .registry_password :
28772903 registry_login (ctx , ctx .registry_url , ctx .registry_username , ctx .registry_password )
28782904 else :
0 commit comments