forked from alessandrodd/api_key_detector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetector.py
31 lines (26 loc) · 1.06 KB
/
detector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import sys
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
sys.path.append(__location__)
from .classifier_singleton import classifier
from .strings_filter_singleton import s_filter
def filter_api_keys(strings):
apikeys = [string for string in strings if s_filter.pre_filter(string)]
classification = classifier.predict_strings(apikeys)
apikeys = [apikeys[i] for i in range(len(apikeys)) if classification[i] > 0.5]
apikeys = [string for string in apikeys if s_filter.post_filter(string)]
return apikeys
def detect_api_keys(strings):
detection = []
for string in strings:
detection.append(s_filter.pre_filter(string))
apikeys = [strings[i] for i in range(len(strings)) if detection[i]]
classification = classifier.predict_strings(apikeys)
j = 0
for i in range(len(detection)):
if detection[i]:
detection[i] = classification[j] > 0.5
j += 1
if detection[i]:
detection[i] = s_filter.post_filter(strings[i])
return detection