[docs]classLoginArgs(BaseModel):"""Args passed to the docker.login hook."""model_config=ConfigDict(arbitrary_types_allowed=True)ctx:Annotated[CfnginContext|None,Field(alias="context",exclude=True)]=Nonedockercfg_path:str|None=None"""Path to a non-default Docker config file."""ecr:ElasticContainerRegistry|None=Field(default=None,exclude=True)"""Information describing an ECR registry."""email:str|None=None"""The email for the registry account."""password:str"""The plaintext password for the registry account."""registry:Annotated[str|None,Field(validate_default=True)]=None"""URI of the registry to login to."""username:str="AWS""""The registry username."""@model_validator(mode="before")@classmethoddef_set_ecr(cls,values:dict[str,Any])->dict[str,Any]:"""Set the value of ``ecr``."""if"ecr"invaluesandisinstance(values["ecr"],dict):values["ecr"]=ElasticContainerRegistry.model_validate({"context":values.get("context"),**values["ecr"]})returnvalues@field_validator("registry",mode="before")@classmethoddef_set_registry(cls,v:Any,info:ValidationInfo)->Any:"""Set the value of ``registry``."""ifv:returnvecr:ElasticContainerRegistry|None=info.data.get("ecr")ifecr:returnecr.fqnreturnNone
[docs]deflogin(*,context:CfnginContext,**kwargs:Any)->DockerHookData:"""Docker login hook. Replicates the functionality of ``docker login`` cli command. kwargs are parsed by :class:`~runway.cfngin.hooks.docker.LoginArgs`. """args=LoginArgs.model_validate({"context":context,**kwargs})docker_hook_data=DockerHookData.from_cfngin_context(context)docker_hook_data.client.login(**args.model_dump())LOGGER.info("logged into %s",args.registry)returndocker_hook_data.update_context(context)