@@ -258,6 +258,7 @@ def acifragmentgen_confcom(
258258 upload_fragment : bool = False ,
259259 no_print : bool = False ,
260260 fragments_json : str = "" ,
261+ out_signed_fragment : bool = False ,
261262):
262263 if container_definitions is None :
263264 container_definitions = []
@@ -364,24 +365,39 @@ def acifragmentgen_confcom(
364365
365366 fragment_text = policy .generate_fragment (namespace , svn , output_type , omit_id = omit_id )
366367
367- if output_type != security_policy .OutputType .DEFAULT and not no_print :
368+ if output_type != security_policy .OutputType .DEFAULT and not no_print and not out_signed_fragment :
368369 print (fragment_text )
369370
370371 # take ".rego" off the end of the filename if it's there, it'll get added back later
371372 output_filename = output_filename .replace (".rego" , "" )
372373 filename = f"{ output_filename or namespace } .rego"
374+
375+ if out_signed_fragment :
376+ filename = os .path .join ("/tmp" , filename )
377+
373378 os_util .write_str_to_file (filename , fragment_text )
374379
375380 if key :
376381 cose_proxy = CoseSignToolProxy ()
377382 iss = cose_proxy .create_issuer (chain )
378383 out_path = filename + ".cose"
379384
385+ if out_signed_fragment :
386+ out_path = os .path .join ("/tmp" , os .path .basename (out_path ))
387+
380388 cose_proxy .cose_sign (filename , key , chain , feed , iss , algo , out_path )
381- if upload_fragment and image_target :
382- oras_proxy .attach_fragment_to_image (image_target , out_path )
383- elif upload_fragment :
384- oras_proxy .push_fragment_to_registry (feed , out_path )
389+
390+ # Preserve default behaviour established since version 1.1.0 of attaching
391+ # the fragment to the first image specified in input
392+ # (or --image-target if specified)
393+ if upload_fragment :
394+ oras_proxy .attach_fragment_to_image (
395+ image_name = image_target or policy_images [0 ].containerImage ,
396+ filename = out_path ,
397+ )
398+
399+ if out_signed_fragment :
400+ sys .stdout .buffer .write (open (out_path , "rb" ).read ())
385401
386402
387403def katapolicygen_confcom (
0 commit comments