From 4b389559ab8bde8324b18236b5917d3c9b44e792 Mon Sep 17 00:00:00 2001 From: Terrtia Date: Tue, 29 Oct 2019 09:13:44 +0100 Subject: [PATCH] chg: [Domain] move Domain to lib/ --- bin/{packages => lib}/Domain.py | 16 ++++++++++++---- bin/packages/Correlation.py | 1 + bin/packages/Cryptocurrency.py | 21 +++++++++++++++++---- 3 files changed, 30 insertions(+), 8 deletions(-) rename bin/{packages => lib}/Domain.py (82%) diff --git a/bin/packages/Domain.py b/bin/lib/Domain.py similarity index 82% rename from bin/packages/Domain.py rename to bin/lib/Domain.py index 76f97735..233fc574 100755 --- a/bin/packages/Domain.py +++ b/bin/lib/Domain.py @@ -12,12 +12,17 @@ import sys import time import redis +sys.path.append(os.path.join(os.environ['AIL_BIN'], 'packages/')) +import Correlation +import Cryptocurrency import Item -sys.path.append(os.path.join(os.environ['AIL_FLASK'], 'modules/')) -import Flask_config +sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib/')) +import ConfigLoader -r_serv_onion = Flask_config.r_serv_onion +config_loader = ConfigLoader.ConfigLoader() +r_serv_onion = config_loader.get_redis_conn("ARDB_Onion") +config_loader = None def get_domain_type(domain): if str(domain).endswith('.onion'): @@ -52,7 +57,7 @@ def get_link_tree(): ### ### correlation ### - +""" def _get_domain_correlation(domain, correlation_name=None, correlation_type=None): res = r_serv_metadata.smembers('item_{}_{}:{}'.format(correlation_name, correlation_type, item_id)) if res: @@ -74,7 +79,10 @@ def get_item_pgp_mail(item_id): def get_item_pgp_correlation(item_id): pass +""" +def _get_domain_correlation(domain, correlation_list): + return Cryptocurrency.get_cryptocurrency_domain(domain) class Domain(object): """docstring for Domain.""" diff --git a/bin/packages/Correlation.py b/bin/packages/Correlation.py index cf923049..dbef4d8d 100755 --- a/bin/packages/Correlation.py +++ b/bin/packages/Correlation.py @@ -49,6 +49,7 @@ class Correlation(object): if not request_dict: return ({'status': 'error', 'reason': 'Malformed JSON'}, 400) + print(correlation_type) field_name = request_dict.get(correlation_type, None) if not field_name: return ( {'status': 'error', 'reason': 'Mandatory parameter(s) not provided'}, 400 ) diff --git a/bin/packages/Cryptocurrency.py b/bin/packages/Cryptocurrency.py index eb5c00e6..d9f657b9 100755 --- a/bin/packages/Cryptocurrency.py +++ b/bin/packages/Cryptocurrency.py @@ -14,7 +14,7 @@ import Item r_serv_metadata = Flask_config.r_serv_metadata -all_cryptocurrency = ['bitcoin', 'etherum'] +all_cryptocurrency = ['bitcoin', 'ethereum', 'bitcoin-cash', 'litecoin', 'monero', 'zcash', 'dash'] digits58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' @@ -41,6 +41,18 @@ def verify_cryptocurrency_address(cryptocurrency_type, cryptocurrency_address): else: return True +def get_all_all_cryptocurrency(): + return all_cryptocurrency + +# check if all crypto type in the list are valid +# if a type is invalid, return the full list of currency types +def sanythise_cryptocurrency_types(cryptocurrency_types): + if cryptocurrency_types is None: + return get_all_all_cryptocurrency() + for currency in cryptocurrency_types: # # TODO: # OPTIMIZE: + if currency not in all_cryptocurrency: + return get_all_all_cryptocurrency() + return cryptocurrency_types def get_cryptocurrency(request_dict, cryptocurrency_type): # basic verification @@ -54,9 +66,10 @@ def get_cryptocurrency(request_dict, cryptocurrency_type): return cryptocurrency.get_correlation(request_dict, cryptocurrency_type, field_name) -# # TODO: add get all cryptocurrency option -def get_cryptocurrency_domain(request_dict, cryptocurrency_type): - res = cryptocurrency.verify_correlation_field_request(request_dict, cryptocurrency_type, item_type='domain') +def get_cryptocurrency_domain(request_dict, cryptocurrency_type=None): + currency_types = sanythise_cryptocurrency_types(cryptocurrency_type) + + res = cryptocurrency.verify_correlation_field_request(request_dict, currency_types, item_type='domain') if res: return res field_name = request_dict.get(cryptocurrency_type)