Skip to content

Commit

Permalink
Add database authentification
Browse files Browse the repository at this point in the history
Signed-off-by: alfred richardsn <rchrdsn@protonmail.ch>
  • Loading branch information
r4rdsn committed Nov 21, 2019
1 parent c820476 commit b29a0fb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ SERVER_PORT=5000
WEBHOOK_PATH=/tellerbot/webhook
DATABASE_NAME=tellerbot
DATABASE_HOST=database
DATABASE_USERNAME=tellerbot
DATABASE_PASSWORD=

# Logging
LOGGER_LEVEL=INFO
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ services:
database:
image: mongo:4.2.1
container_name: ${DATABASE_HOST}
environment:
- MONGO_INITDB_ROOT_USERNAME=${DATABASE_USERNAME}
- MONGO_INITDB_ROOT_PASSWORD=${DATABASE_PASSWORD}
command: mongod --quiet
ports:
- 27017
Expand Down
2 changes: 2 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def getenv_bool(key, default=None):
WEBHOOK_PATH = getenv("WEBHOOK_PATH")
DATABASE_NAME = getenv("DATABASE_NAME", "tellerbot")
DATABASE_HOST = getenv("DATABASE_HOST", "127.0.0.1")
DATABASE_USERNAME = getenv("DATABASE_USERNAME")
DATABASE_PASSWORD = getenv("DATABASE_PASSWORD")

LOGGER_LEVEL = getenv("LOGGER_LEVEL")
LOG_FILENAME = getenv("LOG_FILENAME")
Expand Down
6 changes: 5 additions & 1 deletion src/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
from src import config


client = AsyncIOMotorClient(config.DATABASE_HOST)
client = AsyncIOMotorClient(
config.DATABASE_HOST,
username=config.DATABASE_USERNAME,
password=config.DATABASE_PASSWORD,
)
database = client[config.DATABASE_NAME]

STATE_KEY = "state"
Expand Down

0 comments on commit b29a0fb

Please sign in to comment.