@@ -213,20 +213,30 @@ def verify_policy(verify_policy_args: argparse.Namespace) -> int:
213213 with open (verify_policy_args .file , encoding = "utf-8" ) as file :
214214 policy_content = file .read ()
215215 elif verify_policy_args .policy :
216- policy_dir = os .path .join (macaron .MACARON_PATH , "resources/policies/datalog" )
217- available_policies = [policy [:- 12 ] for policy in os .listdir (policy_dir ) if policy .endswith (".dl.template" )]
216+ policy_dir = os .path .join (macaron .MACARON_PATH , "resources" , "policies" , "datalog" )
217+ policy_suffix = ".dl"
218+ template_suffix = f"{ policy_suffix } .template"
219+ available_policies = [
220+ os .path .splitext (policy )[0 ].replace (policy_suffix , "" )
221+ for policy in os .listdir (policy_dir )
222+ if policy .endswith (template_suffix )
223+ ]
218224 if verify_policy_args .policy not in available_policies :
219225 logger .error (
220226 "The policy %s is not available. Available policies are: %s" ,
221227 verify_policy_args .policy ,
222228 available_policies ,
223229 )
224230 return os .EX_USAGE
225- policy_path = os .path .join (policy_dir , f"{ verify_policy_args .policy } .dl.template " )
231+ policy_path = os .path .join (policy_dir , f"{ verify_policy_args .policy } { template_suffix } " )
226232 with open (policy_path , encoding = "utf-8" ) as file :
227233 policy_content = file .read ()
228- if verify_policy_args .package_url :
234+ try :
235+ PackageURL .from_string (verify_policy_args .package_url )
229236 policy_content = policy_content .replace ("<PACKAGE_PURL>" , verify_policy_args .package_url )
237+ except ValueError as err :
238+ logger .error ("The package url %s is not valid. Error: %s" , verify_policy_args .package_url , err )
239+ return os .EX_USAGE
230240
231241 if policy_content :
232242 result = run_policy_engine (verify_policy_args .database , policy_content )
0 commit comments