Skip to content

Commit

Permalink
Removes unused config parts
Browse files Browse the repository at this point in the history
  • Loading branch information
JWittmeyer committed Nov 14, 2024
1 parent 0b9393b commit de0af28
Show file tree
Hide file tree
Showing 19 changed files with 19 additions and 348 deletions.
20 changes: 0 additions & 20 deletions api/misc.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,12 @@
from starlette.endpoints import HTTPEndpoint
from starlette.responses import JSONResponse
from starlette import status
from fastapi import Request

from config_handler import (
base_config_json,
full_config_json,
get_config_value,
)


class IsManagedRest(HTTPEndpoint):
def get(self, request) -> JSONResponse:
is_managed = get_config_value("is_managed")
return JSONResponse(is_managed, status_code=status.HTTP_200_OK)


class IsDemoRest(HTTPEndpoint):
def get(self, request) -> JSONResponse:
is_managed = get_config_value("is_demo")
return JSONResponse(is_managed, status_code=status.HTTP_200_OK)


class FullConfigRest(HTTPEndpoint):
def get(self, request: Request) -> JSONResponse:
return full_config_json()


class BaseConfigRest(HTTPEndpoint):
def get(self, request: Request) -> JSONResponse:
return base_config_json()
4 changes: 0 additions & 4 deletions api/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from controller.upload_task import manager as upload_task_manager
from controller.auth import manager as auth_manager
from controller.transfer import association_transfer_manager
from controller.auth import manager as auth
from controller.project import manager as project_manager
from controller.attribute import manager as attribute_manager

Expand Down Expand Up @@ -135,7 +134,6 @@ def get(self, request) -> JSONResponse:

class PrepareFileImport(HTTPEndpoint):
async def post(self, request) -> JSONResponse:
auth.check_is_demo_without_info()
project_id = request.path_params["project_id"]
request_body = await request.json()

Expand Down Expand Up @@ -168,7 +166,6 @@ async def post(self, request) -> JSONResponse:

class JSONImport(HTTPEndpoint):
async def post(self, request) -> JSONResponse:
auth.check_is_demo_without_info()
project_id = request.path_params["project_id"]
request_body = await request.json()
user_id = request_body["user_id"]
Expand Down Expand Up @@ -272,7 +269,6 @@ async def post(self, request) -> JSONResponse:

class UploadTaskInfo(HTTPEndpoint):
def get(self, request) -> JSONResponse:
auth.check_is_demo_without_info()
project_id = request.path_params["project_id"]
task_id = request.path_params["task_id"]
user_id = request.query_params["user_id"]
Expand Down
6 changes: 0 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
from api.healthcheck import Healthcheck
from starlette.middleware import Middleware
from api.misc import (
BaseConfigRest,
FullConfigRest,
IsDemoRest,
IsManagedRest,
)
from api.project import ProjectDetails
from api.transfer import (
Expand Down Expand Up @@ -124,7 +121,6 @@
)

routes = [
Route("/base_config", BaseConfigRest),
Route("/full_config", FullConfigRest),
Route("/notify/{path:path}", Notify),
Route("/healthcheck", Healthcheck),
Expand All @@ -145,8 +141,6 @@
CognitionPrepareProject,
),
Route("/project/{project_id:str}/import/task/{task_id:str}", UploadTaskInfo),
Route("/is_managed", IsManagedRest),
Route("/is_demo", IsDemoRest),
Mount("/api", app=fastapi_app, name="REST API"),
Mount(
"/internal/api", app=fastapi_app_internal, name="INTERNAL REST API"
Expand Down
10 changes: 2 additions & 8 deletions base_config.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
{
"is_managed": null,
"is_demo": null,
"allow_data_tracking": true,
"s3_region": null,
"KERN_S3_ENDPOINT": null,
"spacy_downloads": [
"en_core_web_sm",
"de_core_news_sm"
],
"tokens": {
"INTERCOM": ""
},
"KERN_S3_ENDPOINT": null
]
}
22 changes: 4 additions & 18 deletions config_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from notify_handler import notify_others_about_change_thread
from fastapi import responses, status

__blacklist_base_config = ["is_managed", "is_demo"]
__config = None

BASE_CONFIG_PATH = "base_config.json"
Expand Down Expand Up @@ -100,14 +99,9 @@ def __load_and_remove_outdated_config_keys():
__save_current_config()


def get_config(basic: bool = True) -> Dict[str, Any]:
global __config, __blacklist_base_config
if not basic:
return __config

return {
key: __config[key] for key in __config if key not in __blacklist_base_config
}
def get_config() -> Dict[str, Any]:
global __config
return __config


def change_json(config_data) -> responses.PlainTextResponse:
Expand All @@ -128,12 +122,4 @@ def change_json(config_data) -> responses.PlainTextResponse:


def full_config_json() -> responses.JSONResponse:
return responses.JSONResponse(
status_code=status.HTTP_200_OK, content=get_config(False)
)


def base_config_json() -> responses.JSONResponse:
return responses.JSONResponse(
status_code=status.HTTP_200_OK, content=get_config(True)
)
return responses.JSONResponse(status_code=status.HTTP_200_OK, content=get_config())
23 changes: 0 additions & 23 deletions controller/auth/manager.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from typing import Any, Dict

