Skip to content

Commit 149b981

Browse files
author
rootware
committed
added identify data api
1 parent 9f05dbd commit 149b981

File tree

5 files changed

+28
-1
lines changed

5 files changed

+28
-1
lines changed

pyredactkit/core_redactor.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ def __init__(self) -> None:
3535
"""
3636
return None
3737

38+
def identify_data(self, line: str) -> list:
39+
"""Function to identify specific option
40+
Args:
41+
line (str) : line to be supplied to identify pattern
42+
Returns:
43+
list (list): list of sensitive data found in lines
44+
"""
45+
sensitive_data = []
46+
for id in id_object.regexes:
47+
redact_pattern = id['pattern']
48+
if re.search(redact_pattern, line):
49+
pattern_string = re.search(redact_pattern, line)
50+
pattern_string = pattern_string.group(0)
51+
sensitive_data.append(pattern_string)
52+
return sensitive_data
53+
3854
def redact_all(self, line: str) -> tuple:
3955
"""Function to redact specific option
4056
Args:

pyredactkit/pyredactkit.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,9 @@ def main():
143143
redact_obj.process_text(args.text)
144144

145145

146+
def api_return_core_identifier(text: str) -> list:
147+
return redact_obj.identify_data(text)
148+
149+
146150
if __name__ == "__main__":
147151
main()

tests/test_common_jobs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pytest
2-
import json
32
import os
43
from pyredactkit.common_jobs import CommonJobs
54

tests/test_core_redact.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ def mocker_text_file(mocker):
6060
mocker.patch(builtin_open, mocked_open)
6161

6262

63+
def test_identify_data_should_return_list(redactor_obj):
64+
assert type(redactor_obj.identify_data(data)) == list, "identify_data function should return a list"
65+
66+
6367
def test_redact_all_function_should_return_string_and_dictionary(redactor_obj):
6468
set1 = redactor_obj.redact_all(data)
6569
set2 = ("This is a string", hash_table)

tests/test_custom_redact_engine.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ def mocker_text_file(mocker):
5858
mocker.patch(builtin_open, mocked_open)
5959

6060

61+
# def test_write_hashmap_should_create_json_file(custom_redactor, tmp_path):
62+
# hash_map = {"key": "value"}
63+
# custom_redactor.write_hashmap(hash_map, filename='fakefile', savedir=tmp_path)
64+
6165
# def test_redact_custom_function_should_return_string_and_dictionary(custom_redactor):
6266
# set1 = custom_redactor.redact_custom(data)
6367
# set2 = ("This is a string", hash_table)

0 commit comments

Comments
 (0)