Skip to content

Commit

Permalink
feat: get focalboard creds
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyqu committed Mar 30, 2024
1 parent 1bb2f5f commit d9c8a95
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ jobs:
docker login docker.pkg.github.com -u $GITHUB_USERNAME -p $GITHUB_TOKEN
touch ${{ env.ROOT_DIR }}/sysblokbot.sqlite
touch ${{ env.ROOT_DIR }}/strings.sqlite
touch ${{ env.ROOT_DIR }}/board_credentials.json
docker run -dit --name sysblokbot-testing \
--env APP_SOURCE="github CI" --restart unless-stopped \
--env TELEGRAM_ERROR_CHAT_ID="${{ env.TELEGRAM_ERROR_CHAT_ID }}" \
Expand All @@ -142,6 +143,7 @@ jobs:
-v ${{ env.ROOT_DIR }}/sysblokbot.sqlite:/app/sysblokbot.sqlite \
-v ${{ env.ROOT_DIR }}/strings.sqlite:/app/strings.sqlite \
-v ${{ env.ROOT_DIR }}/persistent_storage.pickle:/app/persistent_storage.pickle \
-v ${{ env.ROOT_DIR }}/board_credentials.json:/app/board_credentials.json \
docker.pkg.github.com/sysblok/sysblokbot/${{ env.IMAGE_NAME }}:testing
- name: Notify us about failure
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ jobs:
docker login docker.pkg.github.com -u $GITHUB_USERNAME -p $GITHUB_TOKEN
touch ${{ env.ROOT_DIR }}/sysblokbot.sqlite
touch ${{ env.ROOT_DIR }}/strings.sqlite
touch ${{ env.ROOT_DIR }}/board_credentials.json
docker run -dit --name sysblokbot-prod \
--env APP_SOURCE="github CI" --restart unless-stopped \
--env TELEGRAM_ERROR_CHAT_ID="${{ env.TELEGRAM_ERROR_CHAT_ID }}" \
Expand All @@ -145,6 +146,7 @@ jobs:
-v ${{ env.ROOT_DIR }}/sysblokbot.sqlite:/app/sysblokbot.sqlite \
-v ${{ env.ROOT_DIR }}/strings.sqlite:/app/strings.sqlite \
-v ${{ env.ROOT_DIR }}/persistent_storage.pickle:/app/persistent_storage.pickle \
-v ${{ env.ROOT_DIR }}/board_credentials.json:/app/board_credentials.json \
docker.pkg.github.com/sysblok/sysblokbot/${{ env.IMAGE_NAME }}:prod
- name: Notify us about failure
Expand Down
6 changes: 6 additions & 0 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ def init_handlers(self):
self.add_admin_handler(
"start", CommandCategories.MOST_USED, handlers.start, "начать чат с ботом"
)
self.add_admin_handler(
"get_board_credentials",
CommandCategories.MOST_USED,
lambda update, context: handlers.get_board_credentials(update, context),
"получить пароль от Focalboard",
)
self.add_admin_handler(
"help",
CommandCategories.MOST_USED,
Expand Down
1 change: 1 addition & 0 deletions src/tg/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

# User-facing handlers
from .start_handler import start
from .get_board_credentials_handler import get_board_credentials

# Plain text message handler
from .user_message_handler import (
Expand Down
31 changes: 31 additions & 0 deletions src/tg/handlers/get_board_credentials_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import json
import logging
import os
import telegram

from ...db.db_client import DBClient
from ...strings import load
from .utils import get_sender_username, reply


logger = logging.getLogger(__name__)


def get_board_credentials(update: telegram.Update, tg_context):
member = next((member for member in DBClient().get_all_members() if member.telegram == f"@{get_sender_username(update)}"), None)
if member is None or not member.trello:
reply(load('get_board_credentials_handler__not_found'), update)
return
try:
with open('board_credentials.json', encoding="utf-8") as fin:
try:
board_json = json.loads(fin.read())
creds = next((cred for cred in board_json if cred["trelloUsername"] == f"@{member.trello}"), None)
if not creds:
reply(load('get_board_credentials_handler__not_found'), update)
return
reply(load('get_board_credentials_handler__found', username=creds["focalboardUsername"], password=creds["focalboardPassword"]), update)
except json.JSONDecodeError as e:
logger.error(e)
except IOError:
logger.warning(f"Board passwords file not found", exc_info=e)

0 comments on commit d9c8a95

Please sign in to comment.