feat: use is_bool to check EMAIL_SMTP_USE_TLS (#1231)
- use is_bool to check EMAIL_SMTP_USE_TLS - use is_bool for yaml values that are boolean
This commit is contained in:
parent
3fea4cabe2
commit
a2dbad35c3
@ -10,7 +10,7 @@ from datetime import timedelta
|
|||||||
|
|
||||||
from .k8sapi import K8sAPI
|
from .k8sapi import K8sAPI
|
||||||
from .models import S3Storage
|
from .models import S3Storage
|
||||||
from .utils import dt_now, to_k8s_date
|
from .utils import dt_now, is_bool, to_k8s_date
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
@ -222,8 +222,8 @@ class CrawlManager(K8sAPI):
|
|||||||
access_key = self._secret_data(storage_secret, "STORE_ACCESS_KEY")
|
access_key = self._secret_data(storage_secret, "STORE_ACCESS_KEY")
|
||||||
secret_key = self._secret_data(storage_secret, "STORE_SECRET_KEY")
|
secret_key = self._secret_data(storage_secret, "STORE_SECRET_KEY")
|
||||||
region = self._secret_data(storage_secret, "STORE_REGION") or ""
|
region = self._secret_data(storage_secret, "STORE_REGION") or ""
|
||||||
use_access_for_presign = (
|
use_access_for_presign = is_bool(
|
||||||
self._secret_data(storage_secret, "STORE_USE_ACCESS_FOR_PRESIGN") == "1"
|
self._secret_data(storage_secret, "STORE_USE_ACCESS_FOR_PRESIGN")
|
||||||
)
|
)
|
||||||
|
|
||||||
self._default_storages[name] = S3Storage(
|
self._default_storages[name] = S3Storage(
|
||||||
|
@ -5,6 +5,7 @@ import smtplib
|
|||||||
import ssl
|
import ssl
|
||||||
|
|
||||||
from email.message import EmailMessage
|
from email.message import EmailMessage
|
||||||
|
from .utils import is_bool
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
@ -17,9 +18,7 @@ class EmailSender:
|
|||||||
self.reply_to = os.environ.get("EMAIL_REPLY_TO") or self.sender
|
self.reply_to = os.environ.get("EMAIL_REPLY_TO") or self.sender
|
||||||
self.smtp_server = os.environ.get("EMAIL_SMTP_HOST")
|
self.smtp_server = os.environ.get("EMAIL_SMTP_HOST")
|
||||||
self.smtp_port = int(os.environ.get("EMAIL_SMTP_PORT", 587))
|
self.smtp_port = int(os.environ.get("EMAIL_SMTP_PORT", 587))
|
||||||
self.smtp_use_tls = (
|
self.smtp_use_tls = is_bool(os.environ.get("EMAIL_SMTP_USE_TLS"))
|
||||||
os.environ.get("EMAIL_SMTP_USE_TLS", "true").lower() != "false"
|
|
||||||
)
|
|
||||||
|
|
||||||
self.default_origin = os.environ.get("APP_ORIGIN")
|
self.default_origin = os.environ.get("APP_ORIGIN")
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ from fastapi import HTTPException
|
|||||||
|
|
||||||
from .pagination import DEFAULT_PAGE_SIZE
|
from .pagination import DEFAULT_PAGE_SIZE
|
||||||
from .models import UserRole, InvitePending, InviteRequest
|
from .models import UserRole, InvitePending, InviteRequest
|
||||||
|
from .utils import is_bool
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
@ -22,7 +23,7 @@ class InviteOps:
|
|||||||
self.invites = mdb["invites"]
|
self.invites = mdb["invites"]
|
||||||
self.orgs = mdb["organizations"]
|
self.orgs = mdb["organizations"]
|
||||||
self.email = email
|
self.email = email
|
||||||
self.allow_dupe_invites = os.environ.get("ALLOW_DUPE_INVITES", "0") == "1"
|
self.allow_dupe_invites = is_bool(os.environ.get("ALLOW_DUPE_INVITES", "0"))
|
||||||
|
|
||||||
async def init_index(self):
|
async def init_index(self):
|
||||||
"""Create TTL index so that invites auto-expire"""
|
"""Create TTL index so that invites auto-expire"""
|
||||||
|
@ -28,7 +28,7 @@ from .basecrawls import init_base_crawls_api
|
|||||||
from .webhooks import init_event_webhooks_api
|
from .webhooks import init_event_webhooks_api
|
||||||
|
|
||||||
from .crawlmanager import CrawlManager
|
from .crawlmanager import CrawlManager
|
||||||
from .utils import run_once_lock, register_exit_handler
|
from .utils import run_once_lock, register_exit_handler, is_bool
|
||||||
|
|
||||||
|
|
||||||
API_PREFIX = "/api"
|
API_PREFIX = "/api"
|
||||||
@ -54,7 +54,7 @@ def main():
|
|||||||
dbclient, mdb = init_db()
|
dbclient, mdb = init_db()
|
||||||
|
|
||||||
settings = {
|
settings = {
|
||||||
"registrationEnabled": os.environ.get("REGISTRATION_ENABLED") == "1",
|
"registrationEnabled": is_bool(os.environ.get("REGISTRATION_ENABLED")),
|
||||||
"jwtTokenLifetime": JWT_TOKEN_LIFETIME,
|
"jwtTokenLifetime": JWT_TOKEN_LIFETIME,
|
||||||
"defaultBehaviorTimeSeconds": int(
|
"defaultBehaviorTimeSeconds": int(
|
||||||
os.environ.get("DEFAULT_BEHAVIOR_TIME_SECONDS", 300)
|
os.environ.get("DEFAULT_BEHAVIOR_TIME_SECONDS", 300)
|
||||||
|
@ -35,7 +35,7 @@ from .models import (
|
|||||||
PaginatedResponse,
|
PaginatedResponse,
|
||||||
)
|
)
|
||||||
from .pagination import DEFAULT_PAGE_SIZE, paginated_format
|
from .pagination import DEFAULT_PAGE_SIZE, paginated_format
|
||||||
|
from .utils import is_bool
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
PASSWORD_SECRET = os.environ.get("PASSWORD_SECRET", uuid.uuid4().hex)
|
PASSWORD_SECRET = os.environ.get("PASSWORD_SECRET", uuid.uuid4().hex)
|
||||||
@ -63,7 +63,7 @@ class UserManager(BaseUserManager[UserCreate, UserDB]):
|
|||||||
self.invites = invites
|
self.invites = invites
|
||||||
self.org_ops = None
|
self.org_ops = None
|
||||||
|
|
||||||
self.registration_enabled = os.environ.get("REGISTRATION_ENABLED") == "1"
|
self.registration_enabled = is_bool(os.environ.get("REGISTRATION_ENABLED"))
|
||||||
|
|
||||||
def set_org_ops(self, ops):
|
def set_org_ops(self, ops):
|
||||||
"""set org ops"""
|
"""set org ops"""
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
""" k8s utils """
|
""" k8s utils """
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
import os
|
import os
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
@ -101,3 +102,10 @@ def parse_jsonl_error_messages(errors):
|
|||||||
flush=True,
|
flush=True,
|
||||||
)
|
)
|
||||||
return parsed_errors
|
return parsed_errors
|
||||||
|
|
||||||
|
|
||||||
|
def is_bool(stri: Optional[str]) -> bool:
|
||||||
|
"""Check if the string parameter is stringly true"""
|
||||||
|
if stri:
|
||||||
|
return stri.lower() in ("true", "1", "yes")
|
||||||
|
return False
|
||||||
|
Loading…
Reference in New Issue
Block a user