2828
2929from .index import Index
3030from .layer import Layer
31+ from .image_manifest import ImageManifest
3132from .manifest import Manifest
3233from .schemas import index as IndexSchema
3334
@@ -83,11 +84,21 @@ def __init__(
8384 self ._container_version = container_data [1 ]
8485
8586 container_url_data = urlsplit (self ._container_url )
87+ self ._token = None
88+
89+ if token is None :
90+ token = getenv ("GL_CLI_REGISTRY_TOKEN" )
91+
92+ if token is not None :
93+ auth_backend = "token"
94+ self ._token = b64encode (token .encode ("utf-8" )).decode ("utf-8" )
95+ else :
96+ auth_backend = "basic"
8697
8798 Registry .__init__ (
8899 self ,
89100 hostname = container_url_data .netloc ,
90- auth_backend = "token" ,
101+ auth_backend = auth_backend ,
91102 insecure = insecure ,
92103 )
93104
@@ -97,11 +108,7 @@ def __init__(
97108 self ._container_name = container_url_data .path [1 :]
98109 self ._logger = logger
99110
100- if token is None :
101- token = getenv ("GL_CLI_REGISTRY_TOKEN" )
102-
103- if token is not None :
104- self ._token = b64encode (token .encode ("utf-8" )).decode ("utf-8" )
111+ if self ._token is not None :
105112 self .auth .set_token_auth (self ._token )
106113 else :
107114 # Authentication credentials from environment
@@ -117,17 +124,7 @@ def __init__(
117124 except Exception as login_error :
118125 self ._logger .error (f"Login error: { str (login_error )} " )
119126
120- def generate_index (self ):
121- """
122- Generates an OCI image index
123-
124- :return: (object) OCI image index
125- :since: 0.7.0
126- """
127-
128- return Index ()
129-
130- def generate_manifest (
127+ def generate_image_manifest (
131128 self ,
132129 cname : str ,
133130 architecture : Optional [str ] = None ,
@@ -145,7 +142,7 @@ def generate_manifest(
145142 :param feature_set: The expanded list of the included features of this manifest
146143
147144 :return: (object) OCI image manifest
148- :since: 0.7 .0
145+ :since: 0.10 .0
149146 """
150147
151148 cname_object = CName (cname , architecture , version )
@@ -162,15 +159,13 @@ def generate_manifest(
162159 if commit is None :
163160 commit = ""
164161
165- manifest = Manifest ()
162+ manifest = ImageManifest ()
166163
167- manifest ["annotations" ] = {}
168- manifest ["annotations" ]["version" ] = version
169- manifest ["annotations" ]["cname" ] = cname
170- manifest ["annotations" ]["architecture" ] = architecture
171- manifest ["annotations" ]["feature_set" ] = feature_set
172- manifest ["annotations" ]["flavor" ] = f"{ cname_object .flavor } -{ architecture } "
173- manifest ["annotations" ]["commit" ] = commit
164+ manifest .version = version
165+ manifest .cname = cname
166+ manifest .arch = architecture
167+ manifest .feature_set = feature_set
168+ manifest .commit = commit
174169
175170 description = (
176171 f"Image: { cname } "
@@ -189,6 +184,43 @@ def generate_manifest(
189184
190185 return manifest
191186
187+ def generate_index (self ):
188+ """
189+ Generates an OCI image index
190+
191+ :return: (object) OCI image index
192+ :since: 0.7.0
193+ """
194+
195+ return Index ()
196+
197+ def generate_manifest (
198+ self ,
199+ version : Optional [str ] = None ,
200+ commit : Optional [str ] = None ,
201+ ):
202+ """
203+ Generates an OCI manifest
204+
205+ :param cname: Canonical name of the manifest
206+ :param architecture: Target architecture of the manifest
207+ :param version: Artifacts version of the manifest
208+ :param commit: The commit hash of the manifest
209+ :param feature_set: The expanded list of the included features of this manifest
210+
211+ :return: (object) OCI manifest
212+ :since: 0.9.2
213+ """
214+
215+ manifest = Manifest ()
216+
217+ manifest .version = version
218+ manifest .commit = commit
219+
220+ manifest .config_from_dict ({}, {})
221+
222+ return manifest
223+
192224 def _get_index_without_response_parsing (self ):
193225 """
194226 Return the response of an OCI image index request.
@@ -520,14 +552,14 @@ def read_or_generate_index(self):
520552
521553 def read_or_generate_manifest (
522554 self ,
523- cname : str ,
555+ cname : Optional [ str ] = None ,
524556 architecture : Optional [str ] = None ,
525557 version : Optional [str ] = None ,
526558 commit : Optional [str ] = None ,
527559 feature_set : Optional [str ] = None ,
528560 ) -> Manifest :
529561 """
530- Reads from registry or generates the OCI image manifest.
562+ Reads from registry or generates the OCI manifest.
531563
532564 :param cname: Canonical name of the manifest
533565 :param architecture: Target architecture of the manifest
@@ -539,19 +571,31 @@ def read_or_generate_manifest(
539571 :since: 0.7.0
540572 """
541573
542- if architecture is None :
543- architecture = CName ( cname , architecture , version ). arch
574+ if cname is None :
575+ manifest_type = Manifest
544576
545- response = self ._get_manifest_without_response_parsing (
546- f"{ self ._container_version } -{ cname } -{ architecture } "
547- )
577+ response = self ._get_manifest_without_response_parsing (
578+ self ._container_version
579+ )
580+ else :
581+ manifest_type = ImageManifest
582+
583+ if architecture is None :
584+ architecture = CName (cname , architecture , version ).arch
585+
586+ response = self ._get_manifest_without_response_parsing (
587+ f"{ self ._container_version } -{ cname } -{ architecture } "
588+ )
548589
549590 if response .ok :
550- manifest = Manifest (** response .json ())
591+ manifest = manifest_type (** response .json ())
551592 elif response .status_code == 404 :
552- manifest = self .generate_manifest (
553- cname , architecture , version , commit , feature_set
554- )
593+ if cname is None :
594+ manifest = self .generate_manifest (version , commit )
595+ else :
596+ manifest = self .generate_image_manifest (
597+ cname , architecture , version , commit , feature_set
598+ )
555599 else :
556600 response .raise_for_status ()
557601
0 commit comments