Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/superannotate/lib/app/interface/base_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BaseInterfaceFacade:

def __init__(self, token: str = None, config_path: str = None):
if token:
config = ConfigEntity(API_TOKEN=token)
config = ConfigEntity(SA_TOKEN=token)
elif config_path:
config_path = Path(config_path)
if not Path(config_path).is_file() or not os.access(config_path, os.R_OK):
Expand Down Expand Up @@ -70,7 +70,7 @@ def _retrieve_configs_from_json(path: Path) -> typing.Union[ConfigEntity]:
with open(path) as json_file:
json_data = json.load(json_file)
token = json_data["token"]
config = ConfigEntity(API_TOKEN=token)
config = ConfigEntity(SA_TOKEN=token)
host = json_data.get("main_endpoint")
verify_ssl = json_data.get("ssl_verify")
if host:
Expand Down Expand Up @@ -99,7 +99,7 @@ def _retrieve_configs_from_env() -> typing.Union[ConfigEntity, None]:
token = os.environ.get("SA_TOKEN")
if not token:
return None
config = ConfigEntity(API_TOKEN=token)
config = ConfigEntity(**dict(os.environ))
host = os.environ.get("SA_URL")
verify_ssl = not os.environ.get("SA_SSL", "True").lower() in ("false", "f", "0")
if host:
Expand All @@ -108,14 +108,6 @@ def _retrieve_configs_from_env() -> typing.Union[ConfigEntity, None]:
config.VERIFY_SSL = verify_ssl
return config

@property
def host(self):
return self._host

@property
def token(self):
return self._token


class Tracker:
def get_mp_instance(self) -> Mixpanel:
Expand Down
3 changes: 1 addition & 2 deletions src/superannotate/lib/app/interface/cli_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def init(token: str):
config_parser.optionxform = str

config_parser["DEFAULT"] = {
"API_TOKEN": token,
"API_URL": constances.BACKEND_URL,
"SA_TOKEN": token,
"LOGGING_LEVEL": "INFO",
"LOGGING_PATH": constances.LOG_FILE_LOCATION,
}
Expand Down
12 changes: 9 additions & 3 deletions src/superannotate/lib/core/entities/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from pydantic.utils import ROOT_KEY
from pydantic.utils import sequence_like
from pydantic.utils import ValueItems
from typing_extensions import Literal

DATE_TIME_FORMAT_ERROR_MESSAGE = (
"does not match expected format YYYY-MM-DDTHH:MM:SS.fffZ"
Expand Down Expand Up @@ -292,12 +293,17 @@ def map_fields(entity: dict) -> dict:


class ConfigEntity(BaseModel):
API_TOKEN: str
API_URL: str = BACKEND_URL
LOGGING_LEVEL: str = "INFO"
API_TOKEN: str = Field(alias="SA_TOKEN")
API_URL: str = Field(alias="SA_URL", default=BACKEND_URL)
LOGGING_LEVEL: Literal[
"NOTSET", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"
] = "INFO"
LOGGING_PATH: str = f"{LOG_FILE_LOCATION}"
VERIFY_SSL: bool = True
ANNOTATION_CHUNK_SIZE = 5000
ITEM_CHUNK_SIZE = 2000
MAX_THREAD_COUNT = 4
MAX_COROUTINE_COUNT = 8

class Config:
extra = Extra.ignore
3 changes: 1 addition & 2 deletions tests/integration/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ def test_init(self):
self.safe_run(self._cli.init, _token)
config = ConfigParser()
config.read(config_ini_path)
assert config["DEFAULT"]["API_TOKEN"] == _token
assert config["DEFAULT"]["API_URL"] == constants.BACKEND_URL
assert config["DEFAULT"]["SA_TOKEN"] == _token
assert config["DEFAULT"]["LOGGING_LEVEL"] == "INFO"
assert config["DEFAULT"]["LOGGING_PATH"] == f"{constants.LOG_FILE_LOCATION}"
2 changes: 1 addition & 1 deletion tests/unit/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_init_via_config_ini(self, get_team_use_case):
config_parser = ConfigParser()
config_parser.optionxform = str
config_parser["DEFAULT"] = {
"API_TOKEN": self._token,
"SA_TOKEN": self._token,
"LOGGING_LEVEL": "DEBUG",
}
config_parser.write(config_ini)
Expand Down