__author__="Vanessa Sochat"__copyright__="Copyright The ORAS Authors."__license__="Apache-2.0"importosfromtypingimportOptionalimportoras.auth.utilsasauth_utilsimportoras.utils
[docs]classDockerClient:""" If running inside a container (or similar without docker) do a manual login """
[docs]deflogin(self,username:str,password:str,registry:str,dockercfg_path:Optional[str]=None,)->dict:""" Manual login means loading and checking the config file :param registry: if provided, use this custom provider instead of default :type registry: oras.provider.Registry or None :param username: the user account name :type username: str :param password: the user account password :type password: str :param dockercfg_str: docker config path :type dockercfg_str: list """ifnotdockercfg_path:dockercfg_path=oras.utils.find_docker_config(exists=False)ifos.path.exists(dockercfg_path):# type: ignorecfg=oras.utils.read_json(dockercfg_path)# type: ignoreelse:oras.utils.mkdir_p(os.path.dirname(dockercfg_path))# type: ignorecfg={"auths":{}}ifregistryincfg["auths"]:cfg["auths"][registry]["auth"]=auth_utils.get_basic_auth(username,password)else:cfg["auths"][registry]={"auth":auth_utils.get_basic_auth(username,password)}oras.utils.write_json(cfg,dockercfg_path)# type: ignorereturn{"Status":"Login Succeeded"}