Add use_tor boolean to envvars

This commit is contained in:
Reckless_Satoshi 2022-08-08 08:58:06 -07:00
parent d73b05f76c
commit 5281176e3c
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
5 changed files with 11 additions and 10 deletions

View File

@ -21,6 +21,7 @@ POSTGRES_HOST='127.0.0.1'
POSTGRES_PORT='5432' POSTGRES_PORT='5432'
# Tor proxy for remote calls (e.g. fetching prices or sending Telegram messages) # Tor proxy for remote calls (e.g. fetching prices or sending Telegram messages)
USE_TOR=True
TOR_PROXY='127.0.0.1:9050' TOR_PROXY='127.0.0.1:9050'
# Auto unlock LND password. Only used in development docker-compose environment. # Auto unlock LND password. Only used in development docker-compose environment.

View File

@ -1,6 +1,4 @@
from datetime import timedelta from datetime import timedelta
from tkinter import N, ON
from tokenize import Octnumber
from django.utils import timezone from django.utils import timezone
from api.lightning.node import LNNode from api.lightning.node import LNNode
from django.db.models import Q, Sum from django.db.models import Q, Sum

View File

@ -2,7 +2,7 @@ from django.core.management.base import BaseCommand, CommandError
from api.models import Profile from api.models import Profile
from api.messages import Telegram from api.messages import Telegram
from api.utils import get_tor_session from api.utils import get_session
from decouple import config from decouple import config
import requests import requests
import time import time
@ -15,7 +15,7 @@ class Command(BaseCommand):
bot_token = config('TELEGRAM_TOKEN') bot_token = config('TELEGRAM_TOKEN')
updates_url = f'https://api.telegram.org/bot{bot_token}/getUpdates' updates_url = f'https://api.telegram.org/bot{bot_token}/getUpdates'
session = get_tor_session() session = get_session()
telegram = Telegram() telegram = Telegram()
def handle(self, *args, **options): def handle(self, *args, **options):
"""Infinite loop to check for telegram updates. """Infinite loop to check for telegram updates.

View File

@ -1,13 +1,13 @@
from decouple import config from decouple import config
from secrets import token_urlsafe from secrets import token_urlsafe
from api.models import Order from api.models import Order
from api.utils import get_tor_session from api.utils import get_session
import time import time
class Telegram(): class Telegram():
''' Simple telegram messages by requesting to API''' ''' Simple telegram messages by requesting to API'''
session = get_tor_session() session = get_session()
def get_context(user): def get_context(user):
"""returns context needed to enable TG notifications""" """returns context needed to enable TG notifications"""

View File

@ -10,12 +10,14 @@ from api.models import Order
logger = logging.getLogger('api.utils') logger = logging.getLogger('api.utils')
TOR_PROXY = config('TOR_PROXY', default='127.0.0.1:9050') 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() session = requests.session()
# Tor uses the 9050 port as the default socks port # Tor uses the 9050 port as the default socks port
session.proxies = {'http': 'socks5://' + TOR_PROXY, if USE_TOR:
'https': 'socks5://' + TOR_PROXY} session.proxies = {'http': 'socks5://' + TOR_PROXY,
'https': 'socks5://' + TOR_PROXY}
return session return session
@ -70,7 +72,7 @@ def get_exchange_rates(currencies):
Returns the median price list. Returns the median price list.
""" """
session = get_tor_session() session = get_session()
APIS = config("MARKET_PRICE_APIS", APIS = config("MARKET_PRICE_APIS",
cast=lambda v: [s.strip() for s in v.split(",")]) cast=lambda v: [s.strip() for s in v.split(",")])