import { IConstruct } from "constructs" ; import { Reportable } from "./reporter" ; export interface PolicyContext { [ key ] : any ; } interface PolicyScope { scope ? : IConstruct ; isApplicable ( node ) : boolean ; } export interface PolicyInterface extends PolicyScope { policyName : string ; description : string ; link : string ; } export abstract class Policy implements PolicyScope { public scope ? : IConstruct ; public abstract validator ( node , reporter , context ) ; public validate ( node , reporter , context ) { if ( this . isApplicable ( node ) ) { this . validator ( node , reporter , context ) ; } } public isApplicable ( node ) { if ( ! this . scope ) throw new Error ( 'If Policy.scope is not defined, `isApplicable` has to be overwritten' ) ; return node . constructor . name === ( this . scope as any ) . prototype . constructor . name ; } } export type IPolicy = Policy & PolicyInterface ;