From 5281176e3c233871da9a3f6ea6552489ff12aa76 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Mon, 8 Aug 2022 08:58:06 -0700 Subject: [PATCH] Add use_tor boolean to envvars --- .env-sample | 1 + api/logics.py | 2 -- api/management/commands/telegram_watcher.py | 4 ++-- api/messages.py | 4 ++-- api/utils.py | 10 ++++++---- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.env-sample b/.env-sample index 2a83e4ec..8a218c5b 100644 --- a/.env-sample +++ b/.env-sample @@ -21,6 +21,7 @@ POSTGRES_HOST='127.0.0.1' POSTGRES_PORT='5432' # Tor proxy for remote calls (e.g. fetching prices or sending Telegram messages) +USE_TOR=True TOR_PROXY='127.0.0.1:9050' # Auto unlock LND password. Only used in development docker-compose environment. diff --git a/api/logics.py b/api/logics.py index b7c3d1dc..abb02d11 100644 --- a/api/logics.py +++ b/api/logics.py @@ -1,6 +1,4 @@ from datetime import timedelta -from tkinter import N, ON -from tokenize import Octnumber from django.utils import timezone from api.lightning.node import LNNode from django.db.models import Q, Sum diff --git a/api/management/commands/telegram_watcher.py b/api/management/commands/telegram_watcher.py index e4afe6a3..5723e319 100644 --- a/api/management/commands/telegram_watcher.py +++ b/api/management/commands/telegram_watcher.py @@ -2,7 +2,7 @@ from django.core.management.base import BaseCommand, CommandError from api.models import Profile from api.messages import Telegram -from api.utils import get_tor_session +from api.utils import get_session from decouple import config import requests import time @@ -15,7 +15,7 @@ class Command(BaseCommand): bot_token = config('TELEGRAM_TOKEN') updates_url = f'https://api.telegram.org/bot{bot_token}/getUpdates' - session = get_tor_session() + session = get_session() telegram = Telegram() def handle(self, *args, **options): """Infinite loop to check for telegram updates. diff --git a/api/messages.py b/api/messages.py index fa882d6a..b22c7c81 100644 --- a/api/messages.py +++ b/api/messages.py @@ -1,13 +1,13 @@ from decouple import config from secrets import token_urlsafe from api.models import Order -from api.utils import get_tor_session +from api.utils import get_session import time class Telegram(): ''' Simple telegram messages by requesting to API''' - session = get_tor_session() + session = get_session() def get_context(user): """returns context needed to enable TG notifications""" diff --git a/api/utils.py b/api/utils.py index 183da3b2..dbaffcb6 100644 --- a/api/utils.py +++ b/api/utils.py @@ -10,12 +10,14 @@ from api.models import Order logger = logging.getLogger('api.utils') TOR_PROXY = config('TOR_PROXY', default='127.0.0.1:9050') +USE_TOR = config('USE_TOR', cast=bool, default=True) -def get_tor_session(): +def get_session(): session = requests.session() # Tor uses the 9050 port as the default socks port - session.proxies = {'http': 'socks5://' + TOR_PROXY, - 'https': 'socks5://' + TOR_PROXY} + if USE_TOR: + session.proxies = {'http': 'socks5://' + TOR_PROXY, + 'https': 'socks5://' + TOR_PROXY} return session @@ -70,7 +72,7 @@ def get_exchange_rates(currencies): Returns the median price list. """ - session = get_tor_session() + session = get_session() APIS = config("MARKET_PRICE_APIS", cast=lambda v: [s.strip() for s in v.split(",")])