@@ -71,8 +71,8 @@ def _load_mirrors(self, cmdline_cache: Optional[pathlib.Path]) -> Dict[str, Dict
7171 raise MirrorError (
7272 "Mirror build cache config is missing a required 'private_key' path."
7373 )
74- self .build_cache_mirror = "buildcache"
75- enabled_mirrors ["buildcache" ] = buildcache
74+ self .build_cache_mirror = "buildcache"
75+ enabled_mirrors ["buildcache" ] = buildcache
7676 else :
7777 self .build_cache_mirror = None
7878
@@ -81,17 +81,13 @@ def _load_mirrors(self, cmdline_cache: Optional[pathlib.Path]) -> Dict[str, Dict
8181 enabled_mirrors ["buildcache" ] = self ._load_cmdline_cache (cmdline_cache )
8282 self .build_cache_mirror = self .CMDLINE_CACHE
8383
84-
8584 bootstrap = mirrors .get ("bootstrap" )
8685 if bootstrap and bootstrap .get ("enabled" , True ):
87- self .bootstrap_mirror = bootstrap
8886 enabled_mirrors ["bootstrap" ] = bootstrap
89- else :
90- self .bootstrap_mirror = None
9187
9288 for name , mirror in mirrors .get ("sourcecache" , {}).items ():
93- if mirror .get ("enabled" , True ):
94- enabled_mirrors [name ] = mirror
89+ if mirror .get ("enabled" , True ):
90+ enabled_mirrors [name ] = mirror
9591
9692 return enabled_mirrors
9793
@@ -182,44 +178,26 @@ def _create_spack_mirrors_yaml(self, dest: pathlib.Path):
182178
183179 raw = {"mirrors" : {}}
184180
185- if self .build_cache_mirror :
186- url = self .mirrors .get ("buildcache" )["url" ]
187- name = self .build_cache_mirror
181+ for name , mirror in self .mirrors .items ():
182+ url = mirror ["url" ]
188183
189- if self .build_cache_mirror .get ("mount_specific" , True ) and self ._mount_point is not None :
190- url = url .rstrip ("/" ) + "/" + self ._mount_point .as_posix ().lstrip ("/" )
184+ # Make the mirror path specific to the mount point
185+ if (name == "buildcache" ):
186+ if mirror ["mount_specific" ] and self ._mount_point is not None :
187+ url = url .rstrip ("/" ) + "/" + self ._mount_point .as_posix ().lstrip ("/" )
191188
192189 raw ["mirrors" ][name ] = {
193190 "fetch" : {"url" : url },
194191 "push" : {"url" : url },
195192 }
196193
197- elif self .mirrors .get ("bootstrap" ):
198- url = self .mirrors .get ("bootstrap" )["url" ]
199-
200- raw ["mirrors" ]["bootstrap" ] = {
201- "fetch" : {"url" : url },
202- "push" : {"url" : url },
203- }
204-
205- elif self .mirrors .get ("sourcecache" ):
206- source_mirrors = self .mirrors .get ("sourcecache" )
207-
208- for name , mirror in source_mirrors .items ():
209- url = mirror ["url" ]
210-
211- raw ["mirrors" ][name ] = {
212- "fetch" : {"url" : url },
213- "push" : {"url" : url },
214- }
215-
216194 with dest .open ("w" ) as file :
217195 yaml .dump (raw , file , default_flow_style = False )
218196
219197 def _create_bootstrap_configs (self , config_root : pathlib .Path ):
220198 """Create the bootstrap.yaml and bootstrap metadata dirs in our build dir."""
221199
222- if not self .bootstrap_mirror :
200+ if not self .mirrors . get ( "bootstrap" ) :
223201 return
224202
225203 bootstrap_yaml = {
@@ -229,17 +207,17 @@ def _create_bootstrap_configs(self, config_root: pathlib.Path):
229207 }
230208 }
231209
232- bs_mirror_path = config_root / f "bootstrap/ { self . bootstrap_mirror } "
210+ bs_mirror_path = config_root / "bootstrap" / "bootstrap-mirror "
233211 mirror = self .mirrors .get ("bootstrap" )
234212 # Tell spack where to find the metadata for each bootstrap mirror.
235213 bootstrap_yaml ["bootstrap" ]["sources" ].append (
236214 {
237- "name" : "bootstrap_mirror " ,
215+ "name" : "bootstrap-mirror " ,
238216 "metadata" : str (bs_mirror_path ),
239217 }
240218 )
241219 # And trust each one
242- bootstrap_yaml ["bootstrap" ]["trusted" ][bootstrap_mirror ] = True
220+ bootstrap_yaml ["bootstrap" ]["trusted" ]["bootstrap-mirror" ] = True
243221
244222 # Create the metadata dir and metadata.yaml
245223 bs_mirror_path .mkdir (parents = True , exist_ok = True )
@@ -256,44 +234,44 @@ def _create_bootstrap_configs(self, config_root: pathlib.Path):
256234 yaml .dump (bootstrap_yaml , file , default_flow_style = False )
257235
258236 def _key_init (self ):
259- key_info = []
260-
261- for name , mirror in self .mirrors .items ():
262- if mirror .get ("private_key" ) is None :
263- continue
237+ key_info = {}
238+
239+ key = self .mirrors ["buildcache" ].get ("private_key" )
264240
265- key = mirror ["private_key" ]
241+ if key is None :
242+ return
266243
267- # if path, check if abs path, if not, append sys config path in front and check again
268- path = pathlib .Path (os .path .expandvars (key ))
244+ # if path, check if abs path, if not, append sys config path in front and check again
245+ path = pathlib .Path (os .path .expandvars (key ))
269246
270- if not path .is_absolute ():
271- # try prepending system config path
272- path = self ._system_config_root / path
247+ if not path .is_absolute ():
248+ # try prepending system config path
249+ path = self ._system_config_root / path
273250
274- if path .is_file ():
275- # use the user-provided file
276- key_info .append ({"path" : pathlib .Path (f"{ name } .pgp" ), "source" : path })
277- else :
278- # convert base64 key to binary
279- try :
280- binary_key = base64 .b64decode (key )
281- except ValueError :
282- raise MirrorError (
283- f"Key for mirror '{ name } ' is not valid: '{ path } '. \n "
284- f"Must be a path to a GPG public key or a base64 encoded GPG public key. \n "
285- f"Check the key listed in mirrors.yaml in system config."
286- )
251+ if path .is_file ():
252+ # use the user-provided file
253+ key_info = {"path" : pathlib .Path (f"buildcache.pgp" ), "source" : path }
254+ else :
255+ # convert base64 key to binary
256+ try :
257+ binary_key = base64 .b64decode (key , validate = True )
258+ print (binary_key )
259+ except ValueError :
260+ raise MirrorError (
261+ f"Key for mirror 'buildcache' is not valid. \n "
262+ f"Must be a path to a GPG public key or a base64 encoded GPG public key. \n "
263+ f"Check the key listed in mirrors.yaml in system config."
264+ )
287265
288- file_type = magic .from_buffer (binary_key , mime = True )
289- if file_type not in ("application/x-gnupg-keyring" , "application/pgp-keys" ):
290- raise MirrorError (
291- f"Key for mirror { name } is not a valid GPG key. \n "
292- f"The file (or base64) was readable, but the data itself was not a PGP key.\n "
293- f"Check the key listed in mirrors.yaml in system config."
294- )
266+ file_type = magic .from_buffer (binary_key , mime = True )
267+ if file_type not in ("application/x-gnupg-keyring" , "application/pgp-keys" ):
268+ raise MirrorError (
269+ f"Key for mirror 'buildcache' is not a valid GPG key. \n "
270+ f"The file (or base64) was readable, but the data itself was not a PGP key.\n "
271+ f"Check the key listed in mirrors.yaml in system config."
272+ )
295273
296- key_info . append ( {"path" : pathlib .Path (f" { name } .pgp" ), "source" : binary_key })
274+ key_info = {"path" : pathlib .Path ("buildcache .pgp" ), "source" : binary_key }
297275
298276 return key_info
299277
@@ -302,17 +280,20 @@ def _key_setup(self, key_store: pathlib.Path):
302280
303281 key_store .mkdir (exist_ok = True )
304282
305- for key_info in self ._keys :
306- path = key_store / key_info ["path" ]
307- source = key_info ["source" ]
308-
309- match source :
310- case pathlib .Path ():
311- # copy source -> path
312- shutil .copy2 (source , path )
313- case bytes ():
314- # open path and copy in bytes
315- with open (path , "wb" ) as writer :
316- writer .write (source )
317- case _:
318- raise TypeError (f"Expected Path or bytes, got { type (source ).__name__ } " )
283+ #for key_info in self._keys:
284+
285+ #path = key_store / key_info["path"]
286+ path = key_store / self ._keys ["path" ]
287+ #source = key_info["source"]
288+ source = self ._keys ["source" ]
289+
290+ match source :
291+ case pathlib .Path ():
292+ # copy source -> path
293+ shutil .copy2 (source , path )
294+ case bytes ():
295+ # open path and copy in bytes
296+ with open (path , "wb" ) as writer :
297+ writer .write (source )
298+ case _:
299+ raise TypeError (f"Expected Path or bytes, got { type (source ).__name__ } " )
0 commit comments