Sadeep Sachintha commited on
Commit ·
5b9bc06
1
Parent(s): 72fdc64
security: Remove hardcoded telegram bot tokens from tracked source files
Browse files- main.py +1 -1
- scratch/test2.py +2 -1
- scratch/test3.py +2 -1
- scratch/test_server.py +2 -1
- test_telegram.py +2 -1
main.py
CHANGED
|
@@ -76,7 +76,7 @@ async def lifespan(app: FastAPI):
|
|
| 76 |
try:
|
| 77 |
connector = aiohttp.TCPConnector(**kwargs)
|
| 78 |
async with aiohttp.ClientSession(connector=connector) as sess:
|
| 79 |
-
async with sess.get("https://api.telegram.org/
|
| 80 |
text = await r.text()
|
| 81 |
diagnostic_results.append(f"Configuration '{name}' SUCCESS: Status {r.status}, body: {text}")
|
| 82 |
except Exception as e:
|
|
|
|
| 76 |
try:
|
| 77 |
connector = aiohttp.TCPConnector(**kwargs)
|
| 78 |
async with aiohttp.ClientSession(connector=connector) as sess:
|
| 79 |
+
async with sess.get(f"https://api.telegram.org/bot{settings.bot_token}/getMe", timeout=5) as r:
|
| 80 |
text = await r.text()
|
| 81 |
diagnostic_results.append(f"Configuration '{name}' SUCCESS: Status {r.status}, body: {text}")
|
| 82 |
except Exception as e:
|
scratch/test2.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import asyncio
|
| 2 |
import aiohttp
|
|
|
|
| 3 |
|
| 4 |
async def main():
|
| 5 |
async with aiohttp.ClientSession() as s:
|
|
@@ -24,7 +25,7 @@ async def main():
|
|
| 24 |
"`/threshold USD EUR < 0.90`"
|
| 25 |
)
|
| 26 |
async with s.post(
|
| 27 |
-
'https://api.telegram.org/
|
| 28 |
json={
|
| 29 |
'chat_id': '@durov',
|
| 30 |
'text': help_text,
|
|
|
|
| 1 |
import asyncio
|
| 2 |
import aiohttp
|
| 3 |
+
from core.config import settings
|
| 4 |
|
| 5 |
async def main():
|
| 6 |
async with aiohttp.ClientSession() as s:
|
|
|
|
| 25 |
"`/threshold USD EUR < 0.90`"
|
| 26 |
)
|
| 27 |
async with s.post(
|
| 28 |
+
f'https://api.telegram.org/bot{settings.bot_token}/sendMessage',
|
| 29 |
json={
|
| 30 |
'chat_id': '@durov',
|
| 31 |
'text': help_text,
|
scratch/test3.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import requests
|
|
|
|
| 2 |
|
| 3 |
-
TOKEN =
|
| 4 |
CHAT_ID = "1234567"
|
| 5 |
|
| 6 |
# Valid markdown
|
|
|
|
| 1 |
import requests
|
| 2 |
+
from core.config import settings
|
| 3 |
|
| 4 |
+
TOKEN = settings.bot_token
|
| 5 |
CHAT_ID = "1234567"
|
| 6 |
|
| 7 |
# Valid markdown
|
scratch/test_server.py
CHANGED
|
@@ -3,9 +3,10 @@ from fastapi import FastAPI, Request
|
|
| 3 |
from aiogram import Bot, Dispatcher, types
|
| 4 |
import uvicorn
|
| 5 |
from bot.handlers import router as bot_router
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
-
bot = Bot(token=
|
| 9 |
dp = Dispatcher()
|
| 10 |
dp.include_router(bot_router)
|
| 11 |
|
|
|
|
| 3 |
from aiogram import Bot, Dispatcher, types
|
| 4 |
import uvicorn
|
| 5 |
from bot.handlers import router as bot_router
|
| 6 |
+
from core.config import settings
|
| 7 |
|
| 8 |
app = FastAPI()
|
| 9 |
+
bot = Bot(token=settings.bot_token)
|
| 10 |
dp = Dispatcher()
|
| 11 |
dp.include_router(bot_router)
|
| 12 |
|
test_telegram.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import requests
|
|
|
|
| 2 |
|
| 3 |
-
TOKEN =
|
| 4 |
CHAT_ID = "1234567"
|
| 5 |
|
| 6 |
help_text = (
|
|
|
|
| 1 |
import requests
|
| 2 |
+
from core.config import settings
|
| 3 |
|
| 4 |
+
TOKEN = settings.bot_token
|
| 5 |
CHAT_ID = "1234567"
|
| 6 |
|
| 7 |
help_text = (
|