File size: 907 Bytes
78c8669 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | """
Credential lookup, in priority order:
1. Environment variables (set as "Secrets" in a Hugging Face Space) --
FB_PAGE_ID and FB_ACCESS_TOKEN.
2. Values saved in the local database via the Settings tab.
Using Space secrets means the token is never stored in the app's
SQLite file and never shown/editable in the UI -- it only lives in
the Space's encrypted secret store and the process environment.
"""
import os
import database as db
ENV_PAGE_ID = "FB_PAGE_ID"
ENV_ACCESS_TOKEN = "FB_ACCESS_TOKEN"
def using_env_secrets() -> bool:
return bool(os.environ.get(ENV_PAGE_ID) and os.environ.get(ENV_ACCESS_TOKEN))
def get_page_id():
return os.environ.get(ENV_PAGE_ID) or db.get_setting("page_id")
def get_access_token():
return os.environ.get(ENV_ACCESS_TOKEN) or db.get_setting("access_token")
def is_configured() -> bool:
return bool(get_page_id() and get_access_token())
|