from fastapi import Request
from config_handler import get_config_value
from exceptions.exceptions import (
AuthManagerError,
NotAllowedInDemoError,
ProjectAccessError,
)
import jwt
Expand All @@ -14,7 +12,6 @@
from submodules.model import enums, exceptions
from submodules.model.business_objects import organization
from submodules.model.models import Organization, Project, User
from controller.misc import manager as misc_manager
import sqlalchemy

DEV_USER_ID = "741df1c2-a531-43b6-b259-df23bc78e9a2"
Expand Down Expand Up @@ -127,26 +124,6 @@ def check_is_admin(request: Any) -> bool:
return False


def check_demo_access(info: Any) -> None:
if not check_is_admin(info.context["request"]) and get_config_value("is_demo"):
check_black_white(info)


def check_black_white(info: Any):
black_white = misc_manager.get_black_white_demo()
if str(info.parent_type) == "Mutation":
if info.field_name not in black_white["mutations"]:
raise NotAllowedInDemoError
elif str(info.parent_type) == "Query":
if info.field_name in black_white["queries"]:
raise NotAllowedInDemoError


def check_is_demo_without_info() -> None:
if get_config_value("is_demo"):
raise NotAllowedInDemoError


def check_is_single_organization() -> bool:
return len(organization_manager.get_all_organizations()) == 1

Expand Down
9 changes: 3 additions & 6 deletions controller/embedding/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,11 @@ def get_current_terms_text(
return term_text


def get_recommended_encoders(is_managed: bool) -> List[Any]:
# only use is_managed if it is really managed
def get_recommended_encoders() -> List[Any]:
# can run into circular import problems if directly resolved here by helper method
recommendations = connector.request_listing_recommended_encoders()
if is_managed:
existing_models = model_manager.get_model_provider_info()
else:
existing_models = []
existing_models = model_manager.get_model_provider_info()

for model in existing_models:
not_yet_known = (
len(
Expand Down
2 changes: 0 additions & 2 deletions controller/information_source/manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from typing import List
from config_handler import get_config_value
from controller.information_source.util import resolve_source_return_type
from submodules.model import InformationSource, LabelingTask, enums
from submodules.model.business_objects import (
Expand Down Expand Up @@ -86,7 +85,6 @@ def delete_information_source(project_id: str, source_id: str) -> None:
if (
information_source_item.type
== enums.InformationSourceType.ACTIVE_LEARNING.value
and get_config_value("is_managed")
):
daemon.run_without_db_token(
__delete_active_learner_from_inference_dir, project_id, source_id
Expand Down
89 changes: 0 additions & 89 deletions controller/misc/black_white_demo.py

This file was deleted.

19 changes: 0 additions & 19 deletions controller/misc/manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from typing import Any, Dict, List
from config_handler import change_json, get_config_value
from controller.misc import black_white_demo
from fast_api.types import ServiceVersionResult
from submodules.model.global_objects import customer_button
from datetime import datetime
Expand All @@ -19,23 +17,6 @@
BASE_URI_UPDATER = os.getenv("UPDATER")


def check_is_managed() -> bool:
return get_config_value("is_managed")


def check_is_demo() -> bool:
return get_config_value("is_demo")


def update_config(dict_str: str) -> None:
config_data = {"dict_string": dict_str}
return change_json(config_data)


def get_black_white_demo() -> Dict[str, List[str]]:
return black_white_demo.get_black_white_demo()


def get_version_overview() -> List[ServiceVersionResult]:
updater_version_overview = __updater_version_overview()
date_format = "%Y-%m-%dT%H:%M:%S.%f" # 2022-09-06T12:10:39.167397
Expand Down
13 changes: 0 additions & 13 deletions controller/organization/manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Any, List, Dict, Optional, Union
from config_handler import get_config_value

from submodules.model import enums
from submodules.model.business_objects import organization, general, user
Expand Down Expand Up @@ -101,18 +100,6 @@ def get_overview_stats(org_id: str) -> List[Dict[str, Union[str, int]]]:
return organization.get_organization_overview_stats(org_id)


def can_create_local(org: bool = True) -> bool:
if get_config_value("is_managed"):
return False
existing_orgs = organization.get_all()
checkvalue = 0 if org else 1
if len(existing_orgs) != checkvalue:
return False
if user.get_count_assigned() != 0:
return False
return True


def __check_notification(org_id: str, key: str, value: Any):
if key in ["gdpr_compliant"]:
notification.send_organization_update(
Expand Down
5 changes: 1 addition & 4 deletions controller/payload/payload_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from dateutil import parser
import datetime

from config_handler import get_config_value
from exceptions.exceptions import PayloadSchedulerError
from submodules.model import enums
from submodules.model.business_objects import (
Expand Down Expand Up @@ -509,9 +508,7 @@ def read_container_logs_thread(


def get_inference_dir() -> str:
if get_config_value("is_managed"):
return os.getenv("INFERENCE_DIR")
return None
return os.getenv("INFERENCE_DIR")


def update_records(
Expand Down
Loading

0 comments on commit de0af28

Please sign in to comment.