Skip to content

Commit

Permalink
Enable YDB connector (#160)
Browse files Browse the repository at this point in the history
* Turn on ydb in OS

* Fix tpe error and oauth row

* Fix issues

* Delete oauth row

---------

Co-authored-by: Valeria Bulanova <[email protected]>
  • Loading branch information
vallbull and vallbull authored Dec 27, 2023
1 parent 6c5031f commit 2563996
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/dl_control_api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ datalens-sqlalchemy-common = {path = "../../lib/dl_sqlalchemy_common"}
datalens-sqlalchemy-clickhouse = {path = "../../lib/dl_sqlalchemy_clickhouse"}
datalens-connector-postgresql = {path = "../../lib/dl_connector_postgresql"}
datalens-connector-clickhouse = {path = "../../lib/dl_connector_clickhouse"}
datalens-connector-ydb = {path = "../../lib/dl_connector_ydb"}
datalens-connector-chyt = {path = "../../lib/dl_connector_chyt"}
datalens-core = {path = "../../lib/dl_core"}
datalens-app-tools = {path = "../../lib/dl_app_tools"}
Expand Down
1 change: 1 addition & 0 deletions app/dl_data_api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ datalens-sqlalchemy-clickhouse = {path = "../../lib/dl_sqlalchemy_clickhouse"}
datalens-connector-postgresql = {path = "../../lib/dl_connector_postgresql"}
datalens-connector-clickhouse = {path = "../../lib/dl_connector_clickhouse"}
datalens-connector-chyt = {path = "../../lib/dl_connector_chyt"}
datalens-connector-ydb = {path = "../../lib/dl_connector_ydb"}
datalens-core = {path = "../../lib/dl_core"}
datalens-app-tools = {path = "../../lib/dl_app_tools"}
datalens-model-tools = {path = "../../lib/dl_model_tools"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from dl_configs.connectors_settings import ConnectorSettingsBase

from dl_connector_ydb.api.ydb.connection_info import YDBConnectionInfoProvider
from dl_connector_ydb.api.ydb.i18n.localizer import Translatable
from dl_connector_ydb.core.ydb.settings import YDBConnectorSettings


Expand All @@ -44,12 +45,13 @@ def _get_base_common_api_schema_items(self, names_source: Type[Enum]) -> list[Fo
]

def _get_default_db_section(self, rc: RowConstructor, connector_settings: YDBConnectorSettings) -> list[FormRow]:
oauth_row = C.OAuthTokenRow(
name=CommonFieldName.token,
fake_value="******" if self.mode == ConnectionFormMode.edit else None,
application=YDBOAuthApplication.ydb,
)
return [
C.OAuthTokenRow(
name=CommonFieldName.token,
fake_value="******" if self.mode == ConnectionFormMode.edit else None,
application=YDBOAuthApplication.ydb,
),
oauth_row,
rc.host_row(default_value=connector_settings.DEFAULT_HOST_VALUE),
rc.port_row(default_value="2135"),
rc.db_name_row(),
Expand Down Expand Up @@ -113,7 +115,10 @@ def get_form_config(
common_api_schema_items = self._get_base_common_api_schema_items(names_source=CommonFieldName)
db_section_rows = self._get_default_db_section(rc=rc, connector_settings=connector_settings)
common_api_schema_items.append(
FormFieldApiSchema(name=CommonFieldName.token, required=self.mode == ConnectionFormMode.create)
FormFieldApiSchema(
name=CommonFieldName.token,
required=self.mode == ConnectionFormMode.create and connector_settings.HAS_AUTH,
)
)
edit_api_schema.items.extend(common_api_schema_items)

Expand Down
29 changes: 26 additions & 3 deletions lib/dl_connector_ydb/dl_connector_ydb/core/ydb/settings.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
from typing import Optional
from typing import (
ClassVar,
Optional,
)

import attr

from dl_configs.connectors_data import ConnectorsDataBase
from dl_configs.connectors_settings import (
ConnectorsConfigType,
ConnectorSettingsBase,
)
from dl_configs.settings_loaders.meta_definition import s_attrib
from dl_core.connectors.settings.primitives import ConnectorSettingsDefinition
from dl_core.connectors.settings.primitives import (
ConnectorSettingsDefinition,
get_connectors_settings_config,
)


@attr.s(frozen=True)
class YDBConnectorSettings(ConnectorSettingsBase):
HAS_AUTH: Optional[bool] = s_attrib("HAS_AUTH", missing=True) # type: ignore
DEFAULT_HOST_VALUE: Optional[str] = s_attrib("DEFAULT_HOST_VALUE", missing=None) # type: ignore


class ConnectorsDataYDBBase(ConnectorsDataBase):
HAS_AUTH: ClassVar[Optional[bool]] = True

@classmethod
def connector_name(cls) -> str:
return "YDB"


def ydb_settings_fallback(full_cfg: ConnectorsConfigType) -> dict[str, ConnectorSettingsBase]:
return dict(YDB=YDBConnectorSettings())
cfg = get_connectors_settings_config(
full_cfg,
object_like_config_key="YDB",
connector_data_class=ConnectorsDataYDBBase,
)
if cfg is None:
return {}
return dict(YDB=YDBConnectorSettings(HAS_AUTH=cfg.HAS_AUTH)) # type: ignore


class YDBSettingDefinition(ConnectorSettingsDefinition):
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ msgstr ""
msgid "label_connector-ydb"
msgstr "YDB"

msgid "field_oauth_row"
msgstr "OAuth token"

msgid "source_templates-tab_title-table"
msgstr "Table"

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ msgstr ""
msgid "label_connector-ydb"
msgstr "YDB"

msgid "field_oauth_row"
msgstr "OAuth-токен"

msgid "source_templates-tab_title-table"
msgstr "Таблица"

Expand Down
3 changes: 2 additions & 1 deletion lib/dl_core/dl_core/services_registry/sr_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from dl_core.us_manager.mutation_cache.usentry_mutation_cache_factory import USEntryMutationCacheFactory
from dl_core.utils import FutureRef
from dl_task_processor.processor import ARQTaskProcessorFactory
from dl_utils.aio import ContextVarExecutor


if TYPE_CHECKING:
Expand Down Expand Up @@ -115,7 +116,7 @@ def make_conn_executor_factory(
LOGGER.info("ATTENTION! It's bleeding edge user")
return DefaultConnExecutorFactory(
async_env=self.async_env,
tpe=None,
tpe=ContextVarExecutor(),
conn_sec_mgr=self.env_manager_factory.make_security_manager(),
rqe_config=self.rqe_config,
services_registry_ref=sr_ref, # type: ignore # TODO: fix
Expand Down
2 changes: 2 additions & 0 deletions metapkg/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2563996

Please sign in to comment.