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