11import time
22from io import BytesIO
33from tarfile import TarFile , TarInfo
4- from typing import TYPE_CHECKING , Optional
4+ from typing import TYPE_CHECKING , Any , Optional
55
66import bcrypt
77from requests import get
@@ -25,7 +25,7 @@ def __init__(
2525 port : int = 5000 ,
2626 username : Optional [str ] = None ,
2727 password : Optional [str ] = None ,
28- ** kwargs ,
28+ ** kwargs : Any ,
2929 ) -> None :
3030 super ().__init__ (image = image , ** kwargs )
3131 self .port : int = port
@@ -35,6 +35,8 @@ def __init__(
3535
3636 def _copy_credentials (self ) -> None :
3737 # Create credentials and write them to the container
38+ if self .password is None :
39+ raise ValueError ("Password cannot be None" )
3840 hashed_password : str = bcrypt .hashpw (
3941 self .password .encode ("utf-8" ),
4042 bcrypt .gensalt (rounds = 12 , prefix = b"2a" ),
@@ -44,7 +46,7 @@ def _copy_credentials(self) -> None:
4446 with BytesIO () as tar_archive_object , TarFile (fileobj = tar_archive_object , mode = "w" ) as tmp_tarfile :
4547 tarinfo : TarInfo = TarInfo (name = self .credentials_path )
4648 tarinfo .size = len (content )
47- tarinfo .mtime = time .time ()
49+ tarinfo .mtime = int ( time .time () )
4850
4951 tmp_tarfile .addfile (tarinfo , BytesIO (content ))
5052 tar_archive_object .seek (0 )
@@ -54,12 +56,13 @@ def _copy_credentials(self) -> None:
5456 def _readiness_probe (self ) -> None :
5557 url : str = f"http://{ self .get_registry ()} /v2"
5658 if self .username and self .password :
57- response : Response = get (url , auth = HTTPBasicAuth (self .username , self .password ), timeout = 1 )
59+ auth_response : Response = get (url , auth = HTTPBasicAuth (self .username , self .password ), timeout = 1 )
60+ auth_response .raise_for_status ()
5861 else :
5962 response : Response = get (url , timeout = 1 )
60- response .raise_for_status ()
63+ response .raise_for_status ()
6164
62- def start (self ):
65+ def start (self ) -> "DockerRegistryContainer" :
6366 if self .username and self .password :
6467 self .with_env ("REGISTRY_AUTH_HTPASSWD_REALM" , "local-registry" )
6568 self .with_env ("REGISTRY_AUTH_HTPASSWD_PATH" , self .credentials_path )
0 commit comments