@@ -206,20 +206,30 @@ def verify_policy(verify_policy_args: argparse.Namespace) -> int:
206206 with open (verify_policy_args .file , encoding = "utf-8" ) as file :
207207 policy_content = file .read ()
208208 elif verify_policy_args .policy :
209- policy_dir = os .path .join (macaron .MACARON_PATH , "resources/policies/datalog" )
210- available_policies = [policy [:- 12 ] for policy in os .listdir (policy_dir ) if policy .endswith (".dl.template" )]
209+ policy_dir = os .path .join (macaron .MACARON_PATH , "resources" , "policies" , "datalog" )
210+ policy_suffix = ".dl"
211+ template_suffix = f"{ policy_suffix } .template"
212+ available_policies = [
213+ os .path .splitext (policy )[0 ].replace (policy_suffix , "" )
214+ for policy in os .listdir (policy_dir )
215+ if policy .endswith (template_suffix )
216+ ]
211217 if verify_policy_args .policy not in available_policies :
212218 logger .error (
213219 "The policy %s is not available. Available policies are: %s" ,
214220 verify_policy_args .policy ,
215221 available_policies ,
216222 )
217223 return os .EX_USAGE
218- policy_path = os .path .join (policy_dir , f"{ verify_policy_args .policy } .dl.template " )
224+ policy_path = os .path .join (policy_dir , f"{ verify_policy_args .policy } { template_suffix } " )
219225 with open (policy_path , encoding = "utf-8" ) as file :
220226 policy_content = file .read ()
221- if verify_policy_args .package_url :
227+ try :
228+ PackageURL .from_string (verify_policy_args .package_url )
222229 policy_content = policy_content .replace ("<PACKAGE_PURL>" , verify_policy_args .package_url )
230+ except ValueError as err :
231+ logger .error ("The package url %s is not valid. Error: %s" , verify_policy_args .package_url , err )
232+ return os .EX_USAGE
223233
224234 if policy_content :
225235 result = run_policy_engine (verify_policy_args .database , policy_content )
0 commit comments