This repository has been archived by the owner on Apr 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from applandinc/refactor/rename-internal-code-…
…objects refactor: Rename Scanner concepts - Rule, Check, Scan
- Loading branch information
Showing
84 changed files
with
1,300 additions
and
1,461 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { AppMap, Event } from '@appland/models'; | ||
import { verbose } from './rules/util'; | ||
import { EventFilter, Rule, ScopeName } from './types'; | ||
|
||
export default class Check { | ||
public id: string; | ||
public options: Record<string, any>; | ||
public scope: ScopeName; | ||
public includeScope: EventFilter[]; | ||
public excludeScope: EventFilter[]; | ||
public includeEvent: EventFilter[]; | ||
public excludeEvent: EventFilter[]; | ||
|
||
constructor(public rule: Rule, options?: Record<string, any>) { | ||
function makeOptions() { | ||
return rule.Options ? new rule.Options() : {}; | ||
} | ||
|
||
this.id = rule.id; | ||
this.options = options || makeOptions(); | ||
this.scope = rule.scope || 'root'; | ||
this.includeScope = []; | ||
this.excludeScope = []; | ||
this.includeEvent = []; | ||
this.excludeEvent = []; | ||
} | ||
|
||
filterScope(event: Event, appMap?: AppMap): boolean { | ||
if (this.includeScope.length > 0 && !this.includeScope.every((fn) => fn(event, appMap))) { | ||
if (verbose()) { | ||
console.warn(`\t'includeScope' clause is not satisifed.`); | ||
} | ||
return false; | ||
} | ||
if (this.excludeScope.some((fn) => fn(event, appMap))) { | ||
if (verbose()) { | ||
console.warn(`\t'excludeScope' clause is not satisifed.`); | ||
} | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
toString(): string { | ||
const tokens = [`[${this.rule.id}]`]; | ||
// eslint-disable-next-line @typescript-eslint/no-this-alias | ||
const self: any = this; | ||
['includeScope', 'excludeScope', 'includeEvent', 'excludeEvent'].forEach((key) => { | ||
if (self[key].length > 0) { | ||
tokens.push(`(${key} ${self[key].join(' && ')})`); | ||
} | ||
}); | ||
return tokens.join(' '); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { AppMap, Event } from '@appland/models'; | ||
import Check from './check'; | ||
import { verbose } from './rules/util'; | ||
import { RuleLogic, ScopeName } from './types'; | ||
|
||
export default class CheckInstance { | ||
check: Check; | ||
ruleLogic: RuleLogic; | ||
|
||
constructor(check: Check) { | ||
this.check = check; | ||
this.ruleLogic = check.rule.build(check.options || {}); | ||
} | ||
|
||
get checkId(): string { | ||
return this.check.id; | ||
} | ||
|
||
get ruleId(): string { | ||
return this.check.rule.id; | ||
} | ||
|
||
get title(): string { | ||
return this.check.rule.title; | ||
} | ||
|
||
get scope(): ScopeName { | ||
return this.check.scope; | ||
} | ||
|
||
get enumerateScope(): boolean { | ||
return this.check.rule.enumerateScope; | ||
} | ||
|
||
filterEvent(event: Event, appMap?: AppMap): boolean { | ||
if (this.ruleLogic.where && !this.ruleLogic.where(event, appMap)) { | ||
if (verbose()) { | ||
console.warn(`\t'where' clause is not satisifed.`); | ||
} | ||
return false; | ||
} | ||
|
||
if ( | ||
this.check.includeEvent.length > 0 && | ||
!this.check.includeEvent.every((fn) => fn(event, appMap)) | ||
) { | ||
if (verbose()) { | ||
console.warn(`\t'includeEvent' clause is not satisifed.`); | ||
} | ||
return false; | ||
} | ||
if (this.check.excludeEvent.some((fn) => fn(event, appMap))) { | ||
if (verbose()) { | ||
console.warn(`\t'excludeEvent' clause is not satisifed.`); | ||
} | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.