Switch to automatic versioning
This commit is contained in:
48
app/config.py
Normal file
48
app/config.py
Normal file
@ -0,0 +1,48 @@
|
||||
"""Configuration module."""
|
||||
|
||||
import os
|
||||
|
||||
|
||||
class Config:
|
||||
"""Configuration module."""
|
||||
def __init__(self) -> None:
|
||||
"""Configuration module."""
|
||||
self.__environment: str = os.environ.get("APP_LIFECYCLE", "DEV").upper()
|
||||
self.__version: str = os.environ["APP_VERSION"]
|
||||
self.__webex_token: str = os.environ["WEBEX_API_KEY"]
|
||||
self.__sentry_dsn: str = os.environ.get("SENTRY_DSN", "")
|
||||
self.__sentry_enabled: bool = bool(
|
||||
os.environ.get("SENTRY_ENABLED", "False").upper() == "TRUE"
|
||||
and self.__sentry_dsn != ""
|
||||
)
|
||||
|
||||
@property
|
||||
def environment(self) -> str:
|
||||
"""Returns the current app lifecycle."""
|
||||
return self.__environment
|
||||
|
||||
@property
|
||||
def version(self) -> str:
|
||||
"""Returns the current app version."""
|
||||
return self.__version
|
||||
|
||||
@property
|
||||
def sentry_enabled(self) -> bool:
|
||||
"""Returns True if Sentry SDK is enabled, else False."""
|
||||
return self.__sentry_enabled
|
||||
|
||||
@property
|
||||
def sentry_dsn(self) -> str:
|
||||
"""Returns the Sentry DSN value if Sentry SDK is enabled AND
|
||||
Sentry DSN is set, else blank string."""
|
||||
if not self.__sentry_enabled:
|
||||
return ""
|
||||
return self.__sentry_dsn
|
||||
|
||||
@property
|
||||
def webex_token(self) -> str:
|
||||
"""Returns the Webex API key."""
|
||||
return self.__webex_token
|
||||
|
||||
|
||||
config: Config = Config()
|
17
app/main.py
17
app/main.py
@ -1,18 +1,29 @@
|
||||
#!/usr/local/bin/python3
|
||||
|
||||
import os
|
||||
import sentry_sdk
|
||||
from sentry_sdk.integrations.stdlib import StdlibIntegration
|
||||
|
||||
from webex_bot.webex_bot import WebexBot
|
||||
|
||||
from app import close, meme
|
||||
from app.config import config
|
||||
|
||||
WBX_API_KEY: str = os.environ["WEBEX_API_KEY"]
|
||||
|
||||
if config.sentry_enabled:
|
||||
apm = sentry_sdk.init(
|
||||
dsn=config.sentry_dsn,
|
||||
enable_tracing=True,
|
||||
environment=config.environment,
|
||||
release=config.version,
|
||||
integrations=[StdlibIntegration()],
|
||||
spotlight=True
|
||||
)
|
||||
|
||||
|
||||
def create_bot() -> WebexBot:
|
||||
"""Create a Bot object."""
|
||||
bot = WebexBot(
|
||||
teams_bot_token=WBX_API_KEY,
|
||||
teams_bot_token=config.webex_token,
|
||||
approved_domains=["cisco.com"],
|
||||
bot_name="MemeBot",
|
||||
include_demo_commands=False,
|
||||
|
Reference in New Issue
Block a user