diff --git a/api/chalicelib/core/assist.py b/api/chalicelib/core/assist.py index 288d8a9b7..fcc845b7f 100644 --- a/api/chalicelib/core/assist.py +++ b/api/chalicelib/core/assist.py @@ -4,8 +4,7 @@ from os.path import exists as path_exists, getsize import jwt import requests from decouple import config -from starlette import status -from fastapi import HTTPException +from fastapi import HTTPException, status import schemas from chalicelib.core import projects diff --git a/api/chalicelib/core/collaboration_msteams.py b/api/chalicelib/core/collaboration_msteams.py index eb60fd653..3b8b2a05e 100644 --- a/api/chalicelib/core/collaboration_msteams.py +++ b/api/chalicelib/core/collaboration_msteams.py @@ -2,8 +2,7 @@ import json import requests from decouple import config -from fastapi import HTTPException -from starlette import status +from fastapi import HTTPException, status import schemas from chalicelib.core import webhook diff --git a/api/chalicelib/core/collaboration_slack.py b/api/chalicelib/core/collaboration_slack.py index 1879b3c2d..707e28c59 100644 --- a/api/chalicelib/core/collaboration_slack.py +++ b/api/chalicelib/core/collaboration_slack.py @@ -1,9 +1,8 @@ -import requests -from decouple import config from datetime import datetime -from fastapi import HTTPException -from starlette import status +import requests +from decouple import config +from fastapi import HTTPException, status import schemas from chalicelib.core import webhook diff --git a/api/chalicelib/core/custom_metrics.py b/api/chalicelib/core/custom_metrics.py index c40316067..9ee84b018 100644 --- a/api/chalicelib/core/custom_metrics.py +++ b/api/chalicelib/core/custom_metrics.py @@ -2,8 +2,7 @@ import json from typing import Union from decouple import config -from fastapi import HTTPException -from starlette import status +from fastapi import HTTPException, status import schemas from chalicelib.core import sessions, funnels, errors, issues, metrics, click_maps, sessions_mobs diff --git a/api/chalicelib/core/metadata.py b/api/chalicelib/core/metadata.py index eba0d7a22..909ecff23 100644 --- a/api/chalicelib/core/metadata.py +++ b/api/chalicelib/core/metadata.py @@ -1,8 +1,7 @@ import re from typing import Optional -from fastapi import HTTPException -from starlette import status +from fastapi import HTTPException, status from chalicelib.core import projects from chalicelib.utils import pg_client diff --git a/api/chalicelib/core/projects.py b/api/chalicelib/core/projects.py index 82103ce9c..865a4a73c 100644 --- a/api/chalicelib/core/projects.py +++ b/api/chalicelib/core/projects.py @@ -1,8 +1,7 @@ import json from typing import Optional -from fastapi import HTTPException -from starlette import status +from fastapi import HTTPException, status import schemas from chalicelib.core import users diff --git a/api/chalicelib/core/signup.py b/api/chalicelib/core/signup.py index 3a56f9186..ec4d99b3b 100644 --- a/api/chalicelib/core/signup.py +++ b/api/chalicelib/core/signup.py @@ -8,7 +8,7 @@ from chalicelib.utils import pg_client from chalicelib.utils.TimeUTC import TimeUTC -def create_step1(data: schemas.UserSignupSchema): +def create_tenant(data: schemas.UserSignupSchema): print(f"===================== SIGNUP STEP 1 AT {TimeUTC.to_human_readable(TimeUTC.now())} UTC") errors = [] if tenants.tenants_exists(): diff --git a/api/chalicelib/core/webhook.py b/api/chalicelib/core/webhook.py index d0ed97d08..fb0906b9c 100644 --- a/api/chalicelib/core/webhook.py +++ b/api/chalicelib/core/webhook.py @@ -2,8 +2,7 @@ import logging from typing import Optional import requests -from fastapi import HTTPException -from starlette import status +from fastapi import HTTPException, status import schemas from chalicelib.utils import pg_client, helper diff --git a/api/chalicelib/utils/github_client_v3.py b/api/chalicelib/utils/github_client_v3.py index 650aeb4fe..6f2d093c6 100644 --- a/api/chalicelib/utils/github_client_v3.py +++ b/api/chalicelib/utils/github_client_v3.py @@ -1,8 +1,7 @@ -import requests from datetime import datetime -from fastapi import HTTPException -from starlette import status +import requests +from fastapi import HTTPException, status class github_formatters: diff --git a/api/chalicelib/utils/jira_client.py b/api/chalicelib/utils/jira_client.py index 4cd6fe566..b55e11cfe 100644 --- a/api/chalicelib/utils/jira_client.py +++ b/api/chalicelib/utils/jira_client.py @@ -2,11 +2,10 @@ import time from datetime import datetime import requests +from fastapi import HTTPException, status from jira import JIRA from jira.exceptions import JIRAError from requests.auth import HTTPBasicAuth -from starlette import status -from fastapi import HTTPException fields = "id, summary, description, creator, reporter, created, assignee, status, updated, comment, issuetype, labels" diff --git a/api/routers/core.py b/api/routers/core.py index 58819a811..f9481f528 100644 --- a/api/routers/core.py +++ b/api/routers/core.py @@ -1,9 +1,8 @@ from typing import Union from decouple import config -from fastapi import Depends, Body, HTTPException, Response +from fastapi import Depends, Body, HTTPException, Response, status from fastapi.responses import JSONResponse -from starlette import status import schemas from chalicelib.core import log_tool_rollbar, sourcemaps, events, sessions_assignments, projects, \ @@ -11,7 +10,7 @@ from chalicelib.core import log_tool_rollbar, sourcemaps, events, sessions_assig log_tool_elasticsearch, log_tool_datadog, \ log_tool_stackdriver, reset_password, log_tool_cloudwatch, log_tool_sentry, log_tool_sumologic, log_tools, sessions, \ log_tool_newrelic, announcements, log_tool_bugsnag, weekly_report, integration_jira_cloud, integration_github, \ - assist, mobile, signup, tenants, boarding, notifications, webhook, users, \ + assist, mobile, tenants, boarding, notifications, webhook, users, \ custom_metrics, saved_search, integrations_global from chalicelib.core.collaboration_msteams import MSTeams from chalicelib.core.collaboration_slack import Slack diff --git a/api/routers/core_dynamic.py b/api/routers/core_dynamic.py index f4d5e9a62..d13fc8970 100644 --- a/api/routers/core_dynamic.py +++ b/api/routers/core_dynamic.py @@ -31,7 +31,7 @@ if not tenants.tenants_exists(use_pool=False): @public_app.post('/signup', tags=['signup']) @public_app.put('/signup', tags=['signup']) async def signup_handler(data: schemas.UserSignupSchema = Body(...)): - return signup.create_step1(data) + return signup.create_tenant(data) @app.get('/account', tags=['accounts']) diff --git a/api/routers/subs/health.py b/api/routers/subs/health.py index 5e3c10f07..2a1588a34 100644 --- a/api/routers/subs/health.py +++ b/api/routers/subs/health.py @@ -1,3 +1,5 @@ +from fastapi import HTTPException, status + from chalicelib.core import health, tenants from routers.base import get_routers @@ -11,4 +13,6 @@ if tenants.tenants_exists(use_pool=False): @health_router.get('/health', tags=["health-check"]) def get_global_health_status(): + if tenants.tenants_exists(): + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Not Found") return {"data": health.get_health()} diff --git a/ee/api/chalicelib/core/custom_metrics.py b/ee/api/chalicelib/core/custom_metrics.py index b7502edd9..96d4b424f 100644 --- a/ee/api/chalicelib/core/custom_metrics.py +++ b/ee/api/chalicelib/core/custom_metrics.py @@ -2,8 +2,7 @@ import json from typing import Union from decouple import config -from fastapi import HTTPException -from starlette import status +from fastapi import HTTPException, status import schemas import schemas_ee diff --git a/ee/api/chalicelib/core/projects.py b/ee/api/chalicelib/core/projects.py index 6b0628de7..467f4185e 100644 --- a/ee/api/chalicelib/core/projects.py +++ b/ee/api/chalicelib/core/projects.py @@ -1,8 +1,7 @@ import json from typing import Optional -from fastapi import HTTPException -from starlette import status +from fastapi import HTTPException, status import schemas from chalicelib.core import users diff --git a/ee/api/chalicelib/core/roles.py b/ee/api/chalicelib/core/roles.py index 79f1caec7..077bb2464 100644 --- a/ee/api/chalicelib/core/roles.py +++ b/ee/api/chalicelib/core/roles.py @@ -1,7 +1,6 @@ from typing import Optional -from fastapi import HTTPException -from starlette import status +from fastapi import HTTPException, status import schemas_ee from chalicelib.core import users, projects diff --git a/ee/api/chalicelib/core/signup.py b/ee/api/chalicelib/core/signup.py index d01e1379a..1344b5e7b 100644 --- a/ee/api/chalicelib/core/signup.py +++ b/ee/api/chalicelib/core/signup.py @@ -11,7 +11,7 @@ from chalicelib.utils import pg_client from chalicelib.utils.TimeUTC import TimeUTC -def create_step1(data: schemas.UserSignupSchema): +def create_tenant(data: schemas.UserSignupSchema): print(f"===================== SIGNUP STEP 1 AT {TimeUTC.to_human_readable(TimeUTC.now())} UTC") errors = [] if not config("MULTI_TENANTS", cast=bool, default=False) and tenants.tenants_exists(): diff --git a/ee/api/chalicelib/core/webhook.py b/ee/api/chalicelib/core/webhook.py index d1e70d3e7..55405cc0d 100644 --- a/ee/api/chalicelib/core/webhook.py +++ b/ee/api/chalicelib/core/webhook.py @@ -2,8 +2,7 @@ import logging from typing import Optional import requests -from fastapi import HTTPException -from starlette import status +from fastapi import HTTPException, status import schemas from chalicelib.utils import pg_client, helper @@ -113,7 +112,7 @@ def add(tenant_id, endpoint, auth_header=None, webhook_type='webhook', name="", def exists_by_name(tenant_id: int, name: str, exclude_id: Optional[int], - webhook_type: str = schemas.WebhookType.webhook) -> bool: + webhook_type: str = schemas.WebhookType.webhook) -> bool: with pg_client.PostgresClient() as cur: query = cur.mogrify(f"""SELECT EXISTS(SELECT 1 FROM public.webhooks diff --git a/ee/api/routers/core_dynamic.py b/ee/api/routers/core_dynamic.py index 34c517ee8..35927097e 100644 --- a/ee/api/routers/core_dynamic.py +++ b/ee/api/routers/core_dynamic.py @@ -31,11 +31,11 @@ async def get_all_signup(): "edition": license.EDITION}} -if not tenants.tenants_exists(use_pool=False): +if config("MULTI_TENANTS", cast=bool, default=False) or not tenants.tenants_exists(use_pool=False): @public_app.post('/signup', tags=['signup']) @public_app.put('/signup', tags=['signup']) async def signup_handler(data: schemas.UserSignupSchema = Body(...)): - return signup.create_step1(data) + return signup.create_tenant(data) @app.get('/account', tags=['accounts']) diff --git a/ee/api/routers/saml.py b/ee/api/routers/saml.py index ee0f0333b..cf52aa720 100644 --- a/ee/api/routers/saml.py +++ b/ee/api/routers/saml.py @@ -1,5 +1,4 @@ -from fastapi import HTTPException -from fastapi import Request, Response +from fastapi import HTTPException, Request, Response, status from chalicelib.utils import SAML2_helper from chalicelib.utils.SAML2_helper import prepare_request, init_saml_auth @@ -12,7 +11,6 @@ from onelogin.saml2.auth import OneLogin_Saml2_Logout_Request from chalicelib.core import users, tenants, roles from starlette.responses import RedirectResponse -from starlette import status @public_app.get("/sso/saml2", tags=["saml2"])