@@ -204,14 +204,29 @@ def verify_policy(verify_policy_args: argparse.Namespace) -> int:
204204 show_prelude (verify_policy_args .database )
205205 return os .EX_OK
206206
207+ policy_content = None
207208 if verify_policy_args .file :
208209 if not os .path .isfile (verify_policy_args .file ):
209210 logger .critical ('The policy file "%s" does not exist.' , verify_policy_args .file )
210211 return os .EX_OSFILE
211212
212213 with open (verify_policy_args .file , encoding = "utf-8" ) as file :
213214 policy_content = file .read ()
215+ elif verify_policy_args .policy :
216+ policy_dir = os .path .join (macaron .MACARON_PATH , "resources/policies/datalog" )
217+ available_policies = [policy [:- 3 ] for policy in os .listdir (policy_dir ) if policy .endswith (".dl" )]
218+ if verify_policy_args .policy not in available_policies :
219+ logger .error (
220+ "The policy %s is not available. Available policies are: %s" ,
221+ verify_policy_args .policy ,
222+ available_policies ,
223+ )
224+ return os .EX_USAGE
225+ policy_path = os .path .join (policy_dir , f"{ verify_policy_args .policy } .dl" )
226+ with open (policy_path , encoding = "utf-8" ) as file :
227+ policy_content = file .read ()
214228
229+ if policy_content :
215230 result = run_policy_engine (verify_policy_args .database , policy_content )
216231 vsa = generate_vsa (policy_content = policy_content , policy_result = result )
217232 # Retrieve the console handler previously configured via the access_handler.
@@ -574,6 +589,7 @@ def main(argv: list[str] | None = None) -> None:
574589
575590 vp_parser .add_argument ("-d" , "--database" , required = True , type = str , help = "Path to the database." )
576591 vp_group .add_argument ("-f" , "--file" , type = str , help = "Path to the Datalog policy." )
592+ vp_group .add_argument ("-p" , "--policy" , help = "Example policy to run." )
577593 vp_group .add_argument ("-s" , "--show-prelude" , action = "store_true" , help = "Show policy prelude." )
578594
579595 # Find the repo and commit of a passed PURL, or the commit of a passed PURL and repo.
0 commit comments