5454from proot_distro .helpers .docker .transport import (
5555 auth_denied_msg ,
5656 auth_note ,
57- auth_opener ,
5857 get_auth_token ,
59- registry_base_url ,
58+ opener ,
6059 _ua ,
6160)
6261
7675
7776
7877def _get_manifest (
79- repo : str , ref : str , token : str , registry : str = "" ,
78+ repo : str , ref : str , token : str , base : str ,
8079 insecure : bool = False ,
8180) -> dict :
82- base = registry_base_url (registry , insecure )
8381 url = f"{ base } /v2/{ repo } /manifests/{ ref } "
8482 headers = {** _ua (), "Accept" : _ACCEPT_HEADER }
8583 if token :
8684 headers ["Authorization" ] = f"Bearer { token } "
8785 req = urllib .request .Request (url , headers = headers )
88- with urllib . request . urlopen (req ) as resp :
86+ with opener ( insecure ). open (req ) as resp :
8987 body = resp .read ()
9088 ct = resp .headers .get ("Content-Type" , "" )
9189 data = json .loads (body )
@@ -134,14 +132,14 @@ def _pick_platform(
134132def _resolve_single_manifest (
135133 image_ref : str , arch : str , insecure : bool = False
136134) -> tuple :
137- """Return (single_image_manifest, token, repo, registry ) for the arch."""
135+ """Return (single_image_manifest, token, repo, base ) for the arch."""
138136 registry , repo , tag = parse_image_ref (image_ref )
139137
140138 log_info (f"Authenticating with registry{ auth_note ()} ..." )
141- token = get_auth_token (repo , registry , insecure = insecure )
139+ token , base = get_auth_token (repo , registry , insecure = insecure )
142140
143141 log_info (f"Fetching manifest for '{ image_ref } '..." )
144- manifest = _get_manifest (repo , tag , token , registry , insecure )
142+ manifest = _get_manifest (repo , tag , token , base , insecure )
145143
146144 if manifest ["_ct" ] in _MANIFEST_LIST_TYPES or "manifests" in manifest :
147145 docker_arch , docker_variant = ARCH_TO_DOCKER .get (arch , (arch , "" ))
@@ -153,27 +151,26 @@ def _resolve_single_manifest(
153151 )
154152 log_info (f"Fetching { arch } manifest..." )
155153 manifest = _get_manifest (
156- repo , target ["digest" ], token , registry , insecure
154+ repo , target ["digest" ], token , base , insecure
157155 )
158156
159- return manifest , token , repo , registry
157+ return manifest , token , repo , base
160158
161159
162160def _fetch_config_blob (
163- repo : str , cfg_digest : str , token : str , registry : str = "" ,
161+ repo : str , cfg_digest : str , token : str , base : str ,
164162 insecure : bool = False ,
165163) -> dict :
166164 """Fetch the image config blob; return parsed dict (empty on error)."""
167165 if not cfg_digest :
168166 return {}
169167 try :
170- base = registry_base_url (registry , insecure )
171168 url = f"{ base } /v2/{ repo } /blobs/{ cfg_digest } "
172169 headers = {** _ua ()}
173170 if token :
174171 headers ["Authorization" ] = f"Bearer { token } "
175172 req = urllib .request .Request (url , headers = headers )
176- with auth_opener ( ).open (req ) as resp :
173+ with opener ( insecure ).open (req ) as resp :
177174 return json .loads (resp .read ())
178175 except Exception :
179176 return {}
@@ -189,16 +186,19 @@ def pull_image(
189186 access. If the manifest is cached but some layers are missing, only
190187 an auth token is fetched before downloading the missing layers.
191188
192- Registry traffic uses HTTPS unless *insecure* is set, in which case a
193- custom registry is contacted over plain HTTP (Docker Hub stays HTTPS
194- regardless). With HTTPS enforced, an HTTP-only registry surfaces a
195- RuntimeError that points the user at ``--allow-insecure``.
189+ Registry traffic uses verified HTTPS unless *insecure* is set. With
190+ *insecure* a custom registry is reached over HTTPS with certificate
191+ verification disabled, falling back to plain HTTP when the registry only
192+ speaks HTTP (Docker Hub stays verified-HTTPS regardless). When enforcing
193+ HTTPS, an untrusted certificate or an HTTP-only registry surfaces a
194+ RuntimeError pointing the user at ``--allow-insecure``.
196195
197196 Returns ``{"manifest": ..., "image_config": ...}``. The caller is
198197 expected to persist these into ``containers/<name>/manifest.json``
199198 so `run`, `reset`, and `login` can later read image_config.
200199 """
201200 token = None
201+ base = None
202202
203203 manifest , repo , image_config = load_manifest_cache (image_ref , arch )
204204 registry = parse_image_ref (image_ref )[0 ]
@@ -216,7 +216,9 @@ def pull_image(
216216 f"layer(s) for '{ image_ref } ' ({ arch } )..." )
217217 try :
218218 log_info (f"Authenticating with registry{ auth_note ()} ..." )
219- token = get_auth_token (repo , registry , insecure = insecure )
219+ token , base = get_auth_token (
220+ repo , registry , insecure = insecure
221+ )
220222 except (urllib .error .URLError , OSError ) as net_err :
221223 if isinstance (net_err , urllib .error .HTTPError ):
222224 if net_err .code in (401 , 403 ):
@@ -234,7 +236,7 @@ def pull_image(
234236 raise RuntimeError (f"Network error: { net_err } " ) from net_err
235237 else :
236238 try :
237- manifest , token , repo , registry = _resolve_single_manifest (
239+ manifest , token , repo , base = _resolve_single_manifest (
238240 image_ref , arch , insecure
239241 )
240242 except (urllib .error .URLError , OSError ) as net_err :
@@ -252,7 +254,7 @@ def pull_image(
252254 raise RuntimeError (f"Network error: { net_err } " ) from net_err
253255 cfg_digest = manifest .get ("config" , {}).get ("digest" , "" )
254256 image_config = _fetch_config_blob (
255- repo , cfg_digest , token , registry , insecure
257+ repo , cfg_digest , token , base , insecure
256258 )
257259 save_manifest_cache (image_ref , arch , manifest , repo , image_config )
258260
@@ -286,7 +288,7 @@ def pull_image(
286288 f"{ i + 1 } /{ n_layers } { size_str } ..." )
287289 try :
288290 layer_path = download_blob (
289- repo , digest , token or "" , registry , insecure
291+ repo , digest , token or "" , base , insecure
290292 )
291293 except urllib .error .HTTPError as dl_err :
292294 if dl_err .code in (401 , 403 ):
0 commit comments