rule engine API
Project description
api-rule-engine
API for sending files to Minereye system and find sensitive information
Introduction
This repo is meant for sending file to Minereye system and find sensitive information defined by the system
Technologies
Python 3.7 or higher
Instalation
pip install api-rule-engine
Python code example
from api_rule_engine.client import send_file
file_path = <add local file path>
file_metadata = {'file_name': file_path.split('/')[-1], 'file_path': file_path}
with open(file_path, 'rb') as f:
res = scan_file(f.read(), file_metadata=file_metadata)
>>> res
{'response_data': {'found_tracking_groups': [{'action_id': '1', 'category_id': '12', 'key': '7',
'label_id': 'None', 'status': 'added', 'tg_name': 'risk.doc'}]}, 'response_status': 200}
Sending list of files in threads
import os
import time
import threading
from api_rule_engine.client import scan_file_callback, get_bytes,
## example of files list
file_list = ['../rule_engine/risk.doc', '../rule_engine/1138059831.xls', '../rule_engine/5.xlsx']
## this is short example of metadata
def simple_metadata(file_path):
return {'file_name': file_path.split('/')[-1], 'file_path': file_path}
d = {}
threads = []
for file_path in file_list:
x = threading.Thread(target=scan_file_callback, args=(os.path.basename(file_path), get_bytes(file_path),
simple_metadata(file_path), {}, d))
threads.append(x)
for x in threads:
x.start()
while len(d) < len(file_list):
time.sleep(1)
print(d)
{'5.xlsx': {'found_tracking_groups': ''},
'1138059831.xls': {'found_tracking_groups': ''},
'risk.doc': {'found_tracking_groups': [{'action_id': '1',
'category_id': '12',
'key': '7',
'label_id': 'None',
'status': 'added',
'tg_name': 'risk.doc'}]}}
getting file_metadata
from api_rule_engine.client import send_file
file_path = '../rule_engine/risk.doc'
file_metadata = {'file_name': file_path.split('/')[-1], 'file_path': file_path}
with open(file_path, 'rb') as f:
res = scan_file(f.read(), file_metadata=file_metadata, fields=['fi_entities_nested'])
res
{'fi_entities_nested': '[{"display_name": "Email", "id": 10, "values": ["sales@symtrex.com"], "count": 1, "pi_score": 78.9806835921147}, {"display_name": "Full name", "id": 160, "values": ["Lynne Krekeler"], "count": 1, "pi_score": 86.41661304637691}]',
'found_tracking_groups': [{'action_id': '1',
'category_id': '12',
'key': '7',
'label_id': 'None',
'status': 'added',
'tg_name': 'risk.doc'}]}
Full Python API
scan_file(file_bytes: bytes, file_metadata={}, fields={})
file_bytes: files bytes,
- file_metadata: dictionary of extra information for finding sensitive information on file, for mor details: full list
- fields: extra metadata to get by request full list: full list
scan_file_callback(file_name: str, file_bytes: bytes, file_metadata: dict, fields: list, return_dict: dict)
file_name - file name,
return_dict - dict for returning answer
return_dict : {file_name : answer}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file api_rule_engine-0.0.21-py3-none-any.whl
.
File metadata
- Download URL: api_rule_engine-0.0.21-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.25.1 requests-toolbelt/0.9.1 urllib3/1.26.2 tqdm/4.60.0 importlib-metadata/4.11.2 keyring/18.0.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92225707eab3f8cebecf96236a9f7f8c65bb4f4b1e69057a67ecde45484a9520 |
|
MD5 | 2152f40a1b78b4dc963f53b1340cb76f |
|
BLAKE2b-256 | 653dc92f46550d7e2c9cce5e4c24dce6909343d5a0afde29228ee066fa2b6765 |