@@ -197,14 +197,29 @@ def verify_policy(verify_policy_args: argparse.Namespace) -> int:
197197 show_prelude (verify_policy_args .database )
198198 return os .EX_OK
199199
200+ policy_content = None
200201 if verify_policy_args .file :
201202 if not os .path .isfile (verify_policy_args .file ):
202203 logger .critical ('The policy file "%s" does not exist.' , verify_policy_args .file )
203204 return os .EX_OSFILE
204205
205206 with open (verify_policy_args .file , encoding = "utf-8" ) as file :
206207 policy_content = file .read ()
208+ elif verify_policy_args .policy :
209+ policy_dir = os .path .join (macaron .MACARON_PATH , "resources/policies/datalog" )
210+ available_policies = [policy [:- 3 ] for policy in os .listdir (policy_dir ) if policy .endswith (".dl" )]
211+ if verify_policy_args .policy not in available_policies :
212+ logger .error (
213+ "The policy %s is not available. Available policies are: %s" ,
214+ verify_policy_args .policy ,
215+ available_policies ,
216+ )
217+ return os .EX_USAGE
218+ policy_path = os .path .join (policy_dir , f"{ verify_policy_args .policy } .dl" )
219+ with open (policy_path , encoding = "utf-8" ) as file :
220+ policy_content = file .read ()
207221
222+ if policy_content :
208223 result = run_policy_engine (verify_policy_args .database , policy_content )
209224 vsa = generate_vsa (policy_content = policy_content , policy_result = result )
210225 if vsa is not None :
@@ -539,6 +554,7 @@ def main(argv: list[str] | None = None) -> None:
539554
540555 vp_parser .add_argument ("-d" , "--database" , required = True , type = str , help = "Path to the database." )
541556 vp_group .add_argument ("-f" , "--file" , type = str , help = "Path to the Datalog policy." )
557+ vp_group .add_argument ("-p" , "--policy" , help = "Example policy to run." )
542558 vp_group .add_argument ("-s" , "--show-prelude" , action = "store_true" , help = "Show policy prelude." )
543559
544560 # Find the repo and commit of a passed PURL, or the commit of a passed PURL and repo.
0 commit comments