16
16
import requests
17
17
18
18
import oras .auth
19
+ import oras .auth .utils
19
20
import oras .container
20
21
import oras .decorator as decorator
21
22
import oras .defaults
@@ -84,6 +85,10 @@ def __init__(
84
85
auth_backend , self .session , insecure , tls_verify = tls_verify
85
86
)
86
87
88
+ # Load all authentication configs once during initialization
89
+ # This avoids re-reading the docker config file for each operation
90
+ self .auth ._auths = oras .auth .utils .load_configs ()
91
+
87
92
def __repr__ (self ) -> str :
88
93
return str (self )
89
94
@@ -307,6 +312,7 @@ def upload_blob(
307
312
return response
308
313
309
314
@decorator .ensure_container
315
+ @decorator .ensure_auth
310
316
def delete_tag (self , container : container_type , tag : str ) -> bool :
311
317
"""
312
318
Delete a tag for a container.
@@ -341,6 +347,7 @@ def delete_tag(self, container: container_type, tag: str) -> bool:
341
347
return True
342
348
343
349
@decorator .ensure_container
350
+ @decorator .ensure_auth
344
351
def get_tags (self , container : container_type , N = None ) -> List [str ]:
345
352
"""
346
353
Retrieve tags for a package.
@@ -405,6 +412,7 @@ def _do_paginated_request(
405
412
url = urllib .parse .urljoin (base_url , link )
406
413
407
414
@decorator .ensure_container
415
+ @decorator .ensure_auth
408
416
def get_blob (
409
417
self ,
410
418
container : container_type ,
@@ -516,6 +524,8 @@ def download_blob(
516
524
raise e
517
525
return outfile
518
526
527
+ @decorator .ensure_container
528
+ @decorator .ensure_auth
519
529
def put_upload (
520
530
self ,
521
531
blob : str ,
@@ -561,6 +571,8 @@ def put_upload(
561
571
)
562
572
return response
563
573
574
+ @decorator .ensure_container
575
+ @decorator .ensure_auth
564
576
def blob_exists (self , layer : dict , container : oras .container .Container ) -> bool :
565
577
"""
566
578
Check if a layer already exists in the registry.
@@ -600,6 +612,8 @@ def _get_location(
600
612
session_url = f"{ prefix } { session_url } "
601
613
return session_url
602
614
615
+ @decorator .ensure_container
616
+ @decorator .ensure_auth
603
617
def chunked_upload (
604
618
self ,
605
619
blob : str ,
@@ -688,6 +702,8 @@ def _parse_response_errors(self, response: requests.Response):
688
702
except Exception :
689
703
pass
690
704
705
+ @decorator .ensure_container
706
+ @decorator .ensure_auth
691
707
def upload_manifest (
692
708
self ,
693
709
manifest : dict ,
@@ -751,9 +767,13 @@ def push(
751
767
"""
752
768
container = self .get_container (target )
753
769
files = files or []
754
- self .auth .load_configs (
755
- container , configs = [config_path ] if config_path else None
756
- )
770
+
771
+ # If a custom config path is provided, load those configs
772
+ if config_path :
773
+ self .auth .load_configs (container , configs = [config_path ])
774
+ else :
775
+ # Use the already loaded auths with ensure_auth pattern
776
+ self .auth .ensure_auth_for_container (container )
757
777
758
778
# Prepare a new manifest
759
779
manifest = oras .oci .NewManifest ()
@@ -866,6 +886,7 @@ def push(
866
886
print (f"Successfully pushed { container } " )
867
887
return response
868
888
889
+ @decorator .ensure_auth
869
890
def pull (
870
891
self ,
871
892
target : str ,
@@ -891,9 +912,13 @@ def pull(
891
912
:type target: str
892
913
"""
893
914
container = self .get_container (target )
894
- self .auth .load_configs (
895
- container , configs = [config_path ] if config_path else None
896
- )
915
+
916
+ # If a custom config path is provided, load those configs
917
+ if config_path :
918
+ self .auth .load_configs (container , configs = [config_path ])
919
+ else :
920
+ # Use the already loaded auths with ensure_auth pattern
921
+ self .auth .ensure_auth_for_container (container )
897
922
manifest = self .get_manifest (container , allowed_media_type )
898
923
outdir = outdir or oras .utils .get_tmpdir ()
899
924
overwrite = overwrite
@@ -933,6 +958,7 @@ def pull(
933
958
return files
934
959
935
960
@decorator .ensure_container
961
+ @decorator .ensure_auth
936
962
def get_manifest (
937
963
self ,
938
964
container : container_type ,
@@ -946,10 +972,6 @@ def get_manifest(
946
972
:param allowed_media_type: one or more allowed media types
947
973
:type allowed_media_type: str
948
974
"""
949
- # Load authentication configs for the container's registry
950
- # This ensures credentials are available for authenticated registries
951
- self .auth .load_configs (container )
952
-
953
975
if not allowed_media_type :
954
976
allowed_media_type = [oras .defaults .default_manifest_media_type ]
955
977
headers = {"Accept" : ";" .join (allowed_media_type )}
0 commit comments