-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
112 lines (103 loc) · 3.13 KB
/
setup.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import utils
host = 'http://localhost:8080/api/darkshield'
search_context_name = "SearchContext"
mask_context_name = "MaskContext"
file_search_context_name = "FileSearchContext"
file_mask_context_name = "FileMaskContext"
def setup(session):
model_url = utils.download_model('en-ner-person.bin',session)
sent_url = utils.download_model('en-sent.bin',session)
token_url = utils.download_model('en-token.bin',session)
search_context = {
"name": search_context_name,
"matchers": [
{
"name": "EmailMatcher",
"type": "pattern",
"pattern": r"\b[\w._%+-]+@[\w.-]+\.[A-Za-z]{2,4}\b"
},
{
"name": "PhoneMatcher",
"type": "pattern",
"pattern": r"\b(\+?1?([ .-]?)?)?(\(?([2-9]\d{2})\)?([ .-]?)?)([2-9]\d{2})([ .-]?)(\d{4})(?: #?[eE][xX][tT]\.? \d{2,6})?\b"
},
{
"name": "NameMatcher",
"type": "ner",
"modelUrl": model_url,
"sentenceDetectorUrl": sent_url,
"tokenizerUrl": token_url
}
]
}
mask_context = {
"name": mask_context_name,
"rules": [
{
"name": "HashRule",
"type": "cosort",
"expression": "hash_sha2($\{INPUT\})"
},
{
"name": "FpeRule",
"type": "cosort",
"expression": "enc_fp_aes256_alphanum($\{INPUT\})"
}
],
"ruleMatchers": [
{
"name": "FpeRuleMatcher",
"type": "name",
"rule": "FpeRule",
"pattern": "PhoneMatcher|NameMatcher"
},
{
"name": "HashRuleMatcher",
"type": "name",
"rule": "HashRule",
"pattern": "EmailMatcher"
}
]
}
file_search_context = {
"name": file_search_context_name,
"matchers": [
{
"name": search_context_name,
"type": "searchContext"
},
{
"name": "NameMatcher",
"type": "jsonPath",
"jsonPath": "$..name"
},
{
"name": "NameMatcher",
"type": "xmlPath",
"xmlPath": "//name"
}
]
}
file_mask_context = {
"name": file_mask_context_name,
"rules": [
{
"name": mask_context_name,
"type": "maskContext"
}
],
"configs": {
"json": {
"prettyPrint": True
}
}
}
utils.create_context("searchContext", search_context,session)
utils.create_context("maskContext", mask_context,session)
utils.create_context("files/fileSearchContext", file_search_context,session)
utils.create_context("files/fileMaskContext", file_mask_context,session)
def teardown(session):
utils.destroy_context("searchContext", search_context_name,session)
utils.destroy_context("maskContext", mask_context_name,session)
utils.destroy_context("files/fileSearchContext", file_search_context_name,session)
utils.destroy_context("files/fileMaskContext", file_mask_context_name,session)