config.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import secrets
  2. from typing import Any, Dict, List, Optional, Union
  3. from pydantic import AnyHttpUrl, BaseSettings, EmailStr, HttpUrl, PostgresDsn, validator
  4. from linebot import LineBotApi, WebhookHandler
  5. class Settings(BaseSettings):
  6. API_V1_STR: str = "/api/v1"
  7. SECRET_KEY: str = secrets.token_urlsafe(32)
  8. # 60 minutes * 24 hours * 8 days = 8 days
  9. ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8
  10. SERVER_NAME: str = "api.ptt.cx"
  11. SERVER_HOST: AnyHttpUrl = "https://api.ptt.cx"
  12. # BACKEND_CORS_ORIGINS is a JSON-formatted list of origins
  13. # e.g: '["http://localhost", "http://localhost:4200", "http://localhost:3000", \
  14. # "http://localhost:8080", "http://local.dockertoolbox.tiangolo.com"]'
  15. BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = ['http://localhost']
  16. @validator("BACKEND_CORS_ORIGINS", pre=True)
  17. def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]:
  18. if isinstance(v, str) and not v.startswith("["):
  19. return [i.strip() for i in v.split(",")]
  20. elif isinstance(v, (list, str)):
  21. return v
  22. raise ValueError(v)
  23. PROJECT_NAME: str = "Ark Backend"
  24. SENTRY_DSN: Optional[HttpUrl] = ""
  25. IMG_PATH: str = "/var/www/ArkCard-Linebot/ArkCard-web/img/nft/"
  26. IMG_HOST: AnyHttpUrl = "https://ark.cards/img/nft/"
  27. # # bot config
  28. line_bot_api = LineBotApi(
  29. "SJT7VPT4RMQFLcS27jQBy3FcC24gtDrkcwJWZ5Xzqesr5T78LOKudHEJzt0k3b2S7"
  30. "n4KPwf27J7DVz2c8NQ4plSaaQylEeB1cYrfejaE/RPG/lCIQBYe4iBTzo26s4i2Pcm"
  31. "T89837per/lTyvhVIKAdB04t89/1O/w1cDnyilFU=")
  32. handler = WebhookHandler("411ae3ef7e766739ed2c2c27b249d010")
  33. @validator("SENTRY_DSN", pre=True)
  34. def sentry_dsn_can_be_blank(cls, v: str) -> Optional[str]:
  35. if len(v) == 0:
  36. return None
  37. return v
  38. SQLALCHEMY_DATABASE_URI = "mysql+pymysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4"
  39. # POSTGRES_SERVER: str
  40. # POSTGRES_USER: str
  41. # POSTGRES_PASSWORD: str
  42. # POSTGRES_DB: str
  43. # SQLALCHEMY_DATABASE_URI: Optional[PostgresDsn] = None
  44. # @validator("SQLALCHEMY_DATABASE_URI", pre=True)
  45. # def assemble_db_connection(cls, v: Optional[str], values: Dict[str, Any]) -> Any:
  46. # if isinstance(v, str):
  47. # return v
  48. # return PostgresDsn.build(
  49. # scheme="postgresql",
  50. # user=values.get("POSTGRES_USER"),
  51. # password=values.get("POSTGRES_PASSWORD"),
  52. # host=values.get("POSTGRES_SERVER"),
  53. # path=f"/{values.get('POSTGRES_DB') or ''}",
  54. # )
  55. SMTP_TLS: bool = True
  56. SMTP_PORT: Optional[int] = 465
  57. SMTP_HOST: Optional[str] = 'smtp.gmail.com'
  58. SMTP_USER: Optional[str] = ''
  59. SMTP_PASSWORD: Optional[str] = 'ckmspyijofyavuwg'
  60. EMAILS_FROM_EMAIL: Optional[EmailStr] = 'verify@choozmo.com'
  61. EMAILS_FROM_NAME: Optional[str] = 'Choozmo Team'
  62. @validator("EMAILS_FROM_NAME")
  63. def get_project_name(cls, v: Optional[str], values: Dict[str, Any]) -> str:
  64. if not v:
  65. return values["PROJECT_NAME"]
  66. return v
  67. EMAIL_RESET_TOKEN_EXPIRE_HOURS: int = 48
  68. EMAIL_TEMPLATES_DIR: str = "/home/conrad/creator/app/email-templates/build"
  69. # EMAIL_TEMPLATES_DIR: str = "/app/app/email-templates/build"
  70. EMAILS_ENABLED: bool = True
  71. @validator("EMAILS_ENABLED", pre=True)
  72. def get_emails_enabled(cls, v: bool, values: Dict[str, Any]) -> bool:
  73. return bool(
  74. values.get("SMTP_HOST")
  75. and values.get("SMTP_PORT")
  76. and values.get("EMAILS_FROM_EMAIL")
  77. )
  78. EMAIL_TEST_USER: EmailStr = "conradlan@choozmo.com" # type: ignore
  79. FIRST_SUPERUSER: EmailStr = "conradlan@choozmo.com"
  80. FIRST_SUPERUSER_PASSWORD: str = "test123"
  81. USERS_OPEN_REGISTRATION: bool = True
  82. class Config:
  83. case_sensitive = True
  84. settings = Settings()