Skip to content

Commit

Permalink
#110 Handle missing config elements correctly (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsimb authored Jun 6, 2024
1 parent bf0ddd4 commit 78bccb2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
23 changes: 22 additions & 1 deletion exasol/nb_connector/extension_wrapper_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import exasol.bucketfs as bfs # type: ignore

from exasol.nb_connector.connections import (open_pyexasol_connection,
from exasol.nb_connector.connections import (open_pyexasol_connection, get_external_host,
get_backend, get_saas_database_id)
from exasol.nb_connector.secret_store import Secrets
from exasol.nb_connector.utils import optional_str_to_bool
Expand All @@ -28,6 +28,27 @@ def str_to_bool(conf: Secrets, key: CKey, default_value: bool) -> bool:
return default_value if prop_value is None else prop_value


def get_optional_external_host(conf: Secrets) -> str | None:
"""
Get the host part of an onprem database URL if the data can be found
in the configuration, otherwise None.
"""
if conf.get(CKey.db_host_name) and conf.get(CKey.db_port):
return get_external_host(conf)
return None


def get_optional_bfs_port(conf: Secrets) -> int | None:
"""
Return the BucketFS service port number if it can be found in the
configuration, otherwise None.
"""
port_str = conf.get(CKey.bfs_port)
if port_str:
return int(port_str)
return None


def encapsulate_bucketfs_credentials(
conf: Secrets, path_in_bucket: str, connection_name: str
) -> None:
Expand Down
9 changes: 5 additions & 4 deletions exasol/nb_connector/sagemaker_extension_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
from exasol_sagemaker_extension.deployment.sme_language_container_deployer import SmeLanguageContainerDeployer # type: ignore

from exasol.nb_connector.connections import (
get_external_host,
open_pyexasol_connection,
)
from exasol.nb_connector.extension_wrapper_common import (
encapsulate_aws_credentials,
str_to_bool
str_to_bool,
get_optional_external_host,
get_optional_bfs_port
)
from exasol.nb_connector.language_container_activation import (
ACTIVATION_KEY_PREFIX,
Expand Down Expand Up @@ -60,12 +61,12 @@ def deploy_language_container(conf: Secrets,
"""

deployer = SmeLanguageContainerDeployer.create(
dsn=get_external_host(conf),
dsn=get_optional_external_host(conf),
db_user=conf.get(CKey.db_user),
db_password=conf.get(CKey.db_password),
bucketfs_name=conf.get(CKey.bfs_service),
bucketfs_host=conf.get(CKey.bfs_host_name, conf.get(CKey.db_host_name)),
bucketfs_port=int(str(conf.get(CKey.bfs_port))),
bucketfs_port=get_optional_bfs_port(conf),
bucketfs_user=conf.get(CKey.bfs_user),
bucketfs_password=conf.get(CKey.bfs_password),
bucketfs_use_https=str_to_bool(conf, CKey.bfs_encryption, True),
Expand Down
11 changes: 5 additions & 6 deletions exasol/nb_connector/transformers_extension_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from exasol_transformers_extension.deployment.scripts_deployer import ScriptsDeployer # type: ignore
from exasol_transformers_extension.deployment.te_language_container_deployer import TeLanguageContainerDeployer # type: ignore

# TODO: Disable this mypy "missing imports" nonsense.

from exasol.nb_connector.connections import (
get_external_host,
open_pyexasol_connection
)
from exasol.nb_connector.extension_wrapper_common import (
encapsulate_bucketfs_credentials,
encapsulate_huggingface_token,
str_to_bool
str_to_bool,
get_optional_external_host,
get_optional_bfs_port
)
from exasol.nb_connector.language_container_activation import (
ACTIVATION_KEY_PREFIX,
Expand Down Expand Up @@ -74,12 +73,12 @@ def deploy_language_container(conf: Secrets,
"""

deployer = TeLanguageContainerDeployer.create(
dsn=get_external_host(conf),
dsn=get_optional_external_host(conf),
db_user=conf.get(CKey.db_user),
db_password=conf.get(CKey.db_password),
bucketfs_name=conf.get(CKey.bfs_service),
bucketfs_host=conf.get(CKey.bfs_host_name, conf.get(CKey.db_host_name)),
bucketfs_port=int(str(conf.get(CKey.bfs_port))),
bucketfs_port=get_optional_bfs_port(conf),
bucketfs_user=conf.get(CKey.bfs_user),
bucketfs_password=conf.get(CKey.bfs_password),
bucketfs_use_https=str_to_bool(conf, CKey.bfs_encryption, True),
Expand Down

0 comments on commit 78bccb2

Please sign in to comment.