2026-01-19 06:06:56 +07:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
"""
|
|
|
|
|
Load credentials from personal vault (config/vault.json)
|
|
|
|
|
Used by Python scripts to securely access credentials
|
|
|
|
|
"""
|
|
|
|
|
|
2026-02-11 08:38:19 +00:00
|
|
|
# Use shared utilities to reduce code duplication
|
|
|
|
|
from common.paths import CONFIG_DIR
|
|
|
|
|
from common.config_loader import load_json_config
|
2026-01-19 06:06:56 +07:00
|
|
|
|
2026-02-11 08:38:19 +00:00
|
|
|
VAULT_PATH = CONFIG_DIR / "vault.json"
|
2026-01-19 06:06:56 +07:00
|
|
|
|
2026-02-08 04:15:17 +00:00
|
|
|
# Default values
|
|
|
|
|
DEFAULT_TELEGRAM_BOT_NAME = "t.me/your_bot_name"
|
|
|
|
|
DEFAULT_TELEGRAM_WEBHOOK_URL = "https://core.telegram.org/bots/api"
|
|
|
|
|
|
2026-01-19 06:06:56 +07:00
|
|
|
|
|
|
|
|
def load_vault():
|
|
|
|
|
"""Load credentials from vault.json"""
|
2026-02-11 08:38:19 +00:00
|
|
|
return load_json_config(VAULT_PATH)
|
2026-01-19 06:06:56 +07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_telegram_token():
|
2026-02-08 04:15:17 +00:00
|
|
|
"""Get Telegram bot token from vault
|
|
|
|
|
|
|
|
|
|
Note: Prefers 'token' field over 'api' field if both exist.
|
|
|
|
|
Both fields are supported for backward compatibility.
|
|
|
|
|
"""
|
2026-01-19 06:06:56 +07:00
|
|
|
vault = load_vault()
|
|
|
|
|
if vault and 'telegram_bot' in vault:
|
2026-02-08 04:12:44 +00:00
|
|
|
return vault['telegram_bot'].get('token') or vault['telegram_bot'].get('api')
|
2026-01-19 06:06:56 +07:00
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
2026-02-08 04:12:44 +00:00
|
|
|
def get_telegram_bot_name():
|
|
|
|
|
"""Get Telegram bot name from vault"""
|
|
|
|
|
vault = load_vault()
|
|
|
|
|
if vault and 'telegram_bot' in vault:
|
2026-02-08 04:15:17 +00:00
|
|
|
return vault['telegram_bot'].get('name', DEFAULT_TELEGRAM_BOT_NAME)
|
|
|
|
|
return DEFAULT_TELEGRAM_BOT_NAME
|
2026-02-08 04:12:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_telegram_webhook_url():
|
|
|
|
|
"""Get Telegram webhook URL from vault"""
|
|
|
|
|
vault = load_vault()
|
|
|
|
|
if vault and 'telegram_bot' in vault:
|
2026-02-08 04:15:17 +00:00
|
|
|
return vault['telegram_bot'].get('webhook_url', DEFAULT_TELEGRAM_WEBHOOK_URL)
|
|
|
|
|
return DEFAULT_TELEGRAM_WEBHOOK_URL
|
2026-02-08 04:12:44 +00:00
|
|
|
|
|
|
|
|
|
2026-01-19 06:06:56 +07:00
|
|
|
def get_telegram_allowed_users():
|
|
|
|
|
"""Get allowed Telegram user IDs from vault"""
|
|
|
|
|
vault = load_vault()
|
|
|
|
|
if vault and 'telegram_bot' in vault:
|
|
|
|
|
return vault['telegram_bot'].get('allowed_user_ids', [])
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
|
2026-02-08 04:12:44 +00:00
|
|
|
def get_github_pat():
|
|
|
|
|
"""Get GitHub Personal Access Token from vault"""
|
|
|
|
|
vault = load_vault()
|
|
|
|
|
if vault and 'github' in vault:
|
|
|
|
|
return vault['github'].get('pat')
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
2026-01-19 06:06:56 +07:00
|
|
|
if __name__ == "__main__":
|
|
|
|
|
# Set environment variables when run directly
|
|
|
|
|
token = get_telegram_token()
|
|
|
|
|
if token:
|
|
|
|
|
os.environ['TELEGRAM_BOT_TOKEN'] = token
|
|
|
|
|
print("✅ Telegram bot token loaded from vault")
|
|
|
|
|
|
2026-02-08 04:12:44 +00:00
|
|
|
bot_name = get_telegram_bot_name()
|
|
|
|
|
if bot_name:
|
|
|
|
|
os.environ['TELEGRAM_BOT_NAME'] = bot_name
|
|
|
|
|
print(f"✅ Telegram bot name: {bot_name}")
|
|
|
|
|
|
|
|
|
|
webhook_url = get_telegram_webhook_url()
|
|
|
|
|
if webhook_url:
|
|
|
|
|
os.environ['TELEGRAM_WEBHOOK_URL'] = webhook_url
|
|
|
|
|
print(f"✅ Telegram webhook URL: {webhook_url}")
|
|
|
|
|
|
2026-01-19 06:06:56 +07:00
|
|
|
allowed_users = get_telegram_allowed_users()
|
|
|
|
|
if allowed_users:
|
|
|
|
|
os.environ['TELEGRAM_ALLOWED_USER_IDS'] = ','.join(map(str, allowed_users))
|
2026-02-08 04:12:44 +00:00
|
|
|
print(f"✅ Allowed users loaded: {len(allowed_users)}")
|
|
|
|
|
|
|
|
|
|
github_pat = get_github_pat()
|
|
|
|
|
if github_pat:
|
|
|
|
|
os.environ['GITHUB_PAT'] = github_pat
|
|
|
|
|
print("✅ GitHub PAT loaded from vault")
